summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-02-02 17:07:49 +0000
committerSam Atkins <atkinssj@gmail.com>2023-02-07 10:43:15 +0000
commit89b8d346fe4e339ac80882d43062d03a71a0d5df (patch)
tree0ce1c187c32a1a19132684abac2abb0c139434c1 /Userland/Libraries
parent65c8dfe923ed6b2be84e11dcdd45636222ca4d5a (diff)
downloadserenity-89b8d346fe4e339ac80882d43062d03a71a0d5df.zip
LibGUI+About: Make AboutDialog creation fallible
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/AboutDialog.cpp51
-rw-r--r--Userland/Libraries/LibGUI/AboutDialog.h8
-rw-r--r--Userland/Libraries/LibGUI/CommonActions.cpp2
3 files changed, 35 insertions, 26 deletions
diff --git a/Userland/Libraries/LibGUI/AboutDialog.cpp b/Userland/Libraries/LibGUI/AboutDialog.cpp
index 27a6e56f63..5d57775221 100644
--- a/Userland/Libraries/LibGUI/AboutDialog.cpp
+++ b/Userland/Libraries/LibGUI/AboutDialog.cpp
@@ -19,40 +19,47 @@
namespace GUI {
-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)
+ErrorOr<NonnullRefPtr<AboutDialog>> AboutDialog::try_create(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window)
{
- resize(413, 204);
- set_title(DeprecatedString::formatted("About {}", m_name));
- set_resizable(false);
-
- if (parent_window)
- set_icon(parent_window->icon());
+ 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 = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
- widget->load_from_gml(about_dialog_gml).release_value_but_fixme_should_propagate_errors();
+ auto widget = TRY(dialog->set_main_widget<Widget>());
+ TRY(widget->load_from_gml(about_dialog_gml));
- auto icon_wrapper = find_descendant_of_type_named<Widget>("icon_wrapper");
+ auto icon_wrapper = widget->find_descendant_of_type_named<Widget>("icon_wrapper");
if (icon) {
icon_wrapper->set_visible(true);
- auto icon_image = find_descendant_of_type_named<ImageWidget>("icon");
- icon_image->set_bitmap(m_icon);
+ auto icon_image = widget->find_descendant_of_type_named<ImageWidget>("icon");
+ icon_image->set_bitmap(icon);
} else {
icon_wrapper->set_visible(false);
}
- find_descendant_of_type_named<GUI::Label>("name")->set_text(m_name);
+ widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name);
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
- find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(m_name != "SerenityOS");
- find_descendant_of_type_named<GUI::Label>("version")->set_text(m_version_string);
+ widget->find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS");
+ widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version);
- auto ok_button = find_descendant_of_type_named<DialogButton>("ok_button");
- ok_button->on_click = [this](auto) {
- done(ExecResult::OK);
+ auto ok_button = widget->find_descendant_of_type_named<DialogButton>("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());
}
}
diff --git a/Userland/Libraries/LibGUI/AboutDialog.h b/Userland/Libraries/LibGUI/AboutDialog.h
index 528563225a..92c2f4b233 100644
--- a/Userland/Libraries/LibGUI/AboutDialog.h
+++ b/Userland/Libraries/LibGUI/AboutDialog.h
@@ -13,16 +13,18 @@
namespace GUI {
class AboutDialog final : public Dialog {
- C_OBJECT(AboutDialog)
+ C_OBJECT_ABSTRACT(AboutDialog)
public:
+ static ErrorOr<NonnullRefPtr<AboutDialog>> try_create(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr);
virtual ~AboutDialog() override = default;
- static void show(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr, Gfx::Bitmap const* window_icon = nullptr)
+ static ErrorOr<void> show(StringView name, StringView version, Gfx::Bitmap const* icon = nullptr, Window* parent_window = nullptr, Gfx::Bitmap const* window_icon = nullptr)
{
- auto dialog = AboutDialog::construct(name, version, icon, parent_window);
+ auto dialog = TRY(AboutDialog::try_create(name, version, icon, parent_window));
if (window_icon)
dialog->set_icon(window_icon);
dialog->exec();
+ return {};
}
private:
diff --git a/Userland/Libraries/LibGUI/CommonActions.cpp b/Userland/Libraries/LibGUI/CommonActions.cpp
index e58fe7dba1..437de549ce 100644
--- a/Userland/Libraries/LibGUI/CommonActions.cpp
+++ b/Userland/Libraries/LibGUI/CommonActions.cpp
@@ -21,7 +21,7 @@ NonnullRefPtr<Action> make_about_action(DeprecatedString const& app_name, Icon c
{
auto weak_parent = AK::make_weak_ptr_if_nonnull<Window>(parent);
auto action = Action::create(DeprecatedString::formatted("&About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) {
- AboutDialog::show(app_name, Core::Version::read_long_version_string(), app_icon.bitmap_for_size(32), weak_parent.ptr());
+ AboutDialog::show(app_name, Core::Version::read_long_version_string(), app_icon.bitmap_for_size(32), weak_parent.ptr()).release_value_but_fixme_should_propagate_errors();
});
action->set_status_tip("Show application about box");
return action;