2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2023-02-02 17:09:27 +00:00
|
|
|
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-05-24 14:26:33 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/AboutDialog.h>
|
2023-02-02 17:09:27 +00:00
|
|
|
#include <LibGUI/AboutDialogGML.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2020-07-22 15:29:51 +02:00
|
|
|
#include <LibGUI/ImageWidget.h>
|
2020-09-18 09:49:51 +02:00
|
|
|
#include <LibGUI/Label.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Widget.h>
|
2022-04-09 09:28:38 +02:00
|
|
|
#include <LibGfx/Font/Font.h>
|
|
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2023-09-13 20:34:46 +01:00
|
|
|
NonnullRefPtr<AboutDialog> AboutDialog::create(String const& name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
|
2019-09-02 19:45:55 +02:00
|
|
|
{
|
2023-08-14 10:56:13 +02:00
|
|
|
auto dialog = adopt_ref(*new AboutDialog(name, version, icon, parent_window));
|
2023-02-02 17:07:49 +00:00
|
|
|
dialog->set_title(DeprecatedString::formatted("About {}", name));
|
2020-03-30 09:01:02 +02:00
|
|
|
|
2023-09-19 01:13:48 +01:00
|
|
|
auto widget = dialog->set_main_widget<Widget>();
|
2023-08-14 10:56:13 +02:00
|
|
|
MUST(widget->load_from_gml(about_dialog_gml));
|
2020-05-24 14:26:33 +00:00
|
|
|
|
2023-02-02 17:07:49 +00:00
|
|
|
auto icon_wrapper = widget->find_descendant_of_type_named<Widget>("icon_wrapper");
|
2020-05-24 14:26:33 +00:00
|
|
|
if (icon) {
|
2023-02-02 17:09:27 +00:00
|
|
|
icon_wrapper->set_visible(true);
|
2023-02-02 17:07:49 +00:00
|
|
|
auto icon_image = widget->find_descendant_of_type_named<ImageWidget>("icon");
|
|
|
|
|
icon_image->set_bitmap(icon);
|
2023-02-02 17:09:27 +00:00
|
|
|
} else {
|
|
|
|
|
icon_wrapper->set_visible(false);
|
2020-05-24 14:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-29 10:41:48 -04:00
|
|
|
widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name);
|
2020-05-24 14:26:33 +00:00
|
|
|
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
|
2023-02-02 17:07:49 +00:00
|
|
|
widget->find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS");
|
2023-04-29 10:41:48 -04:00
|
|
|
widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version);
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2023-02-02 17:07:49 +00:00
|
|
|
auto ok_button = widget->find_descendant_of_type_named<DialogButton>("ok_button");
|
|
|
|
|
ok_button->on_click = [dialog](auto) {
|
|
|
|
|
dialog->done(ExecResult::OK);
|
2019-09-02 19:45:55 +02:00
|
|
|
};
|
2023-02-02 17:07:49 +00:00
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 20:34:46 +01:00
|
|
|
AboutDialog::AboutDialog(String const& name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
|
2023-02-02 17:07:49 +00:00
|
|
|
: Dialog(parent_window)
|
2023-09-13 20:34:46 +01:00
|
|
|
, m_name(name)
|
2023-02-28 16:39:41 +01:00
|
|
|
, m_version_string(move(version))
|
|
|
|
|
, m_icon(move(icon))
|
2023-02-02 17:07:49 +00:00
|
|
|
{
|
|
|
|
|
resize(413, 204);
|
|
|
|
|
set_resizable(false);
|
|
|
|
|
|
|
|
|
|
if (parent_window)
|
|
|
|
|
set_icon(parent_window->icon());
|
2019-09-02 19:45:55 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-14 10:56:13 +02:00
|
|
|
void AboutDialog::show(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window, RefPtr<Gfx::Bitmap const> window_icon)
|
2023-02-28 16:39:41 +01:00
|
|
|
{
|
2023-08-14 10:56:13 +02:00
|
|
|
auto dialog = AboutDialog::create(move(name), move(version), move(icon), parent_window);
|
2023-02-28 16:39:41 +01:00
|
|
|
if (window_icon)
|
|
|
|
|
dialog->set_icon(window_icon);
|
|
|
|
|
dialog->exec();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
}
|