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>
73 #include <ApplicationServices/ApplicationServices.h>
75 #include <boost/bind.hpp>
89 using boost::shared_ptr;
90 using boost::weak_ptr;
91 using boost::scoped_array;
92 using boost::optional;
93 using boost::dynamic_pointer_cast;
96 using namespace dcpomatic;
103 /* Allow spare IDs after _history for the recent files list */
106 /* Allow spare IDs for CPLs */
107 ID_view_full_screen = 200,
109 ID_view_closed_captions,
110 ID_view_scale_appropriate,
113 ID_view_scale_quarter,
114 ID_help_report_a_problem,
116 ID_tools_check_for_updates,
118 ID_tools_system_information,
119 /* IDs for shortcuts (with no associated menu item) */
125 class DOMFrame : public wxFrame
129 : wxFrame (0, -1, _("DCP-o-matic Player"))
131 , _update_news_requested (false)
133 , _mode (Config::instance()->player_mode())
137 , _history_position (0)
138 , _history_separator (0)
139 , _system_information_dialog (0)
140 , _view_full_screen (0)
141 , _view_dual_screen (0)
143 dcpomatic_log.reset (new NullLog());
145 #if defined(DCPOMATIC_WINDOWS)
146 maybe_open_console ();
147 cout << "DCP-o-matic Player is starting." << "\n";
150 wxMenuBar* bar = new wxMenuBar;
152 set_menu_sensitivity ();
155 #ifdef DCPOMATIC_WINDOWS
156 SetIcon (wxIcon (std_to_wx ("id")));
159 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
160 update_from_config (Config::PLAYER_DEBUG_LOG);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
165 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
166 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
167 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
170 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
171 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
172 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
183 /* Use a panel as the only child of the Frame so that we avoid
184 the dark-grey background on Windows.
186 _overall_panel = new wxPanel (this, wxID_ANY);
188 _viewer.reset (new FilmViewer (_overall_panel));
189 #ifdef DCPOMATIC_VARIANT_SWAROOP
190 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
192 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
194 _controls = new StandardControls (_overall_panel, _viewer, false);
196 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
197 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
198 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
199 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
200 _info = new PlayerInformation (_overall_panel, _viewer);
201 setup_main_sizer (Config::instance()->player_mode());
203 int accelerators = 4;
205 int accelerators = 3;
208 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
209 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
210 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
211 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
213 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
215 wxAcceleratorTable accel_table (accelerators, accel);
216 SetAcceleratorTable (accel_table);
219 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
220 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
221 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
225 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
226 #ifdef DCPOMATIC_VARIANT_SWAROOP
227 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
228 MonitorChecker::instance()->run ();
229 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
230 LockFileChecker::instance()->run ();
234 #ifdef DCPOMATIC_VARIANT_SWAROOP
235 sc->check_restart ();
239 #ifdef DCPOMATIC_VARIANT_SWAROOP
240 void monitor_checker_state_changed ()
242 if (!MonitorChecker::instance()->ok()) {
244 error_dialog (this, _("The required display devices are not connected correctly."));
248 void lock_checker_state_changed ()
250 if (!LockFileChecker::instance()->ok()) {
252 error_dialog (this, _("The lock file is not present."));
257 void setup_main_sizer (Config::PlayerMode mode)
259 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
260 if (mode != Config::PLAYER_MODE_DUAL) {
261 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
263 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
264 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
265 _overall_panel->SetSizer (main_sizer);
266 _overall_panel->Layout ();
269 bool playback_permitted ()
271 #ifdef DCPOMATIC_VARIANT_SWAROOP
272 if (!MonitorChecker::instance()->ok()) {
273 error_dialog (this, _("The required display devices are not connected correctly."));
276 if (!LockFileChecker::instance()->ok()) {
277 error_dialog (this, _("The lock file is not present."));
281 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
286 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
287 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
288 if (d && !d->kdm_timing_window_valid()) {
293 #ifdef DCPOMATIC_VARIANT_SWAROOP
294 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
295 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
296 if (c && !c->kdm_timing_window_valid()) {
303 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
309 void playback_started (DCPTime time)
311 /* XXX: this only logs the first piece of content; probably should be each piece? */
312 if (_film->content().empty()) {
316 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
318 DCPExaminer ex (dcp, true);
319 shared_ptr<dcp::CPL> playing_cpl;
320 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
321 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
325 DCPOMATIC_ASSERT (playing_cpl);
329 "playback-started %s %s %s",
330 time.timecode(_film->video_frame_rate()).c_str(),
331 dcp->directories().front().string().c_str(),
332 playing_cpl->annotation_text().c_str()
337 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
341 "playback-started %s %s",
342 time.timecode(_film->video_frame_rate()).c_str(),
343 ffmpeg->path(0).string().c_str()
349 void playback_stopped (DCPTime time)
351 #ifdef DCPOMATIC_VARIANT_SWAROOP
353 boost::filesystem::remove (Config::path("position"));
359 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
362 void set_decode_reduction (optional<int> reduction)
364 _viewer->set_dcp_decode_reduction (reduction);
365 _info->triggered_update ();
366 Config::instance()->set_decode_reduction (reduction);
369 void load_dcp (boost::filesystem::path dir)
371 DCPOMATIC_ASSERT (_film);
375 shared_ptr<DCPContent> dcp (new DCPContent(dir));
376 _film->examine_and_add_content (dcp, true);
377 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
378 if (!ok || !report_errors_from_last_job(this)) {
381 #ifndef DCPOMATIC_VARIANT_SWAROOP
382 Config::instance()->add_to_player_history (dir);
384 } catch (dcp::DCPReadError& e) {
385 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
389 void reset_film_weak (weak_ptr<Film> weak_film)
391 shared_ptr<Film> film = weak_film.lock ();
397 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
400 _film->set_tolerant (true);
401 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
402 _viewer->set_film (_film);
403 _controls->set_film (_film);
404 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
405 _info->triggered_update ();
408 void film_changed (ChangeType type, Film::Property property)
410 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
414 if (_viewer->playing ()) {
418 /* Start off as Flat */
419 _film->set_container (Ratio::from_id("185"));
421 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
422 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
424 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
429 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
430 if (r->id() == "239") {
431 /* Any scope content means we use scope */
432 _film->set_container(r);
436 /* Any 3D content means we use 3D mode */
437 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
438 _film->set_three_d (true);
442 _viewer->seek (DCPTime(), true);
443 _info->triggered_update ();
445 set_menu_sensitivity ();
447 wxMenuItemList old = _cpl_menu->GetMenuItems();
448 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
449 _cpl_menu->Remove (*i);
452 if (_film->content().size() == 1) {
453 /* Offer a CPL menu */
454 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
456 DCPExaminer ex (first, true);
457 int id = ID_view_cpl;
458 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
459 wxMenuItem* j = _cpl_menu->AppendRadioItem(
461 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
463 j->Check(!first->cpl() || i->id() == *first->cpl());
472 bool report_errors_from_last_job (wxWindow* parent) const
474 JobManager* jm = JobManager::instance ();
476 DCPOMATIC_ASSERT (!jm->get().empty());
478 shared_ptr<Job> last = jm->get().back();
479 if (last->finished_in_error()) {
480 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()));
487 void setup_menu (wxMenuBar* m)
489 _file_menu = new wxMenu;
490 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
491 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
492 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
494 _history_position = _file_menu->GetMenuItems().GetCount();
496 _file_menu->AppendSeparator ();
497 _file_menu->Append (ID_file_close, _("&Close"));
498 _file_menu->AppendSeparator ();
501 _file_menu->Append (wxID_EXIT, _("&Exit"));
503 _file_menu->Append (wxID_EXIT, _("&Quit"));
507 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
509 wxMenu* edit = new wxMenu;
510 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
513 prefs->Enable (Config::instance()->have_write_permission());
515 _cpl_menu = new wxMenu;
517 wxMenu* view = new wxMenu;
518 optional<int> c = Config::instance()->decode_reduction();
519 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
520 view->AppendSeparator();
521 #ifndef DCPOMATIC_VARIANT_SWAROOP
522 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
523 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
526 view->AppendSeparator();
527 view->Append(ID_view_closed_captions, _("Closed captions..."));
528 view->AppendSeparator();
529 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
530 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
531 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
532 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
534 wxMenu* tools = new wxMenu;
535 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
536 tools->AppendSeparator ();
537 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
538 tools->Append (ID_tools_timing, _("Timing..."));
539 tools->Append (ID_tools_system_information, _("System information..."));
541 wxMenu* help = new wxMenu;
543 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
545 help->Append (wxID_ABOUT, _("About"));
547 help->Append (ID_help_report_a_problem, _("Report a problem..."));
549 m->Append (_file_menu, _("&File"));
551 m->Append (edit, _("&Edit"));
553 m->Append (view, _("&View"));
554 m->Append (tools, _("&Tools"));
555 m->Append (help, _("&Help"));
560 wxString d = wxStandardPaths::Get().GetDocumentsDir();
561 if (Config::instance()->last_player_load_directory()) {
562 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
565 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
570 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
571 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
578 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
580 Config::instance()->set_last_player_load_directory (dcp.parent_path());
588 wxDirDialog* c = new wxDirDialog (
590 _("Select DCP to open as OV"),
591 wxStandardPaths::Get().GetDocumentsDir(),
592 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
598 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
599 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
606 DCPOMATIC_ASSERT (_film);
607 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
608 DCPOMATIC_ASSERT (dcp);
609 dcp->add_ov (wx_to_std(c->GetPath()));
610 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
611 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
612 if (!ok || !report_errors_from_last_job(this)) {
615 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
619 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
621 _film->set_container(r);
627 _info->triggered_update ();
632 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
634 if (d->ShowModal() == wxID_OK) {
635 DCPOMATIC_ASSERT (_film);
636 #ifdef DCPOMATIC_VARIANT_SWAROOP
637 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
640 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
641 } catch (exception& e) {
642 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
648 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
649 #ifndef DCPOMATIC_VARIANT_SWAROOP
650 DCPOMATIC_ASSERT (dcp);
654 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
655 dcp->examine (_film, shared_ptr<Job>());
657 } catch (exception& e) {
658 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
665 _info->triggered_update ();
668 void file_history (wxCommandEvent& event)
670 vector<boost::filesystem::path> history = Config::instance()->player_history ();
671 int n = event.GetId() - ID_file_history;
672 if (n >= 0 && n < static_cast<int> (history.size ())) {
674 load_dcp (history[n]);
675 } catch (exception& e) {
676 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
684 _info->triggered_update ();
685 set_menu_sensitivity ();
693 void edit_preferences ()
695 if (!Config::instance()->have_write_permission()) {
699 if (!_config_dialog) {
700 _config_dialog = create_player_config_dialog ();
702 _config_dialog->Show (this);
705 void view_cpl (wxCommandEvent& ev)
707 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
708 DCPOMATIC_ASSERT (dcp);
709 DCPExaminer ex (dcp, true);
710 int id = ev.GetId() - ID_view_cpl;
711 DCPOMATIC_ASSERT (id >= 0);
712 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
713 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
714 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
720 dcp->set_cpl ((*i)->id());
721 dcp->examine (_film, shared_ptr<Job>());
724 void view_full_screen ()
726 if (_mode == Config::PLAYER_MODE_FULL) {
727 _mode = Config::PLAYER_MODE_WINDOW;
729 _mode = Config::PLAYER_MODE_FULL;
735 void view_dual_screen ()
737 if (_mode == Config::PLAYER_MODE_DUAL) {
738 _mode = Config::PLAYER_MODE_WINDOW;
740 _mode = Config::PLAYER_MODE_DUAL;
748 if (_view_full_screen) {
749 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
751 if (_view_dual_screen) {
752 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
758 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
759 _info->Show (_mode != Config::PLAYER_MODE_FULL);
760 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
761 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
762 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
764 if (_mode == Config::PLAYER_MODE_DUAL) {
765 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
766 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
767 _dual_screen->ShowFullScreen (true);
768 _viewer->panel()->Reparent (_dual_screen);
769 _dual_screen->Show ();
770 if (wxDisplay::GetCount() > 1) {
771 switch (Config::instance()->image_display()) {
773 _dual_screen->Move (0, 0);
774 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
777 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
778 // (0, 0) doesn't seem to work for some strange reason
785 _viewer->panel()->Reparent (_overall_panel);
786 _dual_screen->Destroy ();
791 setup_main_sizer (_mode);
794 void view_closed_captions ()
796 _viewer->show_closed_captions ();
801 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
802 DCPOMATIC_ASSERT (dcp);
804 JobManager* jm = JobManager::instance ();
805 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
806 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
811 DCPOMATIC_ASSERT (!jm->get().empty());
812 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
813 DCPOMATIC_ASSERT (last);
815 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
820 void tools_check_for_updates ()
822 UpdateChecker::instance()->run ();
823 _update_news_requested = true;
828 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
833 void tools_system_information ()
835 if (!_system_information_dialog) {
836 _system_information_dialog = new SystemInformationDialog (this, _viewer);
839 _system_information_dialog->Show ();
844 AboutDialog* d = new AboutDialog (this);
849 void help_report_a_problem ()
851 ReportProblemDialog* d = new ReportProblemDialog (this);
852 if (d->ShowModal () == wxID_OK) {
858 void update_checker_state_changed ()
860 UpdateChecker* uc = UpdateChecker::instance ();
862 bool const announce =
863 _update_news_requested ||
864 (uc->stable() && Config::instance()->check_for_updates()) ||
865 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
867 _update_news_requested = false;
873 if (uc->state() == UpdateChecker::YES) {
874 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
875 dialog->ShowModal ();
877 } else if (uc->state() == UpdateChecker::FAILED) {
878 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
880 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
883 _update_news_requested = false;
886 void config_changed (Config::Property prop)
888 /* Instantly save any config changes when using the player GUI */
890 Config::instance()->write_config();
891 } catch (FileError& e) {
892 if (prop != Config::HISTORY) {
896 _("Could not write to config file at %s. Your changes have not been saved."),
897 std_to_wx(e.file().string())
901 } catch (exception& e) {
904 _("Could not write to config file. Your changes have not been saved.")
908 update_from_config (prop);
911 void update_from_config (Config::Property prop)
913 for (int i = 0; i < _history_items; ++i) {
914 delete _file_menu->Remove (ID_file_history + i);
917 if (_history_separator) {
918 _file_menu->Remove (_history_separator);
920 delete _history_separator;
921 _history_separator = 0;
923 int pos = _history_position;
925 /* Clear out non-existant history items before we re-build the menu */
926 Config::instance()->clean_player_history ();
927 vector<boost::filesystem::path> history = Config::instance()->player_history ();
929 if (!history.empty ()) {
930 _history_separator = _file_menu->InsertSeparator (pos++);
933 for (size_t i = 0; i < history.size(); ++i) {
936 s = String::compose ("&%1 %2", i + 1, history[i].string());
938 s = history[i].string();
940 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
943 _history_items = history.size ();
945 if (prop == Config::PLAYER_DEBUG_LOG) {
946 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
948 dcpomatic_log.reset (new FileLog(*p));
950 dcpomatic_log.reset (new NullLog());
952 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
956 void set_menu_sensitivity ()
958 _tools_verify->Enable (static_cast<bool>(_film));
959 _file_add_ov->Enable (static_cast<bool>(_film));
960 _file_add_kdm->Enable (static_cast<bool>(_film));
961 _view_cpl->Enable (static_cast<bool>(_film));
964 void start_stop_pressed ()
966 if (_viewer->playing()) {
975 _viewer->seek_by (-_viewer->one_video_frame(), true);
978 void forward_frame ()
980 _viewer->seek_by (_viewer->one_video_frame(), true);
985 wxFrame* _dual_screen;
986 bool _update_news_requested;
987 PlayerInformation* _info;
988 Config::PlayerMode _mode;
989 wxPreferencesEditor* _config_dialog;
990 wxPanel* _overall_panel;
992 wxMenuItem* _view_cpl;
995 int _history_position;
996 wxMenuItem* _history_separator;
997 shared_ptr<FilmViewer> _viewer;
999 SystemInformationDialog* _system_information_dialog;
1000 boost::shared_ptr<Film> _film;
1001 boost::signals2::scoped_connection _config_changed_connection;
1002 wxMenuItem* _file_add_ov;
1003 wxMenuItem* _file_add_kdm;
1004 wxMenuItem* _tools_verify;
1005 wxMenuItem* _view_full_screen;
1006 wxMenuItem* _view_dual_screen;
1009 static const wxCmdLineEntryDesc command_line_description[] = {
1010 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1011 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1012 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1015 class PlayServer : public Server
1018 explicit PlayServer (DOMFrame* frame)
1019 : Server (PLAYER_PLAY_PORT)
1023 void handle (shared_ptr<Socket> socket)
1026 int const length = socket->read_uint32 ();
1027 scoped_array<char> buffer (new char[length]);
1028 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1029 string s (buffer.get());
1030 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1031 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1042 * @brief The magic App class for wxWidgets.
1044 class App : public wxApp
1051 #ifdef DCPOMATIC_LINUX
1060 wxSplashScreen* splash = 0;
1062 wxInitAllImageHandlers ();
1064 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1065 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1067 splash = maybe_show_splash ();
1069 SetAppName (_("DCP-o-matic Player"));
1071 if (!wxApp::OnInit()) {
1075 #ifdef DCPOMATIC_LINUX
1076 unsetenv ("UBUNTU_MENUPROXY");
1080 ProcessSerialNumber serial;
1081 GetCurrentProcess (&serial);
1082 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1085 dcpomatic_setup_path_encoding ();
1087 /* Enable i18n; this will create a Config object
1088 to look for a force-configured language. This Config
1089 object will be wrong, however, because dcpomatic_setup
1090 hasn't yet been called and there aren't any filters etc.
1093 dcpomatic_setup_i18n ();
1095 /* Set things up, including filters etc.
1096 which will now be internationalised correctly.
1100 /* Force the configuration to be re-loaded correctly next
1105 signal_manager = new wxSignalManager (this);
1107 _frame = new DOMFrame ();
1108 SetTopWindow (_frame);
1109 _frame->Maximize ();
1116 PlayServer* server = new PlayServer (_frame);
1117 new thread (boost::bind (&PlayServer::run, server));
1119 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1121 _frame->load_dcp (_dcp_to_load);
1122 } catch (exception& e) {
1123 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1127 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1129 if (Config::instance()->check_for_updates ()) {
1130 UpdateChecker::instance()->run ();
1133 catch (exception& e)
1138 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1144 void OnInitCmdLine (wxCmdLineParser& parser)
1146 parser.SetDesc (command_line_description);
1147 parser.SetSwitchChars (wxT ("-"));
1150 bool OnCmdLineParsed (wxCmdLineParser& parser)
1152 if (parser.GetParamCount() > 0) {
1153 _dcp_to_load = wx_to_std (parser.GetParam (0));
1157 if (parser.Found("c", &config)) {
1158 Config::override_path = wx_to_std (config);
1164 void report_exception ()
1168 } catch (FileError& e) {
1172 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1173 std_to_wx (e.what()),
1174 std_to_wx (e.file().string().c_str ())
1177 } catch (exception& e) {
1181 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1182 std_to_wx (e.what ())
1186 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1190 /* An unhandled exception has occurred inside the main event loop */
1191 bool OnExceptionInMainLoop ()
1193 report_exception ();
1194 /* This will terminate the program */
1198 void OnUnhandledException ()
1200 report_exception ();
1205 signal_manager->ui_idle ();
1208 void config_failed_to_load ()
1210 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1213 void config_warning (string m)
1215 message_dialog (_frame, std_to_wx (m));
1219 string _dcp_to_load;