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"
57 #include <dcp/raw_convert.h>
58 #include <dcp/exceptions.h>
60 #include <wx/stdpaths.h>
61 #include <wx/splash.h>
62 #include <wx/cmdline.h>
63 #include <wx/preferences.h>
64 #include <wx/progdlg.h>
65 #include <wx/display.h>
67 #include <ApplicationServices/ApplicationServices.h>
69 #include <boost/bind.hpp>
83 using boost::shared_ptr;
84 using boost::weak_ptr;
85 using boost::scoped_array;
86 using boost::optional;
87 using boost::dynamic_pointer_cast;
96 /* Allow spare IDs after _history for the recent files list */
99 /* Allow spare IDs for CPLs */
100 ID_view_full_screen = 200,
102 ID_view_closed_captions,
103 ID_view_scale_appropriate,
106 ID_view_scale_quarter,
107 ID_help_report_a_problem,
109 ID_tools_check_for_updates,
110 /* IDs for shortcuts (with no associated menu item) */
116 class DOMFrame : public wxFrame
120 : wxFrame (0, -1, _("DCP-o-matic Player"))
122 , _update_news_requested (false)
124 , _mode (Config::instance()->player_mode())
128 , _history_position (0)
129 , _history_separator (0)
130 , _view_full_screen (0)
131 , _view_dual_screen (0)
133 dcpomatic_log.reset (new NullLog());
135 #if defined(DCPOMATIC_WINDOWS)
136 maybe_open_console ();
137 cout << "DCP-o-matic Player is starting." << "\n";
140 wxMenuBar* bar = new wxMenuBar;
142 set_menu_sensitivity ();
145 #ifdef DCPOMATIC_WINDOWS
146 SetIcon (wxIcon (std_to_wx ("id")));
149 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
150 update_from_config ();
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
171 /* Use a panel as the only child of the Frame so that we avoid
172 the dark-grey background on Windows.
174 _overall_panel = new wxPanel (this, wxID_ANY);
176 _viewer.reset (new FilmViewer (_overall_panel));
177 #ifdef DCPOMATIC_VARIANT_SWAROOP
178 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
180 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
182 _controls = new StandardControls (_overall_panel, _viewer, false);
184 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
185 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
186 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
187 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, 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 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
296 FILE* f = fopen_boost(*log, "a");
298 /* XXX: this only logs the first piece of content; probably should be each piece? */
300 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
302 DCPExaminer ex (dcp);
303 shared_ptr<dcp::CPL> playing_cpl;
304 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
305 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
309 DCPOMATIC_ASSERT (playing_cpl);
313 "%s playback-started %s %s %s\n",
314 dcp::LocalTime().as_string().c_str(),
315 time.timecode(_film->video_frame_rate()).c_str(),
316 dcp->directories().front().string().c_str(),
317 playing_cpl->annotation_text().c_str()
321 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
325 "%s playback-started %s %s\n",
326 dcp::LocalTime().as_string().c_str(),
327 time.timecode(_film->video_frame_rate()).c_str(),
328 ffmpeg->path(0).string().c_str()
335 void playback_seeked (DCPTime time)
337 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
342 FILE* f = fopen_boost(*log, "a");
343 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
347 void playback_stopped (DCPTime time)
349 #ifdef DCPOMATIC_VARIANT_SWAROOP
351 boost::filesystem::remove (Config::path("position"));
357 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
362 FILE* f = fopen_boost(*log, "a");
363 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
367 void set_decode_reduction (optional<int> reduction)
369 _viewer->set_dcp_decode_reduction (reduction);
370 _info->triggered_update ();
371 Config::instance()->set_decode_reduction (reduction);
374 void load_dcp (boost::filesystem::path dir)
376 DCPOMATIC_ASSERT (_film);
380 shared_ptr<DCPContent> dcp (new DCPContent(dir));
381 _film->examine_and_add_content (dcp, true);
382 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
383 if (!ok || !report_errors_from_last_job(this)) {
386 #ifndef DCPOMATIC_VARIANT_SWAROOP
387 Config::instance()->add_to_player_history (dir);
389 } catch (dcp::DCPReadError& e) {
390 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
394 void reset_film_weak (weak_ptr<Film> weak_film)
396 shared_ptr<Film> film = weak_film.lock ();
402 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
405 _viewer->set_film (_film);
406 _controls->set_film (_film);
407 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
408 _info->triggered_update ();
411 void film_changed (ChangeType type, Film::Property property)
413 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
417 if (_viewer->playing ()) {
421 /* Start off as Flat */
422 _film->set_container (Ratio::from_id("185"));
424 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
425 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
427 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
432 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
433 if (r->id() == "239") {
434 /* Any scope content means we use scope */
435 _film->set_container(r);
439 /* Any 3D content means we use 3D mode */
440 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
441 _film->set_three_d (true);
445 _viewer->seek (DCPTime(), true);
446 _info->triggered_update ();
448 set_menu_sensitivity ();
450 wxMenuItemList old = _cpl_menu->GetMenuItems();
451 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
452 _cpl_menu->Remove (*i);
455 if (_film->content().size() == 1) {
456 /* Offer a CPL menu */
457 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
459 DCPExaminer ex (first);
460 int id = ID_view_cpl;
461 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
462 wxMenuItem* j = _cpl_menu->AppendRadioItem(
464 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
466 j->Check(!first->cpl() || i->id() == *first->cpl());
475 void setup_menu (wxMenuBar* m)
477 _file_menu = new wxMenu;
478 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
479 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
480 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
482 _history_position = _file_menu->GetMenuItems().GetCount();
484 _file_menu->AppendSeparator ();
485 _file_menu->Append (ID_file_close, _("&Close"));
486 _file_menu->AppendSeparator ();
489 _file_menu->Append (wxID_EXIT, _("&Exit"));
491 _file_menu->Append (wxID_EXIT, _("&Quit"));
495 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
497 wxMenu* edit = new wxMenu;
498 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
501 prefs->Enable (Config::instance()->have_write_permission());
503 _cpl_menu = new wxMenu;
505 wxMenu* view = new wxMenu;
506 optional<int> c = Config::instance()->decode_reduction();
507 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
508 view->AppendSeparator();
509 #ifndef DCPOMATIC_VARIANT_SWAROOP
510 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
511 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
514 view->AppendSeparator();
515 view->Append(ID_view_closed_captions, _("Closed captions..."));
516 view->AppendSeparator();
517 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
518 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
519 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
520 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
522 wxMenu* tools = new wxMenu;
523 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
524 tools->AppendSeparator ();
525 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
527 wxMenu* help = new wxMenu;
529 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
531 help->Append (wxID_ABOUT, _("About"));
533 help->Append (ID_help_report_a_problem, _("Report a problem..."));
535 m->Append (_file_menu, _("&File"));
537 m->Append (edit, _("&Edit"));
539 m->Append (view, _("&View"));
540 m->Append (tools, _("&Tools"));
541 m->Append (help, _("&Help"));
546 wxString d = wxStandardPaths::Get().GetDocumentsDir();
547 if (Config::instance()->last_player_load_directory()) {
548 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
551 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
556 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
557 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
564 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
566 Config::instance()->set_last_player_load_directory (dcp.parent_path());
574 wxDirDialog* c = new wxDirDialog (
576 _("Select DCP to open as OV"),
577 wxStandardPaths::Get().GetDocumentsDir(),
578 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
584 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
585 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
592 DCPOMATIC_ASSERT (_film);
593 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
594 DCPOMATIC_ASSERT (dcp);
595 dcp->add_ov (wx_to_std(c->GetPath()));
596 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
597 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
598 if (!ok || !report_errors_from_last_job(this)) {
601 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
605 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
607 _film->set_container(r);
613 _info->triggered_update ();
618 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
620 if (d->ShowModal() == wxID_OK) {
621 DCPOMATIC_ASSERT (_film);
622 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
623 DCPOMATIC_ASSERT (dcp);
625 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
626 dcp->examine (_film, shared_ptr<Job>());
627 } catch (exception& e) {
628 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
635 _info->triggered_update ();
638 void file_history (wxCommandEvent& event)
640 vector<boost::filesystem::path> history = Config::instance()->player_history ();
641 int n = event.GetId() - ID_file_history;
642 if (n >= 0 && n < static_cast<int> (history.size ())) {
643 load_dcp (history[n]);
650 _info->triggered_update ();
651 set_menu_sensitivity ();
659 void edit_preferences ()
661 if (!Config::instance()->have_write_permission()) {
665 if (!_config_dialog) {
666 _config_dialog = create_player_config_dialog ();
668 _config_dialog->Show (this);
671 void view_cpl (wxCommandEvent& ev)
673 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
674 DCPOMATIC_ASSERT (dcp);
675 DCPExaminer ex (dcp);
676 int id = ev.GetId() - ID_view_cpl;
677 DCPOMATIC_ASSERT (id >= 0);
678 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
679 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
680 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
686 dcp->set_cpl ((*i)->id());
687 dcp->examine (_film, shared_ptr<Job>());
690 void view_full_screen ()
692 if (_mode == Config::PLAYER_MODE_FULL) {
693 _mode = Config::PLAYER_MODE_WINDOW;
695 _mode = Config::PLAYER_MODE_FULL;
701 void view_dual_screen ()
703 if (_mode == Config::PLAYER_MODE_DUAL) {
704 _mode = Config::PLAYER_MODE_WINDOW;
706 _mode = Config::PLAYER_MODE_DUAL;
714 if (_view_full_screen) {
715 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
717 if (_view_dual_screen) {
718 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
724 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
725 _info->Show (_mode != Config::PLAYER_MODE_FULL);
726 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
727 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
728 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
730 if (_mode == Config::PLAYER_MODE_DUAL) {
731 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
732 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
733 _dual_screen->ShowFullScreen (true);
734 _viewer->panel()->Reparent (_dual_screen);
735 _dual_screen->Show ();
736 if (wxDisplay::GetCount() > 1) {
737 switch (Config::instance()->image_display()) {
739 _dual_screen->Move (0, 0);
740 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
743 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
744 // (0, 0) doesn't seem to work for some strange reason
751 _viewer->panel()->Reparent (_overall_panel);
752 _dual_screen->Destroy ();
757 setup_main_sizer (_mode);
760 void view_closed_captions ()
762 _viewer->show_closed_captions ();
767 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
768 DCPOMATIC_ASSERT (dcp);
770 JobManager* jm = JobManager::instance ();
771 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
772 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
777 DCPOMATIC_ASSERT (!jm->get().empty());
778 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
779 DCPOMATIC_ASSERT (last);
781 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
786 void tools_check_for_updates ()
788 UpdateChecker::instance()->run ();
789 _update_news_requested = true;
794 AboutDialog* d = new AboutDialog (this);
799 void help_report_a_problem ()
801 ReportProblemDialog* d = new ReportProblemDialog (this);
802 if (d->ShowModal () == wxID_OK) {
808 void update_checker_state_changed ()
810 UpdateChecker* uc = UpdateChecker::instance ();
812 bool const announce =
813 _update_news_requested ||
814 (uc->stable() && Config::instance()->check_for_updates()) ||
815 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
817 _update_news_requested = false;
823 if (uc->state() == UpdateChecker::YES) {
824 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
825 dialog->ShowModal ();
827 } else if (uc->state() == UpdateChecker::FAILED) {
828 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
830 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
833 _update_news_requested = false;
836 void config_changed (Config::Property prop)
838 /* Instantly save any config changes when using the player GUI */
840 Config::instance()->write_config();
841 } catch (FileError& e) {
842 if (prop != Config::HISTORY) {
846 _("Could not write to config file at %s. Your changes have not been saved."),
847 std_to_wx(e.file().string())
851 } catch (exception& e) {
854 _("Could not write to config file. Your changes have not been saved.")
858 update_from_config ();
861 void update_from_config ()
863 for (int i = 0; i < _history_items; ++i) {
864 delete _file_menu->Remove (ID_file_history + i);
867 if (_history_separator) {
868 _file_menu->Remove (_history_separator);
870 delete _history_separator;
871 _history_separator = 0;
873 int pos = _history_position;
875 vector<boost::filesystem::path> history = Config::instance()->player_history ();
877 if (!history.empty ()) {
878 _history_separator = _file_menu->InsertSeparator (pos++);
881 for (size_t i = 0; i < history.size(); ++i) {
884 s = String::compose ("&%1 %2", i + 1, history[i].string());
886 s = history[i].string();
888 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
891 _history_items = history.size ();
894 void set_menu_sensitivity ()
896 _tools_verify->Enable (static_cast<bool>(_film));
897 _file_add_ov->Enable (static_cast<bool>(_film));
898 _file_add_kdm->Enable (static_cast<bool>(_film));
899 _view_cpl->Enable (static_cast<bool>(_film));
902 void start_stop_pressed ()
904 if (_viewer->playing()) {
913 _viewer->seek_by (-_viewer->one_video_frame(), true);
916 void forward_frame ()
918 _viewer->seek_by (_viewer->one_video_frame(), true);
923 wxFrame* _dual_screen;
924 bool _update_news_requested;
925 PlayerInformation* _info;
926 Config::PlayerMode _mode;
927 wxPreferencesEditor* _config_dialog;
928 wxPanel* _overall_panel;
930 wxMenuItem* _view_cpl;
933 int _history_position;
934 wxMenuItem* _history_separator;
935 shared_ptr<FilmViewer> _viewer;
937 boost::shared_ptr<Film> _film;
938 boost::signals2::scoped_connection _config_changed_connection;
939 wxMenuItem* _file_add_ov;
940 wxMenuItem* _file_add_kdm;
941 wxMenuItem* _tools_verify;
942 wxMenuItem* _view_full_screen;
943 wxMenuItem* _view_dual_screen;
946 static const wxCmdLineEntryDesc command_line_description[] = {
947 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
948 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
949 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
952 class PlayServer : public Server
955 explicit PlayServer (DOMFrame* frame)
956 : Server (PLAYER_PLAY_PORT)
960 void handle (shared_ptr<Socket> socket)
963 int const length = socket->read_uint32 ();
964 scoped_array<char> buffer (new char[length]);
965 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
966 string s (buffer.get());
967 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
968 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
979 * @brief The magic App class for wxWidgets.
981 class App : public wxApp
993 wxSplashScreen* splash = 0;
995 wxInitAllImageHandlers ();
997 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
998 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1000 splash = maybe_show_splash ();
1002 SetAppName (_("DCP-o-matic Player"));
1004 if (!wxApp::OnInit()) {
1008 #ifdef DCPOMATIC_LINUX
1009 unsetenv ("UBUNTU_MENUPROXY");
1013 ProcessSerialNumber serial;
1014 GetCurrentProcess (&serial);
1015 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1018 dcpomatic_setup_path_encoding ();
1020 /* Enable i18n; this will create a Config object
1021 to look for a force-configured language. This Config
1022 object will be wrong, however, because dcpomatic_setup
1023 hasn't yet been called and there aren't any filters etc.
1026 dcpomatic_setup_i18n ();
1028 /* Set things up, including filters etc.
1029 which will now be internationalised correctly.
1033 /* Force the configuration to be re-loaded correctly next
1038 signal_manager = new wxSignalManager (this);
1040 _frame = new DOMFrame ();
1041 SetTopWindow (_frame);
1042 _frame->Maximize ();
1049 PlayServer* server = new PlayServer (_frame);
1050 new thread (boost::bind (&PlayServer::run, server));
1052 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1054 _frame->load_dcp (_dcp_to_load);
1055 } catch (exception& e) {
1056 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1060 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1062 if (Config::instance()->check_for_updates ()) {
1063 UpdateChecker::instance()->run ();
1066 catch (exception& e)
1071 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1077 void OnInitCmdLine (wxCmdLineParser& parser)
1079 parser.SetDesc (command_line_description);
1080 parser.SetSwitchChars (wxT ("-"));
1083 bool OnCmdLineParsed (wxCmdLineParser& parser)
1085 if (parser.GetParamCount() > 0) {
1086 _dcp_to_load = wx_to_std (parser.GetParam (0));
1090 if (parser.Found("c", &config)) {
1091 Config::override_path = wx_to_std (config);
1097 void report_exception ()
1101 } catch (FileError& e) {
1105 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1106 std_to_wx (e.what()),
1107 std_to_wx (e.file().string().c_str ())
1110 } catch (exception& e) {
1114 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1115 std_to_wx (e.what ())
1119 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1123 /* An unhandled exception has occurred inside the main event loop */
1124 bool OnExceptionInMainLoop ()
1126 report_exception ();
1127 /* This will terminate the program */
1131 void OnUnhandledException ()
1133 report_exception ();
1138 signal_manager->ui_idle ();
1141 void config_failed_to_load ()
1143 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1146 void config_warning (string m)
1148 message_dialog (_frame, std_to_wx (m));
1152 string _dcp_to_load;