/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * Copyright (c) 2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include namespace GUI { ErrorOr> AboutDialog::try_create(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window) { auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AboutDialog(name, version, icon, parent_window))); dialog->set_title(DeprecatedString::formatted("About {}", name)); auto widget = TRY(dialog->set_main_widget()); TRY(widget->load_from_gml(about_dialog_gml)); auto icon_wrapper = widget->find_descendant_of_type_named("icon_wrapper"); if (icon) { icon_wrapper->set_visible(true); auto icon_image = widget->find_descendant_of_type_named("icon"); icon_image->set_bitmap(icon); } else { icon_wrapper->set_visible(false); } widget->find_descendant_of_type_named("name")->set_text(name); // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name widget->find_descendant_of_type_named("serenity_os")->set_visible(name != "SerenityOS"); widget->find_descendant_of_type_named("version")->set_text(version); auto ok_button = widget->find_descendant_of_type_named("ok_button"); ok_button->on_click = [dialog](auto) { dialog->done(ExecResult::OK); }; return dialog; } AboutDialog::AboutDialog(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window) : Dialog(parent_window) , m_name(name) , m_icon(icon) , m_version_string(version) { resize(413, 204); set_resizable(false); if (parent_window) set_icon(parent_window->icon()); } }