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 "kdm_timing_panel.h"
26 #include "lib/cinema.h"
27 #include "lib/config.h"
29 #include "lib/screen.h"
30 #include <libcxml/cxml.h>
31 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
32 #include "dir_picker_ctrl.h"
34 #include <wx/filepicker.h>
36 #include <wx/treectrl.h>
37 #include <wx/stdpaths.h>
38 #include <wx/listctrl.h>
48 using boost::shared_ptr;
50 KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
51 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
54 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
56 /* Font for sub-headings */
57 wxFont subheading_font (*wxNORMAL_FONT);
58 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
60 /* Sub-heading: Screens */
61 wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
62 h->SetFont (subheading_font);
63 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
64 _screens = new ScreensPanel (this);
65 vertical->Add (_screens, 1, wxEXPAND);
67 /* Sub-heading: Timing */
68 h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
69 h->SetFont (subheading_font);
70 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
71 _timing = new KDMTimingPanel (this);
72 vertical->Add (_timing);
74 /* Sub-heading: CPL */
75 h = new wxStaticText (this, wxID_ANY, _("CPL"));
76 h->SetFont (subheading_font);
77 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
80 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
81 add_label_to_sizer (s, this, _("CPL"), true);
82 _cpl = new wxChoice (this, wxID_ANY);
83 s->Add (_cpl, 1, wxEXPAND);
84 _cpl_browse = new wxButton (this, wxID_ANY, _("Browse..."));
85 s->Add (_cpl_browse, 0);
86 vertical->Add (s, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
89 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
90 add_label_to_sizer (table, this, _("DCP directory"), true);
91 _dcp_directory = new wxStaticText (this, wxID_ANY, "");
92 table->Add (_dcp_directory);
93 add_label_to_sizer (table, this, _("CPL ID"), true);
94 _cpl_id = new wxStaticText (this, wxID_ANY, "");
96 add_label_to_sizer (table, this, _("CPL annotation text"), true);
97 _cpl_annotation_text = new wxStaticText (this, wxID_ANY, "");
98 table->Add (_cpl_annotation_text);
99 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
101 _cpls = film->cpls ();
102 update_cpl_choice ();
105 /* Sub-heading: Output */
106 h = new wxStaticText (this, wxID_ANY, _("Output"));
107 h->SetFont (subheading_font);
108 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
110 table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, 0);
112 add_label_to_sizer (table, this, _("KDM type"), true);
113 _type = new wxChoice (this, wxID_ANY);
114 _type->Append ("Modified Transitional 1", ((void *) dcp::MODIFIED_TRANSITIONAL_1));
115 if (!film->interop ()) {
116 _type->Append ("DCI Any", ((void *) dcp::DCI_ANY));
117 _type->Append ("DCI Specific", ((void *) dcp::DCI_SPECIFIC));
119 table->Add (_type, 1, wxEXPAND);
120 _type->SetSelection (0);
122 _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
123 table->Add (_write_to, 1, wxEXPAND);
125 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
126 _folder = new DirPickerCtrl (this);
128 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
131 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
133 table->Add (_folder, 1, wxEXPAND);
135 _email = new wxRadioButton (this, wxID_ANY, _("Send by email"));
136 table->Add (_email, 1, wxEXPAND);
137 table->AddSpacer (0);
139 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
141 /* Make an overall sizer to get a nice border, and put some buttons in */
143 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
144 overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
146 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
148 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
151 _write_to->SetValue (true);
155 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
157 _cpl->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&KDMDialog::update_cpl_summary, this));
158 _cpl_browse->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::cpl_browse_clicked, this));
160 _write_to->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
161 _email->Bind (wxEVT_COMMAND_RADIOBUTTON_SELECTED, boost::bind (&KDMDialog::setup_sensitivity, this));
163 setup_sensitivity ();
165 SetSizer (overall_sizer);
166 overall_sizer->Layout ();
167 overall_sizer->SetSizeHints (this);
171 KDMDialog::setup_sensitivity ()
173 _screens->setup_sensitivity ();
175 bool const sd = _cpl->GetSelection() != -1;
177 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
179 ok->Enable (!_screens->screens().empty() && sd);
182 _folder->Enable (_write_to->GetValue ());
185 boost::filesystem::path
186 KDMDialog::cpl () const
188 int const item = _cpl->GetSelection ();
189 DCPOMATIC_ASSERT (item >= 0);
190 return _cpls[item].cpl_file;
193 boost::filesystem::path
194 KDMDialog::directory () const
196 return wx_to_std (_folder->GetPath ());
200 KDMDialog::write_to () const
202 return _write_to->GetValue ();
206 KDMDialog::formulation () const
208 return (dcp::Formulation) reinterpret_cast<intptr_t> (_type->GetClientData (_type->GetSelection()));
212 KDMDialog::update_cpl_choice ()
216 for (vector<CPLSummary>::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
217 _cpl->Append (std_to_wx (i->cpl_id));
219 if (_cpls.size() > 0) {
220 _cpl->SetSelection (0);
224 update_cpl_summary ();
228 KDMDialog::update_cpl_summary ()
230 int const n = _cpl->GetSelection();
231 if (n == wxNOT_FOUND) {
235 _dcp_directory->SetLabel (std_to_wx (_cpls[n].dcp_directory));
236 _cpl_id->SetLabel (std_to_wx (_cpls[n].cpl_id));
237 _cpl_annotation_text->SetLabel (std_to_wx (_cpls[n].cpl_annotation_text));
241 KDMDialog::cpl_browse_clicked ()
243 wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
244 if (d->ShowModal() == wxID_CANCEL) {
249 boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
250 boost::filesystem::path dcp_dir = cpl_file.parent_path ();
254 /* XXX: hack alert */
255 cxml::Document cpl_document ("CompositionPlaylist");
256 cpl_document.read_file (cpl_file);
261 dcp_dir.filename().string(),
262 cpl_document.string_child("Id").substr (9),
263 cpl_document.string_child ("ContentTitleText"),
267 } catch (cxml::Error) {
268 error_dialog (this, _("This is not a valid CPL file"));
272 update_cpl_choice ();
273 _cpl->SetSelection (_cpls.size() - 1);
274 update_cpl_summary ();
277 list<shared_ptr<Screen> >
278 KDMDialog::screens () const
280 return _screens->screens ();
283 boost::posix_time::ptime
284 KDMDialog::from () const
286 return _timing->from ();
289 boost::posix_time::ptime
290 KDMDialog::until () const
292 return _timing->until ();