From 8e3431d56d25dc90c588d2729feba5a9a133a289 Mon Sep 17 00:00:00 2001 From: Faeliore Date: Thu, 29 Jul 2021 21:03:55 -0400 Subject: [PATCH] MailSettings: Add basic mail settings dialog MailSettings: Add a GML file for Mail settings MailSettings: Add an AF desktop file for Mail Settings MailSettings: Unveil /res in mail settings, fix GML MailSettings: Mail settings texteditor->textbox MailSettings: Update mail username to correct category in settings Modified Mail settings GML to properly represent ports >100 MailSettings: Update/fix mail settings GML MailSettings: Adjust GML, add icons for mail settings MailSettings: Change Okay button to OK MailSettings: Change mail setting reset button to revert MailSettings: Fix incorrect variable names in mail settings MailSettings: Add newlines af EOF of all mail setting files MailSettings: Mail settings linting issues fixed MailSettings: Increase size of icon features Code cleaning/styling changes as per gunnarbeutner review Made settings descriptions more friendly per sin-ack review MailSettings: Fixes as per PR comments MailSettings: Fix checkbox weirdness MailSettings: Adjust width of checkbox MailSettings: Remove unneccessary update() call MailSettings: Replace port SpinBox with ComboBox MailSettings: Add colons to labels, remove port 110 option MailSettings: Remove custom model, use ItemListModel MailSettings: Change relative icon paths to absolute ones --- Base/res/apps/MailSettings.af | 5 + Base/res/graphics/mail-server-settings.png | Bin 0 -> 828 bytes Base/res/graphics/mail-user-settings.png | Bin 0 -> 732 bytes Base/res/icons/16x16/app-mail-settings.png | Bin 0 -> 521 bytes Base/res/icons/32x32/app-mail-settings.png | Bin 0 -> 610 bytes Userland/Applications/CMakeLists.txt | 1 + .../Applications/MailSettings/CMakeLists.txt | 17 ++ .../MailSettings/MailSettingsWindow.cpp | 127 +++++++++++++++ .../MailSettings/MailSettingsWindow.gml | 146 ++++++++++++++++++ .../MailSettings/MailSettingsWindow.h | 37 +++++ Userland/Applications/MailSettings/main.cpp | 37 +++++ 11 files changed, 370 insertions(+) create mode 100644 Base/res/apps/MailSettings.af create mode 100644 Base/res/graphics/mail-server-settings.png create mode 100644 Base/res/graphics/mail-user-settings.png create mode 100644 Base/res/icons/16x16/app-mail-settings.png create mode 100644 Base/res/icons/32x32/app-mail-settings.png create mode 100644 Userland/Applications/MailSettings/CMakeLists.txt create mode 100644 Userland/Applications/MailSettings/MailSettingsWindow.cpp create mode 100644 Userland/Applications/MailSettings/MailSettingsWindow.gml create mode 100644 Userland/Applications/MailSettings/MailSettingsWindow.h create mode 100644 Userland/Applications/MailSettings/main.cpp diff --git a/Base/res/apps/MailSettings.af b/Base/res/apps/MailSettings.af new file mode 100644 index 0000000000..4d92c6135e --- /dev/null +++ b/Base/res/apps/MailSettings.af @@ -0,0 +1,5 @@ +[App] +Name=Mail Settings +Executable=/bin/MailSettings +Category=Settings +Description=Configure the Mail application diff --git a/Base/res/graphics/mail-server-settings.png b/Base/res/graphics/mail-server-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..18762435a28ab762ee5b22af35668211869630c8 GIT binary patch literal 828 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANNfEt$^F0iMpz3I#>^X_+~x z3=A3*YbV-z9Cna78Xvq=NtC_2LnCE{pV*Qvt1Qv30L3d@YprI){9^T$nj|9besJr9 z2gj4H9y}Tu&K~Y4@Q0zWxHza}qR{{8B2h=G3hwlmf0rwN&#*8oY1UOkzKmVDYL5*K z=SGS$ujfdR_&dWbByF0Zx+mur+4%1tK7Q3ZwE5Qj-^E{6M0PXUO{|zExy*Nuqs`V# z={es!o!2O=KJxrXvRdqf9}{199nYWhS&!SsIAz(S&qoxK4DTQE;@;e}QqW(hJ=Ax3 zjpEylrz*QQhppOh%=RaDb7XDm%-1IE0>_o6DLA$?adl}NbZZHlE5hx0tAFc9{#|vQ zFvz~d!gc-Pyt^+&6nTwOM^sS3Ov6UcRHYYWlv*mwy&02AXfO`f>ZHDnkR4CBu?Hj~n@-WFo@c5QPM`vX)=@)&eSRdZvo2^tIdHvAktBZCzC@$>sacbEvbfH%xuub|e zYpyEW?5BKtK1<#>mwqa}?u^4El`z&{hXuENmi%>i;xCsJ;}V;b@&4!b-%dY%{YS-) zTaiq!e%=*VWLPtQ`C0SD>n?XXNVTSHi2OINK_gJr$yPp7L}*ig=Ca2pufN+K)lg-3 kD%$9qYGB8ol{HK)>T5*0{BGznFfcH9y85}Sb4q9e05Dx}GXMYp literal 0 HcmV?d00001 diff --git a/Base/res/graphics/mail-user-settings.png b/Base/res/graphics/mail-user-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..ad7e375f5e94ca148b6c54818481c8f6ce52ee18 GIT binary patch literal 732 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANNfEt$^F0iMpz3I#>^X_+~x z3=A3*YbV-z9Cna78Xvq=NtC_2LnCE{pV*Qvt1Qv30L3d@YprI){9^T$nj|9besJr9 z2gj4H9y}Tu&K~Y4@Q0zWxHza}qR{{8B2h=G3hwlmf0rwN&#*8oY1UOkzKmVDYL5*K z=SGS$ujfdR_&dWbByF0Zx+mur+4%1tK7Q3ZwE5Qj-^E{6M0PXUO{|zExy*Nuqs`V# z={es!o!2O=KJxrXvRdqf9}{199nYWhS&!SsIAz(S&qoxK4DTQE;@;e}QqW(hJ=Ax3 zjpEylrz*QQhppOh%=RaDb7XDm%-1IE0>_o6DLA$?adl}NbZZHlE5hx0tAFc9{#|vQ zF6HrG;xxc*2?%tr!i15GQs$(F;>Av}$v% z@ZxFI=02g)c4#ZhFO_2lq!W9luJW9;q)_x}NsL+Bhu}54g;&jef4zHET~8%zE@$kI z7sdvzY2pRTt3G@y`Y*QIIBqsGL&DVMAC#vsOgO4I^G*AcUp3(u_O1CO5-B5;w5!;D n*Hoj5*h6wo(z9=VW_)ya$MW6Zws12rFfe$!`njxgN@xNAGJ!oc literal 0 HcmV?d00001 diff --git a/Base/res/icons/16x16/app-mail-settings.png b/Base/res/icons/16x16/app-mail-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..9f9db7c952f5b433b5712a6fa8466328dfc43784 GIT binary patch literal 521 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4i*LmhONKMUokK+DrY)72Y5O=D-;yvr)B1( zGB9XNoI7Eo*Wmz>w*6OuOzkfd zm{xiJvtNeI{PhuT@m0rGSH3&HS>kA_#@yAL4D_`&d^>t>%_-j15&LC-v_E3sD7!RL zrA{c{Ju~ITn_rnmy!AF`bHg6Jd35JX=;d5c0n0I-?_Q2anQT2f817}{%XJBApO7eDhVff$P ze`Y@e0|RG)M`SSrgPt-7Ggd6MFJoX}sPlAj4AD5hb;3d3W&;71<6*lxGLEUvU|O&x zTfyeX?XxadHrn{~Fi!NJGEwK}p5=F~58p3L__fTA!RnCf={=H$43npnsCXJhzTEoj z%Bi5vZ}O)d);-HzaDV+$)%njp<_b#fWM8z+wEZ-ntv|!G#fQ&vM>L$gTXQ8wHm_6b cd3hM~ZBORUQf!|X7#J8lUHx3vIVCg!01AHQaR2}S literal 0 HcmV?d00001 diff --git a/Base/res/icons/32x32/app-mail-settings.png b/Base/res/icons/32x32/app-mail-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..2aa7b56467af9e86af427a05921271dfee54aa3c GIT binary patch literal 610 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4i*LmhMUEk>KPaql{1~413aCb6$*;-(=u~X z85lGs&YiH)>u`Wb+x{y_t|dWM9Zqc5o4OAkT&l(5sCbMkY`KZ&#u-N@ED^bX!2DwS zO9hU7jrt27ys2N@+#I>5;D1SruLT! zOsl;A*)PLp{`v^F_^M;8E8m^pEO9hdWA5rr2KrhXz8yWc<`nPhi2brZ+8?oRlwBIB zQYVz}o|$sv&96)&-g=v}xnYmqJi7BGboLIJ;;#0y9h$;IT2+^P<|@mSE!AUX{63}S zQcJ|%nQ2;iE=%Xc@VPKg%)2~cd*Jg*FUgb1O8S!v+_n5CxBtBVerx~cs>`p=eO|!v z>RQt(Q@O*xmDlhkzLlJ|UV78Cy8UYtkF8Aq_w$&(sCq#4fith>GcYhPC3(BMFzl6& zeZ$Paz`$AH5n0T@pr;JNj1^1m%NQ6Ku6w#ThIkx*JLRBgvjUI9{>rI_~dP`0}93Gb7oh7LipRdbDfmru~~4O_qH&0cP3 z`rm=?N}31jmIKMF7;QG|%T1{ZWoD4_ITSvt?beQ1kGhLh#!u~@>ObM#xytiL!XF-K Q1_lNOPgg&ebxsLQ0CjZ_YybcN literal 0 HcmV?d00001 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 +#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::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(); + main_widget.set_fill_with_background_color(true); + main_widget.set_layout(); + main_widget.layout()->set_margins({ 4, 4, 4, 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(); + }; +} 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 +#include + +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 m_common_ports; + RefPtr m_config; + + RefPtr m_server_inputbox; + RefPtr m_port_combobox; + RefPtr m_tls_checkbox; + RefPtr m_email_inputbox; + + RefPtr m_reset_button; + RefPtr m_ok_button; + RefPtr m_cancel_button; + RefPtr 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 +#include +#include + +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(); +}