2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include <boost/filesystem.hpp>
22 #include "gtk/film_viewer.h"
23 #include "gtk/film_editor.h"
24 #include "gtk/film_player.h"
25 #include "gtk/job_manager_view.h"
26 #include "gtk/config_dialog.h"
28 #include "gtk/job_wrapper.h"
29 #include "gtk/dvd_title_dialog.h"
30 #include "gtk/gtk_util.h"
32 #include "lib/format.h"
33 #include "lib/config.h"
34 #include "lib/filter.h"
36 #include "lib/scaler.h"
37 #include "lib/exceptions.h"
40 using namespace boost;
42 static Gtk::Window* window = 0;
43 static FilmViewer* film_viewer = 0;
44 static FilmEditor* film_editor = 0;
45 static FilmPlayer* film_player = 0;
46 static Film* film = 0;
48 class FilmChangedDialog : public Gtk::MessageDialog
52 : Gtk::MessageDialog ("", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE)
55 s << "Save changes to film \"" << film->name() << "\" before closing?";
56 set_message (s.str ());
57 add_button ("Close _without saving", Gtk::RESPONSE_NO);
58 add_button ("_Cancel", Gtk::RESPONSE_CANCEL);
59 add_button ("_Save", Gtk::RESPONSE_YES);
64 maybe_save_then_delete_film ()
73 case Gtk::RESPONSE_CANCEL:
75 case Gtk::RESPONSE_YES:
76 film->write_metadata ();
78 case Gtk::RESPONSE_NO:
91 Gtk::FileChooserDialog c (*window, "New Film", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
92 c.add_button ("_Cancel", Gtk::RESPONSE_CANCEL);
93 c.add_button ("C_reate", Gtk::RESPONSE_ACCEPT);
95 int const r = c.run ();
96 if (r == Gtk::RESPONSE_ACCEPT) {
97 if (maybe_save_then_delete_film ()) {
100 film = new Film (c.get_filename ());
101 #if BOOST_FILESYSTEM_VERSION == 3
102 film->set_name (filesystem::path (c.get_filename().c_str()).filename().generic_string());
104 film->set_name (filesystem::path (c.get_filename().c_str()).filename());
106 film_viewer->set_film (film);
107 film_editor->set_film (film);
114 Gtk::FileChooserDialog c (*window, "Open Film", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
115 c.add_button ("_Cancel", Gtk::RESPONSE_CANCEL);
116 c.add_button ("_Open", Gtk::RESPONSE_ACCEPT);
118 int const r = c.run ();
119 if (r == Gtk::RESPONSE_ACCEPT) {
120 if (maybe_save_then_delete_film ()) {
123 film = new Film (c.get_filename ());
124 film_viewer->set_film (film);
125 film_editor->set_film (film);
132 film->write_metadata ();
138 if (maybe_save_then_delete_film ()) {
150 Config::instance()->write ();
156 JobWrapper::make_dcp (film, true);
160 jobs_make_dcp_from_existing_transcode ()
162 JobWrapper::make_dcp (film, false);
166 jobs_copy_from_dvd ()
170 if (d.run () != Gtk::RESPONSE_OK) {
173 film->copy_from_dvd ();
174 } catch (DVDError& e) {
175 error_dialog (e.what ());
180 jobs_send_dcp_to_tms ()
182 film->send_dcp_to_tms ();
186 jobs_examine_content ()
188 film->examine_content ();
195 d.set_name ("DVD-o-matic");
196 d.set_version (DVDOMATIC_VERSION);
199 s << "DCP generation from arbitrary formats\n\n"
200 << "Using " << dependency_version_summary() << "\n";
201 d.set_comments (s.str ());
203 vector<string> authors;
204 authors.push_back ("Carl Hetherington");
205 authors.push_back ("Terrence Meiczinger");
206 authors.push_back ("Paul Davis");
207 d.set_authors (authors);
209 d.set_website ("http://carlh.net/software/dvdomatic");
216 setup_menu (Gtk::MenuBar& m)
218 using namespace Gtk::Menu_Helpers;
220 Gtk::Menu* file = manage (new Gtk::Menu);
221 MenuList& file_items (file->items ());
222 file_items.push_back (MenuElem ("_New...", sigc::ptr_fun (file_new)));
223 file_items.push_back (MenuElem ("_Open...", sigc::ptr_fun (file_open)));
224 file_items.push_back (SeparatorElem ());
225 file_items.push_back (MenuElem ("_Save", sigc::ptr_fun (file_save)));
226 file_items.push_back (SeparatorElem ());
227 file_items.push_back (MenuElem ("_Quit", sigc::ptr_fun (file_quit)));
229 Gtk::Menu* edit = manage (new Gtk::Menu);
230 MenuList& edit_items (edit->items ());
231 edit_items.push_back (MenuElem ("_Preferences...", sigc::ptr_fun (edit_preferences)));
233 Gtk::Menu* jobs = manage (new Gtk::Menu);
234 MenuList& jobs_items (jobs->items ());
235 jobs_items.push_back (MenuElem ("_Make DCP", sigc::ptr_fun (jobs_make_dcp)));
236 jobs_items.push_back (MenuElem ("_Send DCP to TMS", sigc::ptr_fun (jobs_send_dcp_to_tms)));
237 jobs_items.push_back (MenuElem ("Copy from _DVD", sigc::ptr_fun (jobs_copy_from_dvd)));
238 jobs_items.push_back (MenuElem ("_Examine content", sigc::ptr_fun (jobs_examine_content)));
239 jobs_items.push_back (MenuElem ("Make DCP from _existing transcode", sigc::ptr_fun (jobs_make_dcp_from_existing_transcode)));
241 Gtk::Menu* help = manage (new Gtk::Menu);
242 MenuList& help_items (help->items ());
243 help_items.push_back (MenuElem ("_About", sigc::ptr_fun (help_about)));
245 MenuList& items (m.items ());
246 items.push_back (MenuElem ("_File", *file));
247 items.push_back (MenuElem ("_Edit", *edit));
248 items.push_back (MenuElem ("_Jobs", *jobs));
249 items.push_back (MenuElem ("_Help", *help));
253 window_closed (GdkEventAny *)
255 if (maybe_save_then_delete_film ()) {
263 file_changed (string f)
271 window->set_title (s.str ());
275 main (int argc, char* argv[])
279 Gtk::Main kit (argc, argv);
281 if (argc == 2 && boost::filesystem::is_directory (argv[1])) {
282 film = new Film (argv[1]);
285 window = new Gtk::Window ();
286 window->signal_delete_event().connect (sigc::ptr_fun (window_closed));
288 film_viewer = new FilmViewer (film);
289 film_editor = new FilmEditor (film);
290 film_player = new FilmPlayer (film);
291 JobManagerView jobs_view;
293 window->set_title ("DVD-o-matic");
297 Gtk::MenuBar menu_bar;
298 vbox.pack_start (menu_bar, false, false);
299 setup_menu (menu_bar);
302 hbox.set_spacing (12);
305 left_vbox.set_spacing (12);
306 left_vbox.pack_start (film_editor->widget (), false, false);
307 // left_vbox.pack_start (film_player->widget (), false, false);
308 hbox.pack_start (left_vbox, false, false);
310 Gtk::VBox right_vbox;
311 right_vbox.pack_start (film_viewer->widget (), true, true);
312 right_vbox.pack_start (jobs_view.widget(), false, false);
313 hbox.pack_start (right_vbox, true, true);
315 vbox.pack_start (hbox, true, true);
320 /* XXX: calling these here is a bit of a hack */
321 film_editor->setup_visibility ();
322 film_player->setup_visibility ();
323 film_viewer->setup_visibility ();
325 film_editor->FileChanged.connect (ptr_fun (file_changed));
327 file_changed (film->directory ());
332 /* XXX this should be in JobManagerView, shouldn't it? */
333 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (jobs_view, &JobManagerView::update), true), 1000);
336 Gtk::Main::run (*window);