Separate CPL choice for KDMs into a separate class.
[dcpomatic.git] / src / wx / kdm_dialog.cc
1 /*
2     Copyright (C) 2012-2015 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 "kdm_dialog.h"
21 #include "cinema_dialog.h"
22 #include "screen_dialog.h"
23 #include "wx_util.h"
24 #include "screens_panel.h"
25 #include "kdm_timing_panel.h"
26 #include "kdm_output_panel.h"
27 #include "kdm_cpl_panel.h"
28 #include "lib/cinema.h"
29 #include "lib/config.h"
30 #include "lib/film.h"
31 #include "lib/screen.h"
32 #include <libcxml/cxml.h>
33 #include <wx/treectrl.h>
34 #include <wx/listctrl.h>
35 #include <iostream>
36
37 using std::string;
38 using std::map;
39 using std::list;
40 using std::pair;
41 using std::cout;
42 using std::vector;
43 using std::make_pair;
44 using boost::shared_ptr;
45
46 KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
47         : wxDialog (parent, wxID_ANY, _("Make KDMs"))
48 {
49         /* Main sizer */
50         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
51
52         /* Font for sub-headings */
53         wxFont subheading_font (*wxNORMAL_FONT);
54         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
55
56         /* Sub-heading: Screens */
57         wxStaticText* h = new wxStaticText (this, wxID_ANY, _("Screens"));
58         h->SetFont (subheading_font);
59         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL);
60         _screens = new ScreensPanel (this);
61         vertical->Add (_screens, 1, wxEXPAND);
62
63         /* Sub-heading: Timing */
64         h = new wxStaticText (this, wxID_ANY, S_("KDM|Timing"));
65         h->SetFont (subheading_font);
66         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
67         _timing = new KDMTimingPanel (this);
68         vertical->Add (_timing);
69
70         /* Sub-heading: CPL */
71         h = new wxStaticText (this, wxID_ANY, _("CPL"));
72         h->SetFont (subheading_font);
73         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
74         _cpl = new KDMCPLPanel (this, film->cpls ());
75         vertical->Add (_cpl);
76
77         /* Sub-heading: Output */
78         h = new wxStaticText (this, wxID_ANY, _("Output"));
79         h->SetFont (subheading_font);
80         vertical->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
81         _output = new KDMOutputPanel (this, film->interop ());
82         vertical->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
83
84         /* Make an overall sizer to get a nice border, and put some buttons in */
85
86         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
87         overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
88
89         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
90         if (buttons) {
91                 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
92         }
93
94         /* Bind */
95
96         _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
97
98         setup_sensitivity ();
99
100         SetSizer (overall_sizer);
101         overall_sizer->Layout ();
102         overall_sizer->SetSizeHints (this);
103 }
104
105 void
106 KDMDialog::setup_sensitivity ()
107 {
108         _screens->setup_sensitivity ();
109         _output->setup_sensitivity ();
110
111         bool const sd = _cpl->has_selected ();
112
113         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
114         if (ok) {
115                 ok->Enable (!_screens->screens().empty() && sd);
116         }
117 }
118
119 boost::filesystem::path
120 KDMDialog::cpl () const
121 {
122         return _cpl->cpl ();
123 }
124
125 list<shared_ptr<Screen> >
126 KDMDialog::screens () const
127 {
128         return _screens->screens ();
129 }
130
131 boost::posix_time::ptime
132 KDMDialog::from () const
133 {
134         return _timing->from ();
135 }
136
137 boost::posix_time::ptime
138 KDMDialog::until () const
139 {
140         return _timing->until ();
141 }
142
143 boost::filesystem::path
144 KDMDialog::directory () const
145 {
146         return _output->directory ();
147 }
148
149 bool
150 KDMDialog::write_to () const
151 {
152         return _output->write_to ();
153 }
154
155 dcp::Formulation
156 KDMDialog::formulation () const
157 {
158         return _output->formulation ();
159 }