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