cea35e3c59edb08ca3183935e3247a02a47174e5
[dcpomatic.git] / src / lib / send_kdm_email_job.cc
1 /*
2     Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "send_kdm_email_job.h"
22 #include "compose.hpp"
23 #include "kdm_with_metadata.h"
24 #include "film.h"
25 #include <list>
26
27 #include "i18n.h"
28
29 using std::string;
30 using std::list;
31 using std::shared_ptr;
32 using boost::optional;
33
34 SendKDMEmailJob::SendKDMEmailJob (
35         list<KDMWithMetadataPtr> kdms,
36         dcp::NameFormat container_name_format,
37         dcp::NameFormat filename_format,
38         string cpl_name
39         )
40         : Job (shared_ptr<Film>())
41         , _container_name_format (container_name_format)
42         , _filename_format (filename_format)
43         , _cpl_name (cpl_name)
44 {
45         BOOST_FOREACH (KDMWithMetadataPtr i, kdms) {
46                 list<KDMWithMetadataPtr> s;
47                 s.push_back (i);
48                 _kdms.push_back (s);
49         }
50 }
51
52 /** @param kdms KDMs to email.
53  *  @param container_name_format Format to ues for folders / ZIP files.
54  *  @param filename_format Format to use for filenames.
55  *  @param name_values Values to substitute into \p container_name_format and \p filename_format.
56  *  @param cpl_name Name of the CPL that the KDMs are for.
57  */
58 SendKDMEmailJob::SendKDMEmailJob (
59         list<list<KDMWithMetadataPtr> > kdms,
60         dcp::NameFormat container_name_format,
61         dcp::NameFormat filename_format,
62         string cpl_name
63         )
64         : Job (shared_ptr<Film>())
65         , _container_name_format (container_name_format)
66         , _filename_format (filename_format)
67         , _cpl_name (cpl_name)
68         , _kdms (kdms)
69 {
70
71 }
72
73 SendKDMEmailJob::~SendKDMEmailJob ()
74 {
75         stop_thread ();
76 }
77
78 string
79 SendKDMEmailJob::name () const
80 {
81         optional<string> f = _kdms.front().front()->get('f');
82         if (!f || f->empty()) {
83                 return _("Email KDMs");
84         }
85
86         return String::compose (_("Email KDMs for %2"), *f);
87 }
88
89 string
90 SendKDMEmailJob::json_name () const
91 {
92         return N_("send_kdm_email");
93 }
94
95 void
96 SendKDMEmailJob::run ()
97 {
98         set_progress_unknown ();
99         email (_kdms, _container_name_format, _filename_format, _cpl_name);
100         set_progress (1);
101         set_state (FINISHED_OK);
102 }