Stub new cinema dialog.
[dcpomatic.git] / src / wx / kdm_dialog.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
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"
26 #include "wx_util.h"
27 #ifdef __WXMSW__
28 #include "dir_picker_ctrl.h"
29 #else
30 #include <wx/filepicker.h>
31 #endif
32
33 using namespace std;
34 using boost::shared_ptr;
35
36 KDMDialog::KDMDialog (wxWindow* parent)
37         : wxDialog (parent, wxID_ANY, _("Make KDMs"))
38 {
39         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
40
41         add_label_to_sizer (vertical, this, "Make KDMs for");
42
43         wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
44         
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);
47
48         _root = _targets->AddRoot ("Foo");
49         shared_ptr<Cinema> csy (new Cinema ("City Screen York"));
50         add_cinema (csy);
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 ();
55
56         wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
57
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);
62
63         targets->Add (target_buttons, 0, wxEXPAND | wxALL, 6);
64
65         vertical->Add (targets, 0, wxEXPAND | wxALL, 6);
66
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);
73         
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);
79
80         add_label_to_sizer (table, this, "Write to");
81
82 #ifdef __WXMSW__
83         _folder = new DirPickerCtrl (this);
84 #else   
85         _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST);
86 #endif
87
88         table->Add (_folder, 1, wxEXPAND);
89         
90         vertical->Add (table, 1, wxEXPAND | wxALL, 6);
91
92         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
93         if (buttons) {
94                 vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
95         }
96
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);
100
101         _new_screen->Enable (false);
102         
103         SetSizer (vertical);
104         vertical->Layout ();
105         vertical->SetSizeHints (this);
106 }
107
108 void
109 KDMDialog::targets_selection_changed (wxCommandEvent &)
110 {
111         wxArrayTreeItemIds s;
112         _targets->GetSelections (s);
113
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;
118                 }
119         }
120         
121         _new_screen->Enable (selected_cinema);  
122 }
123
124 void
125 KDMDialog::add_cinema (shared_ptr<Cinema> c)
126 {
127         _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c;
128 }
129
130 void
131 KDMDialog::add_screen (shared_ptr<Cinema> c, shared_ptr<Screen> s)
132 {
133         map<wxTreeItemId, shared_ptr<Cinema> >::const_iterator i = _cinemas.begin();
134         while (i != _cinemas.end() && i->second != c) {
135                 ++i;
136         }
137
138         if (i == _cinemas.end()) {
139                 return;
140         }
141
142         _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s;
143 }
144
145 void
146 KDMDialog::new_cinema_clicked (wxCommandEvent &)
147 {
148         NewCinemaDialog* d = new NewCinemaDialog (this);
149         d->ShowModal ();
150         d->Destroy ();
151 }
152
153 void
154 KDMDialog::new_screen_clicked (wxCommandEvent &)
155 {
156
157 }