summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-05-27 23:05:29 +0100
committerCarl Hetherington <cth@carlh.net>2018-05-27 23:05:46 +0100
commit2115fca942897260bb338c8093ada5186d9b775d (patch)
tree2dfbfdc6e6749fa6125e31feb95158cf1723d5f2 /src
parent1158dd504d0838b0c359b2cf1d63615c4ecb0a53 (diff)
Add missing icons and make emailing work.
Diffstat (limited to 'src')
-rw-r--r--src/lib/send_notification_email_job.cc79
-rw-r--r--src/lib/send_notification_email_job.h34
-rw-r--r--src/lib/wscript1
-rw-r--r--src/wx/job_view.cc11
4 files changed, 123 insertions, 2 deletions
diff --git a/src/lib/send_notification_email_job.cc b/src/lib/send_notification_email_job.cc
new file mode 100644
index 000000000..6d7882e71
--- /dev/null
+++ b/src/lib/send_notification_email_job.cc
@@ -0,0 +1,79 @@
+/*
+ Copyright (C) 2018 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_notification_email_job.h"
+#include "exceptions.h"
+#include "config.h"
+#include "emailer.h"
+#include "compose.hpp"
+#include <boost/foreach.hpp>
+#include <list>
+
+#include "i18n.h"
+
+using std::string;
+using std::list;
+using boost::shared_ptr;
+
+/** @param body Email body */
+SendNotificationEmailJob::SendNotificationEmailJob (string body)
+ : Job (shared_ptr<Film>())
+ , _body (body)
+{
+
+}
+
+string
+SendNotificationEmailJob::name () const
+{
+ return _("Email notification");
+}
+
+string
+SendNotificationEmailJob::json_name () const
+{
+ return N_("send_notification_email");
+}
+
+void
+SendNotificationEmailJob::run ()
+{
+ Config* config = Config::instance ();
+
+ if (config->mail_server().empty()) {
+ throw NetworkError (_("No mail server configured in preferences"));
+ }
+
+ set_progress_unknown ();
+ list<string> to;
+ to.push_back (config->notification_to ());
+ Emailer email (config->notification_from(), to, config->notification_subject(), _body);
+ BOOST_FOREACH (string i, config->notification_cc()) {
+ email.add_cc (i);
+ }
+ if (!config->notification_bcc().empty()) {
+ email.add_bcc (config->notification_bcc ());
+ }
+
+ email.send (config->mail_server(), config->mail_port(), config->mail_user(), config->mail_password());
+
+ set_progress (1);
+ set_state (FINISHED_OK);
+}
diff --git a/src/lib/send_notification_email_job.h b/src/lib/send_notification_email_job.h
new file mode 100644
index 000000000..f6ca3fbd6
--- /dev/null
+++ b/src/lib/send_notification_email_job.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2018 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 "job.h"
+
+class SendNotificationEmailJob : public Job
+{
+public:
+ SendNotificationEmailJob (std::string body);
+
+ std::string name () const;
+ std::string json_name () const;
+ void run ();
+
+private:
+ std::string _body;
+};
diff --git a/src/lib/wscript b/src/lib/wscript
index 9e7d83903..b6784dbaa 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -127,6 +127,7 @@ sources = """
screen.cc
screen_kdm.cc
send_kdm_email_job.cc
+ send_notification_email_job.cc
send_problem_report_job.cc
server.cc
shuffler.cc
diff --git a/src/wx/job_view.cc b/src/wx/job_view.cc
index acf42bc8b..9a1a12ca7 100644
--- a/src/wx/job_view.cc
+++ b/src/wx/job_view.cc
@@ -21,14 +21,18 @@
#include "job_view.h"
#include "wx_util.h"
#include "lib/job.h"
+#include "lib/job_manager.h"
#include "lib/compose.hpp"
#include "lib/config.h"
+#include "lib/send_notification_email_job.h"
+#include "lib/transcode_job.h"
#include <wx/wx.h>
using std::string;
using std::min;
using boost::shared_ptr;
using boost::bind;
+using boost::dynamic_pointer_cast;
JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
: _job (job)
@@ -129,12 +133,15 @@ JobView::finished ()
_details->Enable (true);
}
- if (_notify->GetValue()) {
+ if (dynamic_pointer_cast<TranscodeJob>(_job) && _notify->GetValue()) {
if (Config::instance()->notification(Config::MESSAGE_BOX)) {
wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
}
if (Config::instance()->notification(Config::EMAIL)) {
-
+ string body = Config::instance()->notification_email();
+ boost::algorithm::replace_all (body, "$JOB_NAME", _job->name());
+ boost::algorithm::replace_all (body, "$JOB_STATUS", _job->status());
+ JobManager::instance()->add (shared_ptr<Job> (new SendNotificationEmailJob (body)));
}
}
}