2 Copyright (C) 2012 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 <wx/treectrl.h>
21 #include <wx/datectrl.h>
22 #include <wx/timectrl.h>
23 #include "lib/cinema.h"
24 #include "kdm_dialog.h"
27 #include "dir_picker_ctrl.h"
29 #include <wx/filepicker.h>
33 using boost::shared_ptr;
35 KDMDialog::KDMDialog (wxWindow* parent)
36 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
38 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
40 add_label_to_sizer (vertical, this, "Make KDMs for");
42 wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
44 _targets = new wxTreeCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS);
45 targets->Add (_targets, 1, wxEXPAND | wxALL, 6);
47 _root = _targets->AddRoot ("Foo");
48 shared_ptr<Cinema> csy (new Cinema ("City Screen York"));
50 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 1")));
51 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 2")));
52 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 3")));
53 _targets->ExpandAll ();
55 wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
57 _new_cinema = new wxButton (this, wxID_ANY, _("New Cinema..."));
58 target_buttons->Add (_new_cinema, 1, wxEXPAND | wxALL, 6);
59 _new_screen = new wxButton (this, wxID_ANY, _("New Screen..."));
60 target_buttons->Add (_new_screen, 1, wxEXPAND | wxALL, 6);
62 targets->Add (target_buttons, 0, wxEXPAND | wxALL, 6);
64 vertical->Add (targets, 0, wxEXPAND | wxALL, 6);
66 wxFlexGridSizer* table = new wxFlexGridSizer (3, 2, 6);
67 add_label_to_sizer (table, this, "From");
68 _from_date = new wxDatePickerCtrl (this, wxID_ANY);
69 table->Add (_from_date, 1, wxEXPAND);
70 _from_time = new wxTimePickerCtrl (this, wxID_ANY);
71 table->Add (_from_time, 1, wxEXPAND);
73 add_label_to_sizer (table, this, "To");
74 _to_date = new wxDatePickerCtrl (this, wxID_ANY);
75 table->Add (_to_date, 1, wxEXPAND);
76 _to_time = new wxTimePickerCtrl (this, wxID_ANY);
77 table->Add (_to_time, 1, wxEXPAND);
79 add_label_to_sizer (table, this, "Write to");
82 _folder = new DirPickerCtrl (this);
84 _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST);
87 table->Add (_folder, 1, wxEXPAND);
89 vertical->Add (table, 1, wxEXPAND | wxALL, 6);
91 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
93 vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
96 _targets->Connect (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler (KDMDialog::targets_selection_changed), 0, this);
98 _new_screen->Enable (false);
102 vertical->SetSizeHints (this);
106 KDMDialog::targets_selection_changed (wxCommandEvent &)
108 wxArrayTreeItemIds s;
109 _targets->GetSelections (s);
111 bool selected_cinema = false;
112 for (size_t i = 0; i < s.GetCount(); ++i) {
113 if (_cinemas.find (s[i]) != _cinemas.end()) {
114 selected_cinema = true;
118 _new_screen->Enable (selected_cinema);
122 KDMDialog::add_cinema (shared_ptr<Cinema> c)
124 _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c;
128 KDMDialog::add_screen (shared_ptr<Cinema> c, shared_ptr<Screen> s)
130 map<wxTreeItemId, shared_ptr<Cinema> >::const_iterator i = _cinemas.begin();
131 while (i != _cinemas.end() && i->second != c) {
135 if (i == _cinemas.end()) {
139 _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s;