/* * Copyright (c) 2021, The SerenityOS developers * * SPDX-License-Identifier: BSD-2-Clause */ #include "MailSettingsWindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include 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::open_for_app("Mail", Core::ConfigFile::AllowWriting::Yes); 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(); main_widget.set_fill_with_background_color(true); main_widget.set_layout(); main_widget.layout()->set_margins(4); main_widget.layout()->set_spacing(6); auto& tab_widget = main_widget.add(); auto& mail_widget = tab_widget.add_tab("Mail"); mail_widget.load_from_gml(mail_settings_window_gml); auto& server_settings_image_label = *main_widget.find_descendant_of_type_named("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("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("server_input"); m_server_inputbox->set_text(m_config->read_entry("Connection", "Server", "")); m_port_combobox = *main_widget.find_descendant_of_type_named("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::create(m_common_ports)); m_tls_checkbox = *main_widget.find_descendant_of_type_named("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("email_input"); m_email_inputbox->set_text(m_config->read_entry("User", "Username", "")); auto& button_container = main_widget.add(); button_container.set_shrink_to_fit(true); button_container.set_layout(); button_container.layout()->set_spacing(6); m_reset_button = button_container.add("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("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("Cancel"); m_cancel_button->set_fixed_width(75); m_cancel_button->on_click = [&](auto) { GUI::Application::the()->quit(); }; m_apply_button = button_container.add("Apply"); m_apply_button->set_fixed_width(75); m_apply_button->on_click = [&](auto) { write_values(); }; }