Add button to send test emails in the mail server prefs (#2216).
authorCarl Hetherington <cth@carlh.net>
Fri, 1 Apr 2022 22:03:12 +0000 (00:03 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 1 Apr 2022 22:03:12 +0000 (00:03 +0200)
src/wx/full_config_dialog.cc
src/wx/send_test_email_dialog.cc [new file with mode: 0644]
src/wx/send_test_email_dialog.h [new file with mode: 0644]
src/wx/wscript

index 127ca412973ba10800248d7cf9ad4b60d96afc26..1c14ad35ca88553cb6c83fbbb9a89bfbf8c1d1ba 100644 (file)
 #include "nag_dialog.h"
 #include "name_format_editor.h"
 #include "password_entry.h"
+#include "send_test_email_dialog.h"
 #include "server_dialog.h"
 #include "static_text.h"
 #include "wx_util.h"
 #include "lib/config.h"
 #include "lib/cross.h"
 #include "lib/dcp_content_type.h"
+#include "lib/emailer.h"
 #include "lib/exceptions.h"
 #include "lib/filter.h"
 #include "lib/log.h"
@@ -762,11 +764,16 @@ private:
                _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 ()
@@ -831,11 +838,41 @@ private:
                Config::instance()->set_mail_password(_password->get());
        }
 
+       void send_test_email_clicked ()
+       {
+               auto dialog = new SendTestEmailDialog(_panel);
+               auto result = dialog->ShowModal();
+               dialog->Destroy();
+               if (result == wxID_OK) {
+                       Emailer emailer(
+                               wx_to_std(dialog->from()),
+                               { wx_to_std(dialog->to()) },
+                               wx_to_std(_("DCP-o-matic test email")),
+                               wx_to_std(_("This is a test email from DCP-o-matic."))
+                               );
+                       auto config = Config::instance();
+                       try {
+                               emailer.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;
 };
 
 
diff --git a/src/wx/send_test_email_dialog.cc b/src/wx/send_test_email_dialog.cc
new file mode 100644 (file)
index 0000000..f9acb38
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+    Copyright (C) 2022 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 "send_test_email_dialog.h"
+
+
+SendTestEmailDialog::SendTestEmailDialog (wxWindow* parent)
+       : TableDialog (parent, _("Send test email"), 2, 1, true)
+{
+       add (_("From address"), true);
+       _from = add (new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(300, -1)));
+       add (_("To address"), true);
+       _to = add (new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(300, -1)));
+
+       layout ();
+}
+
+
diff --git a/src/wx/send_test_email_dialog.h b/src/wx/send_test_email_dialog.h
new file mode 100644 (file)
index 0000000..fa47160
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2022 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 "table_dialog.h"
+
+
+class wxTextCtrl;
+
+
+class SendTestEmailDialog : public TableDialog
+{
+public:
+       SendTestEmailDialog (wxWindow* parent);
+
+       wxString from () const {
+               return _from->GetValue();
+       }
+
+       wxString to () const {
+               return _to->GetValue();
+       }
+
+private:
+       wxTextCtrl* _from;
+       wxTextCtrl* _to;
+};
+
index d2e16c2fea832da6416487ff2ddf95beec280fb7..e000a9ed84b56c0b72101b1a67054cc5ff0686e2 100644 (file)
@@ -129,6 +129,7 @@ sources = """
           screens_panel.cc
           self_dkdm_dialog.cc
           send_i18n_dialog.cc
+          send_test_email_dialog.cc
           server_dialog.cc
           servers_list_dialog.cc
           simple_video_view.cc