2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "kdm_dialog.h"
21 #include "cinema_dialog.h"
22 #include "screen_dialog.h"
24 #include "screens_panel.h"
25 #include "lib/cinema.h"
26 #include "lib/config.h"
28 #include "lib/screen.h"
29 #include <libcxml/cxml.h>
30 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
31 #include "dir_picker_ctrl.h"
33 #include <wx/filepicker.h>
35 #include <wx/treectrl.h>
36 #include <wx/datectrl.h>
37 #include <wx/timectrl.h>
38 #include <wx/stdpaths.h>
39 #include <wx/listctrl.h>
49 using boost::shared_ptr;
51 KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
52 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
55 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
57 /* Font for sub-headings */
58 wxFont subheading_font (*wxNORMAL_FONT);
59 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
61 /* Sub-heading: Screens */
62 wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
63 h->SetFont (subheading_font);
64 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
65 _screens = new ScreensPanel (this);
66 vertical->Add (_screens, 1, wxEXPAND);
68 /* Sub-heading: Timing */
69 h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
70 h->SetFont (subheading_font);
71 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
73 wxFlexGridSizer* table = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
74 add_label_to_sizer (table, this, _("From"), true);
77 _from_date = new wxDatePickerCtrl (this, wxID_ANY, from);
78 table->Add (_from_date, 1, wxEXPAND);
79 _from_time = new wxTimePickerCtrl (this, wxID_ANY, from);
80 table->Add (_from_time, 1, wxEXPAND);
82 add_label_to_sizer (table, this, _("Until"), true);
85 to.Add (wxDateSpan (0, 0, 1, 0));
86 _until_date = new wxDatePickerCtrl (this, wxID_ANY, to);
87 table->Add (_until_date, 1, wxEXPAND);
88 _until_time = new wxTimePickerCtrl (this, wxID_ANY, to);
89 table->Add (_until_time, 1, wxEXPAND);
91 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
94 /* Sub-heading: CPL */
95 h = new wxStaticText (this, wxID_ANY, _("CPL"));
96 h->SetFont (subheading_font);
97 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
100 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
101 add_label_to_sizer (s, this, _("CPL"), true);
102 _cpl = new wxChoice (this, wxID_ANY);
103 s->Add (_cpl, 1, wxEXPAND);
104 _cpl_browse = new wxButton (this, wxID_ANY, _("Browse..."));
105 s->Add (_cpl_browse, 0);
106 vertical->Add (s, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
109 table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
110 add_label_to_sizer (table, this, _("DCP directory"), true);
111 _dcp_directory = new wxStaticText (this, wxID_ANY, "");
112 table->Add (_dcp_directory);
113 add_label_to_sizer (table, this, _("CPL ID"), true);
114 _cpl_id = new wxStaticText (this, wxID_ANY, "");
115 table->Add (_cpl_id);
116 add_label_to_sizer (table, this, _("CPL annotation text"), true);
117 _cpl_annotation_text = new wxStaticText (this, wxID_ANY, "");
118 table->Add (_cpl_annotation_text);
119 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
121 _cpls = film->cpls ();
122 update_cpl_choice ();
125 /* Sub-heading: Output */
126 h = new wxStaticText (this, wxID_ANY, _("Output"));
127 h->SetFont (subheading_font);
128 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
130 table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
132 add_label_to_sizer (table, this, _("KDM type"), true);
133 _type = new wxChoice (this, wxID_ANY);
134 _type->Append ("Modified Transitional 1", ((void *) dcp::MODIFIED_TRANSITIONAL_1));
135 if (!film->interop ()) {
136 _type->Append ("DCI Any", ((void *) dcp::DCI_ANY));
137 _type->Append ("DCI Specific", ((void *) dcp::DCI_SPECIFIC));
139 table->Add (_type, 1, wxEXPAND);
140 _type->SetSelection (0);
142 _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
143 table->Add (_write_to, 1, wxEXPAND);
145 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
146 _folder = new DirPickerCtrl (this);
148 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
151 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
153 table->Add (_folder, 1, wxEXPAND);
155 _email = new wxRadioButton (this, wxID_ANY, _("Send by email"));
156 table->Add (_email, 1, wxEXPAND);
157 table->AddSpacer (0);
159 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
161 /* Make an overall sizer to get a nice border, and put some buttons in */
163 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
164 overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
166 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
168 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
171 _write_to->SetValue (true);
175 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
177 _cpl->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&KDMDialog::update_cpl_summary, this));
178 _cpl_browse->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::cpl_browse_clicked, this));
180 _write_to->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
181 _email->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
183 setup_sensitivity ();
185 SetSizer (overall_sizer);
186 overall_sizer->Layout ();
187 overall_sizer->SetSizeHints (this);
191 KDMDialog::setup_sensitivity ()
193 _screens->setup_sensitivity ();
195 bool const sd = _cpl->GetSelection() != -1;
197 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
199 ok->Enable (!_screens->screens().empty() && sd);
202 _folder->Enable (_write_to->GetValue ());
205 boost::posix_time::ptime
206 KDMDialog::from () const
208 return posix_time (_from_date, _from_time);
211 boost::posix_time::ptime
212 KDMDialog::posix_time (wxDatePickerCtrl* date_picker, wxTimePickerCtrl* time_picker)
214 wxDateTime const date = date_picker->GetValue ();
215 wxDateTime const time = time_picker->GetValue ();
216 return boost::posix_time::ptime (
217 boost::gregorian::date (date.GetYear(), date.GetMonth() + 1, date.GetDay()),
218 boost::posix_time::time_duration (time.GetHour(), time.GetMinute(), time.GetSecond())
222 boost::posix_time::ptime
223 KDMDialog::until () const
225 return posix_time (_until_date, _until_time);
228 boost::filesystem::path
229 KDMDialog::cpl () const
231 int const item = _cpl->GetSelection ();
232 DCPOMATIC_ASSERT (item >= 0);
233 return _cpls[item].cpl_file;
236 boost::filesystem::path
237 KDMDialog::directory () const
239 return wx_to_std (_folder->GetPath ());
243 KDMDialog::write_to () const
245 return _write_to->GetValue ();
249 KDMDialog::formulation () const
251 return (dcp::Formulation) reinterpret_cast<intptr_t> (_type->GetClientData (_type->GetSelection()));
255 KDMDialog::update_cpl_choice ()
259 for (vector<CPLSummary>::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
260 _cpl->Append (std_to_wx (i->cpl_id));
262 if (_cpls.size() > 0) {
263 _cpl->SetSelection (0);
267 update_cpl_summary ();
271 KDMDialog::update_cpl_summary ()
273 int const n = _cpl->GetSelection();
274 if (n == wxNOT_FOUND) {
278 _dcp_directory->SetLabel (std_to_wx (_cpls[n].dcp_directory));
279 _cpl_id->SetLabel (std_to_wx (_cpls[n].cpl_id));
280 _cpl_annotation_text->SetLabel (std_to_wx (_cpls[n].cpl_annotation_text));
284 KDMDialog::cpl_browse_clicked ()
286 wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
287 if (d->ShowModal() == wxID_CANCEL) {
292 boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
293 boost::filesystem::path dcp_dir = cpl_file.parent_path ();
297 /* XXX: hack alert */
298 cxml::Document cpl_document ("CompositionPlaylist");
299 cpl_document.read_file (cpl_file);
304 dcp_dir.filename().string(),
305 cpl_document.string_child("Id").substr (9),
306 cpl_document.string_child ("ContentTitleText"),
310 } catch (cxml::Error) {
311 error_dialog (this, _("This is not a valid CPL file"));
315 update_cpl_choice ();
316 _cpl->SetSelection (_cpls.size() - 1);
317 update_cpl_summary ();
320 list<shared_ptr<Screen> >
321 KDMDialog::screens () const
323 return _screens->screens ();