mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:47:35 +00:00
MailSettings: Convert MailSettingsWidget
to a failable factory
This commit is contained in:
parent
1ad81687e7
commit
b0bd1e5eb5
2 changed files with 17 additions and 5 deletions
|
@ -36,13 +36,20 @@ void MailSettingsWidget::apply_settings()
|
||||||
Config::write_string("Mail"sv, "User"sv, "Username"sv, m_email);
|
Config::write_string("Mail"sv, "User"sv, "Username"sv, m_email);
|
||||||
}
|
}
|
||||||
|
|
||||||
MailSettingsWidget::MailSettingsWidget()
|
ErrorOr<NonnullRefPtr<MailSettingsWidget>> MailSettingsWidget::try_create()
|
||||||
|
{
|
||||||
|
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MailSettingsWidget()));
|
||||||
|
TRY(widget->setup());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> MailSettingsWidget::setup()
|
||||||
{
|
{
|
||||||
// Common port values for email fetching
|
// Common port values for email fetching
|
||||||
m_common_ports.append("143");
|
m_common_ports.append("143");
|
||||||
m_common_ports.append("993");
|
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<GUI::TextBox>("server_input");
|
m_server_inputbox = *find_descendant_of_type_named<GUI::TextBox>("server_input");
|
||||||
m_server_inputbox->set_text(Config::read_string("Mail"sv, "Connection"sv, "Server"sv, ""sv));
|
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<GUI::ComboBox>("port_input");
|
m_port_combobox = *find_descendant_of_type_named<GUI::ComboBox>("port_input");
|
||||||
m_port_combobox->set_text(Config::read_string("Mail"sv, "Connection"sv, "Port"sv, "993"sv));
|
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_only_allow_values_from_model(false);
|
||||||
m_port_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_common_ports));
|
m_port_combobox->set_model(*TRY(GUI::ItemListModel<DeprecatedString>::try_create(m_common_ports)));
|
||||||
m_port_combobox->on_change = [&](auto, auto) {
|
m_port_combobox->on_change = [&](auto, auto) {
|
||||||
set_modified(true);
|
set_modified(true);
|
||||||
};
|
};
|
||||||
|
@ -69,4 +76,6 @@ MailSettingsWidget::MailSettingsWidget()
|
||||||
m_email_inputbox->on_change = [&]() {
|
m_email_inputbox->on_change = [&]() {
|
||||||
set_modified(true);
|
set_modified(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,17 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
|
||||||
class MailSettingsWidget final : public GUI::SettingsWindow::Tab {
|
class MailSettingsWidget final : public GUI::SettingsWindow::Tab {
|
||||||
C_OBJECT(MailSettingsWidget)
|
C_OBJECT_ABSTRACT(MailSettingsWidget)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<MailSettingsWidget>> try_create();
|
||||||
|
|
||||||
virtual void apply_settings() override;
|
virtual void apply_settings() override;
|
||||||
virtual void reset_default_values() override;
|
virtual void reset_default_values() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MailSettingsWidget();
|
MailSettingsWidget() = default;
|
||||||
|
ErrorOr<void> setup();
|
||||||
|
|
||||||
DeprecatedString m_server;
|
DeprecatedString m_server;
|
||||||
DeprecatedString m_port;
|
DeprecatedString m_port;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue