AboutDialog.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_size_policy(SizePolicy::Fill, SizePolicy::Fill);
  54. content_container.set_layout<HorizontalBoxLayout>();
  55. auto& left_container = content_container.add<Widget>();
  56. left_container.set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
  57. left_container.set_preferred_size(60, 0);
  58. left_container.set_layout<VerticalBoxLayout>();
  59. left_container.layout()->set_margins({ 0, 12, 0, 0 });
  60. if (icon) {
  61. auto& icon_wrapper = left_container.add<Widget>();
  62. icon_wrapper.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  63. icon_wrapper.set_preferred_size(32, 48);
  64. icon_wrapper.set_layout<VerticalBoxLayout>();
  65. auto& icon_image = icon_wrapper.add<ImageWidget>();
  66. icon_image.set_bitmap(m_icon);
  67. }
  68. auto& right_container = content_container.add<Widget>();
  69. right_container.set_layout<VerticalBoxLayout>();
  70. right_container.layout()->set_margins({ 0, 12, 12, 8 });
  71. auto make_label = [&](const StringView& text, bool bold = false) {
  72. auto& label = right_container.add<Label>(text);
  73. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  74. label.set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  75. label.set_preferred_size(0, 14);
  76. if (bold)
  77. label.set_font(Gfx::Font::default_bold_font());
  78. };
  79. make_label(m_name, true);
  80. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  81. if (m_name != "SerenityOS")
  82. make_label("SerenityOS");
  83. make_label(version_string());
  84. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2020");
  85. right_container.layout()->add_spacer();
  86. auto& button_container = right_container.add<Widget>();
  87. button_container.set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  88. button_container.set_preferred_size(0, 23);
  89. button_container.set_layout<HorizontalBoxLayout>();
  90. button_container.layout()->add_spacer();
  91. auto& ok_button = button_container.add<Button>("OK");
  92. ok_button.set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  93. ok_button.set_preferred_size(80, 23);
  94. ok_button.on_click = [this](auto) {
  95. done(Dialog::ExecOK);
  96. };
  97. }
  98. AboutDialog::~AboutDialog()
  99. {
  100. }
  101. String AboutDialog::version_string() const
  102. {
  103. auto version_config = Core::ConfigFile::open("/res/version.ini");
  104. auto major_version = version_config->read_entry("Version", "Major", "0");
  105. auto minor_version = version_config->read_entry("Version", "Minor", "0");
  106. auto git_version = version_config->read_entry("Version", "Git", "");
  107. StringBuilder builder;
  108. builder.append("Version ");
  109. builder.append(major_version);
  110. builder.append('.');
  111. builder.append(minor_version);
  112. if (git_version != "") {
  113. builder.append(".g");
  114. builder.append(git_version);
  115. }
  116. return builder.to_string();
  117. }
  118. }