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/exceptions.h"
48 #include "lib/cinema.h"
49 #include "lib/screen_kdm.h"
50 #include "lib/send_kdm_email_job.h"
51 #include "lib/server_finder.h"
52 #include "lib/update_checker.h"
53 #include "lib/cross.h"
54 #include "lib/content_factory.h"
55 #include "lib/compose.hpp"
56 #include <dcp/exceptions.h>
57 #include <wx/generic/aboutdlgg.h>
58 #include <wx/stdpaths.h>
59 #include <wx/cmdline.h>
60 #include <wx/preferences.h>
61 #include <wx/splash.h>
66 #include <ApplicationServices/ApplicationServices.h>
68 #include <boost/filesystem.hpp>
82 using std::wstringstream;
87 using boost::shared_ptr;
88 using boost::dynamic_pointer_cast;
90 class FilmChangedDialog
93 FilmChangedDialog (string name)
95 _dialog = new wxMessageDialog (
97 wxString::Format (_("Save changes to film \"%s\" before closing?"), std_to_wx (name).data()),
98 /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
99 /// project (Film) has been changed since it was last saved.
101 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
105 ~FilmChangedDialog ()
112 return _dialog->ShowModal ();
117 FilmChangedDialog (FilmChangedDialog const &);
119 wxMessageDialog* _dialog;
123 #define NEEDS_FILM 0x1
124 #define NOT_DURING_DCP_CREATION 0x2
125 #define NEEDS_CPL 0x4
126 #define NEEDS_SELECTED_VIDEO_CONTENT 0x8
128 map<wxMenuItem*, int> menu_items;
135 /* Allow spare IDs after _history for the recent files list */
136 ID_content_scale_to_fit_width = 100,
137 ID_content_scale_to_fit_height,
140 ID_jobs_send_dcp_to_tms,
142 ID_tools_video_waveform,
144 ID_tools_encoding_servers,
145 ID_tools_check_for_updates,
146 ID_tools_restore_default_preferences,
147 ID_help_report_a_problem,
148 /* IDs for shortcuts (with no associated menu item) */
152 class DOMFrame : public wxFrame
155 DOMFrame (wxString const & title)
156 : wxFrame (NULL, -1, title)
157 , _video_waveform_dialog (0)
159 , _servers_list_dialog (0)
163 , _history_position (0)
164 , _history_separator (0)
166 #if defined(DCPOMATIC_WINDOWS)
167 if (Config::instance()->win32_console ()) {
170 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
171 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
172 FILE* hf_out = _fdopen(hCrt, "w");
173 setvbuf(hf_out, NULL, _IONBF, 1);
176 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
177 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
178 FILE* hf_in = _fdopen(hCrt, "r");
179 setvbuf(hf_in, NULL, _IONBF, 128);
182 cout << "DCP-o-matic is starting." << "\n";
186 wxMenuBar* bar = new wxMenuBar;
190 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
193 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_new, this), ID_file_new);
194 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_open, this), ID_file_open);
195 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_save, this), ID_file_save);
196 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
197 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
198 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
199 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_width, this), ID_content_scale_to_fit_width);
200 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::content_scale_to_fit_height, this), ID_content_scale_to_fit_height);
201 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_dcp, this), ID_jobs_make_dcp);
202 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_kdms, this), ID_jobs_make_kdms);
203 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
204 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_show_dcp, this), ID_jobs_show_dcp);
205 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_video_waveform, this), ID_tools_video_waveform);
206 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_hints, this), ID_tools_hints);
207 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_encoding_servers, this), ID_tools_encoding_servers);
208 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
209 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
210 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
211 Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
213 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1));
215 /* Use a panel as the only child of the Frame so that we avoid
216 the dark-grey background on Windows.
218 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
220 _film_viewer = new FilmViewer (overall_panel);
221 _film_editor = new FilmEditor (overall_panel, _film_viewer);
222 JobManagerView* job_manager_view = new JobManagerView (overall_panel);
224 wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
225 right_sizer->Add (_film_viewer, 2, wxEXPAND | wxALL, 6);
226 right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
228 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
229 main_sizer->Add (_film_editor, 1, wxEXPAND | wxALL, 6);
230 main_sizer->Add (right_sizer, 2, wxEXPAND | wxALL, 6);
232 set_menu_sensitivity ();
234 _film_editor->FileChanged.connect (bind (&DOMFrame::file_changed, this, _1));
237 JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
239 overall_panel->SetSizer (main_sizer);
241 wxAcceleratorEntry accel[1];
242 accel[0].Set (wxACCEL_CTRL, static_cast<int>('A'), ID_add_file);
243 Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file);
244 wxAcceleratorTable accel_table (1, accel);
245 SetAcceleratorTable (accel_table);
247 /* Instantly save any config changes when using the DCP-o-matic GUI */
248 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
251 void new_film (boost::filesystem::path path)
253 shared_ptr<Film> film (new Film (path));
254 film->write_metadata ();
255 film->set_name (path.filename().generic_string());
259 void load_film (boost::filesystem::path file)
262 maybe_save_then_delete_film ();
264 shared_ptr<Film> film (new Film (file));
265 list<string> const notes = film->read_metadata ();
267 if (film->state_version() == 4) {
270 _("This film was created with an old version of DVD-o-matic and may not load correctly "
271 "in this version. Please check the film's settings carefully.")
275 for (list<string>::const_iterator i = notes.begin(); i != notes.end(); ++i) {
276 error_dialog (0, std_to_wx (*i));
281 catch (std::exception& e) {
282 wxString p = std_to_wx (file.string ());
283 wxCharBuffer b = p.ToUTF8 ();
284 error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
287 void set_film (shared_ptr<Film> film)
290 _film_viewer->set_film (_film);
291 _film_editor->set_film (_film);
292 set_menu_sensitivity ();
293 Config::instance()->add_to_history (_film->directory ());
296 shared_ptr<Film> film () const {
302 void file_changed (boost::filesystem::path f)
304 string s = wx_to_std (_("DCP-o-matic"));
306 s += " - " + f.string ();
309 SetTitle (std_to_wx (s));
314 NewFilmDialog* d = new NewFilmDialog (this);
315 int const r = d->ShowModal ();
319 if (boost::filesystem::is_directory (d->get_path()) && !boost::filesystem::is_empty(d->get_path())) {
320 if (!confirm_dialog (
323 String::compose (wx_to_std (_("The directory %1 already exists and is not empty. "
324 "Are you sure you want to use it?")),
325 d->get_path().string().c_str())
330 } else if (boost::filesystem::is_regular_file (d->get_path())) {
333 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())
338 maybe_save_then_delete_film ();
339 new_film (d->get_path ());
347 wxDirDialog* c = new wxDirDialog (
349 _("Select film to open"),
350 std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
351 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
357 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
358 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
365 load_film (wx_to_std (c->GetPath ()));
373 _film->write_metadata ();
376 void file_history (wxCommandEvent& event)
378 vector<boost::filesystem::path> history = Config::instance()->history ();
379 int n = event.GetId() - ID_file_history;
380 if (n >= 0 && n < static_cast<int> (history.size ())) {
381 load_film (history[n]);
387 /* false here allows the close handler to veto the close request */
391 void edit_preferences ()
393 if (!_config_dialog) {
394 _config_dialog = create_config_dialog ();
396 _config_dialog->Show (this);
399 void tools_restore_default_preferences ()
401 Config::restore_defaults ();
404 void jobs_make_dcp ()
410 if (!_film->should_be_enough_disk_space (required, available, can_hard_link)) {
413 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);
415 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);
417 if (!confirm_dialog (this, message)) {
423 /* It seems to make sense to auto-save metadata here, since the make DCP may last
424 a long time, and crashes/power failures are moderately likely.
426 _film->write_metadata ();
428 } catch (BadSettingError& e) {
429 error_dialog (this, wxString::Format (_("Bad setting for %s (%s)"), std_to_wx(e.setting()).data(), std_to_wx(e.what()).data()));
430 } catch (std::exception& e) {
431 error_dialog (this, wxString::Format (_("Could not make DCP: %s"), std_to_wx(e.what()).data()));
435 void jobs_make_kdms ()
441 KDMDialog* d = new KDMDialog (this, _film);
442 if (d->ShowModal () != wxID_OK) {
448 if (d->write_to ()) {
449 ScreenKDM::write_files (
451 ScreenKDM::collect (d->screens(), _film->make_kdms (d->screens(), d->cpl(), d->from(), d->until(), d->formulation())),
455 JobManager::instance()->add (
456 shared_ptr<Job> (new SendKDMEmailJob (_film, d->screens (), d->cpl (), d->from (), d->until (), d->formulation ()))
459 } catch (dcp::NotEncryptedError& e) {
460 error_dialog (this, _("CPL's content is not encrypted."));
461 } catch (exception& e) {
462 error_dialog (this, e.what ());
464 error_dialog (this, _("An unknown exception occurred."));
470 void content_scale_to_fit_width ()
472 VideoContentList vc = _film_editor->content_panel()->selected_video ();
473 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
474 (*i)->scale_and_crop_to_fit_width ();
478 void content_scale_to_fit_height ()
480 VideoContentList vc = _film_editor->content_panel()->selected_video ();
481 for (VideoContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
482 (*i)->scale_and_crop_to_fit_height ();
486 void jobs_send_dcp_to_tms ()
488 _film->send_dcp_to_tms ();
491 void jobs_show_dcp ()
493 #ifdef DCPOMATIC_WINDOWS
495 args << "/select," << _film->dir (_film->dcp_name(false));
496 ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
499 #ifdef DCPOMATIC_LINUX
500 int r = system ("which nautilus");
501 if (WEXITSTATUS (r) == 0) {
502 r = system (string ("nautilus " + _film->directory().string()).c_str ());
503 if (WEXITSTATUS (r)) {
504 error_dialog (this, _("Could not show DCP (could not run nautilus)"));
507 int r = system ("which konqueror");
508 if (WEXITSTATUS (r) == 0) {
509 r = system (string ("konqueror " + _film->directory().string()).c_str ());
510 if (WEXITSTATUS (r)) {
511 error_dialog (this, _("Could not show DCP (could not run konqueror)"));
518 int r = system (string ("open -R " + _film->dir (_film->dcp_name (false)).string ()).c_str ());
519 if (WEXITSTATUS (r)) {
520 error_dialog (this, _("Could not show DCP"));
525 void tools_video_waveform ()
527 if (!_video_waveform_dialog) {
528 _video_waveform_dialog = new VideoWaveformDialog (this, _film_viewer);
531 _video_waveform_dialog->Show ();
536 if (!_hints_dialog) {
537 _hints_dialog = new HintsDialog (this, _film);
540 _hints_dialog->Show ();
543 void tools_encoding_servers ()
545 if (!_servers_list_dialog) {
546 _servers_list_dialog = new ServersListDialog (this);
549 _servers_list_dialog->Show ();
552 void tools_check_for_updates ()
554 UpdateChecker::instance()->run ();
559 AboutDialog* d = new AboutDialog (this);
564 void help_report_a_problem ()
566 ReportProblemDialog* d = new ReportProblemDialog (this, _film);
567 if (d->ShowModal () == wxID_OK) {
575 if (!JobManager::instance()->work_to_do ()) {
579 wxMessageDialog* d = new wxMessageDialog (
581 _("There are unfinished jobs; are you sure you want to quit?"),
582 _("Unfinished jobs"),
583 wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
586 bool const r = d->ShowModal() == wxID_YES;
591 void close (wxCloseEvent& ev)
593 if (!should_close ()) {
598 /* We don't want to hear about any more configuration changes, since they
599 cause the File menu to be altered, which itself will be deleted around
600 now (without, as far as I can see, any way for us to find out).
602 _config_changed_connection.disconnect ();
604 maybe_save_then_delete_film ();
608 void set_menu_sensitivity ()
610 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
611 list<shared_ptr<Job> >::iterator i = jobs.begin();
612 while (i != jobs.end() && (*i)->json_name() != "transcode") {
615 bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
616 bool const have_cpl = _film && !_film->cpls().empty ();
617 bool const have_selected_video_content = !_film_editor->content_panel()->selected_video().empty();
619 for (map<wxMenuItem*, int>::iterator j = menu_items.begin(); j != menu_items.end(); ++j) {
623 if ((j->second & NEEDS_FILM) && !_film) {
627 if ((j->second & NOT_DURING_DCP_CREATION) && dcp_creation) {
631 if ((j->second & NEEDS_CPL) && !have_cpl) {
635 if ((j->second & NEEDS_SELECTED_VIDEO_CONTENT) && !have_selected_video_content) {
639 j->first->Enable (enabled);
643 void maybe_save_then_delete_film ()
649 if (_film->dirty ()) {
650 FilmChangedDialog d (_film->name ());
655 _film->write_metadata ();
663 void add_item (wxMenu* menu, wxString text, int id, int sens)
665 wxMenuItem* item = menu->Append (id, text);
666 menu_items.insert (make_pair (item, sens));
669 void setup_menu (wxMenuBar* m)
671 _file_menu = new wxMenu;
672 add_item (_file_menu, _("New...\tCtrl-N"), ID_file_new, ALWAYS);
673 add_item (_file_menu, _("&Open...\tCtrl-O"), ID_file_open, ALWAYS);
674 _file_menu->AppendSeparator ();
675 add_item (_file_menu, _("&Save\tCtrl-S"), ID_file_save, NEEDS_FILM);
677 _history_position = _file_menu->GetMenuItems().GetCount();
680 _file_menu->AppendSeparator ();
684 add_item (_file_menu, _("&Exit"), wxID_EXIT, ALWAYS);
686 add_item (_file_menu, _("&Quit"), wxID_EXIT, ALWAYS);
690 add_item (_file_menu, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
692 wxMenu* edit = new wxMenu;
693 add_item (edit, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
696 wxMenu* content = new wxMenu;
697 add_item (content, _("Scale to fit &width"), ID_content_scale_to_fit_width, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
698 add_item (content, _("Scale to fit &height"), ID_content_scale_to_fit_height, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
700 wxMenu* jobs_menu = new wxMenu;
701 add_item (jobs_menu, _("&Make DCP\tCtrl-M"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
702 add_item (jobs_menu, _("Make &KDMs...\tCtrl-K"), ID_jobs_make_kdms, NEEDS_FILM);
703 add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
704 add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
706 wxMenu* tools = new wxMenu;
707 add_item (tools, _("Video waveform..."), ID_tools_video_waveform, NEEDS_FILM);
708 add_item (tools, _("Hints..."), ID_tools_hints, 0);
709 add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
710 add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
711 tools->AppendSeparator ();
712 add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
714 wxMenu* help = new wxMenu;
716 add_item (help, _("About DCP-o-matic"), wxID_ABOUT, ALWAYS);
718 add_item (help, _("About"), wxID_ABOUT, ALWAYS);
720 add_item (help, _("Report a problem..."), ID_help_report_a_problem, NEEDS_FILM);
722 m->Append (_file_menu, _("&File"));
724 m->Append (edit, _("&Edit"));
726 m->Append (content, _("&Content"));
727 m->Append (jobs_menu, _("&Jobs"));
728 m->Append (tools, _("&Tools"));
729 m->Append (help, _("&Help"));
732 void config_changed ()
734 for (int i = 0; i < _history_items; ++i) {
735 delete _file_menu->Remove (ID_file_history + i);
738 if (_history_separator) {
739 _file_menu->Remove (_history_separator);
741 delete _history_separator;
742 _history_separator = 0;
744 int pos = _history_position;
746 vector<boost::filesystem::path> history = Config::instance()->history ();
748 if (!history.empty ()) {
749 _history_separator = _file_menu->InsertSeparator (pos++);
752 for (size_t i = 0; i < history.size(); ++i) {
755 s << "&" << (i + 1) << " ";
757 s << history[i].string();
758 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s.str ()));
761 _history_items = history.size ();
764 FilmEditor* _film_editor;
765 FilmViewer* _film_viewer;
766 VideoWaveformDialog* _video_waveform_dialog;
767 HintsDialog* _hints_dialog;
768 ServersListDialog* _servers_list_dialog;
769 wxPreferencesEditor* _config_dialog;
771 shared_ptr<Film> _film;
773 int _history_position;
774 wxMenuItem* _history_separator;
775 boost::signals2::scoped_connection _config_changed_connection;
778 static const wxCmdLineEntryDesc command_line_description[] = {
779 { wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
780 { wxCMD_LINE_OPTION, "c", "content", "add content file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
781 { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
782 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
786 * @brief The magic App class for wxWidgets.
788 class App : public wxApp
801 wxInitAllImageHandlers ();
803 wxSplashScreen* splash = 0;
805 if (!Config::have_existing ()) {
807 boost::filesystem::path p = shared_path () / "splash.png";
808 if (bitmap.LoadFile (std_to_wx (p.string ()), wxBITMAP_TYPE_PNG)) {
809 splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1);
813 } catch (boost::filesystem::filesystem_error& e) {
814 /* Maybe we couldn't find the splash image; never mind */
817 SetAppName (_("DCP-o-matic"));
819 if (!wxApp::OnInit()) {
823 #ifdef DCPOMATIC_LINUX
824 unsetenv ("UBUNTU_MENUPROXY");
828 ProcessSerialNumber serial;
829 GetCurrentProcess (&serial);
830 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
833 dcpomatic_setup_path_encoding ();
835 /* Enable i18n; this will create a Config object
836 to look for a force-configured language. This Config
837 object will be wrong, however, because dcpomatic_setup
838 hasn't yet been called and there aren't any filters etc.
841 dcpomatic_setup_i18n ();
843 /* Set things up, including filters etc.
844 which will now be internationalised correctly.
848 /* Force the configuration to be re-loaded correctly next
853 _frame = new DOMFrame (_("DCP-o-matic"));
854 SetTopWindow (_frame);
861 if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {
863 _frame->load_film (_film_to_load);
864 } catch (exception& e) {
865 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), _film_to_load, e.what())));
869 if (!_film_to_create.empty ()) {
870 _frame->new_film (_film_to_create);
871 if (!_content_to_add.empty ()) {
872 _frame->film()->examine_and_add_content (content_factory (_frame->film(), _content_to_add));
876 signal_manager = new wxSignalManager (this);
877 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
879 Bind (wxEVT_TIMER, boost::bind (&App::check, this));
880 _timer.reset (new wxTimer (this));
881 _timer->Start (1000);
883 UpdateChecker::instance()->StateChanged.connect (boost::bind (&App::update_checker_state_changed, this));
884 if (Config::instance()->check_for_updates ()) {
885 UpdateChecker::instance()->run ();
892 error_dialog (0, wxString::Format ("DCP-o-matic could not start: %s", e.what ()));
896 void OnInitCmdLine (wxCmdLineParser& parser)
898 parser.SetDesc (command_line_description);
899 parser.SetSwitchChars (wxT ("-"));
902 bool OnCmdLineParsed (wxCmdLineParser& parser)
904 if (parser.GetParamCount() > 0) {
905 if (parser.Found (wxT ("new"))) {
906 _film_to_create = wx_to_std (parser.GetParam (0));
908 _film_to_load = wx_to_std (parser.GetParam (0));
913 if (parser.Found (wxT ("content"), &content)) {
914 _content_to_add = wx_to_std (content);
920 /* An unhandled exception has occurred inside the main event loop */
921 bool OnExceptionInMainLoop ()
925 } catch (FileError& e) {
929 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
930 std_to_wx (e.what()),
931 std_to_wx (e.file().string().c_str ())
934 } catch (exception& e) {
938 _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
939 std_to_wx (e.what ())
943 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
946 /* This will terminate the program */
950 void OnUnhandledException ()
952 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
957 signal_manager->ui_idle ();
963 ServerFinder::instance()->rethrow ();
964 } catch (exception& e) {
965 error_dialog (0, std_to_wx (e.what ()));
969 void update_checker_state_changed ()
971 UpdateChecker* uc = UpdateChecker::instance ();
972 if (uc->state() == UpdateChecker::YES && (uc->stable() || uc->test())) {
973 UpdateDialog* dialog = new UpdateDialog (_frame, uc->stable (), uc->test ());
974 dialog->ShowModal ();
976 } else if (uc->state() == UpdateChecker::FAILED) {
977 if (!UpdateChecker::instance()->last_emit_was_first ()) {
978 error_dialog (_frame, _("The DCP-o-matic download server could not be contacted."));
981 if (!UpdateChecker::instance()->last_emit_was_first ()) {
982 error_dialog (_frame, _("There are no new versions of DCP-o-matic available."));
988 shared_ptr<wxTimer> _timer;
989 string _film_to_load;
990 string _film_to_create;
991 string _content_to_add;