AboutDialog.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/StringBuilder.h>
  27. #include <LibCore/ConfigFile.h>
  28. #include <LibGUI/AboutDialog.h>
  29. #include <LibGUI/BoxLayout.h>
  30. #include <LibGUI/Button.h>
  31. #include <LibGUI/ImageWidget.h>
  32. #include <LibGUI/Label.h>
  33. #include <LibGUI/Widget.h>
  34. #include <LibGfx/Font.h>
  35. namespace GUI {
  36. AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window* parent_window)
  37. : Dialog(parent_window)
  38. , m_name(name)
  39. , m_icon(icon)
  40. {
  41. resize(413, 205);
  42. set_title(String::format("About %s", m_name.characters()));
  43. set_resizable(false);
  44. if (parent_window)
  45. set_icon(parent_window->icon());
  46. auto& widget = set_main_widget<Widget>();
  47. widget.set_fill_with_background_color(true);
  48. widget.set_layout<VerticalBoxLayout>();
  49. widget.layout()->set_spacing(0);
  50. auto& banner_image = widget.add<GUI::ImageWidget>();
  51. banner_image.load_from_file("/res/graphics/brand-banner.png");
  52. auto& content_container = widget.add<Widget>();
  53. content_container.set_layout<HorizontalBoxLayout>();
  54. auto& left_container = content_container.add<Widget>();
  55. left_container.set_fixed_width(60);
  56. left_container.set_layout<VerticalBoxLayout>();
  57. left_container.layout()->set_margins({ 0, 12, 0, 0 });
  58. if (icon) {
  59. auto& icon_wrapper = left_container.add<Widget>();
  60. icon_wrapper.set_fixed_size(32, 48);
  61. icon_wrapper.set_layout<VerticalBoxLayout>();
  62. auto& icon_image = icon_wrapper.add<ImageWidget>();
  63. icon_image.set_bitmap(m_icon);
  64. }
  65. auto& right_container = content_container.add<Widget>();
  66. right_container.set_layout<VerticalBoxLayout>();
  67. right_container.layout()->set_margins({ 0, 12, 12, 8 });
  68. auto make_label = [&](const StringView& text, bool bold = false) {
  69. auto& label = right_container.add<Label>(text);
  70. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  71. label.set_fixed_height(14);
  72. if (bold)
  73. label.set_font(Gfx::Font::default_bold_font());
  74. };
  75. make_label(m_name, true);
  76. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  77. if (m_name != "SerenityOS")
  78. make_label("SerenityOS");
  79. make_label(version_string());
  80. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2020");
  81. right_container.layout()->add_spacer();
  82. auto& button_container = right_container.add<Widget>();
  83. button_container.set_fixed_height(23);
  84. button_container.set_layout<HorizontalBoxLayout>();
  85. button_container.layout()->add_spacer();
  86. auto& ok_button = button_container.add<Button>("OK");
  87. ok_button.set_fixed_size(80, 23);
  88. ok_button.on_click = [this](auto) {
  89. done(Dialog::ExecOK);
  90. };
  91. }
  92. AboutDialog::~AboutDialog()
  93. {
  94. }
  95. String AboutDialog::version_string() const
  96. {
  97. auto version_config = Core::ConfigFile::open("/res/version.ini");
  98. auto major_version = version_config->read_entry("Version", "Major", "0");
  99. auto minor_version = version_config->read_entry("Version", "Minor", "0");
  100. auto git_version = version_config->read_entry("Version", "Git", "");
  101. StringBuilder builder;
  102. builder.append("Version ");
  103. builder.append(major_version);
  104. builder.append('.');
  105. builder.append(minor_version);
  106. if (git_version != "") {
  107. builder.append(".g");
  108. builder.append(git_version);
  109. }
  110. return builder.to_string();
  111. }
  112. }