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