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