2 Copyright (C) 2015-2022 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/>.
22 #include "check_box.h"
23 #include "confirm_kdm_email_dialog.h"
24 #include "dcpomatic_button.h"
25 #include "extra_kdm_email_dialog.h"
26 #include "kdm_advanced_dialog.h"
27 #include "kdm_choice.h"
28 #include "kdm_output_panel.h"
29 #include "kdm_timing_panel.h"
30 #include "name_format_editor.h"
32 #include "lib/cinema.h"
33 #include "lib/config.h"
34 #include "lib/send_kdm_email_job.h"
35 #include <dcp/exceptions.h>
36 #include <dcp/types.h>
37 #include <dcp/warnings.h>
38 #ifdef DCPOMATIC_USE_OWN_PICKER
39 #include "dir_picker_ctrl.h"
41 LIBDCP_DISABLE_WARNINGS
42 #include <wx/filepicker.h>
43 LIBDCP_ENABLE_WARNINGS
45 LIBDCP_DISABLE_WARNINGS
46 #include <wx/stdpaths.h>
47 LIBDCP_ENABLE_WARNINGS
54 using std::make_shared;
56 using std::shared_ptr;
58 #if BOOST_VERSION >= 106100
59 using namespace boost::placeholders;
63 KDMOutputPanel::KDMOutputPanel (wxWindow* parent)
64 : wxPanel (parent, wxID_ANY)
65 , _forensic_mark_video (true)
66 , _forensic_mark_audio (true)
67 , _forensic_mark_audio_up_to (12)
69 auto table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
70 table->AddGrowableCol (1);
72 add_label_to_sizer (table, this, _("KDM type"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
74 auto type = new wxBoxSizer (wxHORIZONTAL);
75 _type = new KDMChoice (this);
76 type->Add (_type, 1, wxTOP, DCPOMATIC_CHOICE_TOP_PAD);
77 _type->set(Config::instance()->default_kdm_type());
78 auto advanced = new Button (this, _("Advanced..."));
79 type->Add (advanced, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
80 table->Add (type, 1, wxTOP, DCPOMATIC_CHOICE_TOP_PAD);
82 add_label_to_sizer(table, this, _("Annotation text"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
83 _annotation_text = new wxTextCtrl(this, wxID_ANY);
84 table->Add(_annotation_text, 1, wxEXPAND);
86 add_label_to_sizer (table, this, _("Folder / ZIP name format"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
87 _container_name_format = new NameFormatEditor (this, Config::instance()->kdm_container_name_format(), dcp::NameFormat::Map(), dcp::NameFormat::Map(), "");
88 table->Add (_container_name_format->panel(), 1, wxEXPAND);
90 auto format = create_label (this, _("Filename format"), true);
91 auto align = new wxBoxSizer (wxHORIZONTAL);
93 align->Add (format, 0, wxTOP, 2);
94 table->Add (align, 0, wxALIGN_RIGHT | wxRIGHT, DCPOMATIC_SIZER_GAP - 2);
96 align->Add (format, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
97 table->Add (align, 0, wxTOP | wxRIGHT | wxALIGN_TOP, DCPOMATIC_SIZER_GAP);
99 dcp::NameFormat::Map titles;
100 titles['f'] = wx_to_std (_("film name"));
101 titles['c'] = wx_to_std (_("cinema"));
102 titles['s'] = wx_to_std (_("screen"));
103 titles['b'] = wx_to_std (_("from date/time"));
104 titles['e'] = wx_to_std (_("to date/time"));
105 dcp::NameFormat::Map ex;
107 ex['c'] = "Lumière";
108 ex['s'] = "Screen 1";
109 ex['b'] = "2012/03/15 12:30";
110 ex['e'] = "2012/03/22 02:30";
111 _filename_format = new NameFormatEditor (this, Config::instance()->kdm_filename_format(), titles, ex, ".xml");
112 table->Add (_filename_format->panel(), 1, wxEXPAND);
114 _write_to = new CheckBox (this, _("Write to"));
115 table->Add (_write_to, 1, wxEXPAND);
117 #ifdef DCPOMATIC_USE_OWN_PICKER
118 _folder = new DirPickerCtrl (this);
120 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
123 auto path = Config::instance()->default_kdm_directory();
125 _folder->SetPath (std_to_wx (path->string ()));
127 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
130 table->Add (_folder, 1, wxEXPAND);
132 auto write_options = new wxBoxSizer(wxVERTICAL);
133 _write_flat = new wxRadioButton (this, wxID_ANY, _("Write all KDMs to the same folder"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
134 write_options->Add (_write_flat, 1, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
135 _write_folder = new wxRadioButton (this, wxID_ANY, _("Write a folder for each cinema's KDMs"));
136 write_options->Add (_write_folder, 1, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
137 _write_zip = new wxRadioButton (this, wxID_ANY, _("Write a ZIP file for each cinema's KDMs"));
138 write_options->Add (_write_zip, 1, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
139 table->AddSpacer (0);
140 table->Add (write_options);
142 _email = new CheckBox (this, _("Send by email"));
143 table->Add (_email, 1, wxEXPAND);
144 auto add_email_addresses = new wxButton(this, wxID_ANY, _("Set additional email addresses..."));
145 table->Add (add_email_addresses);
147 switch (Config::instance()->last_kdm_write_type().get_value_or(Config::KDM_WRITE_FLAT)) {
148 case Config::KDM_WRITE_FLAT:
149 _write_flat->SetValue (true);
151 case Config::KDM_WRITE_FOLDER:
152 _write_folder->SetValue (true);
154 case Config::KDM_WRITE_ZIP:
155 _write_zip->SetValue (true);
159 _write_to->SetValue (Config::instance()->write_kdms_to_disk());
160 _email->SetValue (Config::instance()->email_kdms());
162 _write_to->bind(&KDMOutputPanel::write_to_changed, this);
163 _email->bind(&KDMOutputPanel::email_changed, this);
164 add_email_addresses->Bind (wxEVT_BUTTON, boost::bind(&KDMOutputPanel::add_email_addresses_clicked, this));
165 _write_flat->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::kdm_write_type_changed, this));
166 _write_folder->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::kdm_write_type_changed, this));
167 _write_zip->Bind (wxEVT_RADIOBUTTON, boost::bind (&KDMOutputPanel::kdm_write_type_changed, this));
168 advanced->Bind (wxEVT_BUTTON, boost::bind (&KDMOutputPanel::advanced_clicked, this));
175 KDMOutputPanel::write_to_changed ()
177 Config::instance()->set_write_kdms_to_disk(_write_to->GetValue());
178 setup_sensitivity ();
184 KDMOutputPanel::email_changed ()
186 Config::instance()->set_email_kdms(_email->GetValue());
187 setup_sensitivity ();
193 KDMOutputPanel::setup_sensitivity ()
195 bool const write = _write_to->GetValue ();
196 _folder->Enable (write);
197 _write_flat->Enable (write);
198 _write_folder->Enable (write);
199 _write_zip->Enable (write);
204 KDMOutputPanel::advanced_clicked ()
206 KDMAdvancedDialog dialog(this, _forensic_mark_video, _forensic_mark_audio, _forensic_mark_audio_up_to);
208 _forensic_mark_video = dialog.forensic_mark_video();
209 _forensic_mark_audio = dialog.forensic_mark_audio();
210 _forensic_mark_audio_up_to = dialog.forensic_mark_audio_up_to();
215 KDMOutputPanel::kdm_write_type_changed ()
217 if (_write_flat->GetValue()) {
218 Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_FLAT);
219 } else if (_write_folder->GetValue()) {
220 Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_FOLDER);
221 } else if (_write_zip->GetValue()) {
222 Config::instance()->set_last_kdm_write_type (Config::KDM_WRITE_ZIP);
227 pair<shared_ptr<Job>, int>
228 KDMOutputPanel::make (
229 list<KDMWithMetadataPtr> kdms, string name, function<bool (boost::filesystem::path)> confirm_overwrite
232 auto const cinema_kdms = collect (kdms);
234 /* Decide whether to proceed */
238 if (_email->GetValue ()) {
240 if (Config::instance()->mail_server().empty ()) {
242 error_dialog (this, _("You must set up a mail server in Preferences before you can send emails."));
245 bool const cinemas_with_no_email = std::any_of(
246 cinema_kdms.begin(), cinema_kdms.end(),
247 [](list<KDMWithMetadataPtr> const& list) { return list.front()->emails().empty(); }
250 if (proceed && cinemas_with_no_email && !confirm_dialog (
252 _("You have selected some cinemas that have no configured email address. Do you want to continue?")
257 if (proceed && Config::instance()->confirm_kdm_email ()) {
259 for (auto const& i: cinema_kdms) {
260 for (auto j: i.front()->emails()) {
261 emails.push_back (j);
265 if (!emails.empty ()) {
266 auto d = new ConfirmKDMEmailDialog (this, emails);
267 if (d->ShowModal() == wxID_CANCEL) {
278 Config::instance()->set_kdm_filename_format (_filename_format->get ());
285 if (_write_to->GetValue()) {
286 if (_write_flat->GetValue()) {
287 written = write_files (
290 _filename_format->get(),
293 } else if (_write_folder->GetValue()) {
294 written = write_directories (
297 _container_name_format->get(),
298 _filename_format->get(),
301 } else if (_write_zip->GetValue()) {
302 written = write_zip_files (
305 _container_name_format->get(),
306 _filename_format->get(),
312 if (_email->GetValue ()) {
313 job = make_shared<SendKDMEmailJob>(
315 _container_name_format->get(),
316 _filename_format->get(),
322 } catch (dcp::NotEncryptedError& e) {
323 error_dialog (this, _("CPL's content is not encrypted."));
324 } catch (exception& e) {
325 error_dialog (this, std_to_wx(e.what()));
327 error_dialog (this, _("An unknown exception occurred."));
330 return make_pair (job, written);
335 KDMOutputPanel::formulation () const
341 boost::filesystem::path
342 KDMOutputPanel::directory () const
344 return wx_to_std (_folder->GetPath ());
349 KDMOutputPanel::add_email_addresses_clicked ()
351 ExtraKDMEmailDialog dialog(this, _extra_addresses);
352 if (dialog.ShowModal() == wxID_OK) {
353 _extra_addresses = dialog.get();
359 KDMOutputPanel::method_selected() const
361 return _write_to->GetValue() || _email->GetValue();
366 KDMOutputPanel::set_annotation_text(string text)
368 checked_set(_annotation_text, std::move(text));
373 KDMOutputPanel::annotation_text() const
375 return wx_to_std(_annotation_text->GetValue());