2 Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/controls.h"
31 #include "lib/cross.h"
32 #include "lib/config.h"
34 #include "lib/update_checker.h"
35 #include "lib/compose.hpp"
36 #include "lib/dcp_content.h"
37 #include "lib/job_manager.h"
40 #include "lib/video_content.h"
41 #include "lib/text_content.h"
42 #include "lib/ratio.h"
43 #include "lib/verify_dcp_job.h"
44 #include "lib/dcp_examiner.h"
45 #include "lib/examine_content_job.h"
46 #include "lib/server.h"
47 #include "lib/dcpomatic_socket.h"
49 #include <wx/stdpaths.h>
50 #include <wx/splash.h>
51 #include <wx/cmdline.h>
52 #include <wx/preferences.h>
53 #include <wx/progdlg.h>
54 #include <wx/display.h>
56 #include <ApplicationServices/ApplicationServices.h>
58 #include <boost/bind.hpp>
72 using boost::shared_ptr;
73 using boost::scoped_array;
74 using boost::optional;
75 using boost::dynamic_pointer_cast;
84 /* Allow spare IDs after _history for the recent files list */
87 /* Allow spare IDs for CPLs */
88 ID_view_full_screen = 200,
90 ID_view_closed_captions,
91 ID_view_scale_appropriate,
94 ID_view_scale_quarter,
95 ID_help_report_a_problem,
97 ID_tools_check_for_updates,
98 /* IDs for shortcuts (with no associated menu item) */
104 class DOMFrame : public wxFrame
108 : wxFrame (0, -1, _("DCP-o-matic Player"))
110 , _update_news_requested (false)
112 , _mode (Config::instance()->player_mode())
116 , _history_position (0)
117 , _history_separator (0)
118 , _view_full_screen (0)
119 , _view_dual_screen (0)
122 #if defined(DCPOMATIC_WINDOWS)
123 maybe_open_console ();
124 cout << "DCP-o-matic Player is starting." << "\n";
127 wxMenuBar* bar = new wxMenuBar;
129 set_menu_sensitivity ();
132 #ifdef DCPOMATIC_WINDOWS
133 SetIcon (wxIcon (std_to_wx ("id")));
136 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
139 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
140 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
141 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
142 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
143 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
144 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
145 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
158 /* Use a panel as the only child of the Frame so that we avoid
159 the dark-grey background on Windows.
161 _overall_panel = new wxPanel (this, wxID_ANY);
163 _viewer.reset (new FilmViewer (_overall_panel));
164 _controls = new Controls (_overall_panel, _viewer, false, false, false);
165 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
166 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
167 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
168 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
169 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
170 _info = new PlayerInformation (_overall_panel, _viewer);
171 setup_main_sizer (true);
173 int accelerators = 4;
175 int accelerators = 3;
178 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
179 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
180 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
181 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
183 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
185 wxAcceleratorTable accel_table (accelerators, accel);
186 SetAcceleratorTable (accel_table);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
193 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
194 _controls->DCPDirectorySelected.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
199 void setup_main_sizer (bool with_viewer)
201 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
203 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
205 main_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
206 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
207 _overall_panel->SetSizer (main_sizer);
208 _overall_panel->Layout ();
211 bool playback_permitted ()
213 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
218 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
219 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
220 if (d && !d->kdm_timing_window_valid()) {
226 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
232 void playback_started (DCPTime time)
234 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
239 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
240 DCPOMATIC_ASSERT (dcp);
241 DCPExaminer ex (dcp);
242 shared_ptr<dcp::CPL> playing_cpl;
243 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
244 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
248 DCPOMATIC_ASSERT (playing_cpl)
250 FILE* f = fopen_boost(*log, "a");
253 "%s playback-started %s %s %s\n",
254 dcp::LocalTime().as_string().c_str(),
255 time.timecode(_film->video_frame_rate()).c_str(),
256 dcp->directories().front().string().c_str(),
257 playing_cpl->annotation_text().c_str()
262 void playback_seeked (DCPTime time)
264 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
269 FILE* f = fopen_boost(*log, "a");
270 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
274 void playback_stopped (DCPTime time)
276 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
281 FILE* f = fopen_boost(*log, "a");
282 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
286 void set_decode_reduction (optional<int> reduction)
288 _viewer->set_dcp_decode_reduction (reduction);
289 _info->triggered_update ();
290 Config::instance()->set_decode_reduction (reduction);
293 void load_dcp (boost::filesystem::path dir)
295 _film.reset (new Film (optional<boost::filesystem::path>()));
296 shared_ptr<DCPContent> dcp;
298 dcp.reset (new DCPContent (_film, dir));
299 } catch (boost::filesystem::filesystem_error& e) {
300 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
304 _film->examine_and_add_content (dcp, true);
305 bool const ok = progress (_("Loading DCP"));
306 if (!ok || !report_errors_from_last_job()) {
310 setup_from_dcp (dcp);
312 if (dcp->three_d()) {
313 _film->set_three_d (true);
316 _viewer->set_film (_film);
317 _viewer->seek (DCPTime(), true);
318 _info->triggered_update ();
320 Config::instance()->add_to_player_history (dir);
322 set_menu_sensitivity ();
324 wxMenuItemList old = _cpl_menu->GetMenuItems();
325 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
326 _cpl_menu->Remove (*i);
329 DCPExaminer ex (dcp);
330 int id = ID_view_cpl;
331 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
332 wxMenuItem* j = _cpl_menu->AppendRadioItem(
334 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
336 j->Check(!dcp->cpl() || i->id() == *dcp->cpl());
343 void setup_menu (wxMenuBar* m)
345 _file_menu = new wxMenu;
346 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
347 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
348 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
350 _history_position = _file_menu->GetMenuItems().GetCount();
352 _file_menu->AppendSeparator ();
353 _file_menu->Append (ID_file_close, _("&Close"));
354 _file_menu->AppendSeparator ();
357 _file_menu->Append (wxID_EXIT, _("&Exit"));
359 _file_menu->Append (wxID_EXIT, _("&Quit"));
363 _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
365 wxMenu* edit = new wxMenu;
366 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
369 _cpl_menu = new wxMenu;
371 wxMenu* view = new wxMenu;
372 optional<int> c = Config::instance()->decode_reduction();
373 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
374 view->AppendSeparator();
375 #ifndef DCPOMATIC_VARIANT_SWAROOP
376 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
377 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
380 view->AppendSeparator();
381 view->Append(ID_view_closed_captions, _("Closed captions..."));
382 view->AppendSeparator();
383 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
384 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
385 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
386 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
388 wxMenu* tools = new wxMenu;
389 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
390 tools->AppendSeparator ();
391 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
393 wxMenu* help = new wxMenu;
395 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
397 help->Append (wxID_ABOUT, _("About"));
399 help->Append (ID_help_report_a_problem, _("Report a problem..."));
401 m->Append (_file_menu, _("&File"));
403 m->Append (edit, _("&Edit"));
405 m->Append (view, _("&View"));
406 m->Append (tools, _("&Tools"));
407 m->Append (help, _("&Help"));
412 wxString d = wxStandardPaths::Get().GetDocumentsDir();
413 if (Config::instance()->last_player_load_directory()) {
414 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
417 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
422 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
423 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
430 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
432 Config::instance()->set_last_player_load_directory (dcp.parent_path());
440 wxDirDialog* c = new wxDirDialog (
442 _("Select DCP to open as OV"),
443 wxStandardPaths::Get().GetDocumentsDir(),
444 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
450 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
451 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
458 DCPOMATIC_ASSERT (_film);
459 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
460 DCPOMATIC_ASSERT (dcp);
461 dcp->add_ov (wx_to_std(c->GetPath()));
462 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
463 bool const ok = progress (_("Loading DCP"));
464 if (!ok || !report_errors_from_last_job()) {
467 setup_from_dcp (dcp);
471 _info->triggered_update ();
476 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
478 if (d->ShowModal() == wxID_OK) {
479 DCPOMATIC_ASSERT (_film);
480 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
481 DCPOMATIC_ASSERT (dcp);
483 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
484 dcp->examine (shared_ptr<Job>());
485 } catch (exception& e) {
486 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
493 _info->triggered_update ();
496 void file_history (wxCommandEvent& event)
498 vector<boost::filesystem::path> history = Config::instance()->player_history ();
499 int n = event.GetId() - ID_file_history;
500 if (n >= 0 && n < static_cast<int> (history.size ())) {
501 load_dcp (history[n]);
507 _viewer->set_film (shared_ptr<Film>());
509 _info->triggered_update ();
510 set_menu_sensitivity ();
518 void edit_preferences ()
520 if (!_config_dialog) {
521 _config_dialog = create_player_config_dialog ();
523 _config_dialog->Show (this);
526 void view_cpl (wxCommandEvent& ev)
528 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
529 DCPOMATIC_ASSERT (dcp);
530 DCPExaminer ex (dcp);
531 int id = ev.GetId() - ID_view_cpl;
532 DCPOMATIC_ASSERT (id >= 0);
533 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
534 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
535 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
541 dcp->set_cpl ((*i)->id());
542 dcp->examine (shared_ptr<Job>());
545 void view_full_screen ()
547 if (_mode == Config::PLAYER_MODE_FULL) {
548 _mode = Config::PLAYER_MODE_WINDOW;
550 _mode = Config::PLAYER_MODE_FULL;
556 void view_dual_screen ()
558 if (_mode == Config::PLAYER_MODE_DUAL) {
559 _mode = Config::PLAYER_MODE_WINDOW;
561 _mode = Config::PLAYER_MODE_DUAL;
569 if (_view_full_screen) {
570 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
572 if (_view_dual_screen) {
573 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
579 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
580 _controls->show_dcp_directory (_mode == Config::PLAYER_MODE_DUAL);
581 _info->Show (_mode != Config::PLAYER_MODE_FULL);
582 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
583 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
585 if (_mode == Config::PLAYER_MODE_DUAL) {
586 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
587 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
588 _dual_screen->ShowFullScreen (true);
589 _viewer->panel()->Reparent (_dual_screen);
590 _dual_screen->Show ();
591 if (wxDisplay::GetCount() > 1) {
592 switch (Config::instance()->image_display()) {
594 _dual_screen->Move (0, 0);
595 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
598 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
599 // (0, 0) doesn't seem to work for some strange reason
606 _viewer->panel()->Reparent (_overall_panel);
607 _dual_screen->Destroy ();
612 setup_main_sizer (_mode != Config::PLAYER_MODE_DUAL);
615 void view_closed_captions ()
617 _viewer->show_closed_captions ();
622 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
623 DCPOMATIC_ASSERT (dcp);
625 JobManager* jm = JobManager::instance ();
626 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
627 bool const ok = progress (_("Verifying DCP"));
632 DCPOMATIC_ASSERT (!jm->get().empty());
633 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
634 DCPOMATIC_ASSERT (last);
636 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
641 void tools_check_for_updates ()
643 UpdateChecker::instance()->run ();
644 _update_news_requested = true;
649 AboutDialog* d = new AboutDialog (this);
654 void help_report_a_problem ()
656 ReportProblemDialog* d = new ReportProblemDialog (this);
657 if (d->ShowModal () == wxID_OK) {
663 void update_checker_state_changed ()
665 UpdateChecker* uc = UpdateChecker::instance ();
667 bool const announce =
668 _update_news_requested ||
669 (uc->stable() && Config::instance()->check_for_updates()) ||
670 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
672 _update_news_requested = false;
678 if (uc->state() == UpdateChecker::YES) {
679 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
680 dialog->ShowModal ();
682 } else if (uc->state() == UpdateChecker::FAILED) {
683 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
685 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
688 _update_news_requested = false;
691 void config_changed ()
693 /* Instantly save any config changes when using the player GUI */
695 Config::instance()->write_config();
696 } catch (exception& e) {
700 _("Could not write to config file at %s. Your changes have not been saved."),
701 std_to_wx (Config::instance()->cinemas_file().string()).data()
706 for (int i = 0; i < _history_items; ++i) {
707 delete _file_menu->Remove (ID_file_history + i);
710 if (_history_separator) {
711 _file_menu->Remove (_history_separator);
713 delete _history_separator;
714 _history_separator = 0;
716 int pos = _history_position;
718 vector<boost::filesystem::path> history = Config::instance()->player_history ();
720 if (!history.empty ()) {
721 _history_separator = _file_menu->InsertSeparator (pos++);
724 for (size_t i = 0; i < history.size(); ++i) {
727 s = String::compose ("&%1 %2", i + 1, history[i].string());
729 s = history[i].string();
731 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
734 _history_items = history.size ();
737 void set_menu_sensitivity ()
739 _tools_verify->Enable (static_cast<bool>(_film));
740 _file_add_ov->Enable (static_cast<bool>(_film));
741 _file_add_kdm->Enable (static_cast<bool>(_film));
742 _view_cpl->Enable (static_cast<bool>(_film));
745 void start_stop_pressed ()
747 if (_viewer->playing()) {
756 _viewer->seek_by (-_viewer->one_video_frame(), true);
759 void forward_frame ()
761 _viewer->seek_by (_viewer->one_video_frame(), true);
766 /** @return false if the task was cancelled */
767 bool progress (wxString task)
769 JobManager* jm = JobManager::instance ();
771 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
775 while (jm->work_to_do() || signal_manager->ui_idle()) {
777 if (!progress->Pulse()) {
778 /* user pressed cancel */
779 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
787 progress->Destroy ();
791 bool report_errors_from_last_job ()
793 JobManager* jm = JobManager::instance ();
795 DCPOMATIC_ASSERT (!jm->get().empty());
797 shared_ptr<Job> last = jm->get().back();
798 if (last->finished_in_error()) {
799 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
806 void setup_from_dcp (shared_ptr<DCPContent> dcp)
808 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
813 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
815 _film->set_container(r);
820 wxFrame* _dual_screen;
821 bool _update_news_requested;
822 PlayerInformation* _info;
823 Config::PlayerMode _mode;
824 wxPreferencesEditor* _config_dialog;
825 wxPanel* _overall_panel;
827 wxMenuItem* _view_cpl;
830 int _history_position;
831 wxMenuItem* _history_separator;
832 shared_ptr<FilmViewer> _viewer;
834 boost::shared_ptr<Film> _film;
835 boost::signals2::scoped_connection _config_changed_connection;
836 wxMenuItem* _file_add_ov;
837 wxMenuItem* _file_add_kdm;
838 wxMenuItem* _tools_verify;
839 wxMenuItem* _view_full_screen;
840 wxMenuItem* _view_dual_screen;
843 static const wxCmdLineEntryDesc command_line_description[] = {
844 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
845 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
848 class PlayServer : public Server
851 explicit PlayServer (DOMFrame* frame)
852 : Server (PLAYER_PLAY_PORT)
856 void handle (shared_ptr<Socket> socket)
859 int const length = socket->read_uint32 ();
860 scoped_array<char> buffer (new char[length]);
861 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
862 string s (buffer.get());
863 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
864 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
875 * @brief The magic App class for wxWidgets.
877 class App : public wxApp
890 wxInitAllImageHandlers ();
892 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
893 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
895 wxSplashScreen* splash = maybe_show_splash ();
897 SetAppName (_("DCP-o-matic Player"));
899 if (!wxApp::OnInit()) {
903 #ifdef DCPOMATIC_LINUX
904 unsetenv ("UBUNTU_MENUPROXY");
908 ProcessSerialNumber serial;
909 GetCurrentProcess (&serial);
910 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
913 dcpomatic_setup_path_encoding ();
915 /* Enable i18n; this will create a Config object
916 to look for a force-configured language. This Config
917 object will be wrong, however, because dcpomatic_setup
918 hasn't yet been called and there aren't any filters etc.
921 dcpomatic_setup_i18n ();
923 /* Set things up, including filters etc.
924 which will now be internationalised correctly.
928 /* Force the configuration to be re-loaded correctly next
933 _frame = new DOMFrame ();
934 SetTopWindow (_frame);
941 signal_manager = new wxSignalManager (this);
943 PlayServer* server = new PlayServer (_frame);
944 new thread (boost::bind (&PlayServer::run, server));
946 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
948 _frame->load_dcp (_dcp_to_load);
949 } catch (exception& e) {
950 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
954 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
956 if (Config::instance()->check_for_updates ()) {
957 UpdateChecker::instance()->run ();
964 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
968 void OnInitCmdLine (wxCmdLineParser& parser)
970 parser.SetDesc (command_line_description);
971 parser.SetSwitchChars (wxT ("-"));
974 bool OnCmdLineParsed (wxCmdLineParser& parser)
976 if (parser.GetParamCount() > 0) {
977 _dcp_to_load = wx_to_std (parser.GetParam (0));
983 void report_exception ()
987 } catch (FileError& e) {
991 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
992 std_to_wx (e.what()),
993 std_to_wx (e.file().string().c_str ())
996 } catch (exception& e) {
1000 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1001 std_to_wx (e.what ())
1005 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1009 /* An unhandled exception has occurred inside the main event loop */
1010 bool OnExceptionInMainLoop ()
1012 report_exception ();
1013 /* This will terminate the program */
1017 void OnUnhandledException ()
1019 report_exception ();
1024 signal_manager->ui_idle ();
1027 void config_failed_to_load ()
1029 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1032 void config_warning (string m)
1034 message_dialog (_frame, std_to_wx (m));
1038 string _dcp_to_load;