AboutDialog.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, 204);
  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, 4, 4 });
  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. label.set_content_margins({ 0, 0, 8, 0 });
  54. if (bold)
  55. label.set_font(Gfx::FontDatabase::default_font().bold_variant());
  56. };
  57. make_label(m_name, true);
  58. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  59. if (m_name != "SerenityOS")
  60. make_label("SerenityOS");
  61. make_label(version_string());
  62. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2021");
  63. right_container.layout()->add_spacer();
  64. auto& button_container = right_container.add<Widget>();
  65. button_container.set_fixed_height(22);
  66. button_container.set_layout<HorizontalBoxLayout>();
  67. button_container.layout()->add_spacer();
  68. auto& ok_button = button_container.add<Button>("OK");
  69. ok_button.set_fixed_width(80);
  70. ok_button.on_click = [this](auto) {
  71. done(Dialog::ExecOK);
  72. };
  73. }
  74. AboutDialog::~AboutDialog()
  75. {
  76. }
  77. String AboutDialog::version_string() const
  78. {
  79. auto version_config = Core::ConfigFile::open("/res/version.ini");
  80. auto major_version = version_config->read_entry("Version", "Major", "0");
  81. auto minor_version = version_config->read_entry("Version", "Minor", "0");
  82. StringBuilder builder;
  83. builder.appendff("Version {}.{}", major_version, minor_version);
  84. if (auto git_version = version_config->read_entry("Version", "Git", ""); git_version != "")
  85. builder.appendff(".g{}", git_version);
  86. return builder.to_string();
  87. }
  88. }