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/ffmpeg_content.h"
53 #include <dcp/raw_convert.h>
54 #include <dcp/exceptions.h>
56 #include <wx/stdpaths.h>
57 #include <wx/splash.h>
58 #include <wx/cmdline.h>
59 #include <wx/preferences.h>
60 #include <wx/progdlg.h>
61 #include <wx/display.h>
63 #include <ApplicationServices/ApplicationServices.h>
65 #include <boost/bind.hpp>
79 using boost::shared_ptr;
80 using boost::scoped_array;
81 using boost::optional;
82 using boost::dynamic_pointer_cast;
91 /* Allow spare IDs after _history for the recent files list */
94 /* Allow spare IDs for CPLs */
95 ID_view_full_screen = 200,
97 ID_view_closed_captions,
98 ID_view_scale_appropriate,
101 ID_view_scale_quarter,
102 ID_help_report_a_problem,
104 ID_tools_check_for_updates,
105 /* IDs for shortcuts (with no associated menu item) */
111 class DOMFrame : public wxFrame
115 : wxFrame (0, -1, _("DCP-o-matic Player"))
117 , _update_news_requested (false)
119 , _mode (Config::instance()->player_mode())
123 , _history_position (0)
124 , _history_separator (0)
125 , _view_full_screen (0)
126 , _view_dual_screen (0)
129 #if defined(DCPOMATIC_WINDOWS)
130 maybe_open_console ();
131 cout << "DCP-o-matic Player is starting." << "\n";
134 wxMenuBar* bar = new wxMenuBar;
136 set_menu_sensitivity ();
139 #ifdef DCPOMATIC_WINDOWS
140 SetIcon (wxIcon (std_to_wx ("id")));
143 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
144 update_from_config ();
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
163 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
165 /* Use a panel as the only child of the Frame so that we avoid
166 the dark-grey background on Windows.
168 _overall_panel = new wxPanel (this, wxID_ANY);
170 _viewer.reset (new FilmViewer (_overall_panel));
171 _controls = new Controls (_overall_panel, _viewer, false);
172 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
173 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
174 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
175 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
176 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
177 #ifdef DCPOMATIC_VARIANT_SWAROOP
178 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
180 _info = new PlayerInformation (_overall_panel, _viewer);
181 setup_main_sizer (Config::instance()->player_mode());
183 int accelerators = 4;
185 int accelerators = 3;
188 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
189 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
190 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
191 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
193 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
195 wxAcceleratorTable accel_table (accelerators, accel);
196 SetAcceleratorTable (accel_table);
199 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
200 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
201 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
205 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
206 #ifdef DCPOMATIC_VARIANT_SWAROOP
207 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
208 MonitorChecker::instance()->run ();
212 #ifdef DCPOMATIC_VARIANT_SWAROOP
214 boost::filesystem::is_regular_file(Config::path("position")) &&
215 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
217 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
218 film->read_metadata (Config::path("spl.xml"));
220 FILE* f = fopen_boost (Config::path("position"), "r");
223 fscanf (f, "%63s", buffer);
224 _viewer->seek (DCPTime(atoi(buffer)), true);
233 void position_changed ()
235 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
239 FILE* f = fopen_boost (Config::path("position"), "w");
241 string const p = dcp::raw_convert<string> (_viewer->position().get());
242 fwrite (p.c_str(), p.length(), 1, f);
247 #ifdef DCPOMATIC_VARIANT_SWAROOP
248 void monitor_checker_state_changed ()
250 if (!MonitorChecker::instance()->ok()) {
251 error_dialog (this, _("The required display devices are not connected correctly."));
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."));
277 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
282 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
283 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
284 if (d && !d->kdm_timing_window_valid()) {
290 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
296 void playback_started (DCPTime time)
298 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
303 FILE* f = fopen_boost(*log, "a");
305 /* XXX: this only logs the first piece of content; probably should be each piece? */
307 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
309 DCPExaminer ex (dcp);
310 shared_ptr<dcp::CPL> playing_cpl;
311 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
312 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
316 DCPOMATIC_ASSERT (playing_cpl);
320 "%s playback-started %s %s %s\n",
321 dcp::LocalTime().as_string().c_str(),
322 time.timecode(_film->video_frame_rate()).c_str(),
323 dcp->directories().front().string().c_str(),
324 playing_cpl->annotation_text().c_str()
328 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
332 "%s playback-started %s %s\n",
333 dcp::LocalTime().as_string().c_str(),
334 time.timecode(_film->video_frame_rate()).c_str(),
335 ffmpeg->path(0).string().c_str()
342 void playback_seeked (DCPTime time)
344 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
349 FILE* f = fopen_boost(*log, "a");
350 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
354 void playback_stopped (DCPTime time)
356 #ifdef DCPOMATIC_VARIANT_SWAROOP
358 boost::filesystem::remove (Config::path("position"));
364 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
369 FILE* f = fopen_boost(*log, "a");
370 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
374 void set_decode_reduction (optional<int> reduction)
376 _viewer->set_dcp_decode_reduction (reduction);
377 _info->triggered_update ();
378 Config::instance()->set_decode_reduction (reduction);
381 void load_dcp (boost::filesystem::path dir)
383 DCPOMATIC_ASSERT (_film);
387 shared_ptr<DCPContent> dcp (new DCPContent(_film, dir));
388 _film->examine_and_add_content (dcp);
389 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
390 if (!ok || !report_errors_from_last_job(this)) {
393 Config::instance()->add_to_player_history (dir);
394 } catch (dcp::DCPReadError& e) {
395 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
399 #ifdef DCPOMATIC_VARIANT_SWAROOP
400 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
402 ScopedTemporary temp;
403 string url = Config::instance()->kdm_server_url();
404 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
405 optional<dcp::EncryptedKDM> kdm;
406 if (dcp->cpl() && !get_from_url(url, false, temp)) {
408 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
409 if (kdm->cpl_id() != dcp->cpl()) {
412 } catch (std::exception& e) {
420 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
422 using namespace boost::filesystem;
423 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
425 return optional<dcp::EncryptedKDM>();
427 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
429 if (file_size(i->path()) < MAX_KDM_SIZE) {
430 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
431 if (kdm.cpl_id() == dcp->cpl()) {
435 } catch (std::exception& e) {
439 return optional<dcp::EncryptedKDM>();
442 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
445 _viewer->set_film (_film);
446 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
449 void film_changed (ChangeType type, Film::Property property)
451 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
455 _film->write_metadata (Config::path("spl.xml"));
457 if (_viewer->playing ()) {
461 /* Start off as Flat */
462 _film->set_container (Ratio::from_id("185"));
464 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
465 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
466 if (dcp && dcp->needs_kdm()) {
467 optional<dcp::EncryptedKDM> kdm;
468 #ifdef DCPOMATIC_VARIANT_SWAROOP
469 kdm = get_kdm_from_url (dcp);
472 kdm = get_kdm_from_directory (dcp);
477 dcp->examine (shared_ptr<Job>());
481 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
486 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
487 if (r->id() == "239") {
488 /* Any scope content means we use scope */
489 _film->set_container(r);
493 /* Any 3D content means we use 3D mode */
494 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
495 _film->set_three_d (true);
499 _viewer->seek (DCPTime(), true);
500 _info->triggered_update ();
502 set_menu_sensitivity ();
504 wxMenuItemList old = _cpl_menu->GetMenuItems();
505 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
506 _cpl_menu->Remove (*i);
509 if (_film->content().size() == 1) {
510 /* Offer a CPL menu */
511 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
513 DCPExaminer ex (first);
514 int id = ID_view_cpl;
515 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
516 wxMenuItem* j = _cpl_menu->AppendRadioItem(
518 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
520 j->Check(!first->cpl() || i->id() == *first->cpl());
529 void setup_menu (wxMenuBar* m)
531 _file_menu = new wxMenu;
532 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
533 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
534 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
536 _history_position = _file_menu->GetMenuItems().GetCount();
538 _file_menu->AppendSeparator ();
539 _file_menu->Append (ID_file_close, _("&Close"));
540 _file_menu->AppendSeparator ();
543 _file_menu->Append (wxID_EXIT, _("&Exit"));
545 _file_menu->Append (wxID_EXIT, _("&Quit"));
549 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
551 wxMenu* edit = new wxMenu;
552 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
555 prefs->Enable (Config::instance()->have_write_permission());
557 _cpl_menu = new wxMenu;
559 wxMenu* view = new wxMenu;
560 optional<int> c = Config::instance()->decode_reduction();
561 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
562 view->AppendSeparator();
563 #ifndef DCPOMATIC_VARIANT_SWAROOP
564 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
565 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
568 view->AppendSeparator();
569 view->Append(ID_view_closed_captions, _("Closed captions..."));
570 view->AppendSeparator();
571 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
572 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
573 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
574 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
576 wxMenu* tools = new wxMenu;
577 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
578 tools->AppendSeparator ();
579 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
581 wxMenu* help = new wxMenu;
583 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
585 help->Append (wxID_ABOUT, _("About"));
587 help->Append (ID_help_report_a_problem, _("Report a problem..."));
589 m->Append (_file_menu, _("&File"));
591 m->Append (edit, _("&Edit"));
593 m->Append (view, _("&View"));
594 m->Append (tools, _("&Tools"));
595 m->Append (help, _("&Help"));
600 wxString d = wxStandardPaths::Get().GetDocumentsDir();
601 if (Config::instance()->last_player_load_directory()) {
602 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
605 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
610 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
611 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
618 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
620 Config::instance()->set_last_player_load_directory (dcp.parent_path());
628 wxDirDialog* c = new wxDirDialog (
630 _("Select DCP to open as OV"),
631 wxStandardPaths::Get().GetDocumentsDir(),
632 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
638 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
639 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
646 DCPOMATIC_ASSERT (_film);
647 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
648 DCPOMATIC_ASSERT (dcp);
649 dcp->add_ov (wx_to_std(c->GetPath()));
650 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
651 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
652 if (!ok || !report_errors_from_last_job(this)) {
655 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
659 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
661 _film->set_container(r);
667 _info->triggered_update ();
672 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
674 if (d->ShowModal() == wxID_OK) {
675 DCPOMATIC_ASSERT (_film);
676 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
677 DCPOMATIC_ASSERT (dcp);
679 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
680 dcp->examine (shared_ptr<Job>());
681 } catch (exception& e) {
682 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
689 _info->triggered_update ();
692 void file_history (wxCommandEvent& event)
694 vector<boost::filesystem::path> history = Config::instance()->player_history ();
695 int n = event.GetId() - ID_file_history;
696 if (n >= 0 && n < static_cast<int> (history.size ())) {
697 load_dcp (history[n]);
704 _info->triggered_update ();
705 set_menu_sensitivity ();
713 void edit_preferences ()
715 if (!Config::instance()->have_write_permission()) {
719 if (!_config_dialog) {
720 _config_dialog = create_player_config_dialog ();
722 _config_dialog->Show (this);
725 void view_cpl (wxCommandEvent& ev)
727 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
728 DCPOMATIC_ASSERT (dcp);
729 DCPExaminer ex (dcp);
730 int id = ev.GetId() - ID_view_cpl;
731 DCPOMATIC_ASSERT (id >= 0);
732 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
733 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
734 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
740 dcp->set_cpl ((*i)->id());
741 dcp->examine (shared_ptr<Job>());
744 void view_full_screen ()
746 if (_mode == Config::PLAYER_MODE_FULL) {
747 _mode = Config::PLAYER_MODE_WINDOW;
749 _mode = Config::PLAYER_MODE_FULL;
755 void view_dual_screen ()
757 if (_mode == Config::PLAYER_MODE_DUAL) {
758 _mode = Config::PLAYER_MODE_WINDOW;
760 _mode = Config::PLAYER_MODE_DUAL;
768 if (_view_full_screen) {
769 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
771 if (_view_dual_screen) {
772 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
778 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
779 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
780 _info->Show (_mode != Config::PLAYER_MODE_FULL);
781 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
782 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
783 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
785 if (_mode == Config::PLAYER_MODE_DUAL) {
786 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
787 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
788 _dual_screen->ShowFullScreen (true);
789 _viewer->panel()->Reparent (_dual_screen);
790 _dual_screen->Show ();
791 if (wxDisplay::GetCount() > 1) {
792 switch (Config::instance()->image_display()) {
794 _dual_screen->Move (0, 0);
795 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
798 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
799 // (0, 0) doesn't seem to work for some strange reason
806 _viewer->panel()->Reparent (_overall_panel);
807 _dual_screen->Destroy ();
812 setup_main_sizer (_mode);
815 void view_closed_captions ()
817 _viewer->show_closed_captions ();
822 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
823 DCPOMATIC_ASSERT (dcp);
825 JobManager* jm = JobManager::instance ();
826 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
827 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
832 DCPOMATIC_ASSERT (!jm->get().empty());
833 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
834 DCPOMATIC_ASSERT (last);
836 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
841 void tools_check_for_updates ()
843 UpdateChecker::instance()->run ();
844 _update_news_requested = true;
849 AboutDialog* d = new AboutDialog (this);
854 void help_report_a_problem ()
856 ReportProblemDialog* d = new ReportProblemDialog (this);
857 if (d->ShowModal () == wxID_OK) {
863 void update_checker_state_changed ()
865 UpdateChecker* uc = UpdateChecker::instance ();
867 bool const announce =
868 _update_news_requested ||
869 (uc->stable() && Config::instance()->check_for_updates()) ||
870 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
872 _update_news_requested = false;
878 if (uc->state() == UpdateChecker::YES) {
879 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
880 dialog->ShowModal ();
882 } else if (uc->state() == UpdateChecker::FAILED) {
883 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
885 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
888 _update_news_requested = false;
891 void config_changed (Config::Property prop)
893 /* Instantly save any config changes when using the player GUI */
895 Config::instance()->write_config();
896 } catch (FileError& e) {
897 if (prop != Config::HISTORY) {
901 _("Could not write to config file at %s. Your changes have not been saved."),
902 std_to_wx(e.file().string())
906 } catch (exception& e) {
909 _("Could not write to config file. Your changes have not been saved.")
913 update_from_config ();
916 void update_from_config ()
918 for (int i = 0; i < _history_items; ++i) {
919 delete _file_menu->Remove (ID_file_history + i);
922 if (_history_separator) {
923 _file_menu->Remove (_history_separator);
925 delete _history_separator;
926 _history_separator = 0;
928 int pos = _history_position;
930 vector<boost::filesystem::path> history = Config::instance()->player_history ();
932 if (!history.empty ()) {
933 _history_separator = _file_menu->InsertSeparator (pos++);
936 for (size_t i = 0; i < history.size(); ++i) {
939 s = String::compose ("&%1 %2", i + 1, history[i].string());
941 s = history[i].string();
943 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
946 _history_items = history.size ();
949 void set_menu_sensitivity ()
951 _tools_verify->Enable (static_cast<bool>(_film));
952 _file_add_ov->Enable (static_cast<bool>(_film));
953 _file_add_kdm->Enable (static_cast<bool>(_film));
954 _view_cpl->Enable (static_cast<bool>(_film));
957 void start_stop_pressed ()
959 if (_viewer->playing()) {
968 _viewer->seek_by (-_viewer->one_video_frame(), true);
971 void forward_frame ()
973 _viewer->seek_by (_viewer->one_video_frame(), true);
978 wxFrame* _dual_screen;
979 bool _update_news_requested;
980 PlayerInformation* _info;
981 Config::PlayerMode _mode;
982 wxPreferencesEditor* _config_dialog;
983 wxPanel* _overall_panel;
985 wxMenuItem* _view_cpl;
988 int _history_position;
989 wxMenuItem* _history_separator;
990 shared_ptr<FilmViewer> _viewer;
992 boost::shared_ptr<Film> _film;
993 boost::signals2::scoped_connection _config_changed_connection;
994 wxMenuItem* _file_add_ov;
995 wxMenuItem* _file_add_kdm;
996 wxMenuItem* _tools_verify;
997 wxMenuItem* _view_full_screen;
998 wxMenuItem* _view_dual_screen;
1001 static const wxCmdLineEntryDesc command_line_description[] = {
1002 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1003 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1006 class PlayServer : public Server
1009 explicit PlayServer (DOMFrame* frame)
1010 : Server (PLAYER_PLAY_PORT)
1014 void handle (shared_ptr<Socket> socket)
1017 int const length = socket->read_uint32 ();
1018 scoped_array<char> buffer (new char[length]);
1019 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1020 string s (buffer.get());
1021 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1022 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1033 * @brief The magic App class for wxWidgets.
1035 class App : public wxApp
1048 wxInitAllImageHandlers ();
1050 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1051 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1053 wxSplashScreen* splash = maybe_show_splash ();
1055 SetAppName (_("DCP-o-matic Player"));
1057 if (!wxApp::OnInit()) {
1061 #ifdef DCPOMATIC_LINUX
1062 unsetenv ("UBUNTU_MENUPROXY");
1066 ProcessSerialNumber serial;
1067 GetCurrentProcess (&serial);
1068 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1071 dcpomatic_setup_path_encoding ();
1073 /* Enable i18n; this will create a Config object
1074 to look for a force-configured language. This Config
1075 object will be wrong, however, because dcpomatic_setup
1076 hasn't yet been called and there aren't any filters etc.
1079 dcpomatic_setup_i18n ();
1081 /* Set things up, including filters etc.
1082 which will now be internationalised correctly.
1086 /* Force the configuration to be re-loaded correctly next
1091 signal_manager = new wxSignalManager (this);
1093 _frame = new DOMFrame ();
1094 SetTopWindow (_frame);
1095 _frame->Maximize ();
1101 PlayServer* server = new PlayServer (_frame);
1102 new thread (boost::bind (&PlayServer::run, server));
1104 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1106 _frame->load_dcp (_dcp_to_load);
1107 } catch (exception& e) {
1108 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1112 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1114 if (Config::instance()->check_for_updates ()) {
1115 UpdateChecker::instance()->run ();
1120 catch (exception& e)
1122 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1126 void OnInitCmdLine (wxCmdLineParser& parser)
1128 parser.SetDesc (command_line_description);
1129 parser.SetSwitchChars (wxT ("-"));
1132 bool OnCmdLineParsed (wxCmdLineParser& parser)
1134 if (parser.GetParamCount() > 0) {
1135 _dcp_to_load = wx_to_std (parser.GetParam (0));
1141 void report_exception ()
1145 } catch (FileError& e) {
1149 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1150 std_to_wx (e.what()),
1151 std_to_wx (e.file().string().c_str ())
1154 } catch (exception& e) {
1158 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1159 std_to_wx (e.what ())
1163 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1167 /* An unhandled exception has occurred inside the main event loop */
1168 bool OnExceptionInMainLoop ()
1170 report_exception ();
1171 /* This will terminate the program */
1175 void OnUnhandledException ()
1177 report_exception ();
1182 signal_manager->ui_idle ();
1185 void config_failed_to_load ()
1187 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1190 void config_warning (string m)
1192 message_dialog (_frame, std_to_wx (m));
1196 string _dcp_to_load;