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 <wx/aboutdlg.h>
23 #include <wx/stdpaths.h>
24 #include "wx/film_viewer.h"
25 #include "wx/film_editor.h"
26 #include "wx/job_manager_view.h"
27 #include "wx/config_dialog.h"
28 #include "wx/job_wrapper.h"
29 //#include "gtk/dvd_title_dialog.h"
30 #include "wx/wx_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 FilmEditor* film_editor = 0;
43 static FilmViewer* film_viewer = 0;
45 static Film* film = 0;
47 static void set_menu_sensitivity ();
49 class FilmChangedDialog
55 s << "Save changes to film \"" << film->name() << "\" before closing?";
56 _dialog = new wxMessageDialog (0, std_to_wx (s.str()), wxT ("Film changed"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION);
66 return _dialog->ShowModal ();
70 wxMessageDialog* _dialog;
75 maybe_save_then_delete_film ()
87 film->write_metadata ();
101 map<wxMenuItem*, Sensitivity> menu_items;
104 add_item (wxMenu* menu, std::string text, int id, Sensitivity sens)
106 wxMenuItem* item = menu->Append (id, std_to_wx (text));
107 menu_items.insert (make_pair (item, sens));
111 set_menu_sensitivity ()
113 for (map<wxMenuItem*, Sensitivity>::iterator i = menu_items.begin(); i != menu_items.end(); ++i) {
114 if (i->second == NEEDS_FILM) {
115 i->first->Enable (film != 0);
117 i->first->Enable (true);
129 ID_jobs_send_dcp_to_tms,
130 ID_jobs_copy_from_dvd,
131 ID_jobs_examine_content,
132 ID_jobs_make_dcp_from_existing_transcode,
137 setup_menu (wxMenuBar* m)
139 wxMenu* file = new wxMenu;
140 add_item (file, "New...", ID_file_new, ALWAYS);
141 add_item (file, "&Open...", ID_file_open, ALWAYS);
142 file->AppendSeparator ();
143 add_item (file, "&Save", ID_file_save, NEEDS_FILM);
144 file->AppendSeparator ();
145 add_item (file, "&Quit", ID_file_quit, ALWAYS);
147 wxMenu* edit = new wxMenu;
148 add_item (edit, "&Preferences...", ID_edit_preferences, ALWAYS);
150 wxMenu* jobs = new wxMenu;
151 add_item (jobs, "&Make DCP", ID_jobs_make_dcp, NEEDS_FILM);
152 add_item (jobs, "&Send DCP to TMS", ID_jobs_send_dcp_to_tms, NEEDS_FILM);
153 add_item (jobs, "Copy from &DVD...", ID_jobs_copy_from_dvd, NEEDS_FILM);
154 jobs->AppendSeparator ();
155 add_item (jobs, "&Examine content", ID_jobs_examine_content, NEEDS_FILM);
156 add_item (jobs, "Make DCP from existing &transcode", ID_jobs_make_dcp_from_existing_transcode, NEEDS_FILM);
158 wxMenu* help = new wxMenu;
159 add_item (help, "About", ID_help_about, ALWAYS);
161 m->Append (file, _("&File"));
162 m->Append (edit, _("&Edit"));
163 m->Append (jobs, _("&Jobs"));
164 m->Append (help, _("&Help"));
168 window_closed (wxCommandEvent &)
170 maybe_save_then_delete_film ();
174 class Frame : public wxFrame
177 Frame (wxString const & title)
178 : wxFrame (NULL, -1, title)
180 wxMenuBar* bar = new wxMenuBar;
184 Connect (ID_file_new, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_new));
185 Connect (ID_file_open, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_open));
186 Connect (ID_file_save, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_save));
187 Connect (ID_file_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_quit));
188 Connect (ID_edit_preferences, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::edit_preferences));
189 Connect (ID_jobs_make_dcp, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_dcp));
190 Connect (ID_jobs_send_dcp_to_tms, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_send_dcp_to_tms));
191 Connect (ID_jobs_copy_from_dvd, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_copy_from_dvd));
192 Connect (ID_jobs_examine_content, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_examine_content));
193 Connect (ID_jobs_make_dcp_from_existing_transcode, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_dcp_from_existing_transcode));
194 Connect (ID_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::help_about));
196 wxPanel* panel = new wxPanel (this);
197 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
198 s->Add (panel, 1, wxEXPAND);
201 film_editor = new FilmEditor (film, panel);
202 film_viewer = new FilmViewer (film, panel);
203 JobManagerView* job_manager_view = new JobManagerView (panel);
205 wxSizer* rhs_sizer = new wxBoxSizer (wxVERTICAL);
206 rhs_sizer->Add (film_viewer, 3, wxEXPAND | wxALL);
207 rhs_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL);
209 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
210 main_sizer->Add (film_editor, 0, wxALL, 6);
211 main_sizer->Add (rhs_sizer, 1, wxEXPAND | wxALL, 6);
212 panel->SetSizer (main_sizer);
214 set_menu_sensitivity ();
216 /* XXX: calling these here is a bit of a hack */
217 film_editor->setup_visibility ();
218 film_viewer->setup_visibility ();
220 film_editor->FileChanged.connect (sigc::mem_fun (*this, &Frame::file_changed));
222 file_changed (film->directory ());
229 file_changed (string f)
237 SetTitle (std_to_wx (s.str()));
240 void file_new (wxCommandEvent &)
242 wxDirDialog* c = new wxDirDialog (this, wxT ("New Film"), wxStandardPaths::Get().GetDocumentsDir());
243 int const r = c->ShowModal ();
247 maybe_save_then_delete_film ();
248 film = new Film (wx_to_std (c->GetPath ()));
249 #if BOOST_FILESYSTEM_VERSION == 3
250 film->set_name (filesystem::path (wx_to_std (c->GetPath())).filename().generic_string());
252 film->set_name (filesystem::path (wx_to_std (c->GetPath())).filename());
254 film_viewer->set_film (film);
255 film_editor->set_film (film);
256 set_menu_sensitivity ();
260 void file_open (wxCommandEvent &)
262 wxDirDialog* c = new wxDirDialog (this, wxT ("Open Film"), wxStandardPaths::Get().GetDocumentsDir(), wxDD_DIR_MUST_EXIST);
263 int const r = c->ShowModal ();
267 maybe_save_then_delete_film ();
268 film = new Film (wx_to_std (c->GetPath ()));
269 film_viewer->set_film (film);
270 film_editor->set_film (film);
271 set_menu_sensitivity ();
275 void file_save (wxCommandEvent &)
277 film->write_metadata ();
280 void file_quit (wxCommandEvent &)
282 maybe_save_then_delete_film ();
286 void edit_preferences (wxCommandEvent &)
288 ConfigDialog* d = new ConfigDialog (this);
291 Config::instance()->write ();
294 void jobs_make_dcp (wxCommandEvent &)
296 JobWrapper::make_dcp (this, film, true);
299 void jobs_make_dcp_from_existing_transcode (wxCommandEvent &)
301 JobWrapper::make_dcp (this, film, false);
304 void jobs_copy_from_dvd (wxCommandEvent &)
308 // if (d.run () != Gtk::RESPONSE_OK) {
311 // film->copy_from_dvd ();
312 // } catch (DVDError& e) {
313 // error_dialog (e.what ());
317 void jobs_send_dcp_to_tms (wxCommandEvent &)
319 film->send_dcp_to_tms ();
322 void jobs_examine_content (wxCommandEvent &)
324 film->examine_content ();
327 void help_about (wxCommandEvent &)
329 wxAboutDialogInfo info;
330 info.SetName (_("DVD-o-matic"));
331 info.SetVersion (wxT (DVDOMATIC_VERSION));
332 info.SetDescription (_("DCP generation from arbitrary formats"));
333 info.SetCopyright (_("(C) Carl Hetherington, Terrence Meiczinger, Paul Davis"));
334 wxArrayString authors;
335 authors.Add (wxT ("Carl Hetherington"));
336 authors.Add (wxT ("Terrence Meiczinger"));
337 authors.Add (wxT ("Paul Davis"));
338 info.SetDevelopers (authors);
339 info.SetWebSite (wxT ("http://carlh.net/software/dvdomatic"));
344 class App : public wxApp
348 if (!wxApp::OnInit ()) {
352 wxInitAllImageHandlers ();
356 // if (argc == 2 && boost::filesystem::is_directory (argv[1])) {
357 // film = new Film (argv[1]);
360 Frame* f = new Frame (_("DVD-o-matic"));