Supporters update.
[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 "check_box.h"
23 #include "dcpomatic_button.h"
24 #include "dcpomatic_choice.h"
25 #include "editable_list.h"
26 #include "full_language_tag_dialog.h"
27 #include "language_tag_widget.h"
28 #include "metadata_dialog.h"
29 #include "rating_dialog.h"
30 #include "region_subtag_widget.h"
31 #include "wx_util.h"
32 #include "lib/film.h"
33 #include "lib/film_property.h"
34 #include <dcp/warnings.h>
35 LIBDCP_DISABLE_WARNINGS
36 #include <wx/notebook.h>
37 #include <wx/spinctrl.h>
38 #include <wx/wx.h>
39 LIBDCP_ENABLE_WARNINGS
40 #include <boost/bind/bind.hpp>
41 #include <boost/weak_ptr.hpp>
42
43
44 using std::weak_ptr;
45 using std::vector;
46 using boost::optional;
47 #if BOOST_VERSION >= 106100
48 using namespace boost::placeholders;
49 #endif
50
51
52 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
53         : wxDialog (parent, wxID_ANY, _("Metadata"))
54         , WeakFilm (weak_film)
55 {
56         for (auto system: dcp::rating_systems()) {
57                 _rating_system_agency_to_name[system.agency] = system.name;
58         }
59 }
60
61
62 void
63 MetadataDialog::setup ()
64 {
65         auto notebook = new wxNotebook (this, wxID_ANY);
66
67         auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
68                 auto panel = new wxPanel (notebook, wxID_ANY);
69                 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
70                 sizer->AddGrowableCol (1, 1);
71                 setup (panel, sizer);
72                 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
73                 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
74                 panel->SetSizer (overall_sizer);
75                 notebook->AddPage (panel, name);
76         };
77
78         prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
79         prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
80
81         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
82         overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
83
84         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
85         if (buttons) {
86                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
87         }
88
89         SetSizer (overall_sizer);
90         overall_sizer->Layout ();
91         overall_sizer->SetSizeHints (this);
92
93         _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this));
94         _enable_release_territory->bind(&MetadataDialog::enable_release_territory_changed, this);
95         _release_territory->Changed.connect(boost::bind(&MetadataDialog::release_territory_changed, this, _1));
96         _enable_facility->bind(&MetadataDialog::enable_facility_changed, this);
97         _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
98         _enable_studio->bind(&MetadataDialog::enable_studio_changed, this);
99         _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
100         _enable_chain->bind(&MetadataDialog::enable_chain_changed, this);
101         _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
102         _temp_version->bind(&MetadataDialog::temp_version_changed, this);
103         _pre_release->bind(&MetadataDialog::pre_release_changed, this);
104         _red_band->bind(&MetadataDialog::red_band_changed, this);
105         _two_d_version_of_three_d->bind(&MetadataDialog::two_d_version_of_three_d_changed, this);
106         _enable_luminance->bind(&MetadataDialog::enable_luminance_changed, this);
107         _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&MetadataDialog::luminance_changed, this));
108         _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&MetadataDialog::luminance_changed, this));
109         _territory_type->bind(&MetadataDialog::territory_type_changed, this);
110
111         _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
112
113         film_changed(ChangeType::DONE, FilmProperty::RELEASE_TERRITORY);
114         film_changed(ChangeType::DONE, FilmProperty::SIGN_LANGUAGE_VIDEO_LANGUAGE);
115         film_changed(ChangeType::DONE, FilmProperty::FACILITY);
116         film_changed(ChangeType::DONE, FilmProperty::STUDIO);
117         film_changed(ChangeType::DONE, FilmProperty::TEMP_VERSION);
118         film_changed(ChangeType::DONE, FilmProperty::PRE_RELEASE);
119         film_changed(ChangeType::DONE, FilmProperty::RED_BAND);
120         film_changed(ChangeType::DONE, FilmProperty::TWO_D_VERSION_OF_THREE_D);
121         film_changed(ChangeType::DONE, FilmProperty::CHAIN);
122         film_changed(ChangeType::DONE, FilmProperty::LUMINANCE);
123         film_changed(ChangeType::DONE, FilmProperty::TERRITORY_TYPE);
124
125         setup_sensitivity ();
126 }
127
128
129 void
130 MetadataDialog::territory_type_changed()
131 {
132         auto data = _territory_type->get_data();
133         if (data) {
134                 film()->set_territory_type(string_to_territory_type(wx_to_std(data->data())));
135         }
136 }
137
138
139 void
140 MetadataDialog::film_changed(ChangeType type, FilmProperty property)
141 {
142         if (type != ChangeType::DONE) {
143                 return;
144         }
145
146         if (property == FilmProperty::SIGN_LANGUAGE_VIDEO_LANGUAGE) {
147                 _sign_language_video_language->set (film()->sign_language_video_language());
148         } else if (property == FilmProperty::RELEASE_TERRITORY) {
149                 auto rt = film()->release_territory();
150                 checked_set (_enable_release_territory, static_cast<bool>(rt));
151                 if (rt) {
152                         _release_territory_copy = *rt;
153                         checked_set(_release_territory, *_release_territory_copy);
154                 }
155         } else if (property == FilmProperty::FACILITY) {
156                 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
157                 if (film()->facility()) {
158                         checked_set (_facility, *film()->facility());
159                 }
160         } else if (property == FilmProperty::STUDIO) {
161                 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
162                 if (film()->studio()) {
163                         checked_set (_studio, *film()->studio());
164                 }
165         } else if (property == FilmProperty::CHAIN) {
166                 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
167                 if (film()->chain()) {
168                         checked_set (_chain, *film()->chain());
169                 }
170         } else if (property == FilmProperty::TEMP_VERSION) {
171                 checked_set (_temp_version, film()->temp_version());
172         } else if (property == FilmProperty::PRE_RELEASE) {
173                 checked_set (_pre_release, film()->pre_release());
174         } else if (property == FilmProperty::RED_BAND) {
175                 checked_set (_red_band, film()->red_band());
176         } else if (property == FilmProperty::TWO_D_VERSION_OF_THREE_D) {
177                 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
178         } else if (property == FilmProperty::LUMINANCE) {
179                 auto lum = film()->luminance();
180                 checked_set (_enable_luminance, static_cast<bool>(lum));
181                 if (lum) {
182                         checked_set (_luminance_value, lum->value());
183                         switch (lum->unit()) {
184                         case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
185                                 checked_set (_luminance_unit, 0);
186                                 break;
187                         case dcp::Luminance::Unit::FOOT_LAMBERT:
188                                 checked_set (_luminance_unit, 1);
189                                 break;
190                         }
191                 } else {
192                         checked_set(_luminance_value, 14);
193                         checked_set (_luminance_unit, 1);
194                 }
195         } else if (property == FilmProperty::TERRITORY_TYPE) {
196                 _territory_type->set_by_data(territory_type_to_string(film()->territory_type()));
197                 setup_sensitivity();
198         }
199 }
200
201
202 void
203 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
204 {
205         add_label_to_sizer(sizer, panel, _("Territory type"), true, 0, wxALIGN_CENTER_VERTICAL);
206         _territory_type = new Choice(panel);
207         _territory_type->add(_("Specific"), wx_to_std(territory_type_to_string(TerritoryType::SPECIFIC)));
208         _territory_type->add(_("International texted"), wx_to_std(territory_type_to_string(TerritoryType::INTERNATIONAL_TEXTED)));
209         _territory_type->add(_("International textless"), wx_to_std(territory_type_to_string(TerritoryType::INTERNATIONAL_TEXTLESS)));
210         sizer->Add(_territory_type);
211
212         _enable_release_territory = new CheckBox(panel, _("Release territory"));
213         sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
214         _release_territory = new RegionSubtagWidget(panel, _("Release territory for this DCP"), film()->release_territory());
215         sizer->Add(_release_territory->sizer(), 0, wxEXPAND);
216
217         vector<EditableListColumn> columns;
218         columns.push_back(EditableListColumn("Agency", 200, true));
219         columns.push_back(EditableListColumn("Label", 400, true));
220         _ratings = new EditableList<dcp::Rating, RatingDialog> (
221                 panel,
222                 columns,
223                 boost::bind(&MetadataDialog::ratings, this),
224                 boost::bind(&MetadataDialog::set_ratings, this, _1),
225                 [this](dcp::Rating r, int c) {
226                         if (c == 0) {
227                                 auto iter = _rating_system_agency_to_name.find(r.agency);
228                                 if (iter != _rating_system_agency_to_name.end()) {
229                                         return iter->second;
230                                 }
231                                 return r.agency;
232                         }
233                         return r.label;
234                 },
235                 EditableListTitle::VISIBLE,
236                 EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
237                 );
238         _ratings->SetMinSize(wxSize(600, -1));
239 }
240
241
242 void
243 MetadataDialog::release_territory_changed(optional<dcp::LanguageTag::RegionSubtag> tag)
244 {
245         if (tag) {
246                 _release_territory_copy = *tag;
247                 film()->set_release_territory(*tag);
248         }
249 }
250
251
252 void
253 MetadataDialog::setup_sensitivity ()
254 {
255         auto const territory_type = film()->territory_type();
256         _enable_release_territory->Enable(territory_type == TerritoryType::SPECIFIC);
257         _sign_language_video_language->enable (film()->has_sign_language_video_channel());
258         auto const enabled = _enable_release_territory->GetValue();
259         _release_territory->enable(enabled && territory_type == TerritoryType::SPECIFIC);
260         _ratings->Enable(territory_type == TerritoryType::SPECIFIC);
261         _facility->Enable (_enable_facility->GetValue());
262         _chain->Enable (_enable_chain->GetValue());
263         _studio->Enable (_enable_studio->GetValue());
264         _luminance_value->Enable (_enable_luminance->GetValue());
265         _luminance_unit->Enable (_enable_luminance->GetValue());
266 }
267
268
269 void
270 MetadataDialog::enable_release_territory_changed ()
271 {
272         setup_sensitivity ();
273         if (_enable_release_territory->GetValue()) {
274                 film()->set_release_territory (_release_territory->get().get_value_or(dcp::LanguageTag::RegionSubtag("US")));
275         } else {
276                 film()->set_release_territory ();
277         }
278 }
279
280
281 void
282 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
283 {
284         add_label_to_sizer (sizer, panel, _("Sign language video language"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
285         _sign_language_video_language = new LanguageTagWidget (panel, _("Language used for any sign language video track"), {}, {});
286         sizer->Add (_sign_language_video_language->sizer(), 1, wxEXPAND);
287
288         _enable_facility = new CheckBox(panel, _("Facility"));
289         sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
290         _facility = new wxTextCtrl (panel, wxID_ANY);
291         sizer->Add (_facility, 1, wxEXPAND);
292
293         _enable_studio = new CheckBox(panel, _("Studio"));
294         sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
295         _studio = new wxTextCtrl (panel, wxID_ANY);
296         sizer->Add (_studio, 1, wxEXPAND);
297
298         _enable_chain = new CheckBox(panel, _("Chain"));
299         sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
300         _chain = new wxTextCtrl (panel, wxID_ANY);
301         sizer->Add (_chain, 1, wxEXPAND);
302
303         _temp_version = new CheckBox(panel, _("Temporary version"));
304         sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
305         sizer->AddSpacer (0);
306
307         _pre_release = new CheckBox(panel, _("Pre-release"));
308         sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
309         sizer->AddSpacer (0);
310
311         _red_band = new CheckBox(panel, _("Red band"));
312         sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
313         sizer->AddSpacer (0);
314
315         _two_d_version_of_three_d = new CheckBox(panel, _("2D version of 3D DCP"));
316         sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
317         sizer->AddSpacer (0);
318
319         _enable_luminance = new CheckBox(panel, _("Luminance"));
320         sizer->Add (_enable_luminance, 0, wxALIGN_CENTER_VERTICAL);
321         {
322                 auto s = new wxBoxSizer (wxHORIZONTAL);
323                 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
324                 _luminance_value->SetRange (0.1, 32.0);
325                 _luminance_value->SetDigits (1);
326                 _luminance_value->SetIncrement (0.1);
327                 s->Add (_luminance_value, 0);
328                 _luminance_unit = new Choice(panel);
329                 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
330                 sizer->Add (s, 1, wxEXPAND);
331         }
332
333         _luminance_unit->add(_("candela per m²"));
334         _luminance_unit->add(_("foot lambert"));
335 }
336
337
338 void
339 MetadataDialog::facility_changed ()
340 {
341         film()->set_facility (wx_to_std(_facility->GetValue()));
342 }
343
344
345 void
346 MetadataDialog::enable_facility_changed ()
347 {
348         setup_sensitivity ();
349         if (_enable_facility->GetValue()) {
350                 film()->set_facility (wx_to_std(_facility->GetValue()));
351         } else {
352                 film()->set_facility ();
353         }
354 }
355
356
357 void
358 MetadataDialog::studio_changed ()
359 {
360         film()->set_studio (wx_to_std(_studio->GetValue()));
361 }
362
363
364 void
365 MetadataDialog::enable_studio_changed ()
366 {
367         setup_sensitivity ();
368         if (_enable_studio->GetValue()) {
369                 film()->set_studio (wx_to_std(_studio->GetValue()));
370         } else {
371                 film()->set_studio ();
372         }
373 }
374
375
376 void
377 MetadataDialog::temp_version_changed ()
378 {
379         film()->set_temp_version(_temp_version->GetValue());
380 }
381
382
383 void
384 MetadataDialog::pre_release_changed ()
385 {
386         film()->set_pre_release(_pre_release->GetValue());
387 }
388
389
390 void
391 MetadataDialog::red_band_changed ()
392 {
393         film()->set_red_band(_red_band->GetValue());
394 }
395
396
397 void
398 MetadataDialog::two_d_version_of_three_d_changed ()
399 {
400         film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
401 }
402
403
404 void
405 MetadataDialog::chain_changed ()
406 {
407         film()->set_chain (wx_to_std(_chain->GetValue()));
408 }
409
410
411 void
412 MetadataDialog::enable_chain_changed ()
413 {
414         setup_sensitivity ();
415         if (_enable_chain->GetValue()) {
416                 chain_changed ();
417         } else {
418                 film()->set_chain ();
419         }
420 }
421
422
423 void
424 MetadataDialog::enable_luminance_changed ()
425 {
426         setup_sensitivity ();
427         if (_enable_luminance->GetValue()) {
428                 luminance_changed ();
429         } else {
430                 film()->set_luminance ();
431         }
432 }
433
434
435 void
436 MetadataDialog::luminance_changed ()
437 {
438         dcp::Luminance::Unit unit;
439         DCPOMATIC_ASSERT(_luminance_unit->get());
440         switch (*_luminance_unit->get()) {
441         case 0:
442                 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
443                 break;
444         case 1:
445                 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
446                 break;
447         default:
448                 DCPOMATIC_ASSERT (false);
449         }
450
451         film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
452 }
453
454
455 void
456 MetadataDialog::sign_language_video_language_changed ()
457 {
458         film()->set_sign_language_video_language(_sign_language_video_language->get());
459 }
460
461
462 vector<dcp::Rating>
463 MetadataDialog::ratings() const
464 {
465         return film()->ratings();
466 }
467
468
469 void
470 MetadataDialog::set_ratings(vector<dcp::Rating> r)
471 {
472         film()->set_ratings(r);
473 }
474