Supporters update.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-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 /** @file src/wx/film_editor.cc
23  *  @brief FilmEditor class.
24  */
25
26
27 #include "content_panel.h"
28 #include "dcp_panel.h"
29 #include "film_editor.h"
30 #include "wx_util.h"
31 #include "lib/content.h"
32 #include "lib/dcp_content.h"
33 #include "lib/film.h"
34 #include "lib/job_manager.h"
35 #include <dcp/warnings.h>
36 LIBDCP_DISABLE_WARNINGS
37 #include <wx/notebook.h>
38 #include <wx/wx.h>
39 LIBDCP_ENABLE_WARNINGS
40
41
42 using std::list;
43 using std::shared_ptr;
44 using std::string;
45 using std::weak_ptr;
46 using boost::optional;
47 #if BOOST_VERSION >= 106100
48 using namespace boost::placeholders;
49 #endif
50
51
52 FilmEditor::FilmEditor(wxWindow* parent, FilmViewer& viewer)
53         : wxPanel (parent)
54 {
55         auto s = new wxBoxSizer (wxVERTICAL);
56
57         auto notebook = new wxNotebook(this, wxID_ANY);
58         s->Add(notebook, 1, wxEXPAND);
59
60         _content_panel = new ContentPanel(notebook, _film, viewer);
61         notebook->AddPage(_content_panel->window(), _("Content"), true);
62         _dcp_panel = new DCPPanel(notebook, _film, viewer);
63         notebook->AddPage(_dcp_panel->panel (), _("DCP"), false);
64
65         JobManager::instance()->ActiveJobsChanged.connect (
66                 bind(&FilmEditor::active_jobs_changed, this, _2)
67                 );
68
69         set_film (shared_ptr<Film> ());
70         SetSizerAndFit (s);
71 }
72
73
74 /** Called when the metadata stored in the Film object has changed;
75  *  so that we can update the GUI.
76  *  @param p Property of the Film that has changed.
77  */
78 void
79 FilmEditor::film_change (ChangeType type, Film::Property p)
80 {
81         if (type != ChangeType::DONE) {
82                 return;
83         }
84
85         ensure_ui_thread ();
86
87         if (!_film) {
88                 return;
89         }
90
91         _content_panel->film_changed (p);
92         _dcp_panel->film_changed (p);
93
94         if (p == Film::Property::CONTENT && !_film->content().empty()) {
95                 /* Select newly-added content */
96                 _content_panel->set_selection (_film->content().back ());
97         }
98 }
99
100
101 void
102 FilmEditor::film_content_change (ChangeType type, int property)
103 {
104         if (type != ChangeType::DONE) {
105                 return;
106         }
107
108         ensure_ui_thread ();
109
110         if (!_film) {
111                 /* We call this method ourselves (as well as using it as a signal handler)
112                    so _film can be 0.
113                 */
114                 return;
115         }
116
117         _content_panel->film_content_changed (property);
118         _dcp_panel->film_content_changed (property);
119 }
120
121
122 /** Sets the Film that we are editing */
123 void
124 FilmEditor::set_film (shared_ptr<Film> film)
125 {
126         set_general_sensitivity (film != nullptr);
127
128         if (_film == film) {
129                 return;
130         }
131
132         _film = film;
133
134         _content_panel->set_film (_film);
135         _dcp_panel->set_film (_film);
136
137         if (!_film) {
138                 return;
139         }
140
141         _film->Change.connect (bind(&FilmEditor::film_change, this, _1, _2));
142         _film->ContentChange.connect (bind(&FilmEditor::film_content_change, this, _1, _3));
143
144         if (!_film->content().empty()) {
145                 _content_panel->set_selection (_film->content().front());
146         }
147 }
148
149
150 void
151 FilmEditor::set_general_sensitivity (bool s)
152 {
153         _content_panel->set_general_sensitivity (s);
154         _dcp_panel->set_general_sensitivity (s);
155 }
156
157
158 void
159 FilmEditor::active_jobs_changed (optional<string> j)
160 {
161         set_general_sensitivity (!j);
162 }
163
164
165 void
166 FilmEditor::first_shown ()
167 {
168         _content_panel->first_shown ();
169 }
170