Fix various small errors in emailed-KDM zip file format (#478).
[dcpomatic.git] / src / lib / send_kdm_email_job.cc
1 /*
2     Copyright (C) 2013 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 "film.h"
24 #include "cinema_kdms.h"
25 #include <list>
26
27 #include "i18n.h"
28
29 using std::string;
30 using std::list;
31 using boost::shared_ptr;
32
33 /** @param cinema_kdms KDMs to email.
34  *  @param container_name_format Format to ues for folders / ZIP files.
35  *  @param filename_format Format to use for filenames.
36  *  @param name_values Values to substitute into \p container_name_format and \p filename_format.
37  *  @param cpl_name Name of the CPL that the KDMs are for.
38  *  @param log Log to write to, or 0.
39  */
40 SendKDMEmailJob::SendKDMEmailJob (
41         list<CinemaKDMs> cinema_kdms,
42         dcp::NameFormat container_name_format,
43         dcp::NameFormat filename_format,
44         dcp::NameFormat::Map name_values,
45         string cpl_name,
46         shared_ptr<Log> log
47         )
48         : Job (shared_ptr<Film>())
49         , _container_name_format (container_name_format)
50         , _filename_format (filename_format)
51         , _name_values (name_values)
52         , _cpl_name (cpl_name)
53         , _cinema_kdms (cinema_kdms)
54         , _log (log)
55 {
56
57 }
58
59 string
60 SendKDMEmailJob::name () const
61 {
62         dcp::NameFormat::Map::const_iterator i = _name_values.find ('f');
63         if (i == _name_values.end() || i->second.empty ()) {
64                 return _("Email KDMs");
65         }
66
67         return String::compose (_("Email KDMs for %1"), i->second);
68 }
69
70 string
71 SendKDMEmailJob::json_name () const
72 {
73         return N_("send_kdm_email");
74 }
75
76 void
77 SendKDMEmailJob::run ()
78 {
79         set_progress_unknown ();
80         CinemaKDMs::email (_cinema_kdms, _container_name_format, _filename_format, _name_values, _cpl_name, _log);
81         set_progress (1);
82         set_state (FINISHED_OK);
83 }