2 Copyright (C) 2015 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_cpl_panel.h"
23 #include <libcxml/cxml.h>
27 KDMCPLPanel::KDMCPLPanel (wxWindow* parent, vector<CPLSummary> cpls)
28 : wxPanel (parent, wxID_ANY)
31 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
34 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
35 add_label_to_sizer (s, this, _("CPL"), true);
36 _cpl = new wxChoice (this, wxID_ANY);
37 s->Add (_cpl, 1, wxEXPAND);
38 _cpl_browse = new wxButton (this, wxID_ANY, _("Browse..."));
39 s->Add (_cpl_browse, 0, wxALIGN_CENTER_VERTICAL);
40 vertical->Add (s, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
43 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
44 add_label_to_sizer (table, this, _("DCP directory"), true);
45 _dcp_directory = new wxStaticText (this, wxID_ANY, "");
46 table->Add (_dcp_directory);
47 add_label_to_sizer (table, this, _("CPL ID"), true);
48 _cpl_id = new wxStaticText (this, wxID_ANY, "");
50 add_label_to_sizer (table, this, _("CPL annotation text"), true);
51 _cpl_annotation_text = new wxStaticText (this, wxID_ANY, "");
52 table->Add (_cpl_annotation_text);
53 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
57 _cpl->Bind (wxEVT_CHOICE, boost::bind (&KDMCPLPanel::update_cpl_summary, this));
58 _cpl_browse->Bind (wxEVT_BUTTON, boost::bind (&KDMCPLPanel::cpl_browse_clicked, this));
60 SetSizerAndFit (vertical);
64 KDMCPLPanel::update_cpl_choice ()
68 for (vector<CPLSummary>::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
69 _cpl->Append (std_to_wx (i->cpl_id));
71 if (_cpls.size() > 0) {
72 _cpl->SetSelection (0);
76 update_cpl_summary ();
80 KDMCPLPanel::update_cpl_summary ()
82 int const n = _cpl->GetSelection();
83 if (n == wxNOT_FOUND) {
87 _dcp_directory->SetLabel (std_to_wx (_cpls[n].dcp_directory));
88 _cpl_id->SetLabel (std_to_wx (_cpls[n].cpl_id));
89 _cpl_annotation_text->SetLabel (std_to_wx (_cpls[n].cpl_annotation_text));
93 KDMCPLPanel::cpl_browse_clicked ()
95 wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
96 if (d->ShowModal() == wxID_CANCEL) {
101 boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
102 boost::filesystem::path dcp_dir = cpl_file.parent_path ();
106 /* XXX: hack alert */
107 cxml::Document cpl_document ("CompositionPlaylist");
108 cpl_document.read_file (cpl_file);
113 dcp_dir.filename().string(),
114 cpl_document.string_child("Id").substr (9),
115 cpl_document.string_child ("ContentTitleText"),
119 } catch (cxml::Error) {
120 error_dialog (this, _("This is not a valid CPL file"));
124 update_cpl_choice ();
125 _cpl->SetSelection (_cpls.size() - 1);
126 update_cpl_summary ();
129 boost::filesystem::path
130 KDMCPLPanel::cpl () const
132 int const item = _cpl->GetSelection ();
133 DCPOMATIC_ASSERT (item >= 0);
134 return _cpls[item].cpl_file;
138 KDMCPLPanel::has_selected () const
140 return _cpl->GetSelection() != -1;