AboutDialog.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include <LibGfx/FontDatabase.h>
  36. namespace GUI {
  37. AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window* parent_window)
  38. : Dialog(parent_window)
  39. , m_name(name)
  40. , m_icon(icon)
  41. {
  42. resize(413, 205);
  43. set_title(String::formatted("About {}", m_name));
  44. set_resizable(false);
  45. if (parent_window)
  46. set_icon(parent_window->icon());
  47. auto& widget = set_main_widget<Widget>();
  48. widget.set_fill_with_background_color(true);
  49. widget.set_layout<VerticalBoxLayout>();
  50. widget.layout()->set_spacing(0);
  51. auto& banner_image = widget.add<GUI::ImageWidget>();
  52. banner_image.load_from_file("/res/graphics/brand-banner.png");
  53. auto& content_container = widget.add<Widget>();
  54. content_container.set_layout<HorizontalBoxLayout>();
  55. auto& left_container = content_container.add<Widget>();
  56. left_container.set_fixed_width(60);
  57. left_container.set_layout<VerticalBoxLayout>();
  58. left_container.layout()->set_margins({ 0, 12, 0, 0 });
  59. if (icon) {
  60. auto& icon_wrapper = left_container.add<Widget>();
  61. icon_wrapper.set_fixed_size(32, 48);
  62. icon_wrapper.set_layout<VerticalBoxLayout>();
  63. auto& icon_image = icon_wrapper.add<ImageWidget>();
  64. icon_image.set_bitmap(m_icon);
  65. }
  66. auto& right_container = content_container.add<Widget>();
  67. right_container.set_layout<VerticalBoxLayout>();
  68. right_container.layout()->set_margins({ 0, 12, 12, 8 });
  69. auto make_label = [&](const StringView& text, bool bold = false) {
  70. auto& label = right_container.add<Label>(text);
  71. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  72. label.set_fixed_height(14);
  73. if (bold)
  74. label.set_font(Gfx::FontDatabase::default_bold_font());
  75. };
  76. make_label(m_name, true);
  77. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  78. if (m_name != "SerenityOS")
  79. make_label("SerenityOS");
  80. make_label(version_string());
  81. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2021");
  82. right_container.layout()->add_spacer();
  83. auto& button_container = right_container.add<Widget>();
  84. button_container.set_fixed_height(23);
  85. button_container.set_layout<HorizontalBoxLayout>();
  86. button_container.layout()->add_spacer();
  87. auto& ok_button = button_container.add<Button>("OK");
  88. ok_button.set_fixed_size(80, 23);
  89. ok_button.on_click = [this](auto) {
  90. done(Dialog::ExecOK);
  91. };
  92. }
  93. AboutDialog::~AboutDialog()
  94. {
  95. }
  96. String AboutDialog::version_string() const
  97. {
  98. auto version_config = Core::ConfigFile::open("/res/version.ini");
  99. auto major_version = version_config->read_entry("Version", "Major", "0");
  100. auto minor_version = version_config->read_entry("Version", "Minor", "0");
  101. auto git_version = version_config->read_entry("Version", "Git", "");
  102. StringBuilder builder;
  103. builder.append("Version ");
  104. builder.append(major_version);
  105. builder.append('.');
  106. builder.append(minor_version);
  107. if (git_version != "") {
  108. builder.append(".g");
  109. builder.append(git_version);
  110. }
  111. return builder.to_string();
  112. }
  113. }