From b0bd1e5eb52a25693e16f10071bcf4a0f0e27988 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sat, 3 Jun 2023 19:12:53 +0200 Subject: [PATCH] MailSettings: Convert `MailSettingsWidget` to a failable factory --- .../MailSettings/MailSettingsWidget.cpp | 15 ++++++++++++--- .../MailSettings/MailSettingsWidget.h | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/MailSettings/MailSettingsWidget.cpp b/Userland/Applications/MailSettings/MailSettingsWidget.cpp index 2e54f12940a..822ff5d44cc 100644 --- a/Userland/Applications/MailSettings/MailSettingsWidget.cpp +++ b/Userland/Applications/MailSettings/MailSettingsWidget.cpp @@ -36,13 +36,20 @@ void MailSettingsWidget::apply_settings() Config::write_string("Mail"sv, "User"sv, "Username"sv, m_email); } -MailSettingsWidget::MailSettingsWidget() +ErrorOr> MailSettingsWidget::try_create() +{ + auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MailSettingsWidget())); + TRY(widget->setup()); + return widget; +} + +ErrorOr MailSettingsWidget::setup() { // Common port values for email fetching m_common_ports.append("143"); m_common_ports.append("993"); - load_from_gml(mail_settings_widget_gml).release_value_but_fixme_should_propagate_errors(); + TRY(load_from_gml(mail_settings_widget_gml)); m_server_inputbox = *find_descendant_of_type_named("server_input"); m_server_inputbox->set_text(Config::read_string("Mail"sv, "Connection"sv, "Server"sv, ""sv)); @@ -53,7 +60,7 @@ MailSettingsWidget::MailSettingsWidget() m_port_combobox = *find_descendant_of_type_named("port_input"); m_port_combobox->set_text(Config::read_string("Mail"sv, "Connection"sv, "Port"sv, "993"sv)); m_port_combobox->set_only_allow_values_from_model(false); - m_port_combobox->set_model(*GUI::ItemListModel::create(m_common_ports)); + m_port_combobox->set_model(*TRY(GUI::ItemListModel::try_create(m_common_ports))); m_port_combobox->on_change = [&](auto, auto) { set_modified(true); }; @@ -69,4 +76,6 @@ MailSettingsWidget::MailSettingsWidget() m_email_inputbox->on_change = [&]() { set_modified(true); }; + + return {}; } diff --git a/Userland/Applications/MailSettings/MailSettingsWidget.h b/Userland/Applications/MailSettings/MailSettingsWidget.h index aef4752a8b3..4af6a9496a1 100644 --- a/Userland/Applications/MailSettings/MailSettingsWidget.h +++ b/Userland/Applications/MailSettings/MailSettingsWidget.h @@ -12,14 +12,17 @@ #include class MailSettingsWidget final : public GUI::SettingsWindow::Tab { - C_OBJECT(MailSettingsWidget) + C_OBJECT_ABSTRACT(MailSettingsWidget) public: + static ErrorOr> try_create(); + virtual void apply_settings() override; virtual void reset_default_values() override; private: - MailSettingsWidget(); + MailSettingsWidget() = default; + ErrorOr setup(); DeprecatedString m_server; DeprecatedString m_port;