2 Copyright (C) 2015-2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #include "lib/config.h"
22 #include "lib/cinema.h"
23 #include "lib/cinema_kdms.h"
24 #include "lib/send_kdm_email_job.h"
25 #include "kdm_output_panel.h"
26 #include "kdm_timing_panel.h"
27 #include "confirm_kdm_email_dialog.h"
29 #include "name_format_editor.h"
30 #include <dcp/exceptions.h>
31 #include <dcp/types.h>
32 #ifdef DCPOMATIC_USE_OWN_PICKER
33 #include "dir_picker_ctrl.h"
35 #include <wx/filepicker.h>
37 #include <wx/stdpaths.h>
44 using boost::shared_ptr;
45 using boost::function;
47 KDMOutputPanel::KDMOutputPanel (wxWindow* parent, bool interop)
48 : wxPanel (parent, wxID_ANY)
50 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
52 add_label_to_sizer (table, this, _("KDM type"), true);
53 _type = new wxChoice (this, wxID_ANY);
54 _type->Append ("Modified Transitional 1", ((void *) dcp::MODIFIED_TRANSITIONAL_1));
55 _type->Append ("Modified Transitional 1 (without AuthorizedDeviceInfo)", ((void *) dcp::MODIFIED_TRANSITIONAL_TEST));
57 _type->Append ("DCI Any", ((void *) dcp::DCI_ANY));
58 _type->Append ("DCI Specific", ((void *) dcp::DCI_SPECIFIC));
60 table->Add (_type, 1, wxEXPAND);
61 _type->SetSelection (0);
64 int flags = wxALIGN_TOP | wxTOP | wxLEFT | wxRIGHT;
65 wxString t = _("Filename format");
67 flags |= wxALIGN_RIGHT;
70 wxStaticText* m = new wxStaticText (this, wxID_ANY, t);
71 table->Add (m, 0, flags, DCPOMATIC_SIZER_Y_GAP);
74 dcp::NameFormat::Map titles;
75 titles['f'] = "film name";
76 titles['c'] = "cinema";
77 titles['s'] = "screen";
78 titles['b'] = "from date/time";
79 titles['e'] = "to date/time";
80 dcp::NameFormat::Map ex;
84 ex['b'] = "2012/03/15 12:30";
85 ex['e'] = "2012/03/22 02:30";
86 _filename_format = new NameFormatEditor (this, Config::instance()->kdm_filename_format(), titles, ex, ".xml");
87 table->Add (_filename_format->panel(), 1, wxEXPAND);
89 _write_to = new wxCheckBox (this, wxID_ANY, _("Write to"));
90 table->Add (_write_to, 1, wxEXPAND);
92 #ifdef DCPOMATIC_USE_OWN_PICKER
93 _folder = new DirPickerCtrl (this);
95 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
98 boost::optional<boost::filesystem::path> path = Config::instance()->default_kdm_directory ();
100 _folder->SetPath (std_to_wx (path->string ()));
102 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
105 table->Add (_folder, 1, wxEXPAND);
107 _email = new wxCheckBox (this, wxID_ANY, _("Send by email"));
108 table->Add (_email, 1, wxEXPAND);
109 table->AddSpacer (0);
111 _write_to->SetValue (true);
113 _write_to->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::setup_sensitivity, this));
114 _email->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::setup_sensitivity, this));
120 KDMOutputPanel::setup_sensitivity ()
122 _folder->Enable (_write_to->GetValue ());
125 pair<shared_ptr<Job>, int>
126 KDMOutputPanel::make (
127 list<ScreenKDM> screen_kdms, string name, KDMTimingPanel* timing, function<bool (boost::filesystem::path)> confirm_overwrite, shared_ptr<Log> log
130 Config::instance()->set_kdm_filename_format (_filename_format->get ());
136 dcp::NameFormat::Map name_values;
137 name_values['f'] = name;
138 name_values['b'] = dcp::LocalTime(timing->from()).date() + " " + dcp::LocalTime(timing->from()).time_of_day();
139 name_values['e'] = dcp::LocalTime(timing->until()).date() + " " + dcp::LocalTime(timing->until()).time_of_day();
141 if (_write_to->GetValue ()) {
142 written = ScreenKDM::write_files (
145 _filename_format->get(),
151 if (_email->GetValue ()) {
153 list<CinemaKDMs> const cinema_kdms = CinemaKDMs::collect (screen_kdms);
157 if (Config::instance()->confirm_kdm_email ()) {
159 BOOST_FOREACH (CinemaKDMs i, cinema_kdms) {
160 BOOST_FOREACH (string j, i.cinema->emails) {
161 emails.push_back (j);
165 ConfirmKDMEmailDialog* d = new ConfirmKDMEmailDialog (this, emails);
166 if (d->ShowModal() == wxID_CANCEL) {
173 new SendKDMEmailJob (
175 _filename_format->get(),
183 } catch (dcp::NotEncryptedError& e) {
184 error_dialog (this, _("CPL's content is not encrypted."));
185 } catch (exception& e) {
186 error_dialog (this, e.what ());
188 error_dialog (this, _("An unknown exception occurred."));
191 return make_pair (job, written);
195 KDMOutputPanel::formulation () const
197 return (dcp::Formulation) reinterpret_cast<intptr_t> (_type->GetClientData (_type->GetSelection()));
200 boost::filesystem::path
201 KDMOutputPanel::directory () const
203 return wx_to_std (_folder->GetPath ());