Store subtitle language(s) in Film, and allow setup of those
[dcpomatic.git] / src / wx / interop_metadata_dialog.cc
1 /*
2     Copyright (C) 2020 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 #include "interop_metadata_dialog.h"
22 #include "editable_list.h"
23 #include "language_tag_widget.h"
24 #include "rating_dialog.h"
25 #include "lib/film.h"
26 #include <dcp/types.h>
27 #include <wx/gbsizer.h>
28
29 using std::string;
30 using std::vector;
31 using boost::weak_ptr;
32 using boost::shared_ptr;
33 #if BOOST_VERSION >= 106100
34 using namespace boost::placeholders;
35 #endif
36
37
38 static string
39 column (dcp::Rating r, int c)
40 {
41         if (c == 0) {
42                 return r.agency;
43         }
44
45         return r.label;
46 }
47
48 InteropMetadataDialog::InteropMetadataDialog (wxWindow* parent, weak_ptr<Film> film)
49         : wxDialog (parent, wxID_ANY, _("Metadata"))
50         , _film (film)
51 {
52         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
53         SetSizer (overall_sizer);
54
55         wxFlexGridSizer* sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
56         sizer->AddGrowableCol (1, 1);
57
58         shared_ptr<Film> f = _film.lock();
59         DCPOMATIC_ASSERT (f);
60
61         _enable_subtitle_language = new wxCheckBox (this, wxID_ANY, _("Subtitle language"));
62         sizer->Add (_enable_subtitle_language, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
63         vector<dcp::LanguageTag> langs = f->subtitle_languages ();
64         _enable_subtitle_language->SetValue (!langs.empty());
65         _subtitle_language = new LanguageTagWidget (this, wxT(""), langs.empty() ? dcp::LanguageTag("en-US") : langs.front());
66         sizer->Add (_subtitle_language->sizer(), 1, wxEXPAND);
67
68         {
69                 int flags = wxALIGN_TOP | wxLEFT | wxRIGHT | wxTOP;
70 #ifdef __WXOSX__
71                 flags |= wxALIGN_RIGHT;
72 #endif
73                 wxStaticText* m = create_label (this, _("Ratings"), true);
74                 sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
75         }
76
77         vector<EditableListColumn> columns;
78         columns.push_back (EditableListColumn(_("Agency"), 200, true));
79         columns.push_back (EditableListColumn(_("Label"), 50, true));
80         _ratings = new EditableList<dcp::Rating, RatingDialog> (
81                 this,
82                 columns,
83                 boost::bind(&InteropMetadataDialog::ratings, this),
84                 boost::bind(&InteropMetadataDialog::set_ratings, this, _1),
85                 boost::bind(&column, _1, _2),
86                 true,
87                 false
88                 );
89         sizer->Add (_ratings, 1, wxEXPAND);
90
91         add_label_to_sizer (sizer, this, _("Content version"), true);
92         _content_version = new wxTextCtrl (this, wxID_ANY);
93         sizer->Add (_content_version, 1, wxEXPAND);
94
95         vector<string> cv = f->content_versions();
96         _content_version->SetValue (std_to_wx(cv.empty() ? "" : cv[0]));
97
98         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
99
100         wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
101         if (buttons) {
102                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
103         }
104
105         overall_sizer->Layout ();
106         overall_sizer->SetSizeHints (this);
107
108         _enable_subtitle_language->Bind (wxEVT_CHECKBOX, boost::bind(&InteropMetadataDialog::setup_sensitivity, this));
109         _subtitle_language->Changed.connect (boost::bind(&InteropMetadataDialog::subtitle_language_changed, this, _1));
110
111         _content_version->Bind (wxEVT_TEXT, boost::bind(&InteropMetadataDialog::content_version_changed, this));
112         _content_version->SetFocus ();
113
114         setup_sensitivity ();
115 }
116
117
118 void
119 InteropMetadataDialog::setup_sensitivity ()
120 {
121         bool const enabled = _enable_subtitle_language->GetValue();
122         _subtitle_language->enable (enabled);
123
124         shared_ptr<Film> film = _film.lock ();
125         DCPOMATIC_ASSERT (film);
126         if (enabled) {
127                 film->set_subtitle_language (_subtitle_language->get());
128         } else {
129                 film->unset_subtitle_language ();
130         }
131 }
132
133
134 void
135 InteropMetadataDialog::subtitle_language_changed (dcp::LanguageTag language)
136 {
137         shared_ptr<Film> film = _film.lock ();
138         DCPOMATIC_ASSERT (film);
139         film->set_subtitle_language (language);
140 }
141
142
143 vector<dcp::Rating>
144 InteropMetadataDialog::ratings () const
145 {
146         shared_ptr<Film> film = _film.lock ();
147         DCPOMATIC_ASSERT (film);
148         return film->ratings ();
149 }
150
151 void
152 InteropMetadataDialog::set_ratings (vector<dcp::Rating> r)
153 {
154         shared_ptr<Film> film = _film.lock ();
155         DCPOMATIC_ASSERT (film);
156         film->set_ratings (r);
157 }
158
159 void
160 InteropMetadataDialog::content_version_changed ()
161 {
162         shared_ptr<Film> film = _film.lock ();
163         DCPOMATIC_ASSERT (film);
164         vector<string> cv;
165         cv.push_back (wx_to_std(_content_version->GetValue()));
166         film->set_content_versions (cv);
167 }