ba478f7d57d4af17c48803116ec6c22cd1a44c11
[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 "wx_util.h"
26 #ifdef __WXMSW__
27 #include "dir_picker_ctrl.h"
28 #else
29 #include <wx/filepicker.h>
30 #endif
31
32 using namespace std;
33 using boost::shared_ptr;
34
35 KDMDialog::KDMDialog (wxWindow* parent)
36         : wxDialog (parent, wxID_ANY, _("Make KDMs"))
37 {
38         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
39
40         add_label_to_sizer (vertical, this, "Make KDMs for");
41
42         wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
43         
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);
46
47         _root = _targets->AddRoot ("Foo");
48         shared_ptr<Cinema> csy (new Cinema ("City Screen York"));
49         add_cinema (csy);
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 ();
54
55         wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
56
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);
61
62         targets->Add (target_buttons, 0, wxEXPAND | wxALL, 6);
63
64         vertical->Add (targets, 0, wxEXPAND | wxALL, 6);
65
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);
72         
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);
78
79         add_label_to_sizer (table, this, "Write to");
80
81 #ifdef __WXMSW__
82         _folder = new DirPickerCtrl (this);
83 #else   
84         _folder = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST);
85 #endif
86
87         table->Add (_folder, 1, wxEXPAND);
88         
89         vertical->Add (table, 1, wxEXPAND | wxALL, 6);
90
91         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
92         if (buttons) {
93                 vertical->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
94         }
95
96         _targets->Connect (wxID_ANY, wxEVT_COMMAND_TREE_SEL_CHANGED, wxCommandEventHandler (KDMDialog::targets_selection_changed), 0, this);
97
98         _new_screen->Enable (false);
99         
100         SetSizer (vertical);
101         vertical->Layout ();
102         vertical->SetSizeHints (this);
103 }
104
105 void
106 KDMDialog::targets_selection_changed (wxCommandEvent &)
107 {
108         wxArrayTreeItemIds s;
109         _targets->GetSelections (s);
110
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;
115                 }
116         }
117         
118         _new_screen->Enable (selected_cinema);  
119 }
120
121 void
122 KDMDialog::add_cinema (shared_ptr<Cinema> c)
123 {
124         _cinemas[_targets->AppendItem (_root, std_to_wx (c->name))] = c;
125 }
126
127 void
128 KDMDialog::add_screen (shared_ptr<Cinema> c, shared_ptr<Screen> s)
129 {
130         map<wxTreeItemId, shared_ptr<Cinema> >::const_iterator i = _cinemas.begin();
131         while (i != _cinemas.end() && i->second != c) {
132                 ++i;
133         }
134
135         if (i == _cinemas.end()) {
136                 return;
137         }
138
139         _screens[_targets->AppendItem (i->first, std_to_wx (s->name))] = s;
140 }