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/standard_controls.h"
31 #include "wx/swaroop_controls.h"
32 #include "lib/cross.h"
33 #include "lib/config.h"
35 #include "lib/internet.h"
36 #include "lib/update_checker.h"
37 #include "lib/compose.hpp"
38 #include "lib/dcp_content.h"
39 #include "lib/job_manager.h"
42 #include "lib/null_log.h"
43 #include "lib/video_content.h"
44 #include "lib/text_content.h"
45 #include "lib/ratio.h"
46 #include "lib/verify_dcp_job.h"
47 #include "lib/dcp_examiner.h"
48 #include "lib/examine_content_job.h"
49 #include "lib/server.h"
50 #include "lib/dcpomatic_socket.h"
51 #include "lib/scoped_temporary.h"
52 #include "lib/monitor_checker.h"
53 #include "lib/lock_file_checker.h"
54 #include "lib/ffmpeg_content.h"
55 #include "lib/dcpomatic_log.h"
56 #include "lib/file_log.h"
58 #include <dcp/raw_convert.h>
59 #include <dcp/exceptions.h>
61 #include <wx/stdpaths.h>
62 #include <wx/splash.h>
63 #include <wx/cmdline.h>
64 #include <wx/preferences.h>
65 #include <wx/progdlg.h>
66 #include <wx/display.h>
68 #include <ApplicationServices/ApplicationServices.h>
70 #include <boost/bind.hpp>
84 using boost::shared_ptr;
85 using boost::weak_ptr;
86 using boost::scoped_array;
87 using boost::optional;
88 using boost::dynamic_pointer_cast;
97 /* Allow spare IDs after _history for the recent files list */
100 /* Allow spare IDs for CPLs */
101 ID_view_full_screen = 200,
103 ID_view_closed_captions,
104 ID_view_scale_appropriate,
107 ID_view_scale_quarter,
108 ID_help_report_a_problem,
110 ID_tools_check_for_updates,
111 /* IDs for shortcuts (with no associated menu item) */
117 class DOMFrame : public wxFrame
121 : wxFrame (0, -1, _("DCP-o-matic Player"))
123 , _update_news_requested (false)
125 , _mode (Config::instance()->player_mode())
129 , _history_position (0)
130 , _history_separator (0)
131 , _view_full_screen (0)
132 , _view_dual_screen (0)
134 dcpomatic_log.reset (new NullLog());
136 #if defined(DCPOMATIC_WINDOWS)
137 maybe_open_console ();
138 cout << "DCP-o-matic Player is starting." << "\n";
141 wxMenuBar* bar = new wxMenuBar;
143 set_menu_sensitivity ();
146 #ifdef DCPOMATIC_WINDOWS
147 SetIcon (wxIcon (std_to_wx ("id")));
150 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
151 update_from_config (Config::PLAYER_DEBUG_LOG);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
170 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
172 /* Use a panel as the only child of the Frame so that we avoid
173 the dark-grey background on Windows.
175 _overall_panel = new wxPanel (this, wxID_ANY);
177 _viewer.reset (new FilmViewer (_overall_panel));
178 #ifdef DCPOMATIC_VARIANT_SWAROOP
179 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
181 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
183 _controls = new StandardControls (_overall_panel, _viewer, false);
185 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
186 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
187 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
188 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
189 _info = new PlayerInformation (_overall_panel, _viewer);
190 setup_main_sizer (Config::instance()->player_mode());
192 int accelerators = 4;
194 int accelerators = 3;
197 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
198 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
199 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
200 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
202 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
204 wxAcceleratorTable accel_table (accelerators, accel);
205 SetAcceleratorTable (accel_table);
208 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
209 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
210 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
214 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
215 #ifdef DCPOMATIC_VARIANT_SWAROOP
216 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
217 MonitorChecker::instance()->run ();
218 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
219 LockFileChecker::instance()->run ();
223 #ifdef DCPOMATIC_VARIANT_SWAROOP
224 sc->check_restart ();
228 #ifdef DCPOMATIC_VARIANT_SWAROOP
229 void monitor_checker_state_changed ()
231 if (!MonitorChecker::instance()->ok()) {
233 error_dialog (this, _("The required display devices are not connected correctly."));
237 void lock_checker_state_changed ()
239 if (!LockFileChecker::instance()->ok()) {
241 error_dialog (this, _("The lock file is not present."));
246 void setup_main_sizer (Config::PlayerMode mode)
248 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
249 if (mode != Config::PLAYER_MODE_DUAL) {
250 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
252 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
253 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
254 _overall_panel->SetSizer (main_sizer);
255 _overall_panel->Layout ();
258 bool playback_permitted ()
260 #ifdef DCPOMATIC_VARIANT_SWAROOP
261 if (!MonitorChecker::instance()->ok()) {
262 error_dialog (this, _("The required display devices are not connected correctly."));
265 if (!LockFileChecker::instance()->ok()) {
266 error_dialog (this, _("The lock file is not present."));
270 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
275 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
276 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
277 if (d && !d->kdm_timing_window_valid()) {
283 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
289 void playback_started (DCPTime time)
291 /* XXX: this only logs the first piece of content; probably should be each piece? */
292 if (_film->content().empty()) {
296 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
298 DCPExaminer ex (dcp);
299 shared_ptr<dcp::CPL> playing_cpl;
300 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
301 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
305 DCPOMATIC_ASSERT (playing_cpl);
309 "playback-started %s %s %s",
310 time.timecode(_film->video_frame_rate()).c_str(),
311 dcp->directories().front().string().c_str(),
312 playing_cpl->annotation_text().c_str()
317 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
321 "playback-started %s %s",
322 time.timecode(_film->video_frame_rate()).c_str(),
323 ffmpeg->path(0).string().c_str()
329 void playback_stopped (DCPTime time)
331 #ifdef DCPOMATIC_VARIANT_SWAROOP
333 boost::filesystem::remove (Config::path("position"));
339 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
342 void set_decode_reduction (optional<int> reduction)
344 _viewer->set_dcp_decode_reduction (reduction);
345 _info->triggered_update ();
346 Config::instance()->set_decode_reduction (reduction);
349 void load_dcp (boost::filesystem::path dir)
351 DCPOMATIC_ASSERT (_film);
355 shared_ptr<DCPContent> dcp (new DCPContent(dir));
356 _film->examine_and_add_content (dcp, true);
357 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
358 if (!ok || !report_errors_from_last_job(this)) {
361 #ifndef DCPOMATIC_VARIANT_SWAROOP
362 Config::instance()->add_to_player_history (dir);
364 } catch (dcp::DCPReadError& e) {
365 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
369 void reset_film_weak (weak_ptr<Film> weak_film)
371 shared_ptr<Film> film = weak_film.lock ();
377 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
380 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
381 _viewer->set_film (_film);
382 _controls->set_film (_film);
383 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
384 _info->triggered_update ();
387 void film_changed (ChangeType type, Film::Property property)
389 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
393 if (_viewer->playing ()) {
397 /* Start off as Flat */
398 _film->set_container (Ratio::from_id("185"));
400 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
401 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
403 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
408 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
409 if (r->id() == "239") {
410 /* Any scope content means we use scope */
411 _film->set_container(r);
415 /* Any 3D content means we use 3D mode */
416 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
417 _film->set_three_d (true);
421 _viewer->seek (DCPTime(), true);
422 _info->triggered_update ();
424 set_menu_sensitivity ();
426 wxMenuItemList old = _cpl_menu->GetMenuItems();
427 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
428 _cpl_menu->Remove (*i);
431 if (_film->content().size() == 1) {
432 /* Offer a CPL menu */
433 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
435 DCPExaminer ex (first);
436 int id = ID_view_cpl;
437 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
438 wxMenuItem* j = _cpl_menu->AppendRadioItem(
440 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
442 j->Check(!first->cpl() || i->id() == *first->cpl());
451 void setup_menu (wxMenuBar* m)
453 _file_menu = new wxMenu;
454 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
455 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
456 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
458 _history_position = _file_menu->GetMenuItems().GetCount();
460 _file_menu->AppendSeparator ();
461 _file_menu->Append (ID_file_close, _("&Close"));
462 _file_menu->AppendSeparator ();
465 _file_menu->Append (wxID_EXIT, _("&Exit"));
467 _file_menu->Append (wxID_EXIT, _("&Quit"));
471 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
473 wxMenu* edit = new wxMenu;
474 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
477 prefs->Enable (Config::instance()->have_write_permission());
479 _cpl_menu = new wxMenu;
481 wxMenu* view = new wxMenu;
482 optional<int> c = Config::instance()->decode_reduction();
483 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
484 view->AppendSeparator();
485 #ifndef DCPOMATIC_VARIANT_SWAROOP
486 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
487 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
490 view->AppendSeparator();
491 view->Append(ID_view_closed_captions, _("Closed captions..."));
492 view->AppendSeparator();
493 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
494 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
495 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
496 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
498 wxMenu* tools = new wxMenu;
499 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
500 tools->AppendSeparator ();
501 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
503 wxMenu* help = new wxMenu;
505 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
507 help->Append (wxID_ABOUT, _("About"));
509 help->Append (ID_help_report_a_problem, _("Report a problem..."));
511 m->Append (_file_menu, _("&File"));
513 m->Append (edit, _("&Edit"));
515 m->Append (view, _("&View"));
516 m->Append (tools, _("&Tools"));
517 m->Append (help, _("&Help"));
522 wxString d = wxStandardPaths::Get().GetDocumentsDir();
523 if (Config::instance()->last_player_load_directory()) {
524 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
527 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
532 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
533 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
540 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
542 Config::instance()->set_last_player_load_directory (dcp.parent_path());
550 wxDirDialog* c = new wxDirDialog (
552 _("Select DCP to open as OV"),
553 wxStandardPaths::Get().GetDocumentsDir(),
554 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
560 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
561 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
568 DCPOMATIC_ASSERT (_film);
569 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
570 DCPOMATIC_ASSERT (dcp);
571 dcp->add_ov (wx_to_std(c->GetPath()));
572 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
573 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
574 if (!ok || !report_errors_from_last_job(this)) {
577 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
581 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
583 _film->set_container(r);
589 _info->triggered_update ();
594 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
596 if (d->ShowModal() == wxID_OK) {
597 DCPOMATIC_ASSERT (_film);
598 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
599 DCPOMATIC_ASSERT (dcp);
601 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
602 dcp->examine (_film, shared_ptr<Job>());
603 } catch (exception& e) {
604 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
611 _info->triggered_update ();
614 void file_history (wxCommandEvent& event)
616 vector<boost::filesystem::path> history = Config::instance()->player_history ();
617 int n = event.GetId() - ID_file_history;
618 if (n >= 0 && n < static_cast<int> (history.size ())) {
620 load_dcp (history[n]);
621 } catch (exception& e) {
622 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
630 _info->triggered_update ();
631 set_menu_sensitivity ();
639 void edit_preferences ()
641 if (!Config::instance()->have_write_permission()) {
645 if (!_config_dialog) {
646 _config_dialog = create_player_config_dialog ();
648 _config_dialog->Show (this);
651 void view_cpl (wxCommandEvent& ev)
653 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
654 DCPOMATIC_ASSERT (dcp);
655 DCPExaminer ex (dcp);
656 int id = ev.GetId() - ID_view_cpl;
657 DCPOMATIC_ASSERT (id >= 0);
658 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
659 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
660 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
666 dcp->set_cpl ((*i)->id());
667 dcp->examine (_film, shared_ptr<Job>());
670 void view_full_screen ()
672 if (_mode == Config::PLAYER_MODE_FULL) {
673 _mode = Config::PLAYER_MODE_WINDOW;
675 _mode = Config::PLAYER_MODE_FULL;
681 void view_dual_screen ()
683 if (_mode == Config::PLAYER_MODE_DUAL) {
684 _mode = Config::PLAYER_MODE_WINDOW;
686 _mode = Config::PLAYER_MODE_DUAL;
694 if (_view_full_screen) {
695 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
697 if (_view_dual_screen) {
698 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
704 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
705 _info->Show (_mode != Config::PLAYER_MODE_FULL);
706 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
707 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
708 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
710 if (_mode == Config::PLAYER_MODE_DUAL) {
711 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
712 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
713 _dual_screen->ShowFullScreen (true);
714 _viewer->panel()->Reparent (_dual_screen);
715 _dual_screen->Show ();
716 if (wxDisplay::GetCount() > 1) {
717 switch (Config::instance()->image_display()) {
719 _dual_screen->Move (0, 0);
720 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
723 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
724 // (0, 0) doesn't seem to work for some strange reason
731 _viewer->panel()->Reparent (_overall_panel);
732 _dual_screen->Destroy ();
737 setup_main_sizer (_mode);
740 void view_closed_captions ()
742 _viewer->show_closed_captions ();
747 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
748 DCPOMATIC_ASSERT (dcp);
750 JobManager* jm = JobManager::instance ();
751 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
752 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
757 DCPOMATIC_ASSERT (!jm->get().empty());
758 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
759 DCPOMATIC_ASSERT (last);
761 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
766 void tools_check_for_updates ()
768 UpdateChecker::instance()->run ();
769 _update_news_requested = true;
774 AboutDialog* d = new AboutDialog (this);
779 void help_report_a_problem ()
781 ReportProblemDialog* d = new ReportProblemDialog (this);
782 if (d->ShowModal () == wxID_OK) {
788 void update_checker_state_changed ()
790 UpdateChecker* uc = UpdateChecker::instance ();
792 bool const announce =
793 _update_news_requested ||
794 (uc->stable() && Config::instance()->check_for_updates()) ||
795 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
797 _update_news_requested = false;
803 if (uc->state() == UpdateChecker::YES) {
804 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
805 dialog->ShowModal ();
807 } else if (uc->state() == UpdateChecker::FAILED) {
808 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
810 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
813 _update_news_requested = false;
816 void config_changed (Config::Property prop)
818 /* Instantly save any config changes when using the player GUI */
820 Config::instance()->write_config();
821 } catch (FileError& e) {
822 if (prop != Config::HISTORY) {
826 _("Could not write to config file at %s. Your changes have not been saved."),
827 std_to_wx(e.file().string())
831 } catch (exception& e) {
834 _("Could not write to config file. Your changes have not been saved.")
838 update_from_config (prop);
841 void update_from_config (Config::Property prop)
843 for (int i = 0; i < _history_items; ++i) {
844 delete _file_menu->Remove (ID_file_history + i);
847 if (_history_separator) {
848 _file_menu->Remove (_history_separator);
850 delete _history_separator;
851 _history_separator = 0;
853 int pos = _history_position;
855 /* Clear out non-existant history items before we re-build the menu */
856 Config::instance()->clean_player_history ();
857 vector<boost::filesystem::path> history = Config::instance()->player_history ();
859 if (!history.empty ()) {
860 _history_separator = _file_menu->InsertSeparator (pos++);
863 for (size_t i = 0; i < history.size(); ++i) {
866 s = String::compose ("&%1 %2", i + 1, history[i].string());
868 s = history[i].string();
870 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
873 _history_items = history.size ();
875 if (prop == Config::PLAYER_DEBUG_LOG) {
876 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
878 dcpomatic_log.reset (new FileLog(*p));
880 dcpomatic_log.reset (new NullLog());
882 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
886 void set_menu_sensitivity ()
888 _tools_verify->Enable (static_cast<bool>(_film));
889 _file_add_ov->Enable (static_cast<bool>(_film));
890 _file_add_kdm->Enable (static_cast<bool>(_film));
891 _view_cpl->Enable (static_cast<bool>(_film));
894 void start_stop_pressed ()
896 if (_viewer->playing()) {
905 _viewer->seek_by (-_viewer->one_video_frame(), true);
908 void forward_frame ()
910 _viewer->seek_by (_viewer->one_video_frame(), true);
915 wxFrame* _dual_screen;
916 bool _update_news_requested;
917 PlayerInformation* _info;
918 Config::PlayerMode _mode;
919 wxPreferencesEditor* _config_dialog;
920 wxPanel* _overall_panel;
922 wxMenuItem* _view_cpl;
925 int _history_position;
926 wxMenuItem* _history_separator;
927 shared_ptr<FilmViewer> _viewer;
929 boost::shared_ptr<Film> _film;
930 boost::signals2::scoped_connection _config_changed_connection;
931 wxMenuItem* _file_add_ov;
932 wxMenuItem* _file_add_kdm;
933 wxMenuItem* _tools_verify;
934 wxMenuItem* _view_full_screen;
935 wxMenuItem* _view_dual_screen;
938 static const wxCmdLineEntryDesc command_line_description[] = {
939 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
940 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
941 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
944 class PlayServer : public Server
947 explicit PlayServer (DOMFrame* frame)
948 : Server (PLAYER_PLAY_PORT)
952 void handle (shared_ptr<Socket> socket)
955 int const length = socket->read_uint32 ();
956 scoped_array<char> buffer (new char[length]);
957 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
958 string s (buffer.get());
959 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
960 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
971 * @brief The magic App class for wxWidgets.
973 class App : public wxApp
985 wxSplashScreen* splash = 0;
987 wxInitAllImageHandlers ();
989 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
990 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
992 splash = maybe_show_splash ();
994 SetAppName (_("DCP-o-matic Player"));
996 if (!wxApp::OnInit()) {
1000 #ifdef DCPOMATIC_LINUX
1001 unsetenv ("UBUNTU_MENUPROXY");
1005 ProcessSerialNumber serial;
1006 GetCurrentProcess (&serial);
1007 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1010 dcpomatic_setup_path_encoding ();
1012 /* Enable i18n; this will create a Config object
1013 to look for a force-configured language. This Config
1014 object will be wrong, however, because dcpomatic_setup
1015 hasn't yet been called and there aren't any filters etc.
1018 dcpomatic_setup_i18n ();
1020 /* Set things up, including filters etc.
1021 which will now be internationalised correctly.
1025 /* Force the configuration to be re-loaded correctly next
1030 signal_manager = new wxSignalManager (this);
1032 _frame = new DOMFrame ();
1033 SetTopWindow (_frame);
1034 _frame->Maximize ();
1041 PlayServer* server = new PlayServer (_frame);
1042 new thread (boost::bind (&PlayServer::run, server));
1044 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1046 _frame->load_dcp (_dcp_to_load);
1047 } catch (exception& e) {
1048 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1052 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1054 if (Config::instance()->check_for_updates ()) {
1055 UpdateChecker::instance()->run ();
1058 catch (exception& e)
1063 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1069 void OnInitCmdLine (wxCmdLineParser& parser)
1071 parser.SetDesc (command_line_description);
1072 parser.SetSwitchChars (wxT ("-"));
1075 bool OnCmdLineParsed (wxCmdLineParser& parser)
1077 if (parser.GetParamCount() > 0) {
1078 _dcp_to_load = wx_to_std (parser.GetParam (0));
1082 if (parser.Found("c", &config)) {
1083 Config::override_path = wx_to_std (config);
1089 void report_exception ()
1093 } catch (FileError& e) {
1097 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1098 std_to_wx (e.what()),
1099 std_to_wx (e.file().string().c_str ())
1102 } catch (exception& e) {
1106 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1107 std_to_wx (e.what ())
1111 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1115 /* An unhandled exception has occurred inside the main event loop */
1116 bool OnExceptionInMainLoop ()
1118 report_exception ();
1119 /* This will terminate the program */
1123 void OnUnhandledException ()
1125 report_exception ();
1130 signal_manager->ui_idle ();
1133 void config_failed_to_load ()
1135 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1138 void config_warning (string m)
1140 message_dialog (_frame, std_to_wx (m));
1144 string _dcp_to_load;