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