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