AboutDialog.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringBuilder.h>
  7. #include <LibCore/ConfigFile.h>
  8. #include <LibGUI/AboutDialog.h>
  9. #include <LibGUI/BoxLayout.h>
  10. #include <LibGUI/Button.h>
  11. #include <LibGUI/ImageWidget.h>
  12. #include <LibGUI/Label.h>
  13. #include <LibGUI/Widget.h>
  14. #include <LibGfx/Font.h>
  15. #include <LibGfx/FontDatabase.h>
  16. namespace GUI {
  17. AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window* parent_window)
  18. : Dialog(parent_window)
  19. , m_name(name)
  20. , m_icon(icon)
  21. {
  22. resize(413, 205);
  23. set_title(String::formatted("About {}", m_name));
  24. set_resizable(false);
  25. if (parent_window)
  26. set_icon(parent_window->icon());
  27. auto& widget = set_main_widget<Widget>();
  28. widget.set_fill_with_background_color(true);
  29. widget.set_layout<VerticalBoxLayout>();
  30. widget.layout()->set_spacing(0);
  31. auto& banner_image = widget.add<GUI::ImageWidget>();
  32. banner_image.load_from_file("/res/graphics/brand-banner.png");
  33. auto& content_container = widget.add<Widget>();
  34. content_container.set_layout<HorizontalBoxLayout>();
  35. auto& left_container = content_container.add<Widget>();
  36. left_container.set_fixed_width(60);
  37. left_container.set_layout<VerticalBoxLayout>();
  38. left_container.layout()->set_margins({ 0, 12, 0, 0 });
  39. if (icon) {
  40. auto& icon_wrapper = left_container.add<Widget>();
  41. icon_wrapper.set_fixed_size(32, 48);
  42. icon_wrapper.set_layout<VerticalBoxLayout>();
  43. auto& icon_image = icon_wrapper.add<ImageWidget>();
  44. icon_image.set_bitmap(m_icon);
  45. }
  46. auto& right_container = content_container.add<Widget>();
  47. right_container.set_layout<VerticalBoxLayout>();
  48. right_container.layout()->set_margins({ 0, 12, 12, 8 });
  49. auto make_label = [&](const StringView& text, bool bold = false) {
  50. auto& label = right_container.add<Label>(text);
  51. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  52. label.set_fixed_height(14);
  53. if (bold)
  54. label.set_font(Gfx::FontDatabase::default_font().bold_variant());
  55. };
  56. make_label(m_name, true);
  57. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  58. if (m_name != "SerenityOS")
  59. make_label("SerenityOS");
  60. make_label(version_string());
  61. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2021");
  62. right_container.layout()->add_spacer();
  63. auto& button_container = right_container.add<Widget>();
  64. button_container.set_fixed_height(23);
  65. button_container.set_layout<HorizontalBoxLayout>();
  66. button_container.layout()->add_spacer();
  67. auto& ok_button = button_container.add<Button>("OK");
  68. ok_button.set_fixed_size(80, 23);
  69. ok_button.on_click = [this](auto) {
  70. done(Dialog::ExecOK);
  71. };
  72. }
  73. AboutDialog::~AboutDialog()
  74. {
  75. }
  76. String AboutDialog::version_string() const
  77. {
  78. auto version_config = Core::ConfigFile::open("/res/version.ini");
  79. auto major_version = version_config->read_entry("Version", "Major", "0");
  80. auto minor_version = version_config->read_entry("Version", "Minor", "0");
  81. auto git_version = version_config->read_entry("Version", "Git", "");
  82. StringBuilder builder;
  83. builder.append("Version ");
  84. builder.append(major_version);
  85. builder.append('.');
  86. builder.append(minor_version);
  87. if (git_version != "") {
  88. builder.append(".g");
  89. builder.append(git_version);
  90. }
  91. return builder.to_string();
  92. }
  93. }