aa61984b36275c9d388005872167b1ed771793b2
[dcpomatic.git] / src / wx / interop_metadata_dialog.cc
1 /*
2     Copyright (C) 2020-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 "editable_list.h"
23 #include "interop_metadata_dialog.h"
24 #include "language_tag_widget.h"
25 #include "rating_dialog.h"
26 #include "lib/film.h"
27 #include <dcp/types.h>
28 #include <wx/gbsizer.h>
29
30
31 using std::string;
32 using std::vector;
33 using std::weak_ptr;
34 using std::shared_ptr;
35 #if BOOST_VERSION >= 106100
36 using namespace boost::placeholders;
37 #endif
38
39
40 InteropMetadataDialog::InteropMetadataDialog (wxWindow* parent, weak_ptr<Film> film)
41         : wxDialog (parent, wxID_ANY, _("Metadata"))
42         , _film (film)
43 {
44         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
45         SetSizer (overall_sizer);
46
47         auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
48         sizer->AddGrowableCol (1, 1);
49
50         auto f = _film.lock();
51         DCPOMATIC_ASSERT (f);
52
53         {
54                 int flags = wxALIGN_TOP | wxLEFT | wxRIGHT | wxTOP;
55 #ifdef __WXOSX__
56                 flags |= wxALIGN_RIGHT;
57 #endif
58                 auto m = create_label (this, _("Ratings"), true);
59                 sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
60         }
61
62         vector<EditableListColumn> columns;
63         columns.push_back (EditableListColumn(_("Agency"), 200, true));
64         columns.push_back (EditableListColumn(_("Label"), 50, true));
65         _ratings = new EditableList<dcp::Rating, RatingDialog> (
66                 this,
67                 columns,
68                 boost::bind(&InteropMetadataDialog::ratings, this),
69                 boost::bind(&InteropMetadataDialog::set_ratings, this, _1),
70                 [](dcp::Rating r, int c) {
71                         if (c == 0) {
72                                 return r.agency;
73                         }
74                         return r.label;
75                 },
76                 true,
77                 false
78                 );
79         sizer->Add (_ratings, 1, wxEXPAND);
80
81         add_label_to_sizer (sizer, this, _("Content version"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
82         _content_version = new wxTextCtrl (this, wxID_ANY);
83         sizer->Add (_content_version, 1, wxEXPAND);
84
85         auto cv = f->content_versions();
86         _content_version->SetValue (std_to_wx(cv.empty() ? "" : cv[0]));
87
88         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
89
90         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
91         if (buttons) {
92                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
93         }
94
95         overall_sizer->Layout ();
96         overall_sizer->SetSizeHints (this);
97
98         _content_version->Bind (wxEVT_TEXT, boost::bind(&InteropMetadataDialog::content_version_changed, this));
99         _content_version->SetFocus ();
100 }
101
102
103 vector<dcp::Rating>
104 InteropMetadataDialog::ratings () const
105 {
106         auto film = _film.lock ();
107         DCPOMATIC_ASSERT (film);
108         return film->ratings ();
109 }
110
111 void
112 InteropMetadataDialog::set_ratings (vector<dcp::Rating> r)
113 {
114         auto film = _film.lock ();
115         DCPOMATIC_ASSERT (film);
116         film->set_ratings (r);
117 }
118
119 void
120 InteropMetadataDialog::content_version_changed ()
121 {
122         auto film = _film.lock ();
123         DCPOMATIC_ASSERT (film);
124         vector<string> cv;
125         cv.push_back (wx_to_std(_content_version->GetValue()));
126         film->set_content_versions (cv);
127 }