Include trimming.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/film_editor.cc
21  *  @brief A wx widget to edit a film's metadata, and perform various functions.
22  */
23
24 #include "lib/film.h"
25 #include "lib/job_manager.h"
26 #include "lib/content.h"
27 #include "lib/dcp_content.h"
28 #include "wx_util.h"
29 #include "film_editor.h"
30 #include "dcp_panel.h"
31 #include "content_panel.h"
32 #include <wx/wx.h>
33 #include <wx/notebook.h>
34 #include <iostream>
35
36 using std::cout;
37 using boost::shared_ptr;
38
39 /** @param f Film to edit */
40 FilmEditor::FilmEditor (wxWindow* parent)
41         : wxPanel (parent)
42 {
43         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
44
45         _main_notebook = new wxNotebook (this, wxID_ANY);
46         s->Add (_main_notebook, 1);
47
48         _content_panel = new ContentPanel (_main_notebook, _film);
49         _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
50         _dcp_panel = new DCPPanel (_main_notebook, _film);
51         _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false);
52         
53         JobManager::instance()->ActiveJobsChanged.connect (
54                 bind (&FilmEditor::active_jobs_changed, this, _1)
55                 );
56
57         set_film (shared_ptr<Film> ());
58         SetSizerAndFit (s);
59 }
60
61
62 /** Called when the metadata stored in the Film object has changed;
63  *  so that we can update the GUI.
64  *  @param p Property of the Film that has changed.
65  */
66 void
67 FilmEditor::film_changed (Film::Property p)
68 {
69         ensure_ui_thread ();
70         
71         if (!_film) {
72                 return;
73         }
74
75         _content_panel->film_changed (p);
76         _dcp_panel->film_changed (p);
77 }
78
79 void
80 FilmEditor::film_content_changed (int property)
81 {
82         ensure_ui_thread ();
83         
84         if (!_film) {
85                 /* We call this method ourselves (as well as using it as a signal handler)
86                    so _film can be 0.
87                 */
88                 return;
89         }
90
91         _content_panel->film_content_changed (property);
92         _dcp_panel->film_content_changed (property);
93 }
94
95 /** Sets the Film that we are editing */
96 void
97 FilmEditor::set_film (shared_ptr<Film> f)
98 {
99         set_general_sensitivity (f != 0);
100
101         if (_film == f) {
102                 return;
103         }
104         
105         _film = f;
106
107         _content_panel->set_film (_film);
108         _dcp_panel->set_film (_film);
109
110         if (_film) {
111                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
112                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
113         }
114
115         if (_film) {
116                 FileChanged (_film->directory ());
117         } else {
118                 FileChanged ("");
119         }
120
121         if (!_film->content().empty ()) {
122                 _content_panel->set_selection (_film->content().front ());
123         }
124 }
125
126 void
127 FilmEditor::set_general_sensitivity (bool s)
128 {
129         _content_panel->set_general_sensitivity (s);
130         _dcp_panel->set_general_sensitivity (s);
131 }
132
133 void
134 FilmEditor::active_jobs_changed (bool a)
135 {
136         set_general_sensitivity (!a);
137 }