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