Disable warnings around all wx includes.
[dcpomatic.git] / src / wx / metadata_dialog.cc
1 /*
2     Copyright (C) 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 "dcpomatic_button.h"
23 #include "full_language_tag_dialog.h"
24 #include "language_tag_widget.h"
25 #include "metadata_dialog.h"
26 #include "wx_util.h"
27 #include "lib/film.h"
28 #include "lib/warnings.h"
29 #include <boost/bind.hpp>
30 #include <boost/weak_ptr.hpp>
31 DCPOMATIC_DISABLE_WARNINGS
32 #include <wx/notebook.h>
33 #include <wx/spinctrl.h>
34 #include <wx/wx.h>
35 DCPOMATIC_ENABLE_WARNINGS
36
37
38 using std::weak_ptr;
39
40
41 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
42         : wxDialog (parent, wxID_ANY, _("Metadata"))
43         , WeakFilm (weak_film)
44 {
45
46 }
47
48
49 void
50 MetadataDialog::setup ()
51 {
52         auto notebook = new wxNotebook (this, wxID_ANY);
53
54         auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
55                 auto panel = new wxPanel (notebook, wxID_ANY);
56                 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
57                 sizer->AddGrowableCol (1, 1);
58                 setup (panel, sizer);
59                 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
60                 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
61                 panel->SetSizer (overall_sizer);
62                 notebook->AddPage (panel, name);
63         };
64
65         prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
66         prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
67
68         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
69         overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
70
71         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
72         if (buttons) {
73                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
74         }
75
76         SetSizer (overall_sizer);
77         overall_sizer->Layout ();
78         overall_sizer->SetSizeHints (this);
79
80         _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this));
81         _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
82         _enable_release_territory->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_release_territory_changed, this));
83         _enable_facility->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_facility_changed, this));
84         _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
85         _enable_studio->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_studio_changed, this));
86         _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
87         _enable_chain->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_chain_changed, this));
88         _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
89         _temp_version->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::temp_version_changed, this));
90         _pre_release->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::pre_release_changed, this));
91         _red_band->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::red_band_changed, this));
92         _two_d_version_of_three_d->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::two_d_version_of_three_d_changed, this));
93         _enable_luminance->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_luminance_changed, this));
94         _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&MetadataDialog::luminance_changed, this));
95         _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&MetadataDialog::luminance_changed, this));
96
97         _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
98
99         film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
100         film_changed (ChangeType::DONE, Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE);
101         film_changed (ChangeType::DONE, Film::Property::FACILITY);
102         film_changed (ChangeType::DONE, Film::Property::STUDIO);
103         film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
104         film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
105         film_changed (ChangeType::DONE, Film::Property::RED_BAND);
106         film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
107         film_changed (ChangeType::DONE, Film::Property::CHAIN);
108         film_changed (ChangeType::DONE, Film::Property::LUMINANCE);
109
110         setup_sensitivity ();
111 }
112
113
114 void
115 MetadataDialog::film_changed (ChangeType type, Film::Property property)
116 {
117         if (type != ChangeType::DONE) {
118                 return;
119         }
120
121         if (property == Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE) {
122                 _sign_language_video_language->set (film()->sign_language_video_language());
123         } else if (property == Film::Property::RELEASE_TERRITORY) {
124                 auto rt = film()->release_territory();
125                 checked_set (_enable_release_territory, static_cast<bool>(rt));
126                 if (rt) {
127                         _release_territory = *rt;
128                         checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
129                 }
130         } else if (property == Film::Property::FACILITY) {
131                 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
132                 if (film()->facility()) {
133                         checked_set (_facility, *film()->facility());
134                 }
135         } else if (property == Film::Property::STUDIO) {
136                 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
137                 if (film()->studio()) {
138                         checked_set (_studio, *film()->studio());
139                 }
140         } else if (property == Film::Property::CHAIN) {
141                 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
142                 if (film()->chain()) {
143                         checked_set (_chain, *film()->chain());
144                 }
145         } else if (property == Film::Property::TEMP_VERSION) {
146                 checked_set (_temp_version, film()->temp_version());
147         } else if (property == Film::Property::PRE_RELEASE) {
148                 checked_set (_pre_release, film()->pre_release());
149         } else if (property == Film::Property::RED_BAND) {
150                 checked_set (_red_band, film()->red_band());
151         } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
152                 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
153         } else if (property == Film::Property::LUMINANCE) {
154                 auto lum = film()->luminance();
155                 checked_set (_enable_luminance, static_cast<bool>(lum));
156                 if (lum) {
157                         checked_set (_luminance_value, lum->value());
158                         switch (lum->unit()) {
159                         case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
160                                 checked_set (_luminance_unit, 0);
161                                 break;
162                         case dcp::Luminance::Unit::FOOT_LAMBERT:
163                                 checked_set (_luminance_unit, 1);
164                                 break;
165                         }
166                 } else {
167                         checked_set (_luminance_unit, 1);
168                 }
169         }
170 }
171
172
173 void
174 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
175 {
176         _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
177         sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
178         {
179                 auto s = new wxBoxSizer (wxHORIZONTAL);
180                 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
181                 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
182                 _edit_release_territory = new Button (panel, _("Edit..."));
183                 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
184                 sizer->Add (s, 0, wxEXPAND);
185         }
186 }
187
188
189 void
190 MetadataDialog::edit_release_territory ()
191 {
192         DCPOMATIC_ASSERT (film()->release_territory());
193         auto d = new RegionSubtagDialog(this, *film()->release_territory());
194         d->ShowModal ();
195         auto tag = d->get();
196         if (tag) {
197                 _release_territory = *tag;
198                 film()->set_release_territory(*tag);
199         }
200         d->Destroy ();
201 }
202
203
204 void
205 MetadataDialog::setup_sensitivity ()
206 {
207         _sign_language_video_language->enable (film()->has_sign_language_video_channel());
208         auto const enabled = _enable_release_territory->GetValue();
209         _release_territory_text->Enable (enabled);
210         _edit_release_territory->Enable (enabled);
211         _facility->Enable (_enable_facility->GetValue());
212         _chain->Enable (_enable_chain->GetValue());
213         _studio->Enable (_enable_studio->GetValue());
214         _luminance_value->Enable (_enable_luminance->GetValue());
215         _luminance_unit->Enable (_enable_luminance->GetValue());
216 }
217
218
219 void
220 MetadataDialog::enable_release_territory_changed ()
221 {
222         setup_sensitivity ();
223         if (_enable_release_territory->GetValue()) {
224                 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
225         } else {
226                 film()->set_release_territory ();
227         }
228 }
229
230
231 void
232 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
233 {
234         add_label_to_sizer (sizer, panel, _("Sign language video language"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
235         _sign_language_video_language = new LanguageTagWidget (panel, _("Language used for any sign language video track"), {}, {});
236         sizer->Add (_sign_language_video_language->sizer(), 1, wxEXPAND);
237
238         _enable_facility = new wxCheckBox (panel, wxID_ANY, _("Facility"));
239         sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
240         _facility = new wxTextCtrl (panel, wxID_ANY);
241         sizer->Add (_facility, 1, wxEXPAND);
242
243         _enable_studio = new wxCheckBox (panel, wxID_ANY, _("Studio"));
244         sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
245         _studio = new wxTextCtrl (panel, wxID_ANY);
246         sizer->Add (_studio, 1, wxEXPAND);
247
248         _enable_chain = new wxCheckBox (panel, wxID_ANY, _("Chain"));
249         sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
250         _chain = new wxTextCtrl (panel, wxID_ANY);
251         sizer->Add (_chain, 1, wxEXPAND);
252
253         _temp_version = new wxCheckBox (panel, wxID_ANY, _("Temporary version"));
254         sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
255         sizer->AddSpacer (0);
256
257         _pre_release = new wxCheckBox (panel, wxID_ANY, _("Pre-release"));
258         sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
259         sizer->AddSpacer (0);
260
261         _red_band = new wxCheckBox (panel, wxID_ANY, _("Red band"));
262         sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
263         sizer->AddSpacer (0);
264
265         _two_d_version_of_three_d = new wxCheckBox (panel, wxID_ANY, _("2D version of 3D DCP"));
266         sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
267         sizer->AddSpacer (0);
268
269         _enable_luminance = new wxCheckBox (panel, wxID_ANY, _("Luminance"));
270         sizer->Add (_enable_luminance, 0, wxALIGN_CENTER_VERTICAL);
271         {
272                 auto s = new wxBoxSizer (wxHORIZONTAL);
273                 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
274                 _luminance_value->SetRange (0.1, 32.0);
275                 _luminance_value->SetDigits (1);
276                 _luminance_value->SetIncrement (0.1);
277                 s->Add (_luminance_value, 0);
278                 _luminance_unit = new wxChoice (panel, wxID_ANY);
279                 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
280                 sizer->Add (s, 1, wxEXPAND);
281         }
282
283         _luminance_unit->Append (wxString::FromUTF8(_("candela per m²")));
284         _luminance_unit->Append (_("foot lambert"));
285
286 }
287
288
289 void
290 MetadataDialog::facility_changed ()
291 {
292         film()->set_facility (wx_to_std(_facility->GetValue()));
293 }
294
295
296 void
297 MetadataDialog::enable_facility_changed ()
298 {
299         setup_sensitivity ();
300         if (_enable_facility->GetValue()) {
301                 film()->set_facility (wx_to_std(_facility->GetValue()));
302         } else {
303                 film()->set_facility ();
304         }
305 }
306
307
308 void
309 MetadataDialog::studio_changed ()
310 {
311         film()->set_studio (wx_to_std(_studio->GetValue()));
312 }
313
314
315 void
316 MetadataDialog::enable_studio_changed ()
317 {
318         setup_sensitivity ();
319         if (_enable_studio->GetValue()) {
320                 film()->set_studio (wx_to_std(_studio->GetValue()));
321         } else {
322                 film()->set_studio ();
323         }
324 }
325
326
327 void
328 MetadataDialog::temp_version_changed ()
329 {
330         film()->set_temp_version(_temp_version->GetValue());
331 }
332
333
334 void
335 MetadataDialog::pre_release_changed ()
336 {
337         film()->set_pre_release(_pre_release->GetValue());
338 }
339
340
341 void
342 MetadataDialog::red_band_changed ()
343 {
344         film()->set_red_band(_red_band->GetValue());
345 }
346
347
348 void
349 MetadataDialog::two_d_version_of_three_d_changed ()
350 {
351         film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
352 }
353
354
355 void
356 MetadataDialog::chain_changed ()
357 {
358         film()->set_chain (wx_to_std(_chain->GetValue()));
359 }
360
361
362 void
363 MetadataDialog::enable_chain_changed ()
364 {
365         setup_sensitivity ();
366         if (_enable_chain->GetValue()) {
367                 chain_changed ();
368         } else {
369                 film()->set_chain ();
370         }
371 }
372
373
374 void
375 MetadataDialog::enable_luminance_changed ()
376 {
377         setup_sensitivity ();
378         if (_enable_luminance->GetValue()) {
379                 luminance_changed ();
380         } else {
381                 film()->set_luminance ();
382         }
383 }
384
385
386 void
387 MetadataDialog::luminance_changed ()
388 {
389         dcp::Luminance::Unit unit;
390         switch (_luminance_unit->GetSelection()) {
391         case 0:
392                 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
393                 break;
394         case 1:
395                 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
396                 break;
397         default:
398                 DCPOMATIC_ASSERT (false);
399         }
400
401         film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
402 }
403
404
405 void
406 MetadataDialog::sign_language_video_language_changed ()
407 {
408         film()->set_sign_language_video_language(_sign_language_video_language->get());
409 }
410