diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-03-01 23:17:09 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-03-01 23:17:13 +0100 |
| commit | 3cad01eefa07e14d64ccf8972a35674dc5b23c4a (patch) | |
| tree | bdfb488b7645f1674b6e3b7c90127835472b191d /src | |
| parent | a1cc8eb29a1e85071bfdb5c7ee3180149be09a69 (diff) | |
Move Email preferences page to its own file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/email_preferences_page.cc | 205 | ||||
| -rw-r--r-- | src/wx/email_preferences_page.h | 61 | ||||
| -rw-r--r-- | src/wx/full_config_dialog.cc | 169 | ||||
| -rw-r--r-- | src/wx/wscript | 1 |
4 files changed, 269 insertions, 167 deletions
diff --git a/src/wx/email_preferences_page.cc b/src/wx/email_preferences_page.cc new file mode 100644 index 000000000..6264b9336 --- /dev/null +++ b/src/wx/email_preferences_page.cc @@ -0,0 +1,205 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "email_preferences_page.h" +#include "password_entry.h" +#include "send_test_email_dialog.h" +#include "wx_variant.h" +#include "lib/email.h" +#include "lib/variant.h" + + +using namespace dcpomatic::preferences; + + +EmailPage::EmailPage(wxSize panel_size, int border) + : Page(panel_size, border) +{ + +} + + +wxString +EmailPage::GetName() const +{ + return _("Email"); +} + + +#ifdef DCPOMATIC_OSX +wxBitmap +EmailPage::GetLargeIcon() const +{ + return wxBitmap(icon_path("email"), wxBITMAP_TYPE_PNG); +} +#endif + + +void +EmailPage::setup() +{ + auto table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); + table->AddGrowableCol(1, 1); + _panel->GetSizer()->Add(table, 1, wxEXPAND | wxALL, _border); + + add_label_to_sizer(table, _panel, _("Outgoing mail server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + { + wxBoxSizer* s = new wxBoxSizer(wxHORIZONTAL); + _server = new wxTextCtrl(_panel, wxID_ANY); + s->Add(_server, 1, wxEXPAND | wxALL); + add_label_to_sizer(s, _panel, _("port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _port = new wxSpinCtrl(_panel, wxID_ANY); + _port->SetRange(0, 65535); + s->Add(_port); + add_label_to_sizer(s, _panel, _("protocol"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _protocol = new wxChoice(_panel, wxID_ANY); + /* Make sure this matches the switches in config_changed and port_changed below */ + _protocol->Append(_("Auto")); + _protocol->Append(_("Plain")); + _protocol->Append(_("STARTTLS")); + _protocol->Append(_("SSL")); + s->Add(_protocol, 1, wxALIGN_CENTER_VERTICAL); + table->Add(s, 1, wxEXPAND | wxALL); + } + + add_label_to_sizer(table, _panel, _("User name"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _user = new wxTextCtrl(_panel, wxID_ANY); + table->Add(_user, 1, wxEXPAND | wxALL); + + add_label_to_sizer(table, _panel, _("Password"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _password = new PasswordEntry(_panel); + table->Add(_password->get_panel(), 1, wxEXPAND | wxALL); + + table->AddSpacer(0); + _send_test_email = new Button(_panel, _("Send test email...")); + table->Add(_send_test_email); + + _server->Bind(wxEVT_TEXT, boost::bind(&EmailPage::server_changed, this)); + _port->Bind(wxEVT_SPINCTRL, boost::bind(&EmailPage::port_changed, this)); + _protocol->Bind(wxEVT_CHOICE, boost::bind(&EmailPage::protocol_changed, this)); + _user->Bind(wxEVT_TEXT, boost::bind(&EmailPage::user_changed, this)); + _password->Changed.connect(boost::bind(&EmailPage::password_changed, this)); + _send_test_email->Bind(wxEVT_BUTTON, boost::bind(&EmailPage::send_test_email_clicked, this)); +} + + +void +EmailPage::config_changed() +{ + auto config = Config::instance(); + + checked_set(_server, config->mail_server()); + checked_set(_port, config->mail_port()); + switch(config->mail_protocol()) { + case EmailProtocol::AUTO: + checked_set(_protocol, 0); + break; + case EmailProtocol::PLAIN: + checked_set(_protocol, 1); + break; + case EmailProtocol::STARTTLS: + checked_set(_protocol, 2); + break; + case EmailProtocol::SSL: + checked_set(_protocol, 3); + break; + } + checked_set(_user, config->mail_user()); + checked_set(_password, config->mail_password()); +} + + +void +EmailPage::server_changed() +{ + Config::instance()->set_mail_server(wx_to_std(_server->GetValue())); +} + + +void +EmailPage::port_changed() +{ + Config::instance()->set_mail_port(_port->GetValue()); +} + + +void +EmailPage::protocol_changed() +{ + switch (_protocol->GetSelection()) { + case 0: + Config::instance()->set_mail_protocol(EmailProtocol::AUTO); + break; + case 1: + Config::instance()->set_mail_protocol(EmailProtocol::PLAIN); + break; + case 2: + Config::instance()->set_mail_protocol(EmailProtocol::STARTTLS); + break; + case 3: + Config::instance()->set_mail_protocol(EmailProtocol::SSL); + break; + } +} + +void +EmailPage::user_changed() +{ + Config::instance()->set_mail_user(wx_to_std(_user->GetValue())); +} + + +void +EmailPage::password_changed() +{ + Config::instance()->set_mail_password(_password->get()); +} + + +void +EmailPage::send_test_email_clicked() +{ + SendTestEmailDialog dialog(_panel); + if (dialog.ShowModal() != wxID_OK) { + return; + } + + Email email( + wx_to_std(dialog.from()), + { wx_to_std(dialog.to()) }, + wx_to_std(variant::wx::insert_dcpomatic(_("%s test email"))), + wx_to_std(variant::wx::insert_dcpomatic(_("This is a test email from %s."))) + ); + auto config = Config::instance(); + try { + email.send(config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); + } catch (NetworkError& e) { + error_dialog(_panel, std_to_wx(e.summary()), std_to_wx(e.detail().get_value_or(""))); + return; + } catch (std::exception& e) { + error_dialog(_panel, _("Test email sending failed."), std_to_wx(e.what())); + return; + } catch (...) { + error_dialog(_panel, _("Test email sending failed.")); + return; + } + message_dialog(_panel, _("Test email sent.")); +} diff --git a/src/wx/email_preferences_page.h b/src/wx/email_preferences_page.h new file mode 100644 index 000000000..8abbcef33 --- /dev/null +++ b/src/wx/email_preferences_page.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2025 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "config_dialog.h" + + +namespace dcpomatic { +namespace preferences { + + +class EmailPage : public Page +{ +public: + EmailPage(wxSize panel_size, int border); + + wxString GetName() const override; + +#ifdef DCPOMATIC_OSX + wxBitmap GetLargeIcon() const override; +#endif + +private: + void setup() override; + void config_changed() override; + void server_changed(); + void port_changed(); + void protocol_changed(); + void user_changed(); + void password_changed(); + void send_test_email_clicked(); + + wxTextCtrl* _server; + wxSpinCtrl* _port; + wxChoice* _protocol; + wxTextCtrl* _user; + PasswordEntry* _password; + Button* _send_test_email; +}; + + +} +} + diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc index fafec106b..6fb56c545 100644 --- a/src/wx/full_config_dialog.cc +++ b/src/wx/full_config_dialog.cc @@ -32,6 +32,7 @@ #include "dir_picker_ctrl.h" #include "editable_list.h" #include "email_dialog.h" +#include "email_preferences_page.h" #include "file_picker_ctrl.h" #include "filter_dialog.h" #include "full_config_dialog.h" @@ -697,172 +698,6 @@ private: }; -class EmailPage : public preferences::Page -{ -public: - EmailPage(wxSize panel_size, int border) - : Page(panel_size, border) - {} - - wxString GetName() const override - { - return _("Email"); - } - -#ifdef DCPOMATIC_OSX - wxBitmap GetLargeIcon() const override - { - return wxBitmap(icon_path("email"), wxBITMAP_TYPE_PNG); - } -#endif - -private: - void setup() override - { - auto table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); - table->AddGrowableCol(1, 1); - _panel->GetSizer()->Add(table, 1, wxEXPAND | wxALL, _border); - - add_label_to_sizer(table, _panel, _("Outgoing mail server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - { - wxBoxSizer* s = new wxBoxSizer(wxHORIZONTAL); - _server = new wxTextCtrl(_panel, wxID_ANY); - s->Add(_server, 1, wxEXPAND | wxALL); - add_label_to_sizer(s, _panel, _("port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _port = new wxSpinCtrl(_panel, wxID_ANY); - _port->SetRange(0, 65535); - s->Add(_port); - add_label_to_sizer(s, _panel, _("protocol"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _protocol = new wxChoice(_panel, wxID_ANY); - /* Make sure this matches the switches in config_changed and port_changed below */ - _protocol->Append(_("Auto")); - _protocol->Append(_("Plain")); - _protocol->Append(_("STARTTLS")); - _protocol->Append(_("SSL")); - s->Add(_protocol, 1, wxALIGN_CENTER_VERTICAL); - table->Add(s, 1, wxEXPAND | wxALL); - } - - add_label_to_sizer(table, _panel, _("User name"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _user = new wxTextCtrl(_panel, wxID_ANY); - table->Add(_user, 1, wxEXPAND | wxALL); - - add_label_to_sizer(table, _panel, _("Password"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _password = new PasswordEntry(_panel); - table->Add(_password->get_panel(), 1, wxEXPAND | wxALL); - - table->AddSpacer(0); - _send_test_email = new Button(_panel, _("Send test email...")); - table->Add(_send_test_email); - - _server->Bind(wxEVT_TEXT, boost::bind(&EmailPage::server_changed, this)); - _port->Bind(wxEVT_SPINCTRL, boost::bind(&EmailPage::port_changed, this)); - _protocol->Bind(wxEVT_CHOICE, boost::bind(&EmailPage::protocol_changed, this)); - _user->Bind(wxEVT_TEXT, boost::bind(&EmailPage::user_changed, this)); - _password->Changed.connect(boost::bind(&EmailPage::password_changed, this)); - _send_test_email->Bind(wxEVT_BUTTON, boost::bind(&EmailPage::send_test_email_clicked, this)); - } - - void config_changed() override - { - auto config = Config::instance(); - - checked_set(_server, config->mail_server()); - checked_set(_port, config->mail_port()); - switch(config->mail_protocol()) { - case EmailProtocol::AUTO: - checked_set(_protocol, 0); - break; - case EmailProtocol::PLAIN: - checked_set(_protocol, 1); - break; - case EmailProtocol::STARTTLS: - checked_set(_protocol, 2); - break; - case EmailProtocol::SSL: - checked_set(_protocol, 3); - break; - } - checked_set(_user, config->mail_user()); - checked_set(_password, config->mail_password()); - } - - void server_changed() - { - Config::instance()->set_mail_server(wx_to_std(_server->GetValue())); - } - - void port_changed() - { - Config::instance()->set_mail_port(_port->GetValue()); - } - - void protocol_changed() - { - switch (_protocol->GetSelection()) { - case 0: - Config::instance()->set_mail_protocol(EmailProtocol::AUTO); - break; - case 1: - Config::instance()->set_mail_protocol(EmailProtocol::PLAIN); - break; - case 2: - Config::instance()->set_mail_protocol(EmailProtocol::STARTTLS); - break; - case 3: - Config::instance()->set_mail_protocol(EmailProtocol::SSL); - break; - } - } - - void user_changed() - { - Config::instance()->set_mail_user(wx_to_std(_user->GetValue())); - } - - void password_changed() - { - Config::instance()->set_mail_password(_password->get()); - } - - void send_test_email_clicked() - { - SendTestEmailDialog dialog(_panel); - if (dialog.ShowModal() != wxID_OK) { - return; - } - - Email email( - wx_to_std(dialog.from()), - { wx_to_std(dialog.to()) }, - wx_to_std(variant::wx::insert_dcpomatic(_("%s test email"))), - wx_to_std(variant::wx::insert_dcpomatic(_("This is a test email from %s."))) - ); - auto config = Config::instance(); - try { - email.send(config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); - } catch (NetworkError& e) { - error_dialog(_panel, std_to_wx(e.summary()), std_to_wx(e.detail().get_value_or(""))); - return; - } catch (std::exception& e) { - error_dialog(_panel, _("Test email sending failed."), std_to_wx(e.what())); - return; - } catch (...) { - error_dialog(_panel, _("Test email sending failed.")); - return; - } - message_dialog(_panel, _("Test email sent.")); - } - - wxTextCtrl* _server; - wxSpinCtrl* _port; - wxChoice* _protocol; - wxTextCtrl* _user; - PasswordEntry* _password; - Button* _send_test_email; -}; - - class KDMEmailPage : public preferences::Page { public: @@ -1845,7 +1680,7 @@ create_full_config_dialog() #endif e->AddPage(new preferences::KeysPage(ps, border)); e->AddPage(new TMSPage(ps, border)); - e->AddPage(new EmailPage(ps, border)); + e->AddPage(new preferences::EmailPage(ps, border)); e->AddPage(new KDMEmailPage(ps, border)); e->AddPage(new NotificationsPage(ps, border)); e->AddPage(new CoverSheetPage(ps, border)); diff --git a/src/wx/wscript b/src/wx/wscript index 4b0af253a..565fb66c1 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -80,6 +80,7 @@ sources = """ download_certificate_panel.cc drive_wipe_warning_dialog.cc email_dialog.cc + email_preferences_page.cc export_subtitles_dialog.cc export_video_file_dialog.cc extra_kdm_email_dialog.cc |
