Fix missing buttons for ratings lists.
[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 <dcp/warnings.h>
29 LIBDCP_DISABLE_WARNINGS
30 #include <wx/gbsizer.h>
31 LIBDCP_ENABLE_WARNINGS
32
33
34 using std::shared_ptr;
35 using std::string;
36 using std::vector;
37 using std::weak_ptr;
38 #if BOOST_VERSION >= 106100
39 using namespace boost::placeholders;
40 #endif
41
42
43 InteropMetadataDialog::InteropMetadataDialog (wxWindow* parent, weak_ptr<Film> film)
44         : MetadataDialog (parent, film)
45 {
46
47 }
48
49 void
50 InteropMetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
51 {
52         MetadataDialog::setup_standard (panel, sizer);
53
54         {
55                 int flags = wxALIGN_TOP | wxLEFT | wxRIGHT | wxTOP;
56 #ifdef __WXOSX__
57                 flags |= wxALIGN_RIGHT;
58 #endif
59                 auto m = create_label (panel, _("Ratings"), true);
60                 sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
61         }
62
63         vector<EditableListColumn> columns;
64         columns.push_back (EditableListColumn(_("Agency"), 200, true));
65         columns.push_back (EditableListColumn(_("Label"), 50, true));
66         _ratings = new EditableList<dcp::Rating, RatingDialog> (
67                 panel,
68                 columns,
69                 boost::bind(&InteropMetadataDialog::ratings, this),
70                 boost::bind(&InteropMetadataDialog::set_ratings, this, _1),
71                 [](dcp::Rating r, int c) {
72                         if (c == 0) {
73                                 return r.agency;
74                         }
75                         return r.label;
76                 },
77                 true,
78                 EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
79                 );
80         sizer->Add (_ratings, 1, wxEXPAND);
81
82         add_label_to_sizer (sizer, panel, _("Content version"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
83         _content_version = new wxTextCtrl (panel, wxID_ANY);
84         sizer->Add (_content_version, 1, wxEXPAND);
85
86         auto cv = film()->content_versions();
87         _content_version->SetValue (std_to_wx(cv.empty() ? "" : cv[0]));
88
89         _content_version->Bind (wxEVT_TEXT, boost::bind(&InteropMetadataDialog::content_version_changed, this));
90         _content_version->SetFocus ();
91 }
92
93
94 vector<dcp::Rating>
95 InteropMetadataDialog::ratings () const
96 {
97         return film()->ratings ();
98 }
99
100
101 void
102 InteropMetadataDialog::set_ratings (vector<dcp::Rating> r)
103 {
104         film()->set_ratings (r);
105 }
106
107
108 void
109 InteropMetadataDialog::content_version_changed ()
110 {
111         film()->set_content_versions ({ wx_to_std(_content_version->GetValue()) });
112 }