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 "kdm_output_panel.h"
27 #include "lib/cinema.h"
28 #include "lib/config.h"
30 #include "lib/screen.h"
31 #include <libcxml/cxml.h>
32 #include <wx/treectrl.h>
33 #include <wx/listctrl.h>
43 using boost::shared_ptr;
45 KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
46 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
49 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
51 /* Font for sub-headings */
52 wxFont subheading_font (*wxNORMAL_FONT);
53 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
55 /* Sub-heading: Screens */
56 wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
57 h->SetFont (subheading_font);
58 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
59 _screens = new ScreensPanel (this);
60 vertical->Add (_screens, 1, wxEXPAND);
62 /* Sub-heading: Timing */
63 h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
64 h->SetFont (subheading_font);
65 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
66 _timing = new KDMTimingPanel (this);
67 vertical->Add (_timing);
69 /* Sub-heading: CPL */
70 h = new wxStaticText (this, wxID_ANY, _("CPL"));
71 h->SetFont (subheading_font);
72 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
75 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
76 add_label_to_sizer (s, this, _("CPL"), true);
77 _cpl = new wxChoice (this, wxID_ANY);
78 s->Add (_cpl, 1, wxEXPAND);
79 _cpl_browse = new wxButton (this, wxID_ANY, _("Browse..."));
80 s->Add (_cpl_browse, 0);
81 vertical->Add (s, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
84 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
85 add_label_to_sizer (table, this, _("DCP directory"), true);
86 _dcp_directory = new wxStaticText (this, wxID_ANY, "");
87 table->Add (_dcp_directory);
88 add_label_to_sizer (table, this, _("CPL ID"), true);
89 _cpl_id = new wxStaticText (this, wxID_ANY, "");
91 add_label_to_sizer (table, this, _("CPL annotation text"), true);
92 _cpl_annotation_text = new wxStaticText (this, wxID_ANY, "");
93 table->Add (_cpl_annotation_text);
94 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
96 _cpls = film->cpls ();
99 /* Sub-heading: Output */
100 h = new wxStaticText (this, wxID_ANY, _("Output"));
101 h->SetFont (subheading_font);
102 vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
103 _output = new KDMOutputPanel (this, film->interop ());
104 vertical->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
106 /* Make an overall sizer to get a nice border, and put some buttons in */
108 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
109 overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
111 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
113 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
118 _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
120 _cpl->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&KDMDialog::update_cpl_summary, this));
121 _cpl_browse->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMDialog::cpl_browse_clicked, this));
123 setup_sensitivity ();
125 SetSizer (overall_sizer);
126 overall_sizer->Layout ();
127 overall_sizer->SetSizeHints (this);
131 KDMDialog::setup_sensitivity ()
133 _screens->setup_sensitivity ();
134 _output->setup_sensitivity ();
136 bool const sd = _cpl->GetSelection() != -1;
138 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
140 ok->Enable (!_screens->screens().empty() && sd);
144 boost::filesystem::path
145 KDMDialog::cpl () const
147 int const item = _cpl->GetSelection ();
148 DCPOMATIC_ASSERT (item >= 0);
149 return _cpls[item].cpl_file;
153 KDMDialog::update_cpl_choice ()
157 for (vector<CPLSummary>::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
158 _cpl->Append (std_to_wx (i->cpl_id));
160 if (_cpls.size() > 0) {
161 _cpl->SetSelection (0);
165 update_cpl_summary ();
169 KDMDialog::update_cpl_summary ()
171 int const n = _cpl->GetSelection();
172 if (n == wxNOT_FOUND) {
176 _dcp_directory->SetLabel (std_to_wx (_cpls[n].dcp_directory));
177 _cpl_id->SetLabel (std_to_wx (_cpls[n].cpl_id));
178 _cpl_annotation_text->SetLabel (std_to_wx (_cpls[n].cpl_annotation_text));
182 KDMDialog::cpl_browse_clicked ()
184 wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
185 if (d->ShowModal() == wxID_CANCEL) {
190 boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
191 boost::filesystem::path dcp_dir = cpl_file.parent_path ();
195 /* XXX: hack alert */
196 cxml::Document cpl_document ("CompositionPlaylist");
197 cpl_document.read_file (cpl_file);
202 dcp_dir.filename().string(),
203 cpl_document.string_child("Id").substr (9),
204 cpl_document.string_child ("ContentTitleText"),
208 } catch (cxml::Error) {
209 error_dialog (this, _("This is not a valid CPL file"));
213 update_cpl_choice ();
214 _cpl->SetSelection (_cpls.size() - 1);
215 update_cpl_summary ();
218 list<shared_ptr<Screen> >
219 KDMDialog::screens () const
221 return _screens->screens ();
224 boost::posix_time::ptime
225 KDMDialog::from () const
227 return _timing->from ();
230 boost::posix_time::ptime
231 KDMDialog::until () const
233 return _timing->until ();
236 boost::filesystem::path
237 KDMDialog::directory () const
239 return _output->directory ();
243 KDMDialog::write_to () const
245 return _output->write_to ();
249 KDMDialog::formulation () const
251 return _output->formulation ();