Supporters update.
[dcpomatic.git] / src / lib / send_kdm_email_job.cc
1 /*
2     Copyright (C) 2013-2021 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
22 #include "compose.hpp"
23 #include "film.h"
24 #include "kdm_with_metadata.h"
25 #include "send_kdm_email_job.h"
26 #include <list>
27
28 #include "i18n.h"
29
30
31 using std::list;
32 using std::shared_ptr;
33 using std::string;
34 using std::vector;
35 using boost::optional;
36
37
38 SendKDMEmailJob::SendKDMEmailJob (
39         list<KDMWithMetadataPtr> kdms,
40         dcp::NameFormat container_name_format,
41         dcp::NameFormat filename_format,
42         string cpl_name,
43         vector<string> extra_addresses
44         )
45         : Job (shared_ptr<Film>())
46         , _container_name_format (container_name_format)
47         , _filename_format (filename_format)
48         , _cpl_name (cpl_name)
49         , _extra_addresses (extra_addresses)
50 {
51         for (auto i: kdms) {
52                 list<KDMWithMetadataPtr> s;
53                 s.push_back (i);
54                 _kdms.push_back (s);
55         }
56 }
57
58
59 /** @param kdms KDMs to email.
60  *  @param container_name_format Format to use for folders / ZIP files.
61  *  @param filename_format Format to use for filenames.
62  *  @param name_values Values to substitute into \p container_name_format and \p filename_format.
63  *  @param cpl_name Name of the CPL that the KDMs are for.
64  */
65 SendKDMEmailJob::SendKDMEmailJob (
66         list<list<KDMWithMetadataPtr>> kdms,
67         dcp::NameFormat container_name_format,
68         dcp::NameFormat filename_format,
69         string cpl_name,
70         vector<string> extra_addresses
71         )
72         : Job (shared_ptr<Film>())
73         , _container_name_format (container_name_format)
74         , _filename_format (filename_format)
75         , _cpl_name (cpl_name)
76         , _kdms (kdms)
77         , _extra_addresses (extra_addresses)
78 {
79
80 }
81
82
83 SendKDMEmailJob::~SendKDMEmailJob ()
84 {
85         stop_thread ();
86 }
87
88
89 string
90 SendKDMEmailJob::name () const
91 {
92         auto f = _kdms.front().front()->get('f');
93         if (!f || f->empty()) {
94                 return _("Email KDMs");
95         }
96
97         return String::compose (_("Email KDMs for %1"), *f);
98 }
99
100
101 string
102 SendKDMEmailJob::json_name () const
103 {
104         return N_("send_kdm_email");
105 }
106
107
108 void
109 SendKDMEmailJob::run ()
110 {
111         set_progress_unknown ();
112         send_emails (_kdms, _container_name_format, _filename_format, _cpl_name, _extra_addresses);
113         set_progress (1);
114         set_state (FINISHED_OK);
115 }