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