2 Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/controls.h"
31 #include "lib/cross.h"
32 #include "lib/config.h"
34 #include "lib/internet.h"
35 #include "lib/update_checker.h"
36 #include "lib/compose.hpp"
37 #include "lib/dcp_content.h"
38 #include "lib/job_manager.h"
41 #include "lib/video_content.h"
42 #include "lib/text_content.h"
43 #include "lib/ratio.h"
44 #include "lib/verify_dcp_job.h"
45 #include "lib/dcp_examiner.h"
46 #include "lib/examine_content_job.h"
47 #include "lib/server.h"
48 #include "lib/dcpomatic_socket.h"
49 #include "lib/scoped_temporary.h"
50 #include "lib/monitor_checker.h"
51 #include "lib/lock_file_checker.h"
52 #include "lib/ffmpeg_content.h"
54 #include <dcp/raw_convert.h>
55 #include <dcp/exceptions.h>
57 #include <wx/stdpaths.h>
58 #include <wx/splash.h>
59 #include <wx/cmdline.h>
60 #include <wx/preferences.h>
61 #include <wx/progdlg.h>
62 #include <wx/display.h>
64 #include <ApplicationServices/ApplicationServices.h>
66 #include <boost/bind.hpp>
80 using boost::shared_ptr;
81 using boost::scoped_array;
82 using boost::optional;
83 using boost::dynamic_pointer_cast;
92 /* Allow spare IDs after _history for the recent files list */
95 /* Allow spare IDs for CPLs */
96 ID_view_full_screen = 200,
98 ID_view_closed_captions,
99 ID_view_scale_appropriate,
102 ID_view_scale_quarter,
103 ID_help_report_a_problem,
105 ID_tools_check_for_updates,
106 /* IDs for shortcuts (with no associated menu item) */
112 class DOMFrame : public wxFrame
116 : wxFrame (0, -1, _("DCP-o-matic Player"))
118 , _update_news_requested (false)
120 , _mode (Config::instance()->player_mode())
124 , _history_position (0)
125 , _history_separator (0)
126 , _view_full_screen (0)
127 , _view_dual_screen (0)
130 #if defined(DCPOMATIC_WINDOWS)
131 maybe_open_console ();
132 cout << "DCP-o-matic Player is starting." << "\n";
135 wxMenuBar* bar = new wxMenuBar;
137 set_menu_sensitivity ();
140 #ifdef DCPOMATIC_WINDOWS
141 SetIcon (wxIcon (std_to_wx ("id")));
144 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
145 update_from_config ();
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
164 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
166 /* Use a panel as the only child of the Frame so that we avoid
167 the dark-grey background on Windows.
169 _overall_panel = new wxPanel (this, wxID_ANY);
171 _viewer.reset (new FilmViewer (_overall_panel));
172 _controls = new Controls (_overall_panel, _viewer, false);
173 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
174 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
175 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
176 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
177 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
178 #ifdef DCPOMATIC_VARIANT_SWAROOP
179 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
181 _info = new PlayerInformation (_overall_panel, _viewer);
182 setup_main_sizer (Config::instance()->player_mode());
184 int accelerators = 4;
186 int accelerators = 3;
189 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
190 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
191 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
192 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
194 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
196 wxAcceleratorTable accel_table (accelerators, accel);
197 SetAcceleratorTable (accel_table);
200 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
201 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
202 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
206 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
207 #ifdef DCPOMATIC_VARIANT_SWAROOP
208 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
209 MonitorChecker::instance()->run ();
210 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
211 LockFileChecker::instance()->run ();
215 #ifdef DCPOMATIC_VARIANT_SWAROOP
217 boost::filesystem::is_regular_file(Config::path("position")) &&
218 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
220 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
221 film->read_metadata (Config::path("spl.xml"));
223 FILE* f = fopen_boost (Config::path("position"), "r");
226 fscanf (f, "%63s", buffer);
227 _viewer->seek (DCPTime(atoi(buffer)), true);
236 void position_changed ()
238 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
242 FILE* f = fopen_boost (Config::path("position"), "w");
244 string const p = dcp::raw_convert<string> (_viewer->position().get());
245 fwrite (p.c_str(), p.length(), 1, f);
250 #ifdef DCPOMATIC_VARIANT_SWAROOP
251 void monitor_checker_state_changed ()
253 if (!MonitorChecker::instance()->ok()) {
255 error_dialog (this, _("The required display devices are not connected correctly."));
259 void lock_checker_state_changed ()
261 if (!LockFileChecker::instance()->ok()) {
263 error_dialog (this, _("The lock file is not present."));
268 void setup_main_sizer (Config::PlayerMode mode)
270 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
271 if (mode != Config::PLAYER_MODE_DUAL) {
272 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
274 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
275 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
276 _overall_panel->SetSizer (main_sizer);
277 _overall_panel->Layout ();
280 bool playback_permitted ()
282 #ifdef DCPOMATIC_VARIANT_SWAROOP
283 if (!MonitorChecker::instance()->ok()) {
284 error_dialog (this, _("The required display devices are not connected correctly."));
287 if (!LockFileChecker::instance()->ok()) {
288 error_dialog (this, _("The lock file is not present."));
292 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
297 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
298 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
299 if (d && !d->kdm_timing_window_valid()) {
305 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
311 void playback_started (DCPTime time)
313 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
318 FILE* f = fopen_boost(*log, "a");
320 /* XXX: this only logs the first piece of content; probably should be each piece? */
322 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
324 DCPExaminer ex (dcp);
325 shared_ptr<dcp::CPL> playing_cpl;
326 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
327 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
331 DCPOMATIC_ASSERT (playing_cpl);
335 "%s playback-started %s %s %s\n",
336 dcp::LocalTime().as_string().c_str(),
337 time.timecode(_film->video_frame_rate()).c_str(),
338 dcp->directories().front().string().c_str(),
339 playing_cpl->annotation_text().c_str()
343 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
347 "%s playback-started %s %s\n",
348 dcp::LocalTime().as_string().c_str(),
349 time.timecode(_film->video_frame_rate()).c_str(),
350 ffmpeg->path(0).string().c_str()
357 void playback_seeked (DCPTime time)
359 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
364 FILE* f = fopen_boost(*log, "a");
365 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
369 void playback_stopped (DCPTime time)
371 #ifdef DCPOMATIC_VARIANT_SWAROOP
373 boost::filesystem::remove (Config::path("position"));
379 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
384 FILE* f = fopen_boost(*log, "a");
385 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
389 void set_decode_reduction (optional<int> reduction)
391 _viewer->set_dcp_decode_reduction (reduction);
392 _info->triggered_update ();
393 Config::instance()->set_decode_reduction (reduction);
396 void load_dcp (boost::filesystem::path dir)
398 DCPOMATIC_ASSERT (_film);
402 shared_ptr<DCPContent> dcp (new DCPContent(_film, dir));
403 _film->examine_and_add_content (dcp);
404 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
405 if (!ok || !report_errors_from_last_job(this)) {
408 Config::instance()->add_to_player_history (dir);
409 } catch (dcp::DCPReadError& e) {
410 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
414 #ifdef DCPOMATIC_VARIANT_SWAROOP
415 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
417 ScopedTemporary temp;
418 string url = Config::instance()->kdm_server_url();
419 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
420 optional<dcp::EncryptedKDM> kdm;
421 if (dcp->cpl() && !get_from_url(url, false, temp)) {
423 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
424 if (kdm->cpl_id() != dcp->cpl()) {
427 } catch (std::exception& e) {
435 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
437 using namespace boost::filesystem;
438 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
440 return optional<dcp::EncryptedKDM>();
442 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
444 if (file_size(i->path()) < MAX_KDM_SIZE) {
445 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
446 if (kdm.cpl_id() == dcp->cpl()) {
450 } catch (std::exception& e) {
454 return optional<dcp::EncryptedKDM>();
457 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
460 _viewer->set_film (_film);
461 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
464 void film_changed (ChangeType type, Film::Property property)
466 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
470 _film->write_metadata (Config::path("spl.xml"));
472 if (_viewer->playing ()) {
476 /* Start off as Flat */
477 _film->set_container (Ratio::from_id("185"));
479 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
480 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
481 if (dcp && dcp->needs_kdm()) {
482 optional<dcp::EncryptedKDM> kdm;
483 #ifdef DCPOMATIC_VARIANT_SWAROOP
484 kdm = get_kdm_from_url (dcp);
487 kdm = get_kdm_from_directory (dcp);
492 dcp->examine (shared_ptr<Job>());
496 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
501 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
502 if (r->id() == "239") {
503 /* Any scope content means we use scope */
504 _film->set_container(r);
508 /* Any 3D content means we use 3D mode */
509 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
510 _film->set_three_d (true);
514 _viewer->seek (DCPTime(), true);
515 _info->triggered_update ();
517 set_menu_sensitivity ();
519 wxMenuItemList old = _cpl_menu->GetMenuItems();
520 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
521 _cpl_menu->Remove (*i);
524 if (_film->content().size() == 1) {
525 /* Offer a CPL menu */
526 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
528 DCPExaminer ex (first);
529 int id = ID_view_cpl;
530 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
531 wxMenuItem* j = _cpl_menu->AppendRadioItem(
533 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
535 j->Check(!first->cpl() || i->id() == *first->cpl());
544 void setup_menu (wxMenuBar* m)
546 _file_menu = new wxMenu;
547 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
548 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
549 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
551 _history_position = _file_menu->GetMenuItems().GetCount();
553 _file_menu->AppendSeparator ();
554 _file_menu->Append (ID_file_close, _("&Close"));
555 _file_menu->AppendSeparator ();
558 _file_menu->Append (wxID_EXIT, _("&Exit"));
560 _file_menu->Append (wxID_EXIT, _("&Quit"));
564 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
566 wxMenu* edit = new wxMenu;
567 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
570 prefs->Enable (Config::instance()->have_write_permission());
572 _cpl_menu = new wxMenu;
574 wxMenu* view = new wxMenu;
575 optional<int> c = Config::instance()->decode_reduction();
576 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
577 view->AppendSeparator();
578 #ifndef DCPOMATIC_VARIANT_SWAROOP
579 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
580 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
583 view->AppendSeparator();
584 view->Append(ID_view_closed_captions, _("Closed captions..."));
585 view->AppendSeparator();
586 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
587 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
588 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
589 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
591 wxMenu* tools = new wxMenu;
592 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
593 tools->AppendSeparator ();
594 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
596 wxMenu* help = new wxMenu;
598 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
600 help->Append (wxID_ABOUT, _("About"));
602 help->Append (ID_help_report_a_problem, _("Report a problem..."));
604 m->Append (_file_menu, _("&File"));
606 m->Append (edit, _("&Edit"));
608 m->Append (view, _("&View"));
609 m->Append (tools, _("&Tools"));
610 m->Append (help, _("&Help"));
615 wxString d = wxStandardPaths::Get().GetDocumentsDir();
616 if (Config::instance()->last_player_load_directory()) {
617 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
620 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
625 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
626 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
633 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
635 Config::instance()->set_last_player_load_directory (dcp.parent_path());
643 wxDirDialog* c = new wxDirDialog (
645 _("Select DCP to open as OV"),
646 wxStandardPaths::Get().GetDocumentsDir(),
647 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
653 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
654 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
661 DCPOMATIC_ASSERT (_film);
662 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
663 DCPOMATIC_ASSERT (dcp);
664 dcp->add_ov (wx_to_std(c->GetPath()));
665 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
666 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
667 if (!ok || !report_errors_from_last_job(this)) {
670 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
674 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
676 _film->set_container(r);
682 _info->triggered_update ();
687 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
689 if (d->ShowModal() == wxID_OK) {
690 DCPOMATIC_ASSERT (_film);
691 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
692 DCPOMATIC_ASSERT (dcp);
694 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
695 dcp->examine (shared_ptr<Job>());
696 } catch (exception& e) {
697 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
704 _info->triggered_update ();
707 void file_history (wxCommandEvent& event)
709 vector<boost::filesystem::path> history = Config::instance()->player_history ();
710 int n = event.GetId() - ID_file_history;
711 if (n >= 0 && n < static_cast<int> (history.size ())) {
712 load_dcp (history[n]);
719 _info->triggered_update ();
720 set_menu_sensitivity ();
728 void edit_preferences ()
730 if (!Config::instance()->have_write_permission()) {
734 if (!_config_dialog) {
735 _config_dialog = create_player_config_dialog ();
737 _config_dialog->Show (this);
740 void view_cpl (wxCommandEvent& ev)
742 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
743 DCPOMATIC_ASSERT (dcp);
744 DCPExaminer ex (dcp);
745 int id = ev.GetId() - ID_view_cpl;
746 DCPOMATIC_ASSERT (id >= 0);
747 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
748 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
749 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
755 dcp->set_cpl ((*i)->id());
756 dcp->examine (shared_ptr<Job>());
759 void view_full_screen ()
761 if (_mode == Config::PLAYER_MODE_FULL) {
762 _mode = Config::PLAYER_MODE_WINDOW;
764 _mode = Config::PLAYER_MODE_FULL;
770 void view_dual_screen ()
772 if (_mode == Config::PLAYER_MODE_DUAL) {
773 _mode = Config::PLAYER_MODE_WINDOW;
775 _mode = Config::PLAYER_MODE_DUAL;
783 if (_view_full_screen) {
784 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
786 if (_view_dual_screen) {
787 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
793 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
794 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
795 _info->Show (_mode != Config::PLAYER_MODE_FULL);
796 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
797 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
798 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
800 if (_mode == Config::PLAYER_MODE_DUAL) {
801 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
802 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
803 _dual_screen->ShowFullScreen (true);
804 _viewer->panel()->Reparent (_dual_screen);
805 _dual_screen->Show ();
806 if (wxDisplay::GetCount() > 1) {
807 switch (Config::instance()->image_display()) {
809 _dual_screen->Move (0, 0);
810 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
813 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
814 // (0, 0) doesn't seem to work for some strange reason
821 _viewer->panel()->Reparent (_overall_panel);
822 _dual_screen->Destroy ();
827 setup_main_sizer (_mode);
830 void view_closed_captions ()
832 _viewer->show_closed_captions ();
837 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
838 DCPOMATIC_ASSERT (dcp);
840 JobManager* jm = JobManager::instance ();
841 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
842 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
847 DCPOMATIC_ASSERT (!jm->get().empty());
848 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
849 DCPOMATIC_ASSERT (last);
851 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
856 void tools_check_for_updates ()
858 UpdateChecker::instance()->run ();
859 _update_news_requested = true;
864 AboutDialog* d = new AboutDialog (this);
869 void help_report_a_problem ()
871 ReportProblemDialog* d = new ReportProblemDialog (this);
872 if (d->ShowModal () == wxID_OK) {
878 void update_checker_state_changed ()
880 UpdateChecker* uc = UpdateChecker::instance ();
882 bool const announce =
883 _update_news_requested ||
884 (uc->stable() && Config::instance()->check_for_updates()) ||
885 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
887 _update_news_requested = false;
893 if (uc->state() == UpdateChecker::YES) {
894 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
895 dialog->ShowModal ();
897 } else if (uc->state() == UpdateChecker::FAILED) {
898 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
900 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
903 _update_news_requested = false;
906 void config_changed (Config::Property prop)
908 /* Instantly save any config changes when using the player GUI */
910 Config::instance()->write_config();
911 } catch (FileError& e) {
912 if (prop != Config::HISTORY) {
916 _("Could not write to config file at %s. Your changes have not been saved."),
917 std_to_wx(e.file().string())
921 } catch (exception& e) {
924 _("Could not write to config file. Your changes have not been saved.")
928 update_from_config ();
931 void update_from_config ()
933 for (int i = 0; i < _history_items; ++i) {
934 delete _file_menu->Remove (ID_file_history + i);
937 if (_history_separator) {
938 _file_menu->Remove (_history_separator);
940 delete _history_separator;
941 _history_separator = 0;
943 int pos = _history_position;
945 vector<boost::filesystem::path> history = Config::instance()->player_history ();
947 if (!history.empty ()) {
948 _history_separator = _file_menu->InsertSeparator (pos++);
951 for (size_t i = 0; i < history.size(); ++i) {
954 s = String::compose ("&%1 %2", i + 1, history[i].string());
956 s = history[i].string();
958 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
961 _history_items = history.size ();
964 void set_menu_sensitivity ()
966 _tools_verify->Enable (static_cast<bool>(_film));
967 _file_add_ov->Enable (static_cast<bool>(_film));
968 _file_add_kdm->Enable (static_cast<bool>(_film));
969 _view_cpl->Enable (static_cast<bool>(_film));
972 void start_stop_pressed ()
974 if (_viewer->playing()) {
983 _viewer->seek_by (-_viewer->one_video_frame(), true);
986 void forward_frame ()
988 _viewer->seek_by (_viewer->one_video_frame(), true);
993 wxFrame* _dual_screen;
994 bool _update_news_requested;
995 PlayerInformation* _info;
996 Config::PlayerMode _mode;
997 wxPreferencesEditor* _config_dialog;
998 wxPanel* _overall_panel;
1000 wxMenuItem* _view_cpl;
1003 int _history_position;
1004 wxMenuItem* _history_separator;
1005 shared_ptr<FilmViewer> _viewer;
1006 Controls* _controls;
1007 boost::shared_ptr<Film> _film;
1008 boost::signals2::scoped_connection _config_changed_connection;
1009 wxMenuItem* _file_add_ov;
1010 wxMenuItem* _file_add_kdm;
1011 wxMenuItem* _tools_verify;
1012 wxMenuItem* _view_full_screen;
1013 wxMenuItem* _view_dual_screen;
1016 static const wxCmdLineEntryDesc command_line_description[] = {
1017 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1018 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1021 class PlayServer : public Server
1024 explicit PlayServer (DOMFrame* frame)
1025 : Server (PLAYER_PLAY_PORT)
1029 void handle (shared_ptr<Socket> socket)
1032 int const length = socket->read_uint32 ();
1033 scoped_array<char> buffer (new char[length]);
1034 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1035 string s (buffer.get());
1036 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1037 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1048 * @brief The magic App class for wxWidgets.
1050 class App : public wxApp
1063 wxInitAllImageHandlers ();
1065 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1066 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1068 wxSplashScreen* splash = maybe_show_splash ();
1070 SetAppName (_("DCP-o-matic Player"));
1072 if (!wxApp::OnInit()) {
1076 #ifdef DCPOMATIC_LINUX
1077 unsetenv ("UBUNTU_MENUPROXY");
1081 ProcessSerialNumber serial;
1082 GetCurrentProcess (&serial);
1083 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1086 dcpomatic_setup_path_encoding ();
1088 /* Enable i18n; this will create a Config object
1089 to look for a force-configured language. This Config
1090 object will be wrong, however, because dcpomatic_setup
1091 hasn't yet been called and there aren't any filters etc.
1094 dcpomatic_setup_i18n ();
1096 /* Set things up, including filters etc.
1097 which will now be internationalised correctly.
1101 /* Force the configuration to be re-loaded correctly next
1106 signal_manager = new wxSignalManager (this);
1108 _frame = new DOMFrame ();
1109 SetTopWindow (_frame);
1110 _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 ();
1135 catch (exception& e)
1137 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1141 void OnInitCmdLine (wxCmdLineParser& parser)
1143 parser.SetDesc (command_line_description);
1144 parser.SetSwitchChars (wxT ("-"));
1147 bool OnCmdLineParsed (wxCmdLineParser& parser)
1149 if (parser.GetParamCount() > 0) {
1150 _dcp_to_load = wx_to_std (parser.GetParam (0));
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;