2 Copyright (C) 2012-2016 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 "kdm_dialog.h"
23 #include "screens_panel.h"
24 #include "kdm_timing_panel.h"
25 #include "kdm_output_panel.h"
26 #include "kdm_cpl_panel.h"
27 #include "confirm_kdm_email_dialog.h"
29 #include "lib/screen.h"
30 #include "lib/screen_kdm.h"
31 #include "lib/send_kdm_email_job.h"
32 #include "lib/job_manager.h"
33 #include "lib/cinema_kdms.h"
34 #include "lib/config.h"
35 #include "lib/cinema.h"
36 #include <libcxml/cxml.h>
37 #include <dcp/exceptions.h>
38 #include <wx/treectrl.h>
39 #include <wx/listctrl.h>
50 using boost::shared_ptr;
52 KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
53 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
57 wxBoxSizer* horizontal = new wxBoxSizer (wxHORIZONTAL);
58 wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
59 wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
61 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
62 horizontal->Add (right, 1, wxEXPAND);
64 /* Font for sub-headings */
65 wxFont subheading_font (*wxNORMAL_FONT);
66 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
68 /* Sub-heading: Screens */
69 wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
70 h->SetFont (subheading_font);
71 left->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
72 _screens = new ScreensPanel (this);
73 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
75 /* Sub-heading: Timing */
76 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
77 h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
78 h->SetFont (subheading_font);
79 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
80 _timing = new KDMTimingPanel (this);
83 /* Sub-heading: CPL */
84 h = new wxStaticText (this, wxID_ANY, _("CPL"));
85 h->SetFont (subheading_font);
86 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
87 _cpl = new KDMCPLPanel (this, film->cpls ());
88 right->Add (_cpl, 0, wxEXPAND);
90 /* Sub-heading: Output */
91 h = new wxStaticText (this, wxID_ANY, _("Output"));
92 h->SetFont (subheading_font);
93 right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
94 _output = new KDMOutputPanel (this, film->interop ());
95 right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
97 _make = new wxButton (this, wxID_ANY, _("Make KDMs"));
98 right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
100 /* Make an overall sizer to get a nice border */
102 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
103 overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
107 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
108 _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
109 _make->Bind (wxEVT_BUTTON, boost::bind (&KDMDialog::make_clicked, this));
111 setup_sensitivity ();
113 SetSizer (overall_sizer);
114 overall_sizer->Layout ();
115 overall_sizer->SetSizeHints (this);
119 KDMDialog::setup_sensitivity ()
121 _screens->setup_sensitivity ();
122 _output->setup_sensitivity ();
123 _make->Enable (!_screens->screens().empty() && _timing->valid() && _cpl->has_selected());
127 KDMDialog::make_clicked ()
129 shared_ptr<const Film> film = _film.lock ();
130 DCPOMATIC_ASSERT (film);
132 _output->save_kdm_name_format ();
135 list<ScreenKDM> screen_kdms = film->make_kdms (
136 _screens->screens(), _cpl->cpl(), _timing->from(), _timing->until(), _output->formulation()
139 dcp::NameFormat::Map name_values;
140 name_values['f'] = film->name();
141 name_values['b'] = dcp::LocalTime(_timing->from()).date() + " " + dcp::LocalTime(_timing->from()).time_of_day();
142 name_values['e'] = dcp::LocalTime(_timing->until()).date() + " " + dcp::LocalTime(_timing->until()).time_of_day();
144 if (_output->write_to ()) {
145 ScreenKDM::write_files (
147 _output->directory(),
148 _output->name_format(),
153 if (_output->email ()) {
155 list<CinemaKDMs> const cinema_kdms = CinemaKDMs::collect (screen_kdms);
159 if (Config::instance()->confirm_kdm_email ()) {
161 BOOST_FOREACH (CinemaKDMs i, cinema_kdms) {
162 BOOST_FOREACH (string j, i.cinema->emails) {
163 emails.push_back (j);
167 ConfirmKDMEmailDialog* d = new ConfirmKDMEmailDialog (this, emails);
168 if (d->ShowModal() == wxID_CANCEL) {
174 JobManager::instance()->add (
175 shared_ptr<Job> (new SendKDMEmailJob (
177 _output->name_format(),
185 } catch (dcp::NotEncryptedError& e) {
186 error_dialog (this, _("CPL's content is not encrypted."));
187 } catch (exception& e) {
188 error_dialog (this, e.what ());
190 error_dialog (this, _("An unknown exception occurred."));