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