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