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"
40 #include "lib/spl_entry.h"
43 #include "lib/video_content.h"
44 #include "lib/text_content.h"
45 #include "lib/ratio.h"
46 #include "lib/verify_dcp_job.h"
47 #include "lib/dcp_examiner.h"
48 #include "lib/examine_content_job.h"
49 #include "lib/server.h"
50 #include "lib/dcpomatic_socket.h"
51 #include "lib/scoped_temporary.h"
52 #include "lib/monitor_checker.h"
54 #include <dcp/raw_convert.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);
203 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
204 _controls->SPLChanged.connect (boost::bind(&DOMFrame::set_spl, this, _1));
205 #ifdef DCPOMATIC_VARIANT_SWAROOP
206 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
207 MonitorChecker::instance()->run ();
211 #ifdef DCPOMATIC_VARIANT_SWAROOP
213 boost::filesystem::is_regular_file(Config::path("position")) &&
214 boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
216 set_spl (SPL(Config::path("spl.xml")));
217 FILE* f = fopen_boost (Config::path("position"), "r");
220 fscanf (f, "%63s", buffer);
221 _viewer->seek (DCPTime(atoi(buffer)), true);
230 void position_changed ()
232 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
236 FILE* f = fopen_boost (Config::path("position"), "w");
238 string const p = dcp::raw_convert<string> (_viewer->position().get());
239 fwrite (p.c_str(), p.length(), 1, f);
244 #ifdef DCPOMATIC_VARIANT_SWAROOP
245 void monitor_checker_state_changed ()
247 if (!MonitorChecker::instance()->ok()) {
248 error_dialog (this, _("The required display devices are not connected correctly."));
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."));
274 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
279 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
280 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
281 if (d && !d->kdm_timing_window_valid()) {
287 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
293 void playback_started (DCPTime time)
295 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
300 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
301 DCPOMATIC_ASSERT (dcp);
302 DCPExaminer ex (dcp);
303 shared_ptr<dcp::CPL> playing_cpl;
304 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
305 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
309 DCPOMATIC_ASSERT (playing_cpl)
311 FILE* f = fopen_boost(*log, "a");
314 "%s playback-started %s %s %s\n",
315 dcp::LocalTime().as_string().c_str(),
316 time.timecode(_film->video_frame_rate()).c_str(),
317 dcp->directories().front().string().c_str(),
318 playing_cpl->annotation_text().c_str()
323 void playback_seeked (DCPTime time)
325 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
330 FILE* f = fopen_boost(*log, "a");
331 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
335 void playback_stopped (DCPTime time)
337 #ifdef DCPOMATIC_VARIANT_SWAROOP
339 boost::filesystem::remove (Config::path("position"));
345 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
350 FILE* f = fopen_boost(*log, "a");
351 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
355 void set_decode_reduction (optional<int> reduction)
357 _viewer->set_dcp_decode_reduction (reduction);
358 _info->triggered_update ();
359 Config::instance()->set_decode_reduction (reduction);
362 void load_dcp (boost::filesystem::path dir)
367 BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
368 spl.playlist.push_back (SPLEntry(j, dir));
371 Config::instance()->add_to_player_history (dir);
374 #ifdef DCPOMATIC_VARIANT_SWAROOP
375 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
377 ScopedTemporary temp;
378 string url = Config::instance()->kdm_server_url();
379 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
380 optional<dcp::EncryptedKDM> kdm;
381 if (dcp->cpl() && !get_from_url(url, false, temp)) {
383 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
384 if (kdm->cpl_id() != dcp->cpl()) {
387 } catch (std::exception& e) {
395 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
397 using namespace boost::filesystem;
398 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
400 return optional<dcp::EncryptedKDM>();
402 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
404 if (file_size(i->path()) < MAX_KDM_SIZE) {
405 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
406 if (kdm.cpl_id() == dcp->cpl()) {
410 } catch (std::exception& e) {
414 return optional<dcp::EncryptedKDM>();
417 void set_spl (SPL spl)
419 #ifdef DCPOMATIC_VARIANT_SWAROOP
420 spl.as_xml (Config::path("spl.xml"));
423 if (_viewer->playing ()) {
427 _film.reset (new Film (optional<boost::filesystem::path>()));
429 if (spl.playlist.empty ()) {
430 _viewer->set_film (_film);
431 _info->triggered_update ();
435 /* Start off as Flat */
436 _film->set_container (Ratio::from_id("185"));
438 /* Put 1 frame of black at the start so when we seek to 0 we don't see anything */
439 DCPTime position = DCPTime::from_frames(1, _film->video_frame_rate());
440 shared_ptr<DCPContent> first;
442 BOOST_FOREACH (SPLEntry i, spl.playlist) {
443 shared_ptr<DCPContent> dcp;
445 dcp.reset (new DCPContent (_film, i.directory));
446 } catch (boost::filesystem::filesystem_error& e) {
447 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
455 _film->examine_and_add_content (dcp, true);
456 bool const ok = progress (_("Loading DCP"));
457 if (!ok || !report_errors_from_last_job()) {
461 dcp->set_position (position + i.black_before);
462 position += dcp->length_after_trim() + i.black_before;
464 /* This DCP has been examined and loaded */
466 if (dcp->needs_kdm()) {
467 optional<dcp::EncryptedKDM> kdm;
468 #ifdef DCPOMATIC_VARIANT_SWAROOP
469 kdm = get_kdm_from_url (dcp);
472 get_kdm_from_directory (dcp);
477 dcp->examine (shared_ptr<Job>());
481 BOOST_FOREACH (shared_ptr<TextContent> j, dcp->text) {
486 Ratio const * r = Ratio::nearest_from_ratio(dcp->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 (dcp->three_d()) {
495 _film->set_three_d (true);
498 _viewer->set_film (_film);
499 _viewer->seek (DCPTime(), true);
500 _info->triggered_update ();
502 set_menu_sensitivity ();
503 _controls->log (wxString::Format(_("Load DCP %s"), i.directory.filename().string().c_str()));
506 wxMenuItemList old = _cpl_menu->GetMenuItems();
507 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
508 _cpl_menu->Remove (*i);
511 if (spl.playlist.size() == 1) {
512 /* Offer a CPL menu */
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());
528 void setup_menu (wxMenuBar* m)
530 _file_menu = new wxMenu;
531 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
532 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
533 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
535 _history_position = _file_menu->GetMenuItems().GetCount();
537 _file_menu->AppendSeparator ();
538 _file_menu->Append (ID_file_close, _("&Close"));
539 _file_menu->AppendSeparator ();
542 _file_menu->Append (wxID_EXIT, _("&Exit"));
544 _file_menu->Append (wxID_EXIT, _("&Quit"));
548 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
550 wxMenu* edit = new wxMenu;
551 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
554 prefs->Enable (Config::instance()->have_write_permission());
556 _cpl_menu = new wxMenu;
558 wxMenu* view = new wxMenu;
559 optional<int> c = Config::instance()->decode_reduction();
560 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
561 view->AppendSeparator();
562 #ifndef DCPOMATIC_VARIANT_SWAROOP
563 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
564 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
567 view->AppendSeparator();
568 view->Append(ID_view_closed_captions, _("Closed captions..."));
569 view->AppendSeparator();
570 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
571 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
572 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
573 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
575 wxMenu* tools = new wxMenu;
576 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
577 tools->AppendSeparator ();
578 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
580 wxMenu* help = new wxMenu;
582 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
584 help->Append (wxID_ABOUT, _("About"));
586 help->Append (ID_help_report_a_problem, _("Report a problem..."));
588 m->Append (_file_menu, _("&File"));
590 m->Append (edit, _("&Edit"));
592 m->Append (view, _("&View"));
593 m->Append (tools, _("&Tools"));
594 m->Append (help, _("&Help"));
599 wxString d = wxStandardPaths::Get().GetDocumentsDir();
600 if (Config::instance()->last_player_load_directory()) {
601 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
604 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
609 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
610 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
617 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
619 Config::instance()->set_last_player_load_directory (dcp.parent_path());
627 wxDirDialog* c = new wxDirDialog (
629 _("Select DCP to open as OV"),
630 wxStandardPaths::Get().GetDocumentsDir(),
631 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
637 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
638 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
645 DCPOMATIC_ASSERT (_film);
646 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
647 DCPOMATIC_ASSERT (dcp);
648 dcp->add_ov (wx_to_std(c->GetPath()));
649 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
650 bool const ok = progress (_("Loading DCP"));
651 if (!ok || !report_errors_from_last_job()) {
654 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
658 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
660 _film->set_container(r);
666 _info->triggered_update ();
671 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
673 if (d->ShowModal() == wxID_OK) {
674 DCPOMATIC_ASSERT (_film);
675 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
676 DCPOMATIC_ASSERT (dcp);
678 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
679 dcp->examine (shared_ptr<Job>());
680 } catch (exception& e) {
681 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
688 _info->triggered_update ();
691 void file_history (wxCommandEvent& event)
693 vector<boost::filesystem::path> history = Config::instance()->player_history ();
694 int n = event.GetId() - ID_file_history;
695 if (n >= 0 && n < static_cast<int> (history.size ())) {
696 load_dcp (history[n]);
702 _viewer->set_film (shared_ptr<Film>());
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);
784 if (_mode == Config::PLAYER_MODE_DUAL) {
785 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
786 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
787 _dual_screen->ShowFullScreen (true);
788 _viewer->panel()->Reparent (_dual_screen);
789 _dual_screen->Show ();
790 if (wxDisplay::GetCount() > 1) {
791 switch (Config::instance()->image_display()) {
793 _dual_screen->Move (0, 0);
794 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
797 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
798 // (0, 0) doesn't seem to work for some strange reason
805 _viewer->panel()->Reparent (_overall_panel);
806 _dual_screen->Destroy ();
811 setup_main_sizer (_mode);
814 void view_closed_captions ()
816 _viewer->show_closed_captions ();
821 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
822 DCPOMATIC_ASSERT (dcp);
824 JobManager* jm = JobManager::instance ();
825 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
826 bool const ok = progress (_("Verifying DCP"));
831 DCPOMATIC_ASSERT (!jm->get().empty());
832 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
833 DCPOMATIC_ASSERT (last);
835 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
840 void tools_check_for_updates ()
842 UpdateChecker::instance()->run ();
843 _update_news_requested = true;
848 AboutDialog* d = new AboutDialog (this);
853 void help_report_a_problem ()
855 ReportProblemDialog* d = new ReportProblemDialog (this);
856 if (d->ShowModal () == wxID_OK) {
862 void update_checker_state_changed ()
864 UpdateChecker* uc = UpdateChecker::instance ();
866 bool const announce =
867 _update_news_requested ||
868 (uc->stable() && Config::instance()->check_for_updates()) ||
869 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
871 _update_news_requested = false;
877 if (uc->state() == UpdateChecker::YES) {
878 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
879 dialog->ShowModal ();
881 } else if (uc->state() == UpdateChecker::FAILED) {
882 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
884 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
887 _update_news_requested = false;
890 void config_changed (Config::Property prop)
892 /* Instantly save any config changes when using the player GUI */
894 Config::instance()->write_config();
895 } catch (FileError& e) {
896 if (prop != Config::HISTORY) {
900 _("Could not write to config file at %s. Your changes have not been saved."),
901 std_to_wx(e.file().string())
905 } catch (exception& e) {
908 _("Could not write to config file. Your changes have not been saved.")
912 update_from_config ();
915 void update_from_config ()
917 for (int i = 0; i < _history_items; ++i) {
918 delete _file_menu->Remove (ID_file_history + i);
921 if (_history_separator) {
922 _file_menu->Remove (_history_separator);
924 delete _history_separator;
925 _history_separator = 0;
927 int pos = _history_position;
929 vector<boost::filesystem::path> history = Config::instance()->player_history ();
931 if (!history.empty ()) {
932 _history_separator = _file_menu->InsertSeparator (pos++);
935 for (size_t i = 0; i < history.size(); ++i) {
938 s = String::compose ("&%1 %2", i + 1, history[i].string());
940 s = history[i].string();
942 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
945 _history_items = history.size ();
948 void set_menu_sensitivity ()
950 _tools_verify->Enable (static_cast<bool>(_film));
951 _file_add_ov->Enable (static_cast<bool>(_film));
952 _file_add_kdm->Enable (static_cast<bool>(_film));
953 _view_cpl->Enable (static_cast<bool>(_film));
956 void start_stop_pressed ()
958 if (_viewer->playing()) {
967 _viewer->seek_by (-_viewer->one_video_frame(), true);
970 void forward_frame ()
972 _viewer->seek_by (_viewer->one_video_frame(), true);
977 /** @return false if the task was cancelled */
978 bool progress (wxString task)
980 JobManager* jm = JobManager::instance ();
982 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
986 while (jm->work_to_do() || signal_manager->ui_idle()) {
988 if (!progress->Pulse()) {
989 /* user pressed cancel */
990 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
998 progress->Destroy ();
1002 bool report_errors_from_last_job ()
1004 JobManager* jm = JobManager::instance ();
1006 DCPOMATIC_ASSERT (!jm->get().empty());
1008 shared_ptr<Job> last = jm->get().back();
1009 if (last->finished_in_error()) {
1010 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
1017 wxFrame* _dual_screen;
1018 bool _update_news_requested;
1019 PlayerInformation* _info;
1020 Config::PlayerMode _mode;
1021 wxPreferencesEditor* _config_dialog;
1022 wxPanel* _overall_panel;
1024 wxMenuItem* _view_cpl;
1027 int _history_position;
1028 wxMenuItem* _history_separator;
1029 shared_ptr<FilmViewer> _viewer;
1030 Controls* _controls;
1031 boost::shared_ptr<Film> _film;
1032 boost::signals2::scoped_connection _config_changed_connection;
1033 wxMenuItem* _file_add_ov;
1034 wxMenuItem* _file_add_kdm;
1035 wxMenuItem* _tools_verify;
1036 wxMenuItem* _view_full_screen;
1037 wxMenuItem* _view_dual_screen;
1040 static const wxCmdLineEntryDesc command_line_description[] = {
1041 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1042 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1045 class PlayServer : public Server
1048 explicit PlayServer (DOMFrame* frame)
1049 : Server (PLAYER_PLAY_PORT)
1053 void handle (shared_ptr<Socket> socket)
1056 int const length = socket->read_uint32 ();
1057 scoped_array<char> buffer (new char[length]);
1058 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1059 string s (buffer.get());
1060 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1061 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1072 * @brief The magic App class for wxWidgets.
1074 class App : public wxApp
1087 wxInitAllImageHandlers ();
1089 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1090 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1092 wxSplashScreen* splash = maybe_show_splash ();
1094 SetAppName (_("DCP-o-matic Player"));
1096 if (!wxApp::OnInit()) {
1100 #ifdef DCPOMATIC_LINUX
1101 unsetenv ("UBUNTU_MENUPROXY");
1105 ProcessSerialNumber serial;
1106 GetCurrentProcess (&serial);
1107 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1110 dcpomatic_setup_path_encoding ();
1112 /* Enable i18n; this will create a Config object
1113 to look for a force-configured language. This Config
1114 object will be wrong, however, because dcpomatic_setup
1115 hasn't yet been called and there aren't any filters etc.
1118 dcpomatic_setup_i18n ();
1120 /* Set things up, including filters etc.
1121 which will now be internationalised correctly.
1125 /* Force the configuration to be re-loaded correctly next
1130 signal_manager = new wxSignalManager (this);
1132 _frame = new DOMFrame ();
1133 SetTopWindow (_frame);
1134 _frame->Maximize ();
1140 PlayServer* server = new PlayServer (_frame);
1141 new thread (boost::bind (&PlayServer::run, server));
1143 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1145 _frame->load_dcp (_dcp_to_load);
1146 } catch (exception& e) {
1147 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1151 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1153 if (Config::instance()->check_for_updates ()) {
1154 UpdateChecker::instance()->run ();
1159 catch (exception& e)
1161 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1165 void OnInitCmdLine (wxCmdLineParser& parser)
1167 parser.SetDesc (command_line_description);
1168 parser.SetSwitchChars (wxT ("-"));
1171 bool OnCmdLineParsed (wxCmdLineParser& parser)
1173 if (parser.GetParamCount() > 0) {
1174 _dcp_to_load = wx_to_std (parser.GetParam (0));
1180 void report_exception ()
1184 } catch (FileError& e) {
1188 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1189 std_to_wx (e.what()),
1190 std_to_wx (e.file().string().c_str ())
1193 } catch (exception& e) {
1197 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1198 std_to_wx (e.what ())
1202 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1206 /* An unhandled exception has occurred inside the main event loop */
1207 bool OnExceptionInMainLoop ()
1209 report_exception ();
1210 /* This will terminate the program */
1214 void OnUnhandledException ()
1216 report_exception ();
1221 signal_manager->ui_idle ();
1224 void config_failed_to_load ()
1226 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1229 void config_warning (string m)
1231 message_dialog (_frame, std_to_wx (m));
1235 string _dcp_to_load;