diff options
-rw-r--r-- | Userland/Applications/MailSettings/CMakeLists.txt | 8 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWidget.cpp | 66 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWidget.gml (renamed from Userland/Applications/MailSettings/MailSettingsWindow.gml) | 0 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWidget.h (renamed from Userland/Applications/MailSettings/MailSettingsWindow.h) | 20 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWindow.cpp | 110 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/main.cpp | 11 |
6 files changed, 84 insertions, 131 deletions
diff --git a/Userland/Applications/MailSettings/CMakeLists.txt b/Userland/Applications/MailSettings/CMakeLists.txt index feeadeccfb..133535b937 100644 --- a/Userland/Applications/MailSettings/CMakeLists.txt +++ b/Userland/Applications/MailSettings/CMakeLists.txt @@ -4,13 +4,13 @@ serenity_component( TARGETS MailSettings ) -compile_gml(MailSettingsWindow.gml MailSettingsWindowGML.h mail_settings_window_gml) +compile_gml(MailSettingsWidget.gml MailSettingsWidgetGML.h mail_settings_widget_gml) set(SOURCES main.cpp - MailSettingsWindow.cpp - MailSettingsWindow.h - MailSettingsWindowGML.h + MailSettingsWidget.cpp + MailSettingsWidget.h + MailSettingsWidgetGML.h ) serenity_app(MailSettings ICON app-mail) diff --git a/Userland/Applications/MailSettings/MailSettingsWidget.cpp b/Userland/Applications/MailSettings/MailSettingsWidget.cpp new file mode 100644 index 0000000000..1e08dda587 --- /dev/null +++ b/Userland/Applications/MailSettings/MailSettingsWidget.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "MailSettingsWidget.h" +#include <Applications/MailSettings/MailSettingsWidgetGML.h> +#include <LibConfig/Client.h> +#include <LibGUI/BoxLayout.h> +#include <LibGUI/CheckBox.h> +#include <LibGUI/ComboBox.h> +#include <LibGUI/ItemListModel.h> +#include <LibGUI/Label.h> +#include <LibGUI/TextBox.h> + +void MailSettingsWidget::reset_default_values() +{ + m_server_inputbox->set_text(""); + m_port_combobox->set_text("993"); + m_tls_checkbox->set_checked(false); + m_email_inputbox->set_text(""); +} + +void MailSettingsWidget::apply_settings() +{ + m_server = m_server_inputbox->get_text(); + m_port = m_port_combobox->text(); + m_tls = m_tls_checkbox->is_checked(); + m_email = m_email_inputbox->get_text(); + + Config::write_string("Mail", "Connection", "Server", m_server); + Config::write_string("Mail", "Connection", "Port", m_port); + Config::write_bool("Mail", "Connection", "TLS", m_tls); + Config::write_string("Mail", "User", "Username", m_email); +} + +MailSettingsWidget::MailSettingsWidget() +{ + // Common port values for email fetching + m_common_ports.append("143"); + m_common_ports.append("993"); + + load_from_gml(mail_settings_widget_gml); + + auto& server_settings_image_label = *find_descendant_of_type_named<GUI::Label>("server_settings_image_label"); + server_settings_image_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/graphics/mail-server-settings.png").release_value_but_fixme_should_propagate_errors()); + + auto& user_settings_image_label = *find_descendant_of_type_named<GUI::Label>("user_settings_image_label"); + user_settings_image_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/graphics/mail-user-settings.png").release_value_but_fixme_should_propagate_errors()); + + m_server_inputbox = *find_descendant_of_type_named<GUI::TextBox>("server_input"); + m_server_inputbox->set_text(Config::read_string("Mail", "Connection", "Server", "")); + + m_port_combobox = *find_descendant_of_type_named<GUI::ComboBox>("port_input"); + m_port_combobox->set_text(Config::read_string("Mail", "Connection", "Port", "993")); + m_port_combobox->set_only_allow_values_from_model(false); + m_port_combobox->set_model(*GUI::ItemListModel<String>::create(m_common_ports)); + + m_tls_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("tls_input"); + m_tls_checkbox->set_checked(Config::read_bool("Mail", "Connection", "TLS", false)); + + m_email_inputbox = *find_descendant_of_type_named<GUI::TextBox>("email_input"); + m_email_inputbox->set_text(Config::read_string("Mail", "User", "Username", "")); +} diff --git a/Userland/Applications/MailSettings/MailSettingsWindow.gml b/Userland/Applications/MailSettings/MailSettingsWidget.gml index 4b82071e02..4b82071e02 100644 --- a/Userland/Applications/MailSettings/MailSettingsWindow.gml +++ b/Userland/Applications/MailSettings/MailSettingsWidget.gml diff --git a/Userland/Applications/MailSettings/MailSettingsWindow.h b/Userland/Applications/MailSettings/MailSettingsWidget.h index 4de6ea94fe..77c45f1038 100644 --- a/Userland/Applications/MailSettings/MailSettingsWindow.h +++ b/Userland/Applications/MailSettings/MailSettingsWidget.h @@ -1,22 +1,25 @@ /* * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include <LibGUI/SettingsWindow.h> #include <LibGUI/TextEditor.h> #include <LibGUI/Window.h> -class MailSettingsWindow final : public GUI::Window { - C_OBJECT(MailSettingsWindow) +class MailSettingsWidget final : public GUI::SettingsWindow::Tab { + C_OBJECT(MailSettingsWidget) -private: - MailSettingsWindow(); +public: + virtual void apply_settings() override; + virtual void reset_default_values() override; - void reset_default_values(); - void write_values(); +private: + MailSettingsWidget(); String m_server; String m_port; @@ -28,9 +31,4 @@ private: RefPtr<GUI::ComboBox> m_port_combobox; RefPtr<GUI::CheckBox> m_tls_checkbox; RefPtr<GUI::TextBox> m_email_inputbox; - - RefPtr<GUI::Button> m_reset_button; - RefPtr<GUI::Button> m_ok_button; - RefPtr<GUI::Button> m_cancel_button; - RefPtr<GUI::Button> m_apply_button; }; diff --git a/Userland/Applications/MailSettings/MailSettingsWindow.cpp b/Userland/Applications/MailSettings/MailSettingsWindow.cpp deleted file mode 100644 index 29f7405840..0000000000 --- a/Userland/Applications/MailSettings/MailSettingsWindow.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2021, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "MailSettingsWindow.h" -#include <Applications/MailSettings/MailSettingsWindowGML.h> -#include <LibConfig/Client.h> -#include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Button.h> -#include <LibGUI/CheckBox.h> -#include <LibGUI/ComboBox.h> -#include <LibGUI/ItemListModel.h> -#include <LibGUI/Label.h> -#include <LibGUI/TabWidget.h> -#include <LibGUI/TextBox.h> -#include <LibGUI/Widget.h> -#include <unistd.h> - -void MailSettingsWindow::reset_default_values() -{ - m_server_inputbox->set_text(""); - m_port_combobox->set_text("993"); - m_tls_checkbox->set_checked(false); - m_email_inputbox->set_text(""); -} - -void MailSettingsWindow::write_values() -{ - m_server = m_server_inputbox->get_text(); - m_port = m_port_combobox->text(); - m_tls = m_tls_checkbox->is_checked(); - m_email = m_email_inputbox->get_text(); - - Config::write_string("Mail", "Connection", "Server", m_server); - Config::write_string("Mail", "Connection", "Port", m_port); - Config::write_bool("Mail", "Connection", "TLS", m_tls); - Config::write_string("Mail", "User", "Username", m_email); -} - -MailSettingsWindow::MailSettingsWindow() -{ - //Common port values for email fetching - m_common_ports.append("143"); - m_common_ports.append("993"); - - auto& main_widget = set_main_widget<GUI::Widget>(); - main_widget.set_fill_with_background_color(true); - main_widget.set_layout<GUI::VerticalBoxLayout>(); - main_widget.layout()->set_margins(4); - main_widget.layout()->set_spacing(6); - - auto& tab_widget = main_widget.add<GUI::TabWidget>(); - auto& mail_widget = tab_widget.add_tab<GUI::Widget>("Mail"); - mail_widget.load_from_gml(mail_settings_window_gml); - - auto& server_settings_image_label = *main_widget.find_descendant_of_type_named<GUI::Label>("server_settings_image_label"); - server_settings_image_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/graphics/mail-server-settings.png").release_value_but_fixme_should_propagate_errors()); - - auto& user_settings_image_label = *main_widget.find_descendant_of_type_named<GUI::Label>("user_settings_image_label"); - user_settings_image_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/graphics/mail-user-settings.png").release_value_but_fixme_should_propagate_errors()); - - m_server_inputbox = *main_widget.find_descendant_of_type_named<GUI::TextBox>("server_input"); - m_server_inputbox->set_text(Config::read_string("Mail", "Connection", "Server", "")); - - m_port_combobox = *main_widget.find_descendant_of_type_named<GUI::ComboBox>("port_input"); - m_port_combobox->set_text(Config::read_string("Mail", "Connection", "Port", "993")); - m_port_combobox->set_only_allow_values_from_model(false); - m_port_combobox->set_model(*GUI::ItemListModel<String>::create(m_common_ports)); - - m_tls_checkbox = *main_widget.find_descendant_of_type_named<GUI::CheckBox>("tls_input"); - m_tls_checkbox->set_checked(Config::read_bool("Mail", "Connection", "TLS", false)); - - m_email_inputbox = *main_widget.find_descendant_of_type_named<GUI::TextBox>("email_input"); - m_email_inputbox->set_text(Config::read_string("Mail", "User", "Username", "")); - - auto& button_container = main_widget.add<GUI::Widget>(); - button_container.set_shrink_to_fit(true); - button_container.set_layout<GUI::HorizontalBoxLayout>(); - button_container.layout()->set_spacing(6); - - m_reset_button = button_container.add<GUI::Button>("Defaults"); - m_reset_button->set_fixed_width(75); - m_reset_button->on_click = [this](auto) { - reset_default_values(); - }; - - button_container.layout()->add_spacer(); - - m_ok_button = button_container.add<GUI::Button>("OK"); - m_ok_button->set_fixed_width(75); - m_ok_button->on_click = [&](auto) { - write_values(); - GUI::Application::the()->quit(); - }; - - m_cancel_button = button_container.add<GUI::Button>("Cancel"); - m_cancel_button->set_fixed_width(75); - m_cancel_button->on_click = [&](auto) { - GUI::Application::the()->quit(); - }; - - m_apply_button = button_container.add<GUI::Button>("Apply"); - m_apply_button->set_fixed_width(75); - m_apply_button->on_click = [&](auto) { - write_values(); - }; -} diff --git a/Userland/Applications/MailSettings/main.cpp b/Userland/Applications/MailSettings/main.cpp index 562ece4249..87b225b71c 100644 --- a/Userland/Applications/MailSettings/main.cpp +++ b/Userland/Applications/MailSettings/main.cpp @@ -1,13 +1,15 @@ /* * Copyright (c) 2021, the SerenityOS developers. + * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ -#include "MailSettingsWindow.h" +#include "MailSettingsWidget.h" #include <LibConfig/Client.h> #include <LibGUI/Application.h> #include <LibGUI/Icon.h> +#include <LibGUI/SettingsWindow.h> #include <unistd.h> int main(int argc, char** argv) @@ -38,11 +40,8 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-mail"); - auto window = MailSettingsWindow::construct(); - window->set_title("Mail Settings"); - window->resize(400, 480); - window->set_resizable(false); - window->set_minimizable(false); + auto window = GUI::SettingsWindow::construct("Mail Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes); + window->add_tab<MailSettingsWidget>("Mail"); window->set_icon(app_icon.bitmap_for_size(16)); window->show(); |