2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "dcpomatic_button.h"
23 #include "full_language_tag_dialog.h"
24 #include "metadata_dialog.h"
27 #include <boost/bind.hpp>
28 #include <boost/weak_ptr.hpp>
29 #include <wx/notebook.h>
36 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
37 : wxDialog (parent, wxID_ANY, _("Metadata"))
38 , WeakFilm (weak_film)
45 MetadataDialog::setup ()
47 auto notebook = new wxNotebook (this, wxID_ANY);
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);
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);
60 prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
61 prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
63 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
64 overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
66 auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
68 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
71 SetSizer (overall_sizer);
72 overall_sizer->Layout ();
73 overall_sizer->SetSizeHints (this);
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 _enable_chain->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_chain_changed, this));
82 _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
83 _temp_version->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::temp_version_changed, this));
84 _pre_release->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::pre_release_changed, this));
85 _red_band->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::red_band_changed, this));
86 _two_d_version_of_three_d->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::two_d_version_of_three_d_changed, this));
88 _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
90 film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
91 film_changed (ChangeType::DONE, Film::Property::FACILITY);
92 film_changed (ChangeType::DONE, Film::Property::STUDIO);
93 film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
94 film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
95 film_changed (ChangeType::DONE, Film::Property::RED_BAND);
96 film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
97 film_changed (ChangeType::DONE, Film::Property::CHAIN);
104 MetadataDialog::film_changed (ChangeType type, Film::Property property)
106 if (type != ChangeType::DONE) {
110 if (property == Film::Property::RELEASE_TERRITORY) {
111 auto rt = film()->release_territory();
112 checked_set (_enable_release_territory, static_cast<bool>(rt));
114 _release_territory = *rt;
115 checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
117 } else if (property == Film::Property::FACILITY) {
118 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
119 if (film()->facility()) {
120 checked_set (_facility, *film()->facility());
122 } else if (property == Film::Property::STUDIO) {
123 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
124 if (film()->studio()) {
125 checked_set (_studio, *film()->studio());
127 } else if (property == Film::Property::CHAIN) {
128 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
129 if (film()->chain()) {
130 checked_set (_chain, *film()->chain());
132 } else if (property == Film::Property::TEMP_VERSION) {
133 checked_set (_temp_version, film()->temp_version());
134 } else if (property == Film::Property::PRE_RELEASE) {
135 checked_set (_pre_release, film()->pre_release());
136 } else if (property == Film::Property::RED_BAND) {
137 checked_set (_red_band, film()->red_band());
138 } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
139 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
145 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
147 _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
148 sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
150 auto s = new wxBoxSizer (wxHORIZONTAL);
151 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
152 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
153 _edit_release_territory = new Button (panel, _("Edit..."));
154 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
155 sizer->Add (s, 0, wxEXPAND);
161 MetadataDialog::edit_release_territory ()
163 DCPOMATIC_ASSERT (film()->release_territory());
164 auto d = new RegionSubtagDialog(this, *film()->release_territory());
168 _release_territory = *tag;
169 film()->set_release_territory(*tag);
176 MetadataDialog::setup_sensitivity ()
178 auto const enabled = _enable_release_territory->GetValue();
179 _release_territory_text->Enable (enabled);
180 _edit_release_territory->Enable (enabled);
181 _facility->Enable (_enable_facility->GetValue());
182 _chain->Enable (_enable_chain->GetValue());
183 _studio->Enable (_enable_studio->GetValue());
188 MetadataDialog::enable_release_territory_changed ()
190 setup_sensitivity ();
191 if (_enable_release_territory->GetValue()) {
192 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
194 film()->set_release_territory ();
200 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
202 _enable_facility = new wxCheckBox (panel, wxID_ANY, _("Facility"));
203 sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
204 _facility = new wxTextCtrl (panel, wxID_ANY);
205 sizer->Add (_facility, 1, wxEXPAND);
207 _enable_studio = new wxCheckBox (panel, wxID_ANY, _("Studio"));
208 sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
209 _studio = new wxTextCtrl (panel, wxID_ANY);
210 sizer->Add (_studio, 1, wxEXPAND);
212 _enable_chain = new wxCheckBox (panel, wxID_ANY, _("Chain"));
213 sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
214 _chain = new wxTextCtrl (panel, wxID_ANY);
215 sizer->Add (_chain, 1, wxEXPAND);
217 _temp_version = new wxCheckBox (panel, wxID_ANY, _("Temporary version"));
218 sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
219 sizer->AddSpacer (0);
221 _pre_release = new wxCheckBox (panel, wxID_ANY, _("Pre-release"));
222 sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
223 sizer->AddSpacer (0);
225 _red_band = new wxCheckBox (panel, wxID_ANY, _("Red band"));
226 sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
227 sizer->AddSpacer (0);
229 _two_d_version_of_three_d = new wxCheckBox (panel, wxID_ANY, _("2D version of 3D DCP"));
230 sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
231 sizer->AddSpacer (0);
236 MetadataDialog::facility_changed ()
238 film()->set_facility (wx_to_std(_facility->GetValue()));
243 MetadataDialog::enable_facility_changed ()
245 setup_sensitivity ();
246 if (_enable_facility->GetValue()) {
247 film()->set_facility (wx_to_std(_facility->GetValue()));
249 film()->set_facility ();
255 MetadataDialog::studio_changed ()
257 film()->set_studio (wx_to_std(_studio->GetValue()));
262 MetadataDialog::enable_studio_changed ()
264 setup_sensitivity ();
265 if (_enable_studio->GetValue()) {
266 film()->set_studio (wx_to_std(_studio->GetValue()));
268 film()->set_studio ();
274 MetadataDialog::temp_version_changed ()
276 film()->set_temp_version(_temp_version->GetValue());
281 MetadataDialog::pre_release_changed ()
283 film()->set_pre_release(_pre_release->GetValue());
288 MetadataDialog::red_band_changed ()
290 film()->set_red_band(_red_band->GetValue());
295 MetadataDialog::two_d_version_of_three_d_changed ()
297 film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
302 MetadataDialog::chain_changed ()
304 film()->set_chain (wx_to_std(_chain->GetValue()));
309 MetadataDialog::enable_chain_changed ()
311 setup_sensitivity ();
312 if (_enable_chain->GetValue()) {
313 film()->set_chain (wx_to_std(_chain->GetValue()));
315 film()->set_chain ();