Add missing icons and make emailing work.
authorCarl Hetherington <cth@carlh.net>
Sun, 27 May 2018 22:05:29 +0000 (23:05 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 27 May 2018 22:05:46 +0000 (23:05 +0100)
graphics/osx/preferences/notifications.png [new file with mode: 0644]
graphics/src/notifications.svg [new file with mode: 0644]
src/lib/send_notification_email_job.cc [new file with mode: 0644]
src/lib/send_notification_email_job.h [new file with mode: 0644]
src/lib/wscript
src/wx/job_view.cc

diff --git a/graphics/osx/preferences/notifications.png b/graphics/osx/preferences/notifications.png
new file mode 100644 (file)
index 0000000..564f82b
Binary files /dev/null and b/graphics/osx/preferences/notifications.png differ
diff --git a/graphics/src/notifications.svg b/graphics/src/notifications.svg
new file mode 100644 (file)
index 0000000..e88a0ae
--- /dev/null
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   id="svg5816"
+   viewBox="0 0 48 48"
+   sodipodi:version="0.32"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   inkscape:version="0.92.3 (2405546, 2018-03-11)"
+   sodipodi:docname="notifications.svg"
+   version="1.1">
+  <defs
+     id="defs3">
+    <linearGradient
+       id="linearGradient2152">
+      <stop
+         id="stop2154"
+         style="stop-color:#9aa29a"
+         offset="0" />
+      <stop
+         id="stop2156"
+         style="stop-color:#b5beb5"
+         offset="1" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient3601"
+       y2="613.94"
+       gradientUnits="userSpaceOnUse"
+       x2="385.04001"
+       gradientTransform="matrix(0.04860254,-0.04951283,0.04860254,0.04951283,-9.7664634,27.282)"
+       y1="63.870998"
+       x1="386.39001">
+      <stop
+         id="stop3797"
+         stop-color="#ffe800"
+         offset="0" />
+      <stop
+         id="stop3799"
+         stop-color="#dfb300"
+         offset="1" />
+    </linearGradient>
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     bordercolor="#666666"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     pagecolor="#ffffff"
+     inkscape:grid-bbox="true"
+     inkscape:zoom="5.6568542"
+     inkscape:pageshadow="2"
+     showgrid="false"
+     borderopacity="1.0"
+     inkscape:current-layer="layer1"
+     inkscape:cx="14.465598"
+     inkscape:cy="3.1824916"
+     inkscape:window-width="1366"
+     inkscape:pageopacity="0.0"
+     inkscape:window-height="704"
+     inkscape:document-units="px"
+     inkscape:snap-global="false"
+     inkscape:window-maximized="1" />
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer">
+    <circle
+       style="fill:#cccccc;stroke:#808080;stroke-width:1.72725451;stroke-miterlimit:4;stroke-dasharray:none"
+       id="path11817"
+       cx="24"
+       cy="24"
+       r="21.526354" />
+    <text
+       xml:space="preserve"
+       style="font-style:normal;font-weight:normal;font-size:47.65264893px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1.19131637;"
+       x="14.448529"
+       y="41.369484"
+       id="text11793"><tspan
+         sodipodi:role="line"
+         id="tspan11791"
+         x="14.448529"
+         y="41.369484"
+         style="fill:#ffffff;stroke:#808080;stroke-width:1.19131637;">!</tspan></text>
+  </g>
+  <metadata
+     id="metadata53">
+    <rdf:RDF>
+      <cc:Work>
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <cc:license
+           rdf:resource="http://creativecommons.org/licenses/publicdomain/" />
+        <dc:publisher>
+          <cc:Agent
+             rdf:about="http://openclipart.org/">
+            <dc:title>Openclipart</dc:title>
+          </cc:Agent>
+        </dc:publisher>
+        <dc:title></dc:title>
+        <dc:date>2010-03-29T08:04:16</dc:date>
+        <dc:description>&quot;E-mail&quot; icon from &lt;a href=&quot;http://tango.freedesktop.org/Tango_Desktop_Project&quot;&gt; Tango Project &lt;/a&gt; \r\n&lt;br&gt;&lt;br&gt;\r\nSince version 0.8.90 Tango Project icons are Public Domain: &lt;a href=&quot;http://tango.freedesktop.org/Frequently_Asked_Questions#Terms_of_Use.3F&quot;&gt; Tango Project FAQ &lt;/a&gt;</dc:description>
+        <dc:source>https://openclipart.org/detail/35215/tango-internet-mail-by-warszawianka</dc:source>
+        <dc:creator>
+          <cc:Agent>
+            <dc:title>warszawianka</dc:title>
+          </cc:Agent>
+        </dc:creator>
+        <dc:subject>
+          <rdf:Bag>
+            <rdf:li>email</rdf:li>
+            <rdf:li>envelope</rdf:li>
+            <rdf:li>externalsource</rdf:li>
+            <rdf:li>icon</rdf:li>
+            <rdf:li>letter</rdf:li>
+            <rdf:li>tango</rdf:li>
+          </rdf:Bag>
+        </dc:subject>
+      </cc:Work>
+      <cc:License
+         rdf:about="http://creativecommons.org/licenses/publicdomain/">
+        <cc:permits
+           rdf:resource="http://creativecommons.org/ns#Reproduction" />
+        <cc:permits
+           rdf:resource="http://creativecommons.org/ns#Distribution" />
+        <cc:permits
+           rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
+      </cc:License>
+    </rdf:RDF>
+  </metadata>
+</svg>
diff --git a/src/lib/send_notification_email_job.cc b/src/lib/send_notification_email_job.cc
new file mode 100644 (file)
index 0000000..6d7882e
--- /dev/null
@@ -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 (file)
index 0000000..f6ca3fb
--- /dev/null
@@ -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;
+};
index 9e7d83903771aae35f5951b84f3041a211d82669..b6784dbaae47eaefaf3a46b5f5290bb00ffd89e9 100644 (file)
@@ -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
index acf42bc8b92a3a6a38cc3b4a72cbd2366a801871..9a1a12ca72a0fc3b45a10f8c5f61cd1f65db7788 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 <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)));
                }
        }
 }