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.
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/wx_util.h"
29 #include "wx/new_film_dialog.h"
30 #include "wx/wx_signal_manager.h"
31 #include "wx/about_dialog.h"
32 #include "wx/kdm_dialog.h"
33 #include "wx/servers_list_dialog.h"
34 #include "wx/hints_dialog.h"
35 #include "wx/update_dialog.h"
36 #include "wx/content_panel.h"
37 #include "wx/report_problem_dialog.h"
38 #include "wx/video_waveform_dialog.h"
40 #include "lib/config.h"
42 #include "lib/video_content.h"
43 #include "lib/version.h"
44 #include "lib/signal_manager.h"
46 #include "lib/job_manager.h"
47 #include "lib/transcode_job.h"
48 #include "lib/exceptions.h"
49 #include "lib/cinema.h"
51 #include "lib/send_kdm_email_job.h"
52 #include "lib/server_finder.h"
53 #include "lib/update_checker.h"
54 #include "lib/cross.h"
55 #include "lib/content_factory.h"
56 #include "lib/compose.hpp"
57 #include <dcp/exceptions.h>
58 #include <wx/generic/aboutdlgg.h>
59 #include <wx/stdpaths.h>
60 #include <wx/cmdline.h>
61 #include <wx/preferences.h>
62 #include <wx/splash.h>
67 #include <ApplicationServices/ApplicationServices.h>
69 #include <boost/filesystem.hpp>
83 using std::wstringstream;
88 using boost::shared_ptr;
89 using boost::dynamic_pointer_cast;
91 class FilmChangedDialog
94 FilmChangedDialog (string name)
96 _dialog = new wxMessageDialog (
98 wxString::Format (_("Save changes to film \"%s\" before closing?"), std_to_wx (name).data()),
99 /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
100 /// project (Film) has been changed since it was last saved.
102 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
106 ~FilmChangedDialog ()
113 return _dialog->ShowModal ();
118 FilmChangedDialog (FilmChangedDialog const &);
120 wxMessageDialog* _dialog;
124 #define NEEDS_FILM 0x1
125 #define NOT_DURING_DCP_CREATION 0x2
126 #define NEEDS_CPL 0x4
127 #define NEEDS_SELECTED_VIDEO_CONTENT 0x8
129 map<wxMenuItem*, int> menu_items;
136 /* Allow spare IDs after _history for the recent files list */
137 ID_content_scale_to_fit_width = 100,
138 ID_content_scale_to_fit_height,
141 ID_jobs_send_dcp_to_tms,
143 ID_tools_video_waveform,
145 ID_tools_encoding_servers,
146 ID_tools_check_for_updates,
147 ID_tools_restore_default_preferences,
148 ID_help_report_a_problem,
149 /* IDs for shortcuts (with no associated menu item) */
153 class DOMFrame : public wxFrame
156 DOMFrame (wxString const & title)
157 : wxFrame (NULL, -1, title)
158 , _video_waveform_dialog (0)
160 , _servers_list_dialog (0)
164 , _history_position (0)
165 , _history_separator (0)
167 #if defined(DCPOMATIC_WINDOWS)
168 if (Config::instance()->win32_console ()) {
171 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
172 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
173 FILE* hf_out = _fdopen(hCrt, "w");
174 setvbuf(hf_out, NULL, _IONBF, 1);
177 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
178 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
179 FILE* hf_in = _fdopen(hCrt, "r");
180 setvbuf(hf_in, NULL, _IONBF, 128);
183 cout << "DCP-o-matic is starting." << "\n";
187 wxMenuBar* bar = new wxMenuBar;
191 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
194 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_new, this), ID_file_new);
195 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_open, this), ID_file_open);
196 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_save, this), ID_file_save);
197 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
198 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
199 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
200 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_width, this), ID_content_scale_to_fit_width);
201 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_height, this), ID_content_scale_to_fit_height);
202 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_dcp, this), ID_jobs_make_dcp);
203 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_kdms, this), ID_jobs_make_kdms);
204 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
205 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_show_dcp, this), ID_jobs_show_dcp);
206 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_video_waveform, this), ID_tools_video_waveform);
207 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_hints, this), ID_tools_hints);
208 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_encoding_servers, this), ID_tools_encoding_servers);
209 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
210 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
211 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
212 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
214 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1));
216 /* Use a panel as the only child of the Frame so that we avoid
217 the dark-grey background on Windows.
219 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
221 _film_viewer = new FilmViewer (overall_panel);
222 _film_editor = new FilmEditor (overall_panel, _film_viewer);
223 JobManagerView* job_manager_view = new JobManagerView (overall_panel);
225 wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
226 right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
227 right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
229 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
230 main_sizer->Add (_film_editor, 1, wxEXPAND | wxALL, 6);
231 main_sizer->Add (right_sizer, 2, wxEXPAND | wxALL, 6);
233 set_menu_sensitivity ();
235 _film_editor->FileChanged.connect (bind (&DOMFrame::file_changed, this, _1));
238 JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
240 overall_panel->SetSizer (main_sizer);
242 wxAcceleratorEntry accel[1];
243 accel[0].Set (wxACCEL_CTRL, static_cast<int>('A'), ID_add_file);
244 Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file);
245 wxAcceleratorTable accel_table (1, accel);
246 SetAcceleratorTable (accel_table);
248 /* Instantly save any config changes when using the DCP-o-matic GUI */
249 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
252 void new_film (boost::filesystem::path path)
254 shared_ptr<Film> film (new Film (path));
255 film->write_metadata ();
256 film->set_name (path.filename().generic_string());
260 void load_film (boost::filesystem::path file)
263 maybe_save_then_delete_film ();
265 shared_ptr<Film> film (new Film (file));
266 list<string> const notes = film->read_metadata ();
268 if (film->state_version() == 4) {
271 _("This film was created with an old version of DVD-o-matic and may not load correctly "
272 "in this version. Please check the film's settings carefully.")
276 for (list<string>::const_iterator i = notes.begin(); i != notes.end(); ++i) {
277 error_dialog (0, std_to_wx (*i));
282 catch (std::exception& e) {
283 wxString p = std_to_wx (file.string ());
284 wxCharBuffer b = p.ToUTF8 ();
285 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
288 void set_film (shared_ptr<Film> film)
291 _film_viewer->set_film (_film);
292 _film_editor->set_film (_film);
293 set_menu_sensitivity ();
294 Config::instance()->add_to_history (_film->directory ());
297 shared_ptr<Film> film () const {
303 void file_changed (boost::filesystem::path f)
305 string s = wx_to_std (_("DCP-o-matic"));
307 s += " - " + f.string ();
310 SetTitle (std_to_wx (s));
315 NewFilmDialog* d = new NewFilmDialog (this);
316 int const r = d->ShowModal ();
320 if (boost::filesystem::is_directory (d->get_path()) && !boost::filesystem::is_empty(d->get_path())) {
321 if (!confirm_dialog (
324 String::compose (wx_to_std (_("The directory %1 already exists and is not empty. "
325 "Are you sure you want to use it?")),
326 d->get_path().string().c_str())
331 } else if (boost::filesystem::is_regular_file (d->get_path())) {
334 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())
339 maybe_save_then_delete_film ();
340 new_film (d->get_path ());
348 wxDirDialog* c = new wxDirDialog (
350 _("Select film to open"),
351 std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
352 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
358 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
359 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
366 load_film (wx_to_std (c->GetPath ()));
374 _film->write_metadata ();
377 void file_history (wxCommandEvent& event)
379 vector<boost::filesystem::path> history = Config::instance()->history ();
380 int n = event.GetId() - ID_file_history;
381 if (n >= 0 && n < static_cast<int> (history.size ())) {
382 load_film (history[n]);
388 /* false here allows the close handler to veto the close request */
392 void edit_preferences ()
394 if (!_config_dialog) {
395 _config_dialog = create_config_dialog ();
397 _config_dialog->Show (this);
400 void tools_restore_default_preferences ()
402 Config::restore_defaults ();
405 void jobs_make_dcp ()
411 if (!_film->should_be_enough_disk_space (required, available, can_hard_link)) {
414 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);
416 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);
418 if (!confirm_dialog (this, message)) {
424 /* It seems to make sense to auto-save metadata here, since the make DCP may last
425 a long time, and crashes/power failures are moderately likely.
427 _film->write_metadata ();
429 } catch (BadSettingError& e) {
430 error_dialog (this, wxString::Format (_("Bad setting for %s (%s)"), std_to_wx(e.setting()).data(), std_to_wx(e.what()).data()));
431 } catch (std::exception& e) {
432 error_dialog (this, wxString::Format (_("Could not make DCP: %s"), std_to_wx(e.what()).data()));
436 void jobs_make_kdms ()
442 KDMDialog* d = new KDMDialog (this, _film);
443 if (d->ShowModal () != wxID_OK) {
449 if (d->write_to ()) {
450 write_kdm_files (_film, d->screens (), d->cpl (), d->from (), d->until (), d->formulation (), d->directory ());
452 JobManager::instance()->add (
453 shared_ptr<Job> (new SendKDMEmailJob (_film, d->screens (), d->cpl (), d->from (), d->until (), d->formulation ()))
456 } catch (dcp::NotEncryptedError& e) {
457 error_dialog (this, _("CPL's content is not encrypted."));
458 } catch (exception& e) {
459 error_dialog (this, e.what ());
461 error_dialog (this, _("An unknown exception occurred."));
467 void content_scale_to_fit_width ()
469 VideoContentList vc = _film_editor->content_panel()->selected_video ();
470 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
471 (*i)->scale_and_crop_to_fit_width ();
475 void content_scale_to_fit_height ()
477 VideoContentList vc = _film_editor->content_panel()->selected_video ();
478 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
479 (*i)->scale_and_crop_to_fit_height ();
483 void jobs_send_dcp_to_tms ()
485 _film->send_dcp_to_tms ();
488 void jobs_show_dcp ()
490 #ifdef DCPOMATIC_WINDOWS
492 args << "/select," << _film->dir (_film->dcp_name(false));
493 ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
496 #ifdef DCPOMATIC_LINUX
497 int r = system ("which nautilus");
498 if (WEXITSTATUS (r) == 0) {
499 r = system (string ("nautilus " + _film->directory().string()).c_str ());
500 if (WEXITSTATUS (r)) {
501 error_dialog (this, _("Could not show DCP (could not run nautilus)"));
504 int r = system ("which konqueror");
505 if (WEXITSTATUS (r) == 0) {
506 r = system (string ("konqueror " + _film->directory().string()).c_str ());
507 if (WEXITSTATUS (r)) {
508 error_dialog (this, _("Could not show DCP (could not run konqueror)"));
515 int r = system (string ("open -R " + _film->dir (_film->dcp_name (false)).string ()).c_str ());
516 if (WEXITSTATUS (r)) {
517 error_dialog (this, _("Could not show DCP"));
522 void tools_video_waveform ()
524 if (!_video_waveform_dialog) {
525 _video_waveform_dialog = new VideoWaveformDialog (this, _film_viewer);
528 _video_waveform_dialog->Show ();
533 if (!_hints_dialog) {
534 _hints_dialog = new HintsDialog (this, _film);
537 _hints_dialog->Show ();
540 void tools_encoding_servers ()
542 if (!_servers_list_dialog) {
543 _servers_list_dialog = new ServersListDialog (this);
546 _servers_list_dialog->Show ();
549 void tools_check_for_updates ()
551 UpdateChecker::instance()->run ();
556 AboutDialog* d = new AboutDialog (this);
561 void help_report_a_problem ()
563 ReportProblemDialog* d = new ReportProblemDialog (this, _film);
564 if (d->ShowModal () == wxID_OK) {
572 if (!JobManager::instance()->work_to_do ()) {
576 wxMessageDialog* d = new wxMessageDialog (
578 _("There are unfinished jobs; are you sure you want to quit?"),
579 _("Unfinished jobs"),
580 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
583 bool const r = d->ShowModal() == wxID_YES;
588 void close (wxCloseEvent& ev)
590 if (!should_close ()) {
595 /* We don't want to hear about any more configuration changes, since they
596 cause the File menu to be altered, which itself will be deleted around
597 now (without, as far as I can see, any way for us to find out).
599 _config_changed_connection.disconnect ();
601 maybe_save_then_delete_film ();
605 void set_menu_sensitivity ()
607 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
608 list<shared_ptr<Job> >::iterator i = jobs.begin();
609 while (i != jobs.end() && dynamic_pointer_cast<TranscodeJob> (*i) == 0) {
612 bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
613 bool const have_cpl = _film && !_film->cpls().empty ();
614 bool const have_selected_video_content = !_film_editor->content_panel()->selected_video().empty();
616 for (map<wxMenuItem*, int>::iterator j = menu_items.begin(); j != menu_items.end(); ++j) {
620 if ((j->second & NEEDS_FILM) && !_film) {
624 if ((j->second & NOT_DURING_DCP_CREATION) && dcp_creation) {
628 if ((j->second & NEEDS_CPL) && !have_cpl) {
632 if ((j->second & NEEDS_SELECTED_VIDEO_CONTENT) && !have_selected_video_content) {
636 j->first->Enable (enabled);
640 void maybe_save_then_delete_film ()
646 if (_film->dirty ()) {
647 FilmChangedDialog d (_film->name ());
652 _film->write_metadata ();
660 void add_item (wxMenu* menu, wxString text, int id, int sens)
662 wxMenuItem* item = menu->Append (id, text);
663 menu_items.insert (make_pair (item, sens));
666 void setup_menu (wxMenuBar* m)
668 _file_menu = new wxMenu;
669 add_item (_file_menu, _("New...\tCtrl-N"), ID_file_new, ALWAYS);
670 add_item (_file_menu, _("&Open...\tCtrl-O"), ID_file_open, ALWAYS);
671 _file_menu->AppendSeparator ();
672 add_item (_file_menu, _("&Save\tCtrl-S"), ID_file_save, NEEDS_FILM);
674 _history_position = _file_menu->GetMenuItems().GetCount();
677 _file_menu->AppendSeparator ();
681 add_item (_file_menu, _("&Exit"), wxID_EXIT, ALWAYS);
683 add_item (_file_menu, _("&Quit"), wxID_EXIT, ALWAYS);
687 add_item (_file_menu, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
689 wxMenu* edit = new wxMenu;
690 add_item (edit, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
693 wxMenu* content = new wxMenu;
694 add_item (content, _("Scale to fit &width"), ID_content_scale_to_fit_width, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
695 add_item (content, _("Scale to fit &height"), ID_content_scale_to_fit_height, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
697 wxMenu* jobs_menu = new wxMenu;
698 add_item (jobs_menu, _("&Make DCP\tCtrl-M"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
699 add_item (jobs_menu, _("Make &KDMs...\tCtrl-K"), ID_jobs_make_kdms, NEEDS_FILM);
700 add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
701 add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
703 wxMenu* tools = new wxMenu;
704 add_item (tools, _("Video waveform..."), ID_tools_video_waveform, NEEDS_FILM);
705 add_item (tools, _("Hints..."), ID_tools_hints, 0);
706 add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
707 add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
708 tools->AppendSeparator ();
709 add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
711 wxMenu* help = new wxMenu;
713 add_item (help, _("About DCP-o-matic"), wxID_ABOUT, ALWAYS);
715 add_item (help, _("About"), wxID_ABOUT, ALWAYS);
717 add_item (help, _("Report a problem..."), ID_help_report_a_problem, NEEDS_FILM);
719 m->Append (_file_menu, _("&File"));
721 m->Append (edit, _("&Edit"));
723 m->Append (content, _("&Content"));
724 m->Append (jobs_menu, _("&Jobs"));
725 m->Append (tools, _("&Tools"));
726 m->Append (help, _("&Help"));
729 void config_changed ()
731 for (int i = 0; i < _history_items; ++i) {
732 delete _file_menu->Remove (ID_file_history + i);
735 if (_history_separator) {
736 _file_menu->Remove (_history_separator);
738 delete _history_separator;
739 _history_separator = 0;
741 int pos = _history_position;
743 vector<boost::filesystem::path> history = Config::instance()->history ();
745 if (!history.empty ()) {
746 _history_separator = _file_menu->InsertSeparator (pos++);
749 for (size_t i = 0; i < history.size(); ++i) {
752 s << "&" << (i + 1) << " ";
754 s << history[i].string();
755 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s.str ()));
758 _history_items = history.size ();
761 FilmEditor* _film_editor;
762 FilmViewer* _film_viewer;
763 VideoWaveformDialog* _video_waveform_dialog;
764 HintsDialog* _hints_dialog;
765 ServersListDialog* _servers_list_dialog;
766 wxPreferencesEditor* _config_dialog;
768 shared_ptr<Film> _film;
770 int _history_position;
771 wxMenuItem* _history_separator;
772 boost::signals2::scoped_connection _config_changed_connection;
775 static const wxCmdLineEntryDesc command_line_description[] = {
776 { wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
777 { wxCMD_LINE_OPTION, "c", "content", "add content file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
778 { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
779 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
783 * @brief The magic App class for wxWidgets.
785 class App : public wxApp
798 wxInitAllImageHandlers ();
800 wxSplashScreen* splash = 0;
802 if (!Config::have_existing ()) {
804 boost::filesystem::path p = shared_path () / "splash.png";
805 if (bitmap.LoadFile (std_to_wx (p.string ()), wxBITMAP_TYPE_PNG)) {
806 splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1);
810 } catch (boost::filesystem::filesystem_error& e) {
811 /* Maybe we couldn't find the splash image; never mind */
814 SetAppName (_("DCP-o-matic"));
816 if (!wxApp::OnInit()) {
820 #ifdef DCPOMATIC_LINUX
821 unsetenv ("UBUNTU_MENUPROXY");
825 ProcessSerialNumber serial;
826 GetCurrentProcess (&serial);
827 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
830 dcpomatic_setup_path_encoding ();
832 /* Enable i18n; this will create a Config object
833 to look for a force-configured language. This Config
834 object will be wrong, however, because dcpomatic_setup
835 hasn't yet been called and there aren't any filters etc.
838 dcpomatic_setup_i18n ();
840 /* Set things up, including filters etc.
841 which will now be internationalised correctly.
845 /* Force the configuration to be re-loaded correctly next
850 _frame = new DOMFrame (_("DCP-o-matic"));
851 SetTopWindow (_frame);
858 if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {
860 _frame->load_film (_film_to_load);
861 } catch (exception& e) {
862 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), _film_to_load, e.what())));
866 if (!_film_to_create.empty ()) {
867 _frame->new_film (_film_to_create);
868 if (!_content_to_add.empty ()) {
869 _frame->film()->examine_and_add_content (content_factory (_frame->film(), _content_to_add));
873 signal_manager = new wxSignalManager (this);
874 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
876 Bind (wxEVT_TIMER, boost::bind (&App::check, this));
877 _timer.reset (new wxTimer (this));
878 _timer->Start (1000);
880 UpdateChecker::instance()->StateChanged.connect (boost::bind (&App::update_checker_state_changed, this));
881 if (Config::instance()->check_for_updates ()) {
882 UpdateChecker::instance()->run ();
889 error_dialog (0, wxString::Format ("DCP-o-matic could not start: %s", e.what ()));
893 void OnInitCmdLine (wxCmdLineParser& parser)
895 parser.SetDesc (command_line_description);
896 parser.SetSwitchChars (wxT ("-"));
899 bool OnCmdLineParsed (wxCmdLineParser& parser)
901 if (parser.GetParamCount() > 0) {
902 if (parser.Found (wxT ("new"))) {
903 _film_to_create = wx_to_std (parser.GetParam (0));
905 _film_to_load = wx_to_std (parser.GetParam (0));
910 if (parser.Found (wxT ("content"), &content)) {
911 _content_to_add = wx_to_std (content);
917 /* An unhandled exception has occurred inside the main event loop */
918 bool OnExceptionInMainLoop ()
922 } catch (FileError& e) {
923 error_dialog (0, wxString::Format (_("An exception occurred: %s (%s).\n\n" + REPORT_PROBLEM), e.what(), e.file().string().c_str ()));
924 } catch (exception& e) {
925 error_dialog (0, wxString::Format (_("An exception occurred: %s.\n\n"), e.what ()) + " " + REPORT_PROBLEM);
927 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
930 /* This will terminate the program */
934 void OnUnhandledException ()
936 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
941 signal_manager->ui_idle ();
947 ServerFinder::instance()->rethrow ();
948 } catch (exception& e) {
949 error_dialog (0, std_to_wx (e.what ()));
953 void update_checker_state_changed ()
955 UpdateChecker* uc = UpdateChecker::instance ();
956 if (uc->state() == UpdateChecker::YES && (uc->stable() || uc->test())) {
957 UpdateDialog* dialog = new UpdateDialog (_frame, uc->stable (), uc->test ());
958 dialog->ShowModal ();
960 } else if (uc->state() == UpdateChecker::FAILED) {
961 if (!UpdateChecker::instance()->last_emit_was_first ()) {
962 error_dialog (_frame, _("The DCP-o-matic download server could not be contacted."));
965 if (!UpdateChecker::instance()->last_emit_was_first ()) {
966 error_dialog (_frame, _("There are no new versions of DCP-o-matic available."));
972 shared_ptr<wxTimer> _timer;
973 string _film_to_load;
974 string _film_to_create;
975 string _content_to_add;