Use release territory from Interop/SMPTE metadata instead of ISDCF metadata dialogue.
[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         _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
76
77         film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
78 }
79
80
81 void
82 MetadataDialog::film_changed (ChangeType type, Film::Property property)
83 {
84         if (type != ChangeType::DONE) {
85                 return;
86         }
87
88         if (property == Film::Property::RELEASE_TERRITORY) {
89                 auto rt = film()->release_territory();
90                 checked_set (_enable_release_territory, static_cast<bool>(rt));
91                 if (rt) {
92                         _release_territory = *rt;
93                         checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
94                 }
95         }
96 }
97
98
99 void
100 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
101 {
102         _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
103         sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
104         {
105                 auto s = new wxBoxSizer (wxHORIZONTAL);
106                 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
107                 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
108                 _edit_release_territory = new Button (panel, _("Edit..."));
109                 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
110                 sizer->Add (s, 0, wxEXPAND);
111         }
112
113         _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
114         _enable_release_territory->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_release_territory_changed, this));
115 }
116
117
118 void
119 MetadataDialog::edit_release_territory ()
120 {
121         DCPOMATIC_ASSERT (film()->release_territory());
122         auto d = new RegionSubtagDialog(this, *film()->release_territory());
123         d->ShowModal ();
124         auto tag = d->get();
125         if (tag) {
126                 _release_territory = *tag;
127                 film()->set_release_territory(*tag);
128         }
129         d->Destroy ();
130 }
131
132
133 void
134 MetadataDialog::setup_sensitivity ()
135 {
136         auto const enabled = _enable_release_territory->GetValue();
137         _release_territory_text->Enable (enabled);
138         _edit_release_territory->Enable (enabled);
139 }
140
141
142 void
143 MetadataDialog::enable_release_territory_changed ()
144 {
145         setup_sensitivity ();
146         if (_enable_release_territory->GetValue()) {
147                 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
148         } else {
149                 film()->set_release_territory ();
150         }
151 }
152