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>
25 #include <wx/aboutdlg.h>
26 #include <wx/stdpaths.h>
27 #include <wx/cmdline.h>
28 #include "wx/film_viewer.h"
29 #include "wx/film_editor.h"
30 #include "wx/job_manager_view.h"
31 #include "wx/config_dialog.h"
32 #include "wx/job_wrapper.h"
33 #include "wx/wx_util.h"
34 #include "wx/new_film_dialog.h"
35 #include "wx/properties_dialog.h"
36 #include "wx/wx_ui_signaller.h"
38 #include "lib/format.h"
39 #include "lib/config.h"
40 #include "lib/filter.h"
42 #include "lib/scaler.h"
43 #include "lib/exceptions.h"
44 #include "lib/version.h"
45 #include "lib/ui_signaller.h"
51 using std::stringstream;
55 using boost::shared_ptr;
57 static FilmEditor* film_editor = 0;
58 static FilmViewer* film_viewer = 0;
59 static shared_ptr<Film> film;
60 static std::string log_level;
61 static std::string film_to_load;
62 static wxMenu* jobs_menu = 0;
64 static void set_menu_sensitivity ();
66 class FilmChangedDialog
72 s << "Save changes to film \"" << film->name() << "\" before closing?";
73 _dialog = new wxMessageDialog (0, std_to_wx (s.str()), _("Film changed"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION);
83 return _dialog->ShowModal ();
87 wxMessageDialog* _dialog;
92 maybe_save_then_delete_film ()
104 film->write_metadata ();
117 map<wxMenuItem*, Sensitivity> menu_items;
120 add_item (wxMenu* menu, std::string text, int id, Sensitivity sens)
122 wxMenuItem* item = menu->Append (id, std_to_wx (text));
123 menu_items.insert (make_pair (item, sens));
127 set_menu_sensitivity ()
129 for (map<wxMenuItem*, Sensitivity>::iterator i = menu_items.begin(); i != menu_items.end(); ++i) {
130 if (i->second == NEEDS_FILM) {
131 i->first->Enable (film != 0);
133 i->first->Enable (true);
146 ID_jobs_send_dcp_to_tms,
148 ID_jobs_examine_content,
153 setup_menu (wxMenuBar* m)
155 wxMenu* file = new wxMenu;
156 add_item (file, "New...", ID_file_new, ALWAYS);
157 add_item (file, "&Open...", ID_file_open, ALWAYS);
158 file->AppendSeparator ();
159 add_item (file, "&Save", ID_file_save, NEEDS_FILM);
160 file->AppendSeparator ();
161 add_item (file, "&Properties...", ID_file_properties, NEEDS_FILM);
162 file->AppendSeparator ();
163 add_item (file, "&Quit", ID_file_quit, ALWAYS);
165 wxMenu* edit = new wxMenu;
166 add_item (edit, "&Preferences...", ID_edit_preferences, ALWAYS);
168 jobs_menu = new wxMenu;
169 add_item (jobs_menu, "&Make DCP", ID_jobs_make_dcp, NEEDS_FILM);
170 add_item (jobs_menu, "&Send DCP to TMS", ID_jobs_send_dcp_to_tms, NEEDS_FILM);
171 add_item (jobs_menu, "S&how DCP", ID_jobs_show_dcp, NEEDS_FILM);
172 jobs_menu->AppendSeparator ();
173 add_item (jobs_menu, "&Examine content", ID_jobs_examine_content, NEEDS_FILM);
175 wxMenu* help = new wxMenu;
176 add_item (help, "About", ID_help_about, ALWAYS);
178 m->Append (file, _("&File"));
179 m->Append (edit, _("&Edit"));
180 m->Append (jobs_menu, _("&Jobs"));
181 m->Append (help, _("&Help"));
185 window_closed (wxCommandEvent &)
187 maybe_save_then_delete_film ();
191 class Frame : public wxFrame
194 Frame (wxString const & title)
195 : wxFrame (NULL, -1, title)
197 wxMenuBar* bar = new wxMenuBar;
201 Connect (ID_file_new, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_new));
202 Connect (ID_file_open, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_open));
203 Connect (ID_file_save, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_save));
204 Connect (ID_file_properties, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_properties));
205 Connect (ID_file_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::file_quit));
206 Connect (ID_edit_preferences, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::edit_preferences));
207 Connect (ID_jobs_make_dcp, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_make_dcp));
208 Connect (ID_jobs_send_dcp_to_tms, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_send_dcp_to_tms));
209 Connect (ID_jobs_show_dcp, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_show_dcp));
210 Connect (ID_jobs_examine_content, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::jobs_examine_content));
211 Connect (ID_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (Frame::help_about));
213 Connect (wxID_ANY, wxEVT_MENU_OPEN, wxMenuEventHandler (Frame::menu_opened));
215 wxPanel* panel = new wxPanel (this);
216 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
217 s->Add (panel, 1, wxEXPAND);
220 film_editor = new FilmEditor (film, panel);
221 film_viewer = new FilmViewer (film, panel);
222 JobManagerView* job_manager_view = new JobManagerView (panel);
224 _top_sizer = new wxBoxSizer (wxHORIZONTAL);
225 _top_sizer->Add (film_editor, 0, wxALL, 6);
226 _top_sizer->Add (film_viewer, 1, wxEXPAND | wxALL, 6);
228 wxBoxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
229 main_sizer->Add (_top_sizer, 2, wxEXPAND | wxALL, 6);
230 main_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
231 panel->SetSizer (main_sizer);
233 set_menu_sensitivity ();
235 /* XXX: calling these here is a bit of a hack */
236 film_editor->setup_visibility ();
238 film_editor->FileChanged.connect (bind (&Frame::file_changed, this, _1));
240 file_changed (film->directory ());
247 film_editor->Connect (wxID_ANY, wxEVT_SIZE, wxSizeEventHandler (Frame::film_editor_sized), 0, this);
252 void film_editor_sized (wxSizeEvent &)
254 static bool in_layout = false;
257 _top_sizer->Layout ();
262 void menu_opened (wxMenuEvent& ev)
264 if (ev.GetMenu() != jobs_menu) {
268 bool const have_dcp = film && film->have_dcp();
269 jobs_menu->Enable (ID_jobs_send_dcp_to_tms, have_dcp);
270 jobs_menu->Enable (ID_jobs_show_dcp, have_dcp);
275 film_viewer->set_film (film);
276 film_editor->set_film (film);
277 set_menu_sensitivity ();
280 void file_changed (string f)
288 SetTitle (std_to_wx (s.str()));
291 void file_new (wxCommandEvent &)
293 NewFilmDialog* d = new NewFilmDialog (this);
294 int const r = d->ShowModal ();
298 if (boost::filesystem::exists (d->get_path())) {
299 error_dialog (this, wxString::Format (_("The directory %s already exists."), d->get_path().c_str()));
303 maybe_save_then_delete_film ();
304 film.reset (new Film (d->get_path (), false));
305 film->log()->set_level (log_level);
306 film->set_name (boost::filesystem::path (d->get_path()).filename().generic_string());
313 void file_open (wxCommandEvent &)
315 wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
316 int const r = c->ShowModal ();
319 maybe_save_then_delete_film ();
321 film.reset (new Film (wx_to_std (c->GetPath ())));
322 film->log()->set_level (log_level);
324 } catch (std::exception& e) {
325 wxString p = c->GetPath ();
326 wxCharBuffer b = p.ToUTF8 ();
327 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), e.what()));
334 void file_save (wxCommandEvent &)
336 film->write_metadata ();
339 void file_properties (wxCommandEvent &)
341 PropertiesDialog* d = new PropertiesDialog (this, film);
346 void file_quit (wxCommandEvent &)
348 maybe_save_then_delete_film ();
352 void edit_preferences (wxCommandEvent &)
354 ConfigDialog* d = new ConfigDialog (this);
357 Config::instance()->write ();
360 void jobs_make_dcp (wxCommandEvent &)
362 JobWrapper::make_dcp (this, film);
365 void jobs_send_dcp_to_tms (wxCommandEvent &)
367 film->send_dcp_to_tms ();
370 void jobs_show_dcp (wxCommandEvent &)
373 string d = film->directory();
375 w.assign (d.begin(), d.end());
376 ShellExecute (0, L"open", w.c_str(), 0, 0, SW_SHOWDEFAULT);
378 int r = system ("which nautilus");
379 if (WEXITSTATUS (r) == 0) {
380 system (string ("nautilus " + film->directory()).c_str ());
382 int r = system ("which konqueror");
383 if (WEXITSTATUS (r) == 0) {
384 system (string ("konqueror " + film->directory()).c_str ());
390 void jobs_examine_content (wxCommandEvent &)
392 film->examine_content ();
395 void help_about (wxCommandEvent &)
397 wxAboutDialogInfo info;
398 info.SetName (_("DVD-o-matic"));
399 if (strcmp (dvdomatic_git_commit, "release") == 0) {
400 info.SetVersion (std_to_wx (String::compose ("version %1", dvdomatic_version)));
402 info.SetVersion (std_to_wx (String::compose ("version %1 git %2", dvdomatic_version, dvdomatic_git_commit)));
404 info.SetDescription (_("Free, open-source DCP generation from almost anything."));
405 info.SetCopyright (_("(C) 2012-2013 Carl Hetherington, Terrence Meiczinger, Paul Davis, Ole Laursen"));
406 wxArrayString authors;
407 authors.Add (wxT ("Carl Hetherington"));
408 authors.Add (wxT ("Terrence Meiczinger"));
409 authors.Add (wxT ("Paul Davis"));
410 authors.Add (wxT ("Ole Laursen"));
411 info.SetDevelopers (authors);
412 info.SetWebSite (wxT ("http://carlh.net/software/dvdomatic"));
419 #if wxMINOR_VERSION == 9
420 static const wxCmdLineEntryDesc command_line_description[] = {
421 { wxCMD_LINE_OPTION, "l", "log", "set log level (silent, verbose or timing)", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
422 { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
423 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
426 static const wxCmdLineEntryDesc command_line_description[] = {
427 { wxCMD_LINE_OPTION, wxT("l"), wxT("log"), wxT("set log level (silent, verbose or timing)"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
428 { wxCMD_LINE_PARAM, 0, 0, wxT("film to load"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
429 { wxCMD_LINE_NONE, wxT(""), wxT(""), wxT(""), wxCmdLineParamType (0), 0 }
433 class App : public wxApp
437 if (!wxApp::OnInit()) {
441 #ifdef DVDOMATIC_POSIX
442 unsetenv ("UBUNTU_MENUPROXY");
445 wxInitAllImageHandlers ();
449 if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) {
451 film.reset (new Film (film_to_load));
452 film->log()->set_level (log_level);
453 } catch (exception& e) {
454 error_dialog (0, std_to_wx (String::compose ("Could not load film %1 (%2)", film_to_load, e.what())));
458 Frame* f = new Frame (_("DVD-o-matic"));
463 ui_signaller = new wxUISignaller (this);
464 this->Connect (-1, wxEVT_IDLE, wxIdleEventHandler (App::idle));
469 void OnInitCmdLine (wxCmdLineParser& parser)
471 parser.SetDesc (command_line_description);
472 parser.SetSwitchChars (wxT ("-"));
475 bool OnCmdLineParsed (wxCmdLineParser& parser)
477 if (parser.GetParamCount() > 0) {
478 film_to_load = wx_to_std (parser.GetParam(0));
482 if (parser.Found(wxT("log"), &log)) {
483 log_level = wx_to_std (log);
489 void idle (wxIdleEvent &)
491 ui_signaller->ui_idle ();