2 Copyright (C) 2012-2015 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.
20 /** @file src/tools/dcpomatic.cc
21 * @brief The main DCP-o-matic GUI.
25 #include "lib/config.h"
27 #include "lib/version.h"
28 #include "lib/signal_manager.h"
30 #include "lib/job_manager.h"
31 #include "lib/transcode_job.h"
32 #include "lib/exceptions.h"
33 #include "lib/cinema.h"
35 #include "lib/send_kdm_email_job.h"
36 #include "lib/server_finder.h"
37 #include "lib/update.h"
38 #include "lib/content_factory.h"
39 #include "wx/film_viewer.h"
40 #include "wx/film_editor.h"
41 #include "wx/job_manager_view.h"
42 #include "wx/config_dialog.h"
43 #include "wx/wx_util.h"
44 #include "wx/new_film_dialog.h"
45 #include "wx/wx_signal_manager.h"
46 #include "wx/about_dialog.h"
47 #include "wx/kdm_dialog.h"
48 #include "wx/servers_list_dialog.h"
49 #include "wx/hints_dialog.h"
50 #include "wx/update_dialog.h"
51 #include "wx/content_panel.h"
52 #include "wx/report_problem_dialog.h"
53 #include <dcp/exceptions.h>
54 #include <wx/generic/aboutdlgg.h>
55 #include <wx/stdpaths.h>
56 #include <wx/cmdline.h>
57 #include <wx/preferences.h>
62 #include <ApplicationServices/ApplicationServices.h>
64 #include <boost/filesystem.hpp>
78 using std::wstringstream;
83 using boost::shared_ptr;
84 using boost::dynamic_pointer_cast;
86 class FilmChangedDialog
89 FilmChangedDialog (string name)
91 _dialog = new wxMessageDialog (
93 wxString::Format (_("Save changes to film \"%s\" before closing?"), std_to_wx (name).data()),
94 /* TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
95 project (Film) has been changed since it was last saved.
98 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
102 ~FilmChangedDialog ()
109 return _dialog->ShowModal ();
114 FilmChangedDialog (FilmChangedDialog const &);
116 wxMessageDialog* _dialog;
120 #define NEEDS_FILM 0x1
121 #define NOT_DURING_DCP_CREATION 0x2
122 #define NEEDS_CPL 0x4
123 #define NEEDS_SELECTED_VIDEO_CONTENT 0x8
125 map<wxMenuItem*, int> menu_items;
132 /* Allow spare IDs after _history for the recent files list */
133 ID_content_scale_to_fit_width = 100,
134 ID_content_scale_to_fit_height,
137 ID_jobs_send_dcp_to_tms,
140 ID_tools_encoding_servers,
141 ID_tools_check_for_updates,
142 ID_tools_restore_default_preferences,
143 ID_help_report_a_problem,
144 /* IDs for shortcuts (with no associated menu item) */
148 class DOMFrame : public wxFrame
151 DOMFrame (wxString const & title)
152 : wxFrame (NULL, -1, title)
154 , _servers_list_dialog (0)
158 , _history_position (0)
159 , _history_separator (0)
161 #if defined(DCPOMATIC_WINDOWS)
162 if (Config::instance()->win32_console ()) {
165 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
166 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
167 FILE* hf_out = _fdopen(hCrt, "w");
168 setvbuf(hf_out, NULL, _IONBF, 1);
171 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
172 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
173 FILE* hf_in = _fdopen(hCrt, "r");
174 setvbuf(hf_in, NULL, _IONBF, 128);
177 cout << "DCP-o-matic is starting." << "\n";
181 wxMenuBar* bar = new wxMenuBar;
185 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
188 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_new, this), ID_file_new);
189 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_open, this), ID_file_open);
190 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_save, this), ID_file_save);
191 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
192 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
193 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
194 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_width, this), ID_content_scale_to_fit_width);
195 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_height, this), ID_content_scale_to_fit_height);
196 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_dcp, this), ID_jobs_make_dcp);
197 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_kdms, this), ID_jobs_make_kdms);
198 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
199 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_show_dcp, this), ID_jobs_show_dcp);
200 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_hints, this), ID_tools_hints);
201 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_encoding_servers, this), ID_tools_encoding_servers);
202 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
203 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
204 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
205 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
207 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1));
209 /* Use a panel as the only child of the Frame so that we avoid
210 the dark-grey background on Windows.
212 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
214 _film_viewer = new FilmViewer (overall_panel);
215 _film_editor = new FilmEditor (overall_panel, _film_viewer);
216 JobManagerView* job_manager_view = new JobManagerView (overall_panel);
218 wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
219 right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
220 right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
222 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
223 main_sizer->Add (_film_editor, 1, wxEXPAND | wxALL, 6);
224 main_sizer->Add (right_sizer, 2, wxEXPAND | wxALL, 6);
226 set_menu_sensitivity ();
228 _film_editor->FileChanged.connect (bind (&DOMFrame::file_changed, this, _1));
231 JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
233 overall_panel->SetSizer (main_sizer);
235 wxAcceleratorEntry accel[1];
236 accel[0].Set (wxACCEL_CTRL, static_cast<int>('A'), ID_add_file);
237 Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file);
238 wxAcceleratorTable accel_table (1, accel);
239 SetAcceleratorTable (accel_table);
241 /* Instantly save any config changes when using the DCP-o-matic GUI */
242 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
245 void new_film (boost::filesystem::path path)
247 shared_ptr<Film> film (new Film (path));
248 film->write_metadata ();
249 film->set_name (path.filename().generic_string());
253 void load_film (boost::filesystem::path file)
256 maybe_save_then_delete_film ();
258 shared_ptr<Film> film (new Film (file));
259 list<string> const notes = film->read_metadata ();
261 if (film->state_version() == 4) {
264 _("This film was created with an old version of DVD-o-matic and may not load correctly "
265 "in this version. Please check the film's settings carefully.")
269 for (list<string>::const_iterator i = notes.begin(); i != notes.end(); ++i) {
270 error_dialog (0, std_to_wx (*i));
275 catch (std::exception& e) {
276 wxString p = std_to_wx (file.string ());
277 wxCharBuffer b = p.ToUTF8 ();
278 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
281 void set_film (shared_ptr<Film> film)
284 _film_viewer->set_film (_film);
285 _film_editor->set_film (_film);
286 set_menu_sensitivity ();
287 Config::instance()->add_to_history (_film->directory ());
290 shared_ptr<Film> film () const {
296 void file_changed (boost::filesystem::path f)
298 string s = wx_to_std (_("DCP-o-matic"));
300 s += " - " + f.string ();
303 SetTitle (std_to_wx (s));
308 NewFilmDialog* d = new NewFilmDialog (this);
309 int const r = d->ShowModal ();
313 if (boost::filesystem::is_directory (d->get_path()) && !boost::filesystem::is_empty(d->get_path())) {
314 if (!confirm_dialog (
317 String::compose (wx_to_std (_("The directory %1 already exists and is not empty. "
318 "Are you sure you want to use it?")),
319 d->get_path().string().c_str())
324 } else if (boost::filesystem::is_regular_file (d->get_path())) {
327 String::compose (wx_to_std (_("%1 already exists as a file, so you cannot use it for a new film.")), d->get_path().c_str())
332 maybe_save_then_delete_film ();
333 new_film (d->get_path ());
341 wxDirDialog* c = new wxDirDialog (
343 _("Select film to open"),
344 std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
345 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
351 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
352 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
359 load_film (wx_to_std (c->GetPath ()));
367 _film->write_metadata ();
370 void file_history (wxCommandEvent& event)
372 vector<boost::filesystem::path> history = Config::instance()->history ();
373 int n = event.GetId() - ID_file_history;
374 if (n >= 0 && n < static_cast<int> (history.size ())) {
375 load_film (history[n]);
381 /* false here allows the close handler to veto the close request */
385 void edit_preferences ()
387 if (!_config_dialog) {
388 _config_dialog = create_config_dialog ();
390 _config_dialog->Show (this);
393 void tools_restore_default_preferences ()
395 Config::restore_defaults ();
398 void jobs_make_dcp ()
404 if (!_film->should_be_enough_disk_space (required, available, can_hard_link)) {
407 message = wxString::Format (_("The DCP for this film will take up about %.1f Gb, and the disk that you are using only has %.1f Gb available. Do you want to continue anyway?"), required, available);
409 message = wxString::Format (_("The DCP and intermediate files for this film will take up about %.1f Gb, and the disk that you are using only has %.1f Gb available. You would need half as much space if the filesystem supported hard links, but it does not. Do you want to continue anyway?"), required, available);
411 if (!confirm_dialog (this, message)) {
417 /* It seems to make sense to auto-save metadata here, since the make DCP may last
418 a long time, and crashes/power failures are moderately likely.
420 _film->write_metadata ();
422 } catch (BadSettingError& e) {
423 error_dialog (this, wxString::Format (_("Bad setting for %s (%s)"), std_to_wx(e.setting()).data(), std_to_wx(e.what()).data()));
424 } catch (std::exception& e) {
425 error_dialog (this, wxString::Format (_("Could not make DCP: %s"), std_to_wx(e.what()).data()));
429 void jobs_make_kdms ()
435 KDMDialog* d = new KDMDialog (this, _film);
436 if (d->ShowModal () != wxID_OK) {
442 if (d->write_to ()) {
443 write_kdm_files (_film, d->screens (), d->cpl (), d->from (), d->until (), d->formulation (), d->directory ());
445 JobManager::instance()->add (
446 shared_ptr<Job> (new SendKDMEmailJob (_film, d->screens (), d->cpl (), d->from (), d->until (), d->formulation ()))
449 } catch (dcp::NotEncryptedError& e) {
450 error_dialog (this, _("CPL's content is not encrypted."));
451 } catch (exception& e) {
452 error_dialog (this, e.what ());
454 error_dialog (this, _("An unknown exception occurred."));
460 void content_scale_to_fit_width ()
462 VideoContentList vc = _film_editor->content_panel()->selected_video ();
463 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
464 (*i)->scale_and_crop_to_fit_width ();
468 void content_scale_to_fit_height ()
470 VideoContentList vc = _film_editor->content_panel()->selected_video ();
471 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
472 (*i)->scale_and_crop_to_fit_height ();
476 void jobs_send_dcp_to_tms ()
478 _film->send_dcp_to_tms ();
481 void jobs_show_dcp ()
483 #ifdef DCPOMATIC_WINDOWS
485 args << "/select," << _film->dir (_film->dcp_name(false));
486 ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
489 #ifdef DCPOMATIC_LINUX
490 int r = system ("which nautilus");
491 if (WEXITSTATUS (r) == 0) {
492 r = system (string ("nautilus " + _film->directory().string()).c_str ());
493 if (WEXITSTATUS (r)) {
494 error_dialog (this, _("Could not show DCP (could not run nautilus)"));
497 int r = system ("which konqueror");
498 if (WEXITSTATUS (r) == 0) {
499 r = system (string ("konqueror " + _film->directory().string()).c_str ());
500 if (WEXITSTATUS (r)) {
501 error_dialog (this, _("Could not show DCP (could not run konqueror)"));
508 int r = system (string ("open -R " + _film->dir (_film->dcp_name (false)).string ()).c_str ());
509 if (WEXITSTATUS (r)) {
510 error_dialog (this, _("Could not show DCP"));
517 if (!_hints_dialog) {
518 _hints_dialog = new HintsDialog (this, _film);
521 _hints_dialog->Show ();
524 void tools_encoding_servers ()
526 if (!_servers_list_dialog) {
527 _servers_list_dialog = new ServersListDialog (this);
530 _servers_list_dialog->Show ();
533 void tools_check_for_updates ()
535 UpdateChecker::instance()->run ();
540 AboutDialog* d = new AboutDialog (this);
545 void help_report_a_problem ()
547 ReportProblemDialog* d = new ReportProblemDialog (this, _film);
548 if (d->ShowModal () == wxID_OK) {
556 if (!JobManager::instance()->work_to_do ()) {
560 wxMessageDialog* d = new wxMessageDialog (
562 _("There are unfinished jobs; are you sure you want to quit?"),
563 _("Unfinished jobs"),
564 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
567 bool const r = d->ShowModal() == wxID_YES;
572 void close (wxCloseEvent& ev)
574 if (!should_close ()) {
579 /* We don't want to hear about any more configuration changes, since they
580 cause the File menu to be altered, which itself will be deleted around
581 now (without, as far as I can see, any way for us to find out).
583 _config_changed_connection.disconnect ();
585 maybe_save_then_delete_film ();
589 void set_menu_sensitivity ()
591 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
592 list<shared_ptr<Job> >::iterator i = jobs.begin();
593 while (i != jobs.end() && dynamic_pointer_cast<TranscodeJob> (*i) == 0) {
596 bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
597 bool const have_cpl = _film && !_film->cpls().empty ();
598 bool const have_selected_video_content = !_film_editor->content_panel()->selected_video().empty();
600 for (map<wxMenuItem*, int>::iterator j = menu_items.begin(); j != menu_items.end(); ++j) {
604 if ((j->second & NEEDS_FILM) && !_film) {
608 if ((j->second & NOT_DURING_DCP_CREATION) && dcp_creation) {
612 if ((j->second & NEEDS_CPL) && !have_cpl) {
616 if ((j->second & NEEDS_SELECTED_VIDEO_CONTENT) && !have_selected_video_content) {
620 j->first->Enable (enabled);
624 void maybe_save_then_delete_film ()
630 if (_film->dirty ()) {
631 FilmChangedDialog d (_film->name ());
636 _film->write_metadata ();
644 void add_item (wxMenu* menu, wxString text, int id, int sens)
646 wxMenuItem* item = menu->Append (id, text);
647 menu_items.insert (make_pair (item, sens));
650 void setup_menu (wxMenuBar* m)
652 _file_menu = new wxMenu;
653 add_item (_file_menu, _("New...\tCtrl-N"), ID_file_new, ALWAYS);
654 add_item (_file_menu, _("&Open...\tCtrl-O"), ID_file_open, ALWAYS);
655 _file_menu->AppendSeparator ();
656 add_item (_file_menu, _("&Save\tCtrl-S"), ID_file_save, NEEDS_FILM);
658 _history_position = _file_menu->GetMenuItems().GetCount();
661 _file_menu->AppendSeparator ();
665 add_item (_file_menu, _("&Exit"), wxID_EXIT, ALWAYS);
667 add_item (_file_menu, _("&Quit"), wxID_EXIT, ALWAYS);
671 add_item (_file_menu, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
673 wxMenu* edit = new wxMenu;
674 add_item (edit, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
677 wxMenu* content = new wxMenu;
678 add_item (content, _("Scale to fit &width"), ID_content_scale_to_fit_width, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
679 add_item (content, _("Scale to fit &height"), ID_content_scale_to_fit_height, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
681 wxMenu* jobs_menu = new wxMenu;
682 add_item (jobs_menu, _("&Make DCP\tCtrl-M"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
683 add_item (jobs_menu, _("Make &KDMs...\tCtrl-K"), ID_jobs_make_kdms, NEEDS_FILM);
684 add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
685 add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
687 wxMenu* tools = new wxMenu;
688 add_item (tools, _("Hints..."), ID_tools_hints, 0);
689 add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
690 add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
691 tools->AppendSeparator ();
692 add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
694 wxMenu* help = new wxMenu;
696 add_item (help, _("About DCP-o-matic"), wxID_ABOUT, ALWAYS);
698 add_item (help, _("About"), wxID_ABOUT, ALWAYS);
700 add_item (help, _("Report a problem..."), ID_help_report_a_problem, NEEDS_FILM);
702 m->Append (_file_menu, _("&File"));
704 m->Append (edit, _("&Edit"));
706 m->Append (content, _("&Content"));
707 m->Append (jobs_menu, _("&Jobs"));
708 m->Append (tools, _("&Tools"));
709 m->Append (help, _("&Help"));
712 void config_changed ()
714 for (int i = 0; i < _history_items; ++i) {
715 delete _file_menu->Remove (ID_file_history + i);
718 if (_history_separator) {
719 _file_menu->Remove (_history_separator);
721 delete _history_separator;
722 _history_separator = 0;
724 int pos = _history_position;
726 vector<boost::filesystem::path> history = Config::instance()->history ();
728 if (!history.empty ()) {
729 _history_separator = _file_menu->InsertSeparator (pos++);
732 for (size_t i = 0; i < history.size(); ++i) {
735 s << "&" << (i + 1) << " ";
737 s << history[i].string();
738 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s.str ()));
741 _history_items = history.size ();
744 FilmEditor* _film_editor;
745 FilmViewer* _film_viewer;
746 HintsDialog* _hints_dialog;
747 ServersListDialog* _servers_list_dialog;
748 wxPreferencesEditor* _config_dialog;
750 shared_ptr<Film> _film;
752 int _history_position;
753 wxMenuItem* _history_separator;
754 boost::signals2::scoped_connection _config_changed_connection;
757 static const wxCmdLineEntryDesc command_line_description[] = {
758 { wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
759 { wxCMD_LINE_OPTION, "c", "content", "add content file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
760 { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
761 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
765 * @brief The magic App class for wxWidgets.
767 class App : public wxApp
780 SetAppName (_("DCP-o-matic"));
782 if (!wxApp::OnInit()) {
786 #ifdef DCPOMATIC_LINUX
787 unsetenv ("UBUNTU_MENUPROXY");
791 ProcessSerialNumber serial;
792 GetCurrentProcess (&serial);
793 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
796 wxInitAllImageHandlers ();
798 /* Enable i18n; this will create a Config object
799 to look for a force-configured language. This Config
800 object will be wrong, however, because dcpomatic_setup
801 hasn't yet been called and there aren't any filters etc.
804 dcpomatic_setup_i18n ();
806 /* Set things up, including filters etc.
807 which will now be internationalised correctly.
811 /* Force the configuration to be re-loaded correctly next
816 _frame = new DOMFrame (_("DCP-o-matic"));
817 SetTopWindow (_frame);
821 if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {
823 _frame->load_film (_film_to_load);
824 } catch (exception& e) {
825 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), _film_to_load, e.what())));
829 if (!_film_to_create.empty ()) {
830 _frame->new_film (_film_to_create);
831 if (!_content_to_add.empty ()) {
832 _frame->film()->examine_and_add_content (content_factory (_frame->film(), _content_to_add));
836 signal_manager = new wxSignalManager (this);
837 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
839 Bind (wxEVT_TIMER, boost::bind (&App::check, this));
840 _timer.reset (new wxTimer (this));
841 _timer->Start (1000);
843 UpdateChecker::instance()->StateChanged.connect (boost::bind (&App::update_checker_state_changed, this));
844 if (Config::instance()->check_for_updates ()) {
845 UpdateChecker::instance()->run ();
852 error_dialog (0, wxString::Format ("DCP-o-matic could not start: %s", e.what ()));
856 void OnInitCmdLine (wxCmdLineParser& parser)
858 parser.SetDesc (command_line_description);
859 parser.SetSwitchChars (wxT ("-"));
862 bool OnCmdLineParsed (wxCmdLineParser& parser)
864 if (parser.GetParamCount() > 0) {
865 if (parser.Found (wxT ("new"))) {
866 _film_to_create = wx_to_std (parser.GetParam (0));
868 _film_to_load = wx_to_std (parser.GetParam (0));
873 if (parser.Found (wxT ("content"), &content)) {
874 _content_to_add = wx_to_std (content);
880 /* An unhandled exception has occurred inside the main event loop */
881 bool OnExceptionInMainLoop ()
885 } catch (FileError& e) {
886 error_dialog (0, wxString::Format (_("An exception occurred: %s (%s).\n\n" + REPORT_PROBLEM), e.what(), e.file().string().c_str ()));
887 } catch (exception& e) {
888 error_dialog (0, wxString::Format (_("An exception occurred: %s.\n\n"), e.what ()) + " " + REPORT_PROBLEM);
890 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
893 /* This will terminate the program */
897 void OnUnhandledException ()
899 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
904 signal_manager->ui_idle ();
910 ServerFinder::instance()->rethrow ();
911 } catch (exception& e) {
912 error_dialog (0, std_to_wx (e.what ()));
916 void update_checker_state_changed ()
918 UpdateChecker* uc = UpdateChecker::instance ();
919 if (uc->state() == UpdateChecker::YES && (uc->stable() || uc->test())) {
920 UpdateDialog* dialog = new UpdateDialog (_frame, uc->stable (), uc->test ());
921 dialog->ShowModal ();
923 } else if (uc->state() == UpdateChecker::FAILED) {
924 if (!UpdateChecker::instance()->last_emit_was_first ()) {
925 error_dialog (_frame, _("The DCP-o-matic download server could not be contacted."));
928 if (!UpdateChecker::instance()->last_emit_was_first ()) {
929 error_dialog (_frame, _("There are no new versions of DCP-o-matic available."));
935 shared_ptr<wxTimer> _timer;
936 string _film_to_load;
937 string _film_to_create;
938 string _content_to_add;