C++11 tidying.
[dcpomatic.git] / src / wx / self_dkdm_dialog.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "self_dkdm_dialog.h"
23 #include "wx_util.h"
24 #include "kdm_output_panel.h"
25 #include "kdm_cpl_panel.h"
26 #include "static_text.h"
27 #include "lib/film.h"
28 #include "lib/screen.h"
29 #include "lib/config.h"
30 #include "lib/warnings.h"
31 #include <libcxml/cxml.h>
32 #ifdef DCPOMATIC_USE_OWN_PICKER
33 #include "dir_picker_ctrl.h"
34 #else
35 DCPOMATIC_DISABLE_WARNINGS
36 #include <wx/filepicker.h>
37 DCPOMATIC_ENABLE_WARNINGS
38 #endif
39 DCPOMATIC_DISABLE_WARNINGS
40 #include <wx/treectrl.h>
41 #include <wx/listctrl.h>
42 #include <wx/stdpaths.h>
43 DCPOMATIC_ENABLE_WARNINGS
44 #include <iostream>
45
46
47 using std::string;
48 using std::map;
49 using std::list;
50 using std::pair;
51 using std::cout;
52 using std::vector;
53 using std::make_pair;
54 using std::shared_ptr;
55 using boost::bind;
56
57
58 SelfDKDMDialog::SelfDKDMDialog (wxWindow* parent, std::shared_ptr<const Film> film)
59         : wxDialog (parent, wxID_ANY, _("Make DKDM for DCP-o-matic"))
60 {
61         /* Main sizer */
62         auto vertical = new wxBoxSizer (wxVERTICAL);
63
64         /* Font for sub-headings */
65         wxFont subheading_font (*wxNORMAL_FONT);
66         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
67
68         /* Sub-heading: CPL */
69         auto h = new StaticText (this, _("CPL"));
70         h->SetFont (subheading_font);
71         vertical->Add (h);
72         _cpl = new KDMCPLPanel (this, film->cpls ());
73         vertical->Add (_cpl);
74
75         /* Sub-heading: output */
76         h = new StaticText (this, _("Output"));
77         h->SetFont (subheading_font);
78         vertical->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
79
80         _internal = new wxRadioButton (this, wxID_ANY, _("Save to KDM Creator tool's list"));
81         vertical->Add (_internal, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
82
83         auto w = new wxBoxSizer (wxHORIZONTAL);
84
85         _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
86         w->Add (_write_to, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
87
88 #ifdef DCPOMATIC_USE_OWN_PICKER
89         _folder = new DirPickerCtrl (this);
90 #else
91         _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
92 #endif
93
94         _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
95
96         w->Add (_folder, 1, wxEXPAND);
97
98         vertical->Add (w, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
99
100         /* Make an overall sizer to get a nice border, and put some buttons in */
101
102         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
103         overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
104
105         auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
106         if (buttons) {
107                 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
108         }
109
110         SetSizer (overall_sizer);
111         overall_sizer->Layout ();
112         overall_sizer->SetSizeHints (this);
113
114         switch (Config::instance()->last_dkdm_write_type().get_value_or(Config::DKDM_WRITE_INTERNAL)) {
115         case Config::DKDM_WRITE_INTERNAL:
116                 _internal->SetValue (true);
117                 break;
118         case Config::DKDM_WRITE_FILE:
119                 _write_to->SetValue (true);
120                 break;
121         }
122         setup_sensitivity ();
123
124         _internal->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
125         _write_to->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
126 }
127
128
129 void
130 SelfDKDMDialog::dkdm_write_type_changed ()
131 {
132         setup_sensitivity ();
133
134         if (_internal->GetValue()) {
135                 Config::instance()->set_last_dkdm_write_type(Config::DKDM_WRITE_INTERNAL);
136         } else if (_write_to->GetValue()) {
137                 Config::instance()->set_last_dkdm_write_type(Config::DKDM_WRITE_FILE);
138         }
139 }
140
141
142 void
143 SelfDKDMDialog::setup_sensitivity ()
144 {
145         _folder->Enable (_write_to->GetValue ());
146
147         auto ok = dynamic_cast<wxButton *>(FindWindowById(wxID_OK, this));
148         if (ok) {
149                 ok->Enable (_cpl->has_selected ());
150         }
151 }
152
153
154 boost::filesystem::path
155 SelfDKDMDialog::cpl () const
156 {
157         return _cpl->cpl ();
158 }
159
160
161 bool
162 SelfDKDMDialog::internal () const
163 {
164         return _internal->GetValue ();
165 }
166
167
168 boost::filesystem::path
169 SelfDKDMDialog::directory () const
170 {
171         return wx_to_std (_folder->GetPath());
172 }