Move some ISDCF flags to the Interop/SMPTE metadata.
[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 "metadata_dialog.h"
25 #include "wx_util.h"
26 #include "lib/film.h"
27 #include <boost/bind.hpp>
28 #include <boost/weak_ptr.hpp>
29 #include <wx/notebook.h>
30 #include <wx/wx.h>
31
32
33 using std::weak_ptr;
34
35
36 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
37         : wxDialog (parent, wxID_ANY, _("Metadata"))
38         , WeakFilm (weak_film)
39 {
40
41 }
42
43
44 void
45 MetadataDialog::setup ()
46 {
47         auto notebook = new wxNotebook (this, wxID_ANY);
48
49         auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
50                 auto panel = new wxPanel (notebook, wxID_ANY);
51                 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
52                 sizer->AddGrowableCol (1, 1);
53                 setup (panel, sizer);
54                 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
55                 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
56                 panel->SetSizer (overall_sizer);
57                 notebook->AddPage (panel, name);
58         };
59
60         prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
61         prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
62
63         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
64         overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
65
66         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
67         if (buttons) {
68                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
69         }
70
71         SetSizer (overall_sizer);
72         overall_sizer->Layout ();
73         overall_sizer->SetSizeHints (this);
74
75         _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
76         _enable_release_territory->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_release_territory_changed, this));
77         _enable_facility->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_facility_changed, this));
78         _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
79         _enable_studio->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_studio_changed, this));
80         _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
81         _temp_version->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::temp_version_changed, this));
82         _pre_release->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::pre_release_changed, this));
83         _red_band->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::red_band_changed, this));
84         _two_d_version_of_three_d->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::two_d_version_of_three_d_changed, this));
85
86         _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
87
88         film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
89         film_changed (ChangeType::DONE, Film::Property::FACILITY);
90         film_changed (ChangeType::DONE, Film::Property::STUDIO);
91         film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
92         film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
93         film_changed (ChangeType::DONE, Film::Property::RED_BAND);
94         film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
95
96         setup_sensitivity ();
97 }
98
99
100 void
101 MetadataDialog::film_changed (ChangeType type, Film::Property property)
102 {
103         if (type != ChangeType::DONE) {
104                 return;
105         }
106
107         if (property == Film::Property::RELEASE_TERRITORY) {
108                 auto rt = film()->release_territory();
109                 checked_set (_enable_release_territory, static_cast<bool>(rt));
110                 if (rt) {
111                         _release_territory = *rt;
112                         checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
113                 }
114         } else if (property == Film::Property::FACILITY) {
115                 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
116                 if (film()->facility()) {
117                         checked_set (_facility, *film()->facility());
118                 }
119         } else if (property == Film::Property::STUDIO) {
120                 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
121                 if (film()->studio()) {
122                         checked_set (_studio, *film()->studio());
123                 }
124         } else if (property == Film::Property::TEMP_VERSION) {
125                 checked_set (_temp_version, film()->temp_version());
126         } else if (property == Film::Property::PRE_RELEASE) {
127                 checked_set (_pre_release, film()->pre_release());
128         } else if (property == Film::Property::RED_BAND) {
129                 checked_set (_red_band, film()->red_band());
130         } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
131                 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
132         }
133 }
134
135
136 void
137 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
138 {
139         _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
140         sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
141         {
142                 auto s = new wxBoxSizer (wxHORIZONTAL);
143                 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
144                 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
145                 _edit_release_territory = new Button (panel, _("Edit..."));
146                 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
147                 sizer->Add (s, 0, wxEXPAND);
148         }
149 }
150
151
152 void
153 MetadataDialog::edit_release_territory ()
154 {
155         DCPOMATIC_ASSERT (film()->release_territory());
156         auto d = new RegionSubtagDialog(this, *film()->release_territory());
157         d->ShowModal ();
158         auto tag = d->get();
159         if (tag) {
160                 _release_territory = *tag;
161                 film()->set_release_territory(*tag);
162         }
163         d->Destroy ();
164 }
165
166
167 void
168 MetadataDialog::setup_sensitivity ()
169 {
170         auto const enabled = _enable_release_territory->GetValue();
171         _release_territory_text->Enable (enabled);
172         _edit_release_territory->Enable (enabled);
173         _facility->Enable (_enable_facility->GetValue());
174         _studio->Enable (_enable_studio->GetValue());
175 }
176
177
178 void
179 MetadataDialog::enable_release_territory_changed ()
180 {
181         setup_sensitivity ();
182         if (_enable_release_territory->GetValue()) {
183                 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
184         } else {
185                 film()->set_release_territory ();
186         }
187 }
188
189
190 void
191 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
192 {
193         _enable_facility = new wxCheckBox (panel, wxID_ANY, _("Facility"));
194         sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
195         _facility = new wxTextCtrl (panel, wxID_ANY);
196         sizer->Add (_facility, 1, wxEXPAND);
197
198         _enable_studio = new wxCheckBox (panel, wxID_ANY, _("Studio"));
199         sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
200         _studio = new wxTextCtrl (panel, wxID_ANY);
201         sizer->Add (_studio, 1, wxEXPAND);
202
203         _temp_version = new wxCheckBox (panel, wxID_ANY, _("Temporary version"));
204         sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
205         sizer->AddSpacer (0);
206
207         _pre_release = new wxCheckBox (panel, wxID_ANY, _("Pre-release"));
208         sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
209         sizer->AddSpacer (0);
210
211         _red_band = new wxCheckBox (panel, wxID_ANY, _("Red band"));
212         sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
213         sizer->AddSpacer (0);
214
215         _two_d_version_of_three_d = new wxCheckBox (panel, wxID_ANY, _("2D version of 3D DCP"));
216         sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
217         sizer->AddSpacer (0);
218 }
219
220
221 void
222 MetadataDialog::facility_changed ()
223 {
224         film()->set_facility (wx_to_std(_facility->GetValue()));
225 }
226
227
228 void
229 MetadataDialog::enable_facility_changed ()
230 {
231         setup_sensitivity ();
232         if (_enable_facility->GetValue()) {
233                 film()->set_facility (wx_to_std(_facility->GetValue()));
234         } else {
235                 film()->set_facility ();
236         }
237 }
238
239
240 void
241 MetadataDialog::studio_changed ()
242 {
243         film()->set_studio (wx_to_std(_studio->GetValue()));
244 }
245
246
247 void
248 MetadataDialog::enable_studio_changed ()
249 {
250         setup_sensitivity ();
251         if (_enable_studio->GetValue()) {
252                 film()->set_studio (wx_to_std(_studio->GetValue()));
253         } else {
254                 film()->set_studio ();
255         }
256 }
257
258
259 void
260 MetadataDialog::temp_version_changed ()
261 {
262         film()->set_temp_version(_temp_version->GetValue());
263 }
264
265
266 void
267 MetadataDialog::pre_release_changed ()
268 {
269         film()->set_pre_release(_pre_release->GetValue());
270 }
271
272
273 void
274 MetadataDialog::red_band_changed ()
275 {
276         film()->set_red_band(_red_band->GetValue());
277 }
278
279
280 void
281 MetadataDialog::two_d_version_of_three_d_changed ()
282 {
283         film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
284 }
285