Fix job ordering when sending notification emails (more of #1286).
[dcpomatic.git] / src / wx / job_view.cc
index b3b6ee68439ce9f294f07473949ff7a2e956951d..43d6f2fedd9ca90f44d4ec3e191fb673af560f2f 100644 (file)
 #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 "lib/analyse_audio_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,8 +134,16 @@ JobView::finished ()
                _details->Enable (true);
        }
 
-       if (_notify->GetValue ()) {
-               wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
+       if ((dynamic_pointer_cast<TranscodeJob>(_job) || dynamic_pointer_cast<AnalyseAudioJob>(_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_after (_job, shared_ptr<Job> (new SendNotificationEmailJob (body)));
+               }
        }
 }