Serenity Operating System
at master 74 lines 2.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022, the SerenityOS developers. 4 * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org> 5 * 6 * SPDX-License-Identifier: BSD-2-Clause 7 */ 8 9#include <AK/StringBuilder.h> 10#include <LibGUI/AboutDialog.h> 11#include <LibGUI/AboutDialogGML.h> 12#include <LibGUI/BoxLayout.h> 13#include <LibGUI/Button.h> 14#include <LibGUI/ImageWidget.h> 15#include <LibGUI/Label.h> 16#include <LibGUI/Widget.h> 17#include <LibGfx/Font/Font.h> 18#include <LibGfx/Font/FontDatabase.h> 19 20namespace GUI { 21 22ErrorOr<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window) 23{ 24 auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AboutDialog(name, version, icon, parent_window))); 25 dialog->set_title(DeprecatedString::formatted("About {}", name)); 26 27 auto widget = TRY(dialog->set_main_widget<Widget>()); 28 TRY(widget->load_from_gml(about_dialog_gml)); 29 30 auto icon_wrapper = widget->find_descendant_of_type_named<Widget>("icon_wrapper"); 31 if (icon) { 32 icon_wrapper->set_visible(true); 33 auto icon_image = widget->find_descendant_of_type_named<ImageWidget>("icon"); 34 icon_image->set_bitmap(icon); 35 } else { 36 icon_wrapper->set_visible(false); 37 } 38 39 widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name.to_deprecated_string()); 40 // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name 41 widget->find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS"); 42 widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version.to_deprecated_string()); 43 44 auto ok_button = widget->find_descendant_of_type_named<DialogButton>("ok_button"); 45 ok_button->on_click = [dialog](auto) { 46 dialog->done(ExecResult::OK); 47 }; 48 49 return dialog; 50} 51 52AboutDialog::AboutDialog(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window) 53 : Dialog(parent_window) 54 , m_name(move(name)) 55 , m_version_string(move(version)) 56 , m_icon(move(icon)) 57{ 58 resize(413, 204); 59 set_resizable(false); 60 61 if (parent_window) 62 set_icon(parent_window->icon()); 63} 64 65ErrorOr<void> AboutDialog::show(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window, RefPtr<Gfx::Bitmap const> window_icon) 66{ 67 auto dialog = TRY(AboutDialog::try_create(move(name), move(version), move(icon), parent_window)); 68 if (window_icon) 69 dialog->set_icon(window_icon); 70 dialog->exec(); 71 return {}; 72} 73 74}