2 Copyright (C) 2012-2021 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 "dkdm_dialog.h"
25 #include "dkdm_output_panel.h"
26 #include "kdm_cpl_panel.h"
27 #include "kdm_timing_panel.h"
28 #include "recipients_panel.h"
29 #include "static_text.h"
31 #include "lib/config.h"
33 #include "lib/job_manager.h"
34 #include "lib/kdm_with_metadata.h"
35 #include "lib/warnings.h"
36 #include <libcxml/cxml.h>
37 #include <dcp/exceptions.h>
38 DCPOMATIC_DISABLE_WARNINGS
39 #include <wx/listctrl.h>
40 #include <wx/treectrl.h>
41 DCPOMATIC_ENABLE_WARNINGS
51 using std::runtime_error;
52 using std::shared_ptr;
56 using boost::optional;
57 #if BOOST_VERSION >= 106100
58 using namespace boost::placeholders;
62 DKDMDialog::DKDMDialog (wxWindow* parent, shared_ptr<const Film> film)
63 : wxDialog (parent, wxID_ANY, _("Make DKDMs"))
67 auto horizontal = new wxBoxSizer (wxHORIZONTAL);
68 auto left = new wxBoxSizer (wxVERTICAL);
69 auto right = new wxBoxSizer (wxVERTICAL);
71 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
72 horizontal->Add (right, 1, wxEXPAND);
74 /* Font for sub-headings */
75 wxFont subheading_font (*wxNORMAL_FONT);
76 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
78 /* Sub-heading: Screens */
79 auto h = new StaticText (this, _("Recipients"));
80 h->SetFont (subheading_font);
81 left->Add (h, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
82 _recipients = new RecipientsPanel (this);
83 left->Add (_recipients, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
85 /* Sub-heading: Timing */
86 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
87 h = new StaticText (this, S_("KDM|Timing"));
88 h->SetFont (subheading_font);
90 _timing = new KDMTimingPanel (this);
93 /* Sub-heading: CPL */
94 h = new StaticText (this, _("CPL"));
95 h->SetFont (subheading_font);
98 vector<CPLSummary> cpls;
99 for (auto const& i: film->cpls()) {
105 _cpl = new KDMCPLPanel (this, cpls);
106 right->Add (_cpl, 0, wxEXPAND);
108 /* Sub-heading: Output */
109 h = new StaticText (this, _("Output"));
110 h->SetFont (subheading_font);
111 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
112 _output = new DKDMOutputPanel (this);
113 right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
115 _make = new Button (this, _("Make DKDMs"));
116 right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
118 /* Make an overall sizer to get a nice border */
120 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
121 overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
125 _recipients->RecipientsChanged.connect (boost::bind(&DKDMDialog::setup_sensitivity, this));
126 _timing->TimingChanged.connect (boost::bind(&DKDMDialog::setup_sensitivity, this));
127 _make->Bind (wxEVT_BUTTON, boost::bind(&DKDMDialog::make_clicked, this));
129 setup_sensitivity ();
131 SetSizer (overall_sizer);
132 overall_sizer->Layout ();
133 overall_sizer->SetSizeHints (this);
138 DKDMDialog::setup_sensitivity ()
140 _recipients->setup_sensitivity ();
141 _output->setup_sensitivity ();
142 _make->Enable (!_recipients->recipients().empty() && _timing->valid() && _cpl->has_selected());
147 DKDMDialog::confirm_overwrite (boost::filesystem::path path)
149 return confirm_dialog (
151 wxString::Format(_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
157 DKDMDialog::make_clicked ()
159 auto film = _film.lock ();
160 DCPOMATIC_ASSERT (film);
162 list<KDMWithMetadataPtr> kdms;
164 for (auto i: _recipients->recipients()) {
165 auto p = kdm_for_dkdm_recipient (film, _cpl->cpl(), i, _timing->from(), _timing->until());
170 } catch (dcp::BadKDMDateError& e) {
171 if (e.starts_too_early()) {
172 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."));
174 error_dialog (this, _("The KDM end period is after (or close to) the end of the signing certficates' validity period. Either use an earlier end time for this KDM or re-create your signing certificates in the DCP-o-matic preferences window."));
177 } catch (runtime_error& e) {
178 error_dialog (this, std_to_wx(e.what()));
182 auto result = _output->make (kdms, film->name(), bind(&DKDMDialog::confirm_overwrite, this, _1));
184 JobManager::instance()->add (result.first);
187 if (result.second > 0) {
188 /* XXX: proper plural form support in wxWidgets? */
189 auto s = result.second == 1 ? _("%d DKDM written to %s") : _("%d DKDMs written to %s");
192 wxString::Format(s, result.second, std_to_wx(_output->directory().string()).data())