2 Copyright (C) 2012-2019 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 "confirm_kdm_email_dialog.h"
23 #include "dcpomatic_button.h"
24 #include "invalid_certificate_period_dialog.h"
25 #include "kdm_cpl_panel.h"
26 #include "kdm_dialog.h"
27 #include "kdm_output_panel.h"
28 #include "kdm_timing_panel.h"
29 #include "screens_panel.h"
30 #include "static_text.h"
32 #include "lib/cinema.h"
33 #include "lib/config.h"
35 #include "lib/job_manager.h"
36 #include "lib/kdm_with_metadata.h"
37 #include "lib/kdm_util.h"
38 #include "lib/screen.h"
39 #include <libcxml/cxml.h>
41 #include <dcp/exceptions.h>
42 #include <dcp/warnings.h>
43 LIBDCP_DISABLE_WARNINGS
44 #include <wx/listctrl.h>
45 #include <wx/treectrl.h>
46 LIBDCP_ENABLE_WARNINGS
54 using std::runtime_error;
55 using std::shared_ptr;
59 using boost::optional;
60 #if BOOST_VERSION >= 106100
61 using namespace boost::placeholders;
65 KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
66 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
70 auto horizontal = new wxBoxSizer (wxHORIZONTAL);
71 auto left = new wxBoxSizer (wxVERTICAL);
72 auto right = new wxBoxSizer (wxVERTICAL);
74 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
75 horizontal->Add (right, 1, wxEXPAND);
77 /* Font for sub-headings */
78 wxFont subheading_font (*wxNORMAL_FONT);
79 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
81 /* Sub-heading: Screens */
82 auto h = new StaticText (this, _("Screens"));
83 h->SetFont (subheading_font);
84 left->Add (h, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
85 _screens = new ScreensPanel (this);
86 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
88 /* Sub-heading: Timing */
89 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
90 h = new StaticText (this, S_("KDM|Timing"));
91 h->SetFont (subheading_font);
93 _timing = new KDMTimingPanel (this);
96 /* Sub-heading: CPL */
97 h = new StaticText (this, _("CPL"));
98 h->SetFont (subheading_font);
101 vector<CPLSummary> cpls;
102 for (auto const& i: film->cpls()) {
108 _cpl = new KDMCPLPanel (this, cpls);
109 right->Add (_cpl, 0, wxEXPAND);
111 /* Sub-heading: Output */
112 h = new StaticText (this, _("Output"));
113 h->SetFont (subheading_font);
114 right->Add(h, 0, wxTOP, DCPOMATIC_SUBHEADING_TOP_PAD);
115 _output = new KDMOutputPanel (this);
116 right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
118 _make = new Button (this, _("Make KDMs"));
119 right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
121 /* Make an overall sizer to get a nice border */
123 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
124 overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
128 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
129 _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
130 _make->Bind (wxEVT_BUTTON, boost::bind (&KDMDialog::make_clicked, this));
131 _cpl->Changed.connect(boost::bind(&KDMDialog::cpl_changed, this));
134 setup_sensitivity ();
136 SetSizer (overall_sizer);
137 overall_sizer->Layout ();
138 overall_sizer->SetSizeHints (this);
143 KDMDialog::cpl_changed()
146 dcp::CPL cpl(_cpl->cpl());
147 if (auto text = cpl.annotation_text()) {
148 _output->set_annotation_text(*text);
157 KDMDialog::setup_sensitivity ()
159 _screens->setup_sensitivity ();
160 _output->setup_sensitivity ();
161 _make->Enable (!_screens->screens().empty() && _timing->valid() && _cpl->has_selected());
166 KDMDialog::confirm_overwrite (boost::filesystem::path path)
168 return confirm_dialog (
170 wxString::Format (_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
176 KDMDialog::make_clicked ()
178 auto film = _film.lock ();
179 DCPOMATIC_ASSERT (film);
181 list<KDMWithMetadataPtr> kdms;
183 /* Start off by enabling forensic marking for all */
184 optional<int> for_audio;
185 if (!_output->forensic_mark_audio()) {
186 /* No forensic marking for audio */
188 } else if (_output->forensic_mark_audio_up_to()) {
189 /* Forensic mark up to this channel; disabled on channels greater than this */
190 for_audio = _output->forensic_mark_audio_up_to();
193 vector<KDMCertificatePeriod> period_checks;
195 std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, this](dcp::LocalTime begin, dcp::LocalTime end) {
196 return film->make_kdm(_cpl->cpl(), begin, end);
199 for (auto i: _screens->screens()) {
200 auto p = kdm_for_screen(make_kdm, i, _timing->from(), _timing->until(), _output->formulation(), !_output->forensic_mark_video(), for_audio, period_checks);
208 period_checks.begin(),
210 [](KDMCertificatePeriod const& p) { return p.overlap != KDMCertificateOverlap::KDM_WITHIN_CERTIFICATE; }
211 ) != period_checks.end()) {
212 InvalidCertificatePeriodDialog dialog(this, period_checks);
213 if (dialog.ShowModal() == wxID_CANCEL) {
218 } catch (dcp::BadKDMDateError& e) {
219 if (e.starts_too_early()) {
220 error_dialog (this, _("The KDM start period is before (or close to) the start of the signing certificate's validity period. Use a later start time for this KDM."));
222 error_dialog (this, _("The KDM end period is after (or close to) the end of the signing certificates' validity period. Either use an earlier end time for this KDM or re-create your signing certificates in the DCP-o-matic preferences window."));
225 } catch (runtime_error& e) {
226 error_dialog (this, std_to_wx(e.what()));
230 auto result = _output->make(kdms, film->dcp_name(), bind (&KDMDialog::confirm_overwrite, this, _1));
232 JobManager::instance()->add (result.first);
235 if (result.second > 0) {
236 /* XXX: proper plural form support in wxWidgets? */
237 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
240 wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())