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"
28 #include "lib/screen.h"
29 #include "lib/screen_kdm.h"
30 #include "lib/send_kdm_email_job.h"
31 #include "lib/job_manager.h"
32 #include "lib/cinema_kdms.h"
33 #include <libcxml/cxml.h>
34 #include <dcp/exceptions.h>
35 #include <wx/treectrl.h>
36 #include <wx/listctrl.h>
47 using boost::shared_ptr;
49 KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
50 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
54 wxBoxSizer* horizontal = new wxBoxSizer (wxHORIZONTAL);
55 wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
56 wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
58 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
59 horizontal->Add (right, 1, wxEXPAND);
61 /* Font for sub-headings */
62 wxFont subheading_font (*wxNORMAL_FONT);
63 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
65 /* Sub-heading: Screens */
66 wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
67 h->SetFont (subheading_font);
68 left->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
69 _screens = new ScreensPanel (this);
70 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
72 /* Sub-heading: Timing */
73 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
74 h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
75 h->SetFont (subheading_font);
76 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
77 _timing = new KDMTimingPanel (this);
80 /* Sub-heading: CPL */
81 h = new wxStaticText (this, wxID_ANY, _("CPL"));
82 h->SetFont (subheading_font);
83 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
84 _cpl = new KDMCPLPanel (this, film->cpls ());
85 right->Add (_cpl, 0, wxEXPAND);
87 /* Sub-heading: Output */
88 h = new wxStaticText (this, wxID_ANY, _("Output"));
89 h->SetFont (subheading_font);
90 right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
91 _output = new KDMOutputPanel (this, film->interop ());
92 right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
94 _make = new wxButton (this, wxID_ANY, _("Make KDMs"));
95 right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
97 /* Make an overall sizer to get a nice border */
99 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
100 overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
104 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
105 _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
106 _make->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::make_clicked, this));
108 setup_sensitivity ();
110 SetSizer (overall_sizer);
111 overall_sizer->Layout ();
112 overall_sizer->SetSizeHints (this);
116 KDMDialog::setup_sensitivity ()
118 _screens->setup_sensitivity ();
119 _output->setup_sensitivity ();
120 _make->Enable (!_screens->screens().empty() && _timing->valid() && _cpl->has_selected());
124 KDMDialog::make_clicked ()
126 shared_ptr<const Film> film = _film.lock ();
127 DCPOMATIC_ASSERT (film);
129 _output->save_kdm_name_format ();
132 list<ScreenKDM> screen_kdms = film->make_kdms (
133 _screens->screens(), _cpl->cpl(), _timing->from(), _timing->until(), _output->formulation()
136 dcp::NameFormat::Map name_values;
137 name_values['f'] = film->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 (_output->write_to ()) {
142 ScreenKDM::write_files (
144 _output->directory(),
145 _output->name_format(),
150 if (_output->email ()) {
151 JobManager::instance()->add (
152 shared_ptr<Job> (new SendKDMEmailJob (
153 CinemaKDMs::collect (screen_kdms),
154 _output->name_format(),
161 } catch (dcp::NotEncryptedError& e) {
162 error_dialog (this, _("CPL's content is not encrypted."));
163 } catch (exception& e) {
164 error_dialog (this, e.what ());
166 error_dialog (this, _("An unknown exception occurred."));