2 Copyright (C) 2012-2018 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"
28 #include "static_text.h"
29 #include "dcpomatic_button.h"
31 #include "lib/screen.h"
32 #include "lib/screen_kdm.h"
33 #include "lib/send_kdm_email_job.h"
34 #include "lib/job_manager.h"
35 #include "lib/cinema_kdms.h"
36 #include "lib/config.h"
37 #include "lib/cinema.h"
38 #include <libcxml/cxml.h>
39 #include <dcp/exceptions.h>
40 #include <wx/treectrl.h>
41 #include <wx/listctrl.h>
52 using std::runtime_error;
53 using boost::shared_ptr;
56 KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
57 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
61 wxBoxSizer* horizontal = new wxBoxSizer (wxHORIZONTAL);
62 wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
63 wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
65 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
66 horizontal->Add (right, 1, wxEXPAND);
68 /* Font for sub-headings */
69 wxFont subheading_font (*wxNORMAL_FONT);
70 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
72 /* Sub-heading: Screens */
73 wxStaticText* h = new StaticText (this, _("Screens"));
74 h->SetFont (subheading_font);
75 left->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
76 _screens = new ScreensPanel (this);
77 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
79 /* Sub-heading: Timing */
80 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
81 h = new StaticText (this, S_("KDM|Timing"));
82 h->SetFont (subheading_font);
83 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
84 _timing = new KDMTimingPanel (this);
87 /* Sub-heading: CPL */
88 h = new StaticText (this, _("CPL"));
89 h->SetFont (subheading_font);
90 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
91 _cpl = new KDMCPLPanel (this, film->cpls ());
92 right->Add (_cpl, 0, wxEXPAND);
94 /* Sub-heading: Output */
95 h = new StaticText (this, _("Output"));
96 h->SetFont (subheading_font);
97 right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
98 _output = new KDMOutputPanel (this, film->interop ());
99 right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
101 _make = new Button (this, _("Make KDMs"));
102 right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
104 /* Make an overall sizer to get a nice border */
106 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
107 overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
111 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
112 _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
113 _make->Bind (wxEVT_BUTTON, boost::bind (&KDMDialog::make_clicked, this));
115 setup_sensitivity ();
117 SetSizer (overall_sizer);
118 overall_sizer->Layout ();
119 overall_sizer->SetSizeHints (this);
123 KDMDialog::setup_sensitivity ()
125 _screens->setup_sensitivity ();
126 _output->setup_sensitivity ();
127 _make->Enable (!_screens->screens().empty() && _timing->valid() && _cpl->has_selected());
131 KDMDialog::confirm_overwrite (boost::filesystem::path path)
133 return confirm_dialog (
135 wxString::Format (_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
140 KDMDialog::make_clicked ()
142 shared_ptr<const Film> film = _film.lock ();
143 DCPOMATIC_ASSERT (film);
145 list<ScreenKDM> screen_kdms;
148 screen_kdms = film->make_kdms (
149 _screens->screens(), _cpl->cpl(), _timing->from(), _timing->until(), _output->formulation(),
150 !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
153 } catch (runtime_error& e) {
154 error_dialog (this, std_to_wx(e.what()));
158 pair<shared_ptr<Job>, int> result = _output->make (screen_kdms, film->name(), _timing, bind (&KDMDialog::confirm_overwrite, this, _1));
160 JobManager::instance()->add (result.first);
163 if (result.second > 0) {
164 /* XXX: proper plural form support in wxWidgets? */
165 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
168 wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())