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"
25 #include "new_cinema_dialog.h"
28 #include "dir_picker_ctrl.h"
30 #include <wx/filepicker.h>
34 using boost::shared_ptr;
36 KDMDialog::KDMDialog (wxWindow* parent)
37 : wxDialog (parent, wxID_ANY, _("Make KDMs"))
39 wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
41 add_label_to_sizer (vertical, this, "Make KDMs for");
43 wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
45 _targets = new wxTreeCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS);
46 targets->Add (_targets, 1, wxEXPAND | wxALL, 6);
48 _root = _targets->AddRoot ("Foo");
49 shared_ptr<Cinema> csy (new Cinema ("City Screen York"));
51 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 1")));
52 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 2")));
53 add_screen (csy, shared_ptr<Screen> (new Screen ("Screen 3")));
54 _targets->ExpandAll ();
56 wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
58 _new_cinema = new wxButton (this, wxID_ANY, _("New Cinema..."));
59 target_buttons->Add (_new_cinema, 1, wxEXPAND | wxALL, 6);
60 _new_screen = new wxButton (this, wxID_ANY, _("New Screen..."));
61 target_buttons->Add (_new_screen, 1, wxEXPAND | wxALL, 6);
63 targets->Add (target_buttons, 0, wxEXPAND | wxALL, 6);
65 vertical->Add (targets, 0, wxEXPAND | wxALL, 6);
67 wxFlexGridSizer* table = new wxFlexGridSizer (3, 2, 6);
68 add_label_to_sizer (table, this, "From");
69 _from_date = new wxDatePickerCtrl (this, wxID_ANY);
70 table->Add (_from_date, 1, wxEXPAND);
71 _from_time = new wxTimePickerCtrl (this, wxID_ANY);
72 table->Add (_from_time, 1, wxEXPAND);
74 add_label_to_sizer (table, this, "To");
75 _to_date = new wxDatePickerCtrl (this, wxID_ANY);
76 table->Add (_to_date, 1, wxEXPAND);
77 _to_time = new wxTimePickerCtrl (this, wxID_ANY);
78 table->Add (_to_time, 1, wxEXPAND);
80 add_label_to_sizer (table, this, "Write to");
83 _folder = new DirPickerCtrl (this);
85 _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST);
88 table->Add (_folder, 1, wxEXPAND);
90 vertical->Add (table, 1, wxEXPAND | wxALL, 6);
92 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
94 vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
97 _targets->Connect (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler (KDMDialog::targets_selection_changed), 0, this);
98 _new_cinema->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::new_cinema_clicked), 0, this);
99 _new_screen->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (KDMDialog::new_screen_clicked), 0, this);
101 _new_screen->Enable (false);
105 vertical->SetSizeHints (this);
109 KDMDialog::targets_selection_changed (wxCommandEvent &)
111 wxArrayTreeItemIds s;
112 _targets->GetSelections (s);
114 bool selected_cinema = false;
115 for (size_t i = 0; i < s.GetCount(); ++i) {
116 if (_cinemas.find (s[i]) != _cinemas.end()) {
117 selected_cinema = true;
121 _new_screen->Enable (selected_cinema);
125 KDMDialog::add_cinema (shared_ptr<Cinema> c)
127 _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c;
131 KDMDialog::add_screen (shared_ptr<Cinema> c, shared_ptr<Screen> s)
133 map<wxTreeItemId, shared_ptr<Cinema> >::const_iterator i = _cinemas.begin();
134 while (i != _cinemas.end() && i->second != c) {
138 if (i == _cinemas.end()) {
142 _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s;
146 KDMDialog::new_cinema_clicked (wxCommandEvent &)
148 NewCinemaDialog* d = new NewCinemaDialog (this);
154 KDMDialog::new_screen_clicked (wxCommandEvent &)