2 Copyright (C) 2017-2019 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 "wx/timer_display.h"
33 #include "wx/system_information_dialog.h"
34 #include "lib/cross.h"
35 #include "lib/config.h"
37 #include "lib/internet.h"
38 #include "lib/update_checker.h"
39 #include "lib/compose.hpp"
40 #include "lib/dcp_content.h"
41 #include "lib/job_manager.h"
44 #include "lib/null_log.h"
45 #include "lib/video_content.h"
46 #include "lib/text_content.h"
47 #include "lib/ratio.h"
48 #include "lib/verify_dcp_job.h"
49 #include "lib/dcp_examiner.h"
50 #include "lib/examine_content_job.h"
51 #include "lib/server.h"
52 #include "lib/dcpomatic_socket.h"
53 #include "lib/scoped_temporary.h"
54 #include "lib/monitor_checker.h"
55 #include "lib/lock_file_checker.h"
56 #include "lib/ffmpeg_content.h"
57 #include "lib/dcpomatic_log.h"
58 #include "lib/file_log.h"
60 #include <dcp/raw_convert.h>
61 #include <dcp/exceptions.h>
63 #include <wx/stdpaths.h>
64 #include <wx/splash.h>
65 #include <wx/cmdline.h>
66 #include <wx/preferences.h>
67 #include <wx/progdlg.h>
68 #include <wx/display.h>
70 #include <ApplicationServices/ApplicationServices.h>
72 #include <boost/bind.hpp>
86 using boost::shared_ptr;
87 using boost::weak_ptr;
88 using boost::scoped_array;
89 using boost::optional;
90 using boost::dynamic_pointer_cast;
93 using namespace dcpomatic;
100 /* Allow spare IDs after _history for the recent files list */
103 /* Allow spare IDs for CPLs */
104 ID_view_full_screen = 200,
106 ID_view_closed_captions,
107 ID_view_scale_appropriate,
110 ID_view_scale_quarter,
111 ID_help_report_a_problem,
113 ID_tools_check_for_updates,
115 ID_tools_system_information,
116 /* IDs for shortcuts (with no associated menu item) */
122 class DOMFrame : public wxFrame
126 : wxFrame (0, -1, _("DCP-o-matic Player"))
128 , _update_news_requested (false)
130 , _mode (Config::instance()->player_mode())
134 , _history_position (0)
135 , _history_separator (0)
136 , _system_information_dialog (0)
137 , _view_full_screen (0)
138 , _view_dual_screen (0)
140 dcpomatic_log.reset (new NullLog());
142 #if defined(DCPOMATIC_WINDOWS)
143 maybe_open_console ();
144 cout << "DCP-o-matic Player is starting." << "\n";
147 wxMenuBar* bar = new wxMenuBar;
149 set_menu_sensitivity ();
152 #ifdef DCPOMATIC_WINDOWS
153 SetIcon (wxIcon (std_to_wx ("id")));
156 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
157 update_from_config (Config::PLAYER_DEBUG_LOG);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
170 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
171 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
172 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
180 /* Use a panel as the only child of the Frame so that we avoid
181 the dark-grey background on Windows.
183 _overall_panel = new wxPanel (this, wxID_ANY);
185 _viewer.reset (new FilmViewer (_overall_panel));
186 #ifdef DCPOMATIC_VARIANT_SWAROOP
187 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
189 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
191 _controls = new StandardControls (_overall_panel, _viewer, false);
193 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
194 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
195 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
196 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
197 _info = new PlayerInformation (_overall_panel, _viewer);
198 setup_main_sizer (Config::instance()->player_mode());
200 int accelerators = 4;
202 int accelerators = 3;
205 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
206 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
207 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
208 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
210 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
212 wxAcceleratorTable accel_table (accelerators, accel);
213 SetAcceleratorTable (accel_table);
216 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
217 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
218 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
222 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
223 #ifdef DCPOMATIC_VARIANT_SWAROOP
224 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
225 MonitorChecker::instance()->run ();
226 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
227 LockFileChecker::instance()->run ();
231 #ifdef DCPOMATIC_VARIANT_SWAROOP
232 sc->check_restart ();
236 #ifdef DCPOMATIC_VARIANT_SWAROOP
237 void monitor_checker_state_changed ()
239 if (!MonitorChecker::instance()->ok()) {
241 error_dialog (this, _("The required display devices are not connected correctly."));
245 void lock_checker_state_changed ()
247 if (!LockFileChecker::instance()->ok()) {
249 error_dialog (this, _("The lock file is not present."));
254 void setup_main_sizer (Config::PlayerMode mode)
256 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
257 if (mode != Config::PLAYER_MODE_DUAL) {
258 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
260 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
261 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
262 _overall_panel->SetSizer (main_sizer);
263 _overall_panel->Layout ();
266 bool playback_permitted ()
268 #ifdef DCPOMATIC_VARIANT_SWAROOP
269 if (!MonitorChecker::instance()->ok()) {
270 error_dialog (this, _("The required display devices are not connected correctly."));
273 if (!LockFileChecker::instance()->ok()) {
274 error_dialog (this, _("The lock file is not present."));
278 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
283 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
284 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
285 if (d && !d->kdm_timing_window_valid()) {
290 #ifdef DCPOMATIC_VARIANT_SWAROOP
291 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
292 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
293 if (c && !c->kdm_timing_window_valid()) {
300 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
306 void playback_started (DCPTime time)
308 /* XXX: this only logs the first piece of content; probably should be each piece? */
309 if (_film->content().empty()) {
313 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
315 DCPExaminer ex (dcp, true);
316 shared_ptr<dcp::CPL> playing_cpl;
317 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
318 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
322 DCPOMATIC_ASSERT (playing_cpl);
326 "playback-started %s %s %s",
327 time.timecode(_film->video_frame_rate()).c_str(),
328 dcp->directories().front().string().c_str(),
329 playing_cpl->annotation_text().c_str()
334 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
338 "playback-started %s %s",
339 time.timecode(_film->video_frame_rate()).c_str(),
340 ffmpeg->path(0).string().c_str()
346 void playback_stopped (DCPTime time)
348 #ifdef DCPOMATIC_VARIANT_SWAROOP
350 boost::filesystem::remove (Config::path("position"));
356 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
359 void set_decode_reduction (optional<int> reduction)
361 _viewer->set_dcp_decode_reduction (reduction);
362 _info->triggered_update ();
363 Config::instance()->set_decode_reduction (reduction);
366 void load_dcp (boost::filesystem::path dir)
368 DCPOMATIC_ASSERT (_film);
372 shared_ptr<DCPContent> dcp (new DCPContent(dir));
373 _film->examine_and_add_content (dcp, true);
374 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
375 if (!ok || !report_errors_from_last_job(this)) {
378 #ifndef DCPOMATIC_VARIANT_SWAROOP
379 Config::instance()->add_to_player_history (dir);
381 } catch (dcp::DCPReadError& e) {
382 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
386 void reset_film_weak (weak_ptr<Film> weak_film)
388 shared_ptr<Film> film = weak_film.lock ();
394 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
397 _film->set_tolerant (true);
398 _viewer->set_film (_film);
399 _controls->set_film (_film);
400 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
401 _info->triggered_update ();
404 void film_changed (ChangeType type, Film::Property property)
406 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
410 if (_viewer->playing ()) {
414 /* Start off as Flat */
415 _film->set_container (Ratio::from_id("185"));
417 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
418 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
420 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
425 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
426 if (r->id() == "239") {
427 /* Any scope content means we use scope */
428 _film->set_container(r);
432 /* Any 3D content means we use 3D mode */
433 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
434 _film->set_three_d (true);
438 _viewer->seek (DCPTime(), true);
439 _info->triggered_update ();
441 set_menu_sensitivity ();
443 wxMenuItemList old = _cpl_menu->GetMenuItems();
444 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
445 _cpl_menu->Remove (*i);
448 if (_film->content().size() == 1) {
449 /* Offer a CPL menu */
450 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
452 DCPExaminer ex (first, true);
453 int id = ID_view_cpl;
454 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
455 wxMenuItem* j = _cpl_menu->AppendRadioItem(
457 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
459 j->Check(!first->cpl() || i->id() == *first->cpl());
468 bool report_errors_from_last_job (wxWindow* parent) const
470 JobManager* jm = JobManager::instance ();
472 DCPOMATIC_ASSERT (!jm->get().empty());
474 shared_ptr<Job> last = jm->get().back();
475 if (last->finished_in_error()) {
476 error_dialog(parent, wxString::Format(_("Could not load DCP.\n\n%s."), std_to_wx(last->error_summary()).data()), std_to_wx(last->error_details()));
483 void setup_menu (wxMenuBar* m)
485 _file_menu = new wxMenu;
486 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
487 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
488 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
490 _history_position = _file_menu->GetMenuItems().GetCount();
492 _file_menu->AppendSeparator ();
493 _file_menu->Append (ID_file_close, _("&Close"));
494 _file_menu->AppendSeparator ();
497 _file_menu->Append (wxID_EXIT, _("&Exit"));
499 _file_menu->Append (wxID_EXIT, _("&Quit"));
503 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
505 wxMenu* edit = new wxMenu;
506 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
509 prefs->Enable (Config::instance()->have_write_permission());
511 _cpl_menu = new wxMenu;
513 wxMenu* view = new wxMenu;
514 optional<int> c = Config::instance()->decode_reduction();
515 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
516 view->AppendSeparator();
517 #ifndef DCPOMATIC_VARIANT_SWAROOP
518 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
519 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
522 view->AppendSeparator();
523 view->Append(ID_view_closed_captions, _("Closed captions..."));
524 view->AppendSeparator();
525 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
526 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
527 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
528 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
530 wxMenu* tools = new wxMenu;
531 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
532 tools->AppendSeparator ();
533 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
534 tools->Append (ID_tools_timing, _("Timing..."));
535 tools->Append (ID_tools_system_information, _("System information..."));
537 wxMenu* help = new wxMenu;
539 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
541 help->Append (wxID_ABOUT, _("About"));
543 help->Append (ID_help_report_a_problem, _("Report a problem..."));
545 m->Append (_file_menu, _("&File"));
547 m->Append (edit, _("&Edit"));
549 m->Append (view, _("&View"));
550 m->Append (tools, _("&Tools"));
551 m->Append (help, _("&Help"));
556 wxString d = wxStandardPaths::Get().GetDocumentsDir();
557 if (Config::instance()->last_player_load_directory()) {
558 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
561 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
566 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
567 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
574 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
576 Config::instance()->set_last_player_load_directory (dcp.parent_path());
584 wxDirDialog* c = new wxDirDialog (
586 _("Select DCP to open as OV"),
587 wxStandardPaths::Get().GetDocumentsDir(),
588 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
594 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
595 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
602 DCPOMATIC_ASSERT (_film);
603 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
604 DCPOMATIC_ASSERT (dcp);
605 dcp->add_ov (wx_to_std(c->GetPath()));
606 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
607 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
608 if (!ok || !report_errors_from_last_job(this)) {
611 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
615 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
617 _film->set_container(r);
623 _info->triggered_update ();
628 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
630 if (d->ShowModal() == wxID_OK) {
631 DCPOMATIC_ASSERT (_film);
632 #ifdef DCPOMATIC_VARIANT_SWAROOP
633 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
636 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
637 } catch (exception& e) {
638 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
644 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
645 #ifndef DCPOMATIC_VARIANT_SWAROOP
646 DCPOMATIC_ASSERT (dcp);
650 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
651 dcp->examine (_film, shared_ptr<Job>());
653 } catch (exception& e) {
654 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
661 _info->triggered_update ();
664 void file_history (wxCommandEvent& event)
666 vector<boost::filesystem::path> history = Config::instance()->player_history ();
667 int n = event.GetId() - ID_file_history;
668 if (n >= 0 && n < static_cast<int> (history.size ())) {
670 load_dcp (history[n]);
671 } catch (exception& e) {
672 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
680 _info->triggered_update ();
681 set_menu_sensitivity ();
689 void edit_preferences ()
691 if (!Config::instance()->have_write_permission()) {
695 if (!_config_dialog) {
696 _config_dialog = create_player_config_dialog ();
698 _config_dialog->Show (this);
701 void view_cpl (wxCommandEvent& ev)
703 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
704 DCPOMATIC_ASSERT (dcp);
705 DCPExaminer ex (dcp, true);
706 int id = ev.GetId() - ID_view_cpl;
707 DCPOMATIC_ASSERT (id >= 0);
708 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
709 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
710 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
716 dcp->set_cpl ((*i)->id());
717 dcp->examine (_film, shared_ptr<Job>());
720 void view_full_screen ()
722 if (_mode == Config::PLAYER_MODE_FULL) {
723 _mode = Config::PLAYER_MODE_WINDOW;
725 _mode = Config::PLAYER_MODE_FULL;
731 void view_dual_screen ()
733 if (_mode == Config::PLAYER_MODE_DUAL) {
734 _mode = Config::PLAYER_MODE_WINDOW;
736 _mode = Config::PLAYER_MODE_DUAL;
744 if (_view_full_screen) {
745 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
747 if (_view_dual_screen) {
748 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
754 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
755 _info->Show (_mode != Config::PLAYER_MODE_FULL);
756 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
757 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
758 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
760 if (_mode == Config::PLAYER_MODE_DUAL) {
761 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
762 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
763 _dual_screen->ShowFullScreen (true);
764 _viewer->panel()->Reparent (_dual_screen);
765 _dual_screen->Show ();
766 if (wxDisplay::GetCount() > 1) {
767 switch (Config::instance()->image_display()) {
769 _dual_screen->Move (0, 0);
770 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
773 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
774 // (0, 0) doesn't seem to work for some strange reason
781 _viewer->panel()->Reparent (_overall_panel);
782 _dual_screen->Destroy ();
787 setup_main_sizer (_mode);
790 void view_closed_captions ()
792 _viewer->show_closed_captions ();
797 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
798 DCPOMATIC_ASSERT (dcp);
800 JobManager* jm = JobManager::instance ();
801 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
802 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
807 DCPOMATIC_ASSERT (!jm->get().empty());
808 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
809 DCPOMATIC_ASSERT (last);
811 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
816 void tools_check_for_updates ()
818 UpdateChecker::instance()->run ();
819 _update_news_requested = true;
824 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
829 void tools_system_information ()
831 if (!_system_information_dialog) {
832 _system_information_dialog = new SystemInformationDialog (this, _viewer);
835 _system_information_dialog->Show ();
840 AboutDialog* d = new AboutDialog (this);
845 void help_report_a_problem ()
847 ReportProblemDialog* d = new ReportProblemDialog (this);
848 if (d->ShowModal () == wxID_OK) {
854 void update_checker_state_changed ()
856 UpdateChecker* uc = UpdateChecker::instance ();
858 bool const announce =
859 _update_news_requested ||
860 (uc->stable() && Config::instance()->check_for_updates()) ||
861 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
863 _update_news_requested = false;
869 if (uc->state() == UpdateChecker::YES) {
870 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
871 dialog->ShowModal ();
873 } else if (uc->state() == UpdateChecker::FAILED) {
874 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
876 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
879 _update_news_requested = false;
882 void config_changed (Config::Property prop)
884 /* Instantly save any config changes when using the player GUI */
886 Config::instance()->write_config();
887 } catch (FileError& e) {
888 if (prop != Config::HISTORY) {
892 _("Could not write to config file at %s. Your changes have not been saved."),
893 std_to_wx(e.file().string())
897 } catch (exception& e) {
900 _("Could not write to config file. Your changes have not been saved.")
904 update_from_config (prop);
907 void update_from_config (Config::Property prop)
909 for (int i = 0; i < _history_items; ++i) {
910 delete _file_menu->Remove (ID_file_history + i);
913 if (_history_separator) {
914 _file_menu->Remove (_history_separator);
916 delete _history_separator;
917 _history_separator = 0;
919 int pos = _history_position;
921 /* Clear out non-existant history items before we re-build the menu */
922 Config::instance()->clean_player_history ();
923 vector<boost::filesystem::path> history = Config::instance()->player_history ();
925 if (!history.empty ()) {
926 _history_separator = _file_menu->InsertSeparator (pos++);
929 for (size_t i = 0; i < history.size(); ++i) {
932 s = String::compose ("&%1 %2", i + 1, history[i].string());
934 s = history[i].string();
936 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
939 _history_items = history.size ();
941 if (prop == Config::PLAYER_DEBUG_LOG) {
942 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
944 dcpomatic_log.reset (new FileLog(*p));
946 dcpomatic_log.reset (new NullLog());
948 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
952 void set_menu_sensitivity ()
954 _tools_verify->Enable (static_cast<bool>(_film));
955 _file_add_ov->Enable (static_cast<bool>(_film));
956 _file_add_kdm->Enable (static_cast<bool>(_film));
957 _view_cpl->Enable (static_cast<bool>(_film));
960 void start_stop_pressed ()
962 if (_viewer->playing()) {
971 _viewer->seek_by (-_viewer->one_video_frame(), true);
974 void forward_frame ()
976 _viewer->seek_by (_viewer->one_video_frame(), true);
981 wxFrame* _dual_screen;
982 bool _update_news_requested;
983 PlayerInformation* _info;
984 Config::PlayerMode _mode;
985 wxPreferencesEditor* _config_dialog;
986 wxPanel* _overall_panel;
988 wxMenuItem* _view_cpl;
991 int _history_position;
992 wxMenuItem* _history_separator;
993 shared_ptr<FilmViewer> _viewer;
995 SystemInformationDialog* _system_information_dialog;
996 boost::shared_ptr<Film> _film;
997 boost::signals2::scoped_connection _config_changed_connection;
998 wxMenuItem* _file_add_ov;
999 wxMenuItem* _file_add_kdm;
1000 wxMenuItem* _tools_verify;
1001 wxMenuItem* _view_full_screen;
1002 wxMenuItem* _view_dual_screen;
1005 static const wxCmdLineEntryDesc command_line_description[] = {
1006 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1007 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1008 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1011 class PlayServer : public Server
1014 explicit PlayServer (DOMFrame* frame)
1015 : Server (PLAYER_PLAY_PORT)
1019 void handle (shared_ptr<Socket> socket)
1022 int const length = socket->read_uint32 ();
1023 scoped_array<char> buffer (new char[length]);
1024 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1025 string s (buffer.get());
1026 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1027 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1038 * @brief The magic App class for wxWidgets.
1040 class App : public wxApp
1052 wxSplashScreen* splash = 0;
1054 wxInitAllImageHandlers ();
1056 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1057 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1059 splash = maybe_show_splash ();
1061 SetAppName (_("DCP-o-matic Player"));
1063 if (!wxApp::OnInit()) {
1067 #ifdef DCPOMATIC_LINUX
1068 unsetenv ("UBUNTU_MENUPROXY");
1072 ProcessSerialNumber serial;
1073 GetCurrentProcess (&serial);
1074 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1077 dcpomatic_setup_path_encoding ();
1079 /* Enable i18n; this will create a Config object
1080 to look for a force-configured language. This Config
1081 object will be wrong, however, because dcpomatic_setup
1082 hasn't yet been called and there aren't any filters etc.
1085 dcpomatic_setup_i18n ();
1087 /* Set things up, including filters etc.
1088 which will now be internationalised correctly.
1092 /* Force the configuration to be re-loaded correctly next
1097 signal_manager = new wxSignalManager (this);
1099 _frame = new DOMFrame ();
1100 SetTopWindow (_frame);
1101 _frame->Maximize ();
1108 PlayServer* server = new PlayServer (_frame);
1109 new thread (boost::bind (&PlayServer::run, server));
1111 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1113 _frame->load_dcp (_dcp_to_load);
1114 } catch (exception& e) {
1115 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1119 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1121 if (Config::instance()->check_for_updates ()) {
1122 UpdateChecker::instance()->run ();
1125 catch (exception& e)
1130 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1136 void OnInitCmdLine (wxCmdLineParser& parser)
1138 parser.SetDesc (command_line_description);
1139 parser.SetSwitchChars (wxT ("-"));
1142 bool OnCmdLineParsed (wxCmdLineParser& parser)
1144 if (parser.GetParamCount() > 0) {
1145 _dcp_to_load = wx_to_std (parser.GetParam (0));
1149 if (parser.Found("c", &config)) {
1150 Config::override_path = wx_to_std (config);
1156 void report_exception ()
1160 } catch (FileError& e) {
1164 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1165 std_to_wx (e.what()),
1166 std_to_wx (e.file().string().c_str ())
1169 } catch (exception& e) {
1173 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1174 std_to_wx (e.what ())
1178 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1182 /* An unhandled exception has occurred inside the main event loop */
1183 bool OnExceptionInMainLoop ()
1185 report_exception ();
1186 /* This will terminate the program */
1190 void OnUnhandledException ()
1192 report_exception ();
1197 signal_manager->ui_idle ();
1200 void config_failed_to_load ()
1202 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1205 void config_warning (string m)
1207 message_dialog (_frame, std_to_wx (m));
1211 string _dcp_to_load;