2 Copyright (C) 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_cpl_panel.h"
22 #include <libcxml/cxml.h>
26 KDMCPLPanel::KDMCPLPanel (wxWindow* parent, vector<CPLSummary> cpls)
27 : wxPanel (parent, wxID_ANY)
30 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
33 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
34 add_label_to_sizer (s, this, _("CPL"), true);
35 _cpl = new wxChoice (this, wxID_ANY);
36 s->Add (_cpl, 1, wxEXPAND);
37 _cpl_browse = new wxButton (this, wxID_ANY, _("Browse..."));
38 s->Add (_cpl_browse, 0);
39 vertical->Add (s, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
42 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
43 add_label_to_sizer (table, this, _("DCP directory"), true);
44 _dcp_directory = new wxStaticText (this, wxID_ANY, "");
45 table->Add (_dcp_directory);
46 add_label_to_sizer (table, this, _("CPL ID"), true);
47 _cpl_id = new wxStaticText (this, wxID_ANY, "");
49 add_label_to_sizer (table, this, _("CPL annotation text"), true);
50 _cpl_annotation_text = new wxStaticText (this, wxID_ANY, "");
51 table->Add (_cpl_annotation_text);
52 vertical->Add (table, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP + 2);
56 _cpl->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&KDMCPLPanel::update_cpl_summary, this));
57 _cpl_browse->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KDMCPLPanel::cpl_browse_clicked, this));
59 SetSizerAndFit (vertical);
63 KDMCPLPanel::update_cpl_choice ()
67 for (vector<CPLSummary>::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
68 _cpl->Append (std_to_wx (i->cpl_id));
70 if (_cpls.size() > 0) {
71 _cpl->SetSelection (0);
75 update_cpl_summary ();
79 KDMCPLPanel::update_cpl_summary ()
81 int const n = _cpl->GetSelection();
82 if (n == wxNOT_FOUND) {
86 _dcp_directory->SetLabel (std_to_wx (_cpls[n].dcp_directory));
87 _cpl_id->SetLabel (std_to_wx (_cpls[n].cpl_id));
88 _cpl_annotation_text->SetLabel (std_to_wx (_cpls[n].cpl_annotation_text));
92 KDMCPLPanel::cpl_browse_clicked ()
94 wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
95 if (d->ShowModal() == wxID_CANCEL) {
100 boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
101 boost::filesystem::path dcp_dir = cpl_file.parent_path ();
105 /* XXX: hack alert */
106 cxml::Document cpl_document ("CompositionPlaylist");
107 cpl_document.read_file (cpl_file);
112 dcp_dir.filename().string(),
113 cpl_document.string_child("Id").substr (9),
114 cpl_document.string_child ("ContentTitleText"),
118 } catch (cxml::Error) {
119 error_dialog (this, _("This is not a valid CPL file"));
123 update_cpl_choice ();
124 _cpl->SetSelection (_cpls.size() - 1);
125 update_cpl_summary ();
128 boost::filesystem::path
129 KDMCPLPanel::cpl () const
131 int const item = _cpl->GetSelection ();
132 DCPOMATIC_ASSERT (item >= 0);
133 return _cpls[item].cpl_file;
137 KDMCPLPanel::has_selected () const
139 return _cpl->GetSelection() != -1;