diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/CMakeLists.txt | 17 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWindow.cpp | 127 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWindow.gml | 146 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/MailSettingsWindow.h | 37 | ||||
-rw-r--r-- | Userland/Applications/MailSettings/main.cpp | 37 |
6 files changed, 365 insertions, 0 deletions
diff --git a/Userland/Applications/CMakeLists.txt b/Userland/Applications/CMakeLists.txt index 8bed54391b..a9bed10c45 100644 --- a/Userland/Applications/CMakeLists.txt +++ b/Userland/Applications/CMakeLists.txt @@ -18,6 +18,7 @@ add_subdirectory(KeyboardMapper) add_subdirectory(KeyboardSettings) add_subdirectory(Magnifier) add_subdirectory(Mail) +add_subdirectory(MailSettings) add_subdirectory(MouseSettings) add_subdirectory(PDFViewer) add_subdirectory(Piano) diff --git a/Userland/Applications/MailSettings/CMakeLists.txt b/Userland/Applications/MailSettings/CMakeLists.txt new file mode 100644 index 0000000000..c2cca5e6f7 --- /dev/null +++ b/Userland/Applications/MailSettings/CMakeLists.txt @@ -0,0 +1,17 @@ +serenity_component( + MailSettings + RECOMMENDED + TARGETS MailSettings +) + +compile_gml(MailSettingsWindow.gml MailSettingsWindowGML.h mail_settings_window_gml) + +set(SOURCES + main.cpp + MailSettingsWindow.cpp + MailSettingsWindow.h + MailSettingsWindowGML.h +) + +serenity_app(MailSettings ICON app-mail-settings) +target_link_libraries(MailSettings LibGUI) diff --git a/Userland/Applications/MailSettings/MailSettingsWindow.cpp b/Userland/Applications/MailSettings/MailSettingsWindow.cpp new file mode 100644 index 0000000000..45a4754ef7 --- /dev/null +++ b/Userland/Applications/MailSettings/MailSettingsWindow.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021, The SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "MailSettingsWindow.h" +#include <Applications/MailSettings/MailSettingsWindowGML.h> +#include <LibCore/ConfigFile.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(); + + m_config->write_entry("Connection", "Server", m_server); + m_config->write_entry("Connection", "Port", m_port); + m_config->write_bool_entry("Connection", "TLS", m_tls); + m_config->write_entry("User", "Username", m_email); + m_config->sync(); +} + +MailSettingsWindow::MailSettingsWindow() +{ + m_config = Core::ConfigFile::get_for_app("Mail"); + if (unveil(m_config->filename().characters(), "rwc") < 0) { + perror("unveil"); + GUI::Application::the()->quit(); + } + + if (unveil("/res", "r") < 0) { + perror("unveil"); + GUI::Application::the()->quit(); + } + + if (unveil(nullptr, nullptr)) { + perror("unveil"); + GUI::Application::the()->quit(); + } + + //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, 4, 4, 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")); + + 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")); + + m_server_inputbox = *main_widget.find_descendant_of_type_named<GUI::TextBox>("server_input"); + m_server_inputbox->set_text(m_config->read_entry("Connection", "Server", "")); + + m_port_combobox = *main_widget.find_descendant_of_type_named<GUI::ComboBox>("port_input"); + m_port_combobox->set_text(m_config->read_entry("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(m_config->read_bool_entry("Connection", "TLS", false)); + + m_email_inputbox = *main_widget.find_descendant_of_type_named<GUI::TextBox>("email_input"); + m_email_inputbox->set_text(m_config->read_entry("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/MailSettingsWindow.gml b/Userland/Applications/MailSettings/MailSettingsWindow.gml new file mode 100644 index 0000000000..9ab7b4ae3c --- /dev/null +++ b/Userland/Applications/MailSettings/MailSettingsWindow.gml @@ -0,0 +1,146 @@ +@GUI::Frame { + fill_with_background_color: true + + layout: @GUI::VerticalBoxLayout { + margins: [10, 10, 10, 10] + spacing: 5 + } + + @GUI::GroupBox { + title: "Server Settings" + fixed_height: 170 + + layout: @GUI::VerticalBoxLayout { + margins: [8, 16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "server_settings_image_label" + } + + @GUI::Label { + text: "These settings specify the mail server from which you would like to fetch your mail." + text_alignment: "CenterLeft" + } + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Widget { + fixed_width: 32 + } + + @GUI::Label { + text: "Server Address:" + fixed_width: 80 + name: "server_label" + text_alignment: "CenterLeft" + } + + @GUI::TextBox { + name: "server_input" + } + } + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Widget { + fixed_width: 32 + } + + @GUI::Label { + text: "Server Port:" + fixed_width: 80 + name: "port_label" + text_alignment: "CenterLeft" + } + + @GUI::ComboBox { + name: "port_input" + } + } + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Widget { + fixed_width: 32 + } + + @GUI::Label { + text: "Use TLS:" + fixed_width: 80 + text_alignment: "CenterLeft" + name: "tls_label" + } + + @GUI::CheckBox { + name: "tls_input" + fixed_width: 14 + + } + } + } + + @GUI::GroupBox { + title: "User Settings" + fixed_height: 110 + + layout: @GUI::VerticalBoxLayout { + margins: [8, 16, 8, 8] + spacing: 2 + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Label { + fixed_width: 32 + fixed_height: 32 + name: "user_settings_image_label" + } + + @GUI::Label { + text: "These settings specify the credentials which will be used to send and receive mail, and how you identify yourself to recipients." + text_alignment: "CenterLeft" + } + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout { + spacing: 16 + } + + @GUI::Widget { + fixed_width: 32 + } + + @GUI::Label { + autosize: true + text: "Email Address:" + fixed_width: 80 + text_alignment: "CenterLeft" + } + + @GUI::TextBox { + name: "email_input" + } + } + } +} diff --git a/Userland/Applications/MailSettings/MailSettingsWindow.h b/Userland/Applications/MailSettings/MailSettingsWindow.h new file mode 100644 index 0000000000..e7d4fdd83c --- /dev/null +++ b/Userland/Applications/MailSettings/MailSettingsWindow.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, The SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibGUI/TextEditor.h> +#include <LibGUI/Window.h> + +class MailSettingsWindow final : public GUI::Window { + C_OBJECT(MailSettingsWindow) + +private: + MailSettingsWindow(); + + void reset_default_values(); + void write_values(); + + String m_server; + String m_port; + bool m_tls { false }; + String m_email; + Vector<String> m_common_ports; + RefPtr<Core::ConfigFile> m_config; + + RefPtr<GUI::TextBox> m_server_inputbox; + 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/main.cpp b/Userland/Applications/MailSettings/main.cpp new file mode 100644 index 0000000000..151fe21784 --- /dev/null +++ b/Userland/Applications/MailSettings/main.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021, The SerenityOS developers + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "MailSettingsWindow.h" +#include <LibGUI/Application.h> +#include <LibGUI/Icon.h> +#include <unistd.h> + +int main(int argc, char** argv) +{ + if (pledge("stdio rpath cpath wpath recvfd sendfd unix proc exec", nullptr) < 0) { + perror("pledge"); + return 1; + } + + auto app = GUI::Application::construct(argc, argv); + + if (pledge("stdio rpath cpath wpath recvfd sendfd proc exec", nullptr) < 0) { + perror("pledge"); + return 1; + } + + auto app_icon = GUI::Icon::default_icon("app-mail-settings"); + + auto window = MailSettingsWindow::construct(); + window->set_title("Mail Settings"); + window->resize(400, 480); + window->set_resizable(false); + window->set_minimizable(false); + window->set_icon(app_icon.bitmap_for_size(16)); + + window->show(); + return app->exec(); +} |