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"
52 #include <dcp/raw_convert.h>
53 #include <dcp/exceptions.h>
55 #include <wx/stdpaths.h>
56 #include <wx/splash.h>
57 #include <wx/cmdline.h>
58 #include <wx/preferences.h>
59 #include <wx/progdlg.h>
60 #include <wx/display.h>
62 #include <ApplicationServices/ApplicationServices.h>
64 #include <boost/bind.hpp>
78 using boost::shared_ptr;
79 using boost::scoped_array;
80 using boost::optional;
81 using boost::dynamic_pointer_cast;
90 /* Allow spare IDs after _history for the recent files list */
93 /* Allow spare IDs for CPLs */
94 ID_view_full_screen = 200,
96 ID_view_closed_captions,
97 ID_view_scale_appropriate,
100 ID_view_scale_quarter,
101 ID_help_report_a_problem,
103 ID_tools_check_for_updates,
104 /* IDs for shortcuts (with no associated menu item) */
110 class DOMFrame : public wxFrame
114 : wxFrame (0, -1, _("DCP-o-matic Player"))
116 , _update_news_requested (false)
118 , _mode (Config::instance()->player_mode())
122 , _history_position (0)
123 , _history_separator (0)
124 , _view_full_screen (0)
125 , _view_dual_screen (0)
128 #if defined(DCPOMATIC_WINDOWS)
129 maybe_open_console ();
130 cout << "DCP-o-matic Player is starting." << "\n";
133 wxMenuBar* bar = new wxMenuBar;
135 set_menu_sensitivity ();
138 #ifdef DCPOMATIC_WINDOWS
139 SetIcon (wxIcon (std_to_wx ("id")));
142 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
143 update_from_config ();
145 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
161 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
162 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
164 /* Use a panel as the only child of the Frame so that we avoid
165 the dark-grey background on Windows.
167 _overall_panel = new wxPanel (this, wxID_ANY);
169 _viewer.reset (new FilmViewer (_overall_panel));
170 _controls = new Controls (_overall_panel, _viewer, false);
171 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
172 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
173 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
174 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
175 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
176 #ifdef DCPOMATIC_VARIANT_SWAROOP
177 _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
179 _info = new PlayerInformation (_overall_panel, _viewer);
180 setup_main_sizer (Config::instance()->player_mode());
182 int accelerators = 4;
184 int accelerators = 3;
187 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
188 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
189 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
190 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
192 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
194 wxAcceleratorTable accel_table (accelerators, accel);
195 SetAcceleratorTable (accel_table);
198 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
199 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
200 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
204 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
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 shared_ptr<Film> film (new Film(boost::optional<boost::filesystem::path>()));
217 film->read_metadata (Config::path("spl.xml"));
219 FILE* f = fopen_boost (Config::path("position"), "r");
222 fscanf (f, "%63s", buffer);
223 _viewer->seek (DCPTime(atoi(buffer)), true);
232 void position_changed ()
234 if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
238 FILE* f = fopen_boost (Config::path("position"), "w");
240 string const p = dcp::raw_convert<string> (_viewer->position().get());
241 fwrite (p.c_str(), p.length(), 1, f);
246 #ifdef DCPOMATIC_VARIANT_SWAROOP
247 void monitor_checker_state_changed ()
249 if (!MonitorChecker::instance()->ok()) {
250 error_dialog (this, _("The required display devices are not connected correctly."));
256 void setup_main_sizer (Config::PlayerMode mode)
258 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
259 if (mode != Config::PLAYER_MODE_DUAL) {
260 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
262 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
263 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
264 _overall_panel->SetSizer (main_sizer);
265 _overall_panel->Layout ();
268 bool playback_permitted ()
270 #ifdef DCPOMATIC_VARIANT_SWAROOP
271 if (!MonitorChecker::instance()->ok()) {
272 error_dialog (this, _("The required display devices are not connected correctly."));
276 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
281 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
282 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
283 if (d && !d->kdm_timing_window_valid()) {
289 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
295 void playback_started (DCPTime time)
297 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
302 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
303 DCPOMATIC_ASSERT (dcp);
304 DCPExaminer ex (dcp);
305 shared_ptr<dcp::CPL> playing_cpl;
306 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
307 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
311 DCPOMATIC_ASSERT (playing_cpl)
313 FILE* f = fopen_boost(*log, "a");
316 "%s playback-started %s %s %s\n",
317 dcp::LocalTime().as_string().c_str(),
318 time.timecode(_film->video_frame_rate()).c_str(),
319 dcp->directories().front().string().c_str(),
320 playing_cpl->annotation_text().c_str()
325 void playback_seeked (DCPTime time)
327 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
332 FILE* f = fopen_boost(*log, "a");
333 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
337 void playback_stopped (DCPTime time)
339 #ifdef DCPOMATIC_VARIANT_SWAROOP
341 boost::filesystem::remove (Config::path("position"));
347 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
352 FILE* f = fopen_boost(*log, "a");
353 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
357 void set_decode_reduction (optional<int> reduction)
359 _viewer->set_dcp_decode_reduction (reduction);
360 _info->triggered_update ();
361 Config::instance()->set_decode_reduction (reduction);
364 void load_dcp (boost::filesystem::path dir)
366 DCPOMATIC_ASSERT (_film);
370 shared_ptr<DCPContent> dcp (new DCPContent(_film, dir));
371 _film->examine_and_add_content (dcp);
372 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
373 if (!ok || !report_errors_from_last_job(this)) {
376 Config::instance()->add_to_player_history (dir);
377 } catch (dcp::DCPReadError& e) {
378 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
382 #ifdef DCPOMATIC_VARIANT_SWAROOP
383 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
385 ScopedTemporary temp;
386 string url = Config::instance()->kdm_server_url();
387 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
388 optional<dcp::EncryptedKDM> kdm;
389 if (dcp->cpl() && !get_from_url(url, false, temp)) {
391 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
392 if (kdm->cpl_id() != dcp->cpl()) {
395 } catch (std::exception& e) {
403 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
405 using namespace boost::filesystem;
406 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
408 return optional<dcp::EncryptedKDM>();
410 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
412 if (file_size(i->path()) < MAX_KDM_SIZE) {
413 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
414 if (kdm.cpl_id() == dcp->cpl()) {
418 } catch (std::exception& e) {
422 return optional<dcp::EncryptedKDM>();
425 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
428 _viewer->set_film (_film);
429 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
432 void film_changed (ChangeType type, Film::Property property)
434 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
438 _film->write_metadata (Config::path("spl.xml"));
440 if (_viewer->playing ()) {
444 /* Start off as Flat */
445 _film->set_container (Ratio::from_id("185"));
447 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
448 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
449 if (dcp && dcp->needs_kdm()) {
450 optional<dcp::EncryptedKDM> kdm;
451 #ifdef DCPOMATIC_VARIANT_SWAROOP
452 kdm = get_kdm_from_url (dcp);
455 get_kdm_from_directory (dcp);
460 dcp->examine (shared_ptr<Job>());
464 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
469 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
470 if (r->id() == "239") {
471 /* Any scope content means we use scope */
472 _film->set_container(r);
476 /* Any 3D content means we use 3D mode */
477 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
478 _film->set_three_d (true);
482 _viewer->seek (DCPTime(), true);
483 _info->triggered_update ();
485 set_menu_sensitivity ();
487 wxMenuItemList old = _cpl_menu->GetMenuItems();
488 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
489 _cpl_menu->Remove (*i);
492 if (_film->content().size() == 1) {
493 /* Offer a CPL menu */
494 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
496 DCPExaminer ex (first);
497 int id = ID_view_cpl;
498 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
499 wxMenuItem* j = _cpl_menu->AppendRadioItem(
501 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
503 j->Check(!first->cpl() || i->id() == *first->cpl());
512 void setup_menu (wxMenuBar* m)
514 _file_menu = new wxMenu;
515 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
516 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
517 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
519 _history_position = _file_menu->GetMenuItems().GetCount();
521 _file_menu->AppendSeparator ();
522 _file_menu->Append (ID_file_close, _("&Close"));
523 _file_menu->AppendSeparator ();
526 _file_menu->Append (wxID_EXIT, _("&Exit"));
528 _file_menu->Append (wxID_EXIT, _("&Quit"));
532 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
534 wxMenu* edit = new wxMenu;
535 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
538 prefs->Enable (Config::instance()->have_write_permission());
540 _cpl_menu = new wxMenu;
542 wxMenu* view = new wxMenu;
543 optional<int> c = Config::instance()->decode_reduction();
544 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
545 view->AppendSeparator();
546 #ifndef DCPOMATIC_VARIANT_SWAROOP
547 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
548 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
551 view->AppendSeparator();
552 view->Append(ID_view_closed_captions, _("Closed captions..."));
553 view->AppendSeparator();
554 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
555 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
556 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
557 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
559 wxMenu* tools = new wxMenu;
560 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
561 tools->AppendSeparator ();
562 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
564 wxMenu* help = new wxMenu;
566 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
568 help->Append (wxID_ABOUT, _("About"));
570 help->Append (ID_help_report_a_problem, _("Report a problem..."));
572 m->Append (_file_menu, _("&File"));
574 m->Append (edit, _("&Edit"));
576 m->Append (view, _("&View"));
577 m->Append (tools, _("&Tools"));
578 m->Append (help, _("&Help"));
583 wxString d = wxStandardPaths::Get().GetDocumentsDir();
584 if (Config::instance()->last_player_load_directory()) {
585 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
588 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
593 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
594 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
601 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
603 Config::instance()->set_last_player_load_directory (dcp.parent_path());
611 wxDirDialog* c = new wxDirDialog (
613 _("Select DCP to open as OV"),
614 wxStandardPaths::Get().GetDocumentsDir(),
615 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
621 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
622 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
629 DCPOMATIC_ASSERT (_film);
630 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
631 DCPOMATIC_ASSERT (dcp);
632 dcp->add_ov (wx_to_std(c->GetPath()));
633 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
634 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
635 if (!ok || !report_errors_from_last_job(this)) {
638 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
642 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
644 _film->set_container(r);
650 _info->triggered_update ();
655 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
657 if (d->ShowModal() == wxID_OK) {
658 DCPOMATIC_ASSERT (_film);
659 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
660 DCPOMATIC_ASSERT (dcp);
662 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
663 dcp->examine (shared_ptr<Job>());
664 } catch (exception& e) {
665 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
672 _info->triggered_update ();
675 void file_history (wxCommandEvent& event)
677 vector<boost::filesystem::path> history = Config::instance()->player_history ();
678 int n = event.GetId() - ID_file_history;
679 if (n >= 0 && n < static_cast<int> (history.size ())) {
680 load_dcp (history[n]);
687 _info->triggered_update ();
688 set_menu_sensitivity ();
696 void edit_preferences ()
698 if (!Config::instance()->have_write_permission()) {
702 if (!_config_dialog) {
703 _config_dialog = create_player_config_dialog ();
705 _config_dialog->Show (this);
708 void view_cpl (wxCommandEvent& ev)
710 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
711 DCPOMATIC_ASSERT (dcp);
712 DCPExaminer ex (dcp);
713 int id = ev.GetId() - ID_view_cpl;
714 DCPOMATIC_ASSERT (id >= 0);
715 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
716 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
717 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
723 dcp->set_cpl ((*i)->id());
724 dcp->examine (shared_ptr<Job>());
727 void view_full_screen ()
729 if (_mode == Config::PLAYER_MODE_FULL) {
730 _mode = Config::PLAYER_MODE_WINDOW;
732 _mode = Config::PLAYER_MODE_FULL;
738 void view_dual_screen ()
740 if (_mode == Config::PLAYER_MODE_DUAL) {
741 _mode = Config::PLAYER_MODE_WINDOW;
743 _mode = Config::PLAYER_MODE_DUAL;
751 if (_view_full_screen) {
752 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
754 if (_view_dual_screen) {
755 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
761 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
762 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
763 _info->Show (_mode != Config::PLAYER_MODE_FULL);
764 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
765 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
766 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
768 if (_mode == Config::PLAYER_MODE_DUAL) {
769 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
770 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
771 _dual_screen->ShowFullScreen (true);
772 _viewer->panel()->Reparent (_dual_screen);
773 _dual_screen->Show ();
774 if (wxDisplay::GetCount() > 1) {
775 switch (Config::instance()->image_display()) {
777 _dual_screen->Move (0, 0);
778 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
781 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
782 // (0, 0) doesn't seem to work for some strange reason
789 _viewer->panel()->Reparent (_overall_panel);
790 _dual_screen->Destroy ();
795 setup_main_sizer (_mode);
798 void view_closed_captions ()
800 _viewer->show_closed_captions ();
805 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
806 DCPOMATIC_ASSERT (dcp);
808 JobManager* jm = JobManager::instance ();
809 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
810 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
815 DCPOMATIC_ASSERT (!jm->get().empty());
816 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
817 DCPOMATIC_ASSERT (last);
819 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
824 void tools_check_for_updates ()
826 UpdateChecker::instance()->run ();
827 _update_news_requested = true;
832 AboutDialog* d = new AboutDialog (this);
837 void help_report_a_problem ()
839 ReportProblemDialog* d = new ReportProblemDialog (this);
840 if (d->ShowModal () == wxID_OK) {
846 void update_checker_state_changed ()
848 UpdateChecker* uc = UpdateChecker::instance ();
850 bool const announce =
851 _update_news_requested ||
852 (uc->stable() && Config::instance()->check_for_updates()) ||
853 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
855 _update_news_requested = false;
861 if (uc->state() == UpdateChecker::YES) {
862 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
863 dialog->ShowModal ();
865 } else if (uc->state() == UpdateChecker::FAILED) {
866 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
868 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
871 _update_news_requested = false;
874 void config_changed (Config::Property prop)
876 /* Instantly save any config changes when using the player GUI */
878 Config::instance()->write_config();
879 } catch (FileError& e) {
880 if (prop != Config::HISTORY) {
884 _("Could not write to config file at %s. Your changes have not been saved."),
885 std_to_wx(e.file().string())
889 } catch (exception& e) {
892 _("Could not write to config file. Your changes have not been saved.")
896 update_from_config ();
899 void update_from_config ()
901 for (int i = 0; i < _history_items; ++i) {
902 delete _file_menu->Remove (ID_file_history + i);
905 if (_history_separator) {
906 _file_menu->Remove (_history_separator);
908 delete _history_separator;
909 _history_separator = 0;
911 int pos = _history_position;
913 vector<boost::filesystem::path> history = Config::instance()->player_history ();
915 if (!history.empty ()) {
916 _history_separator = _file_menu->InsertSeparator (pos++);
919 for (size_t i = 0; i < history.size(); ++i) {
922 s = String::compose ("&%1 %2", i + 1, history[i].string());
924 s = history[i].string();
926 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
929 _history_items = history.size ();
932 void set_menu_sensitivity ()
934 _tools_verify->Enable (static_cast<bool>(_film));
935 _file_add_ov->Enable (static_cast<bool>(_film));
936 _file_add_kdm->Enable (static_cast<bool>(_film));
937 _view_cpl->Enable (static_cast<bool>(_film));
940 void start_stop_pressed ()
942 if (_viewer->playing()) {
951 _viewer->seek_by (-_viewer->one_video_frame(), true);
954 void forward_frame ()
956 _viewer->seek_by (_viewer->one_video_frame(), true);
961 wxFrame* _dual_screen;
962 bool _update_news_requested;
963 PlayerInformation* _info;
964 Config::PlayerMode _mode;
965 wxPreferencesEditor* _config_dialog;
966 wxPanel* _overall_panel;
968 wxMenuItem* _view_cpl;
971 int _history_position;
972 wxMenuItem* _history_separator;
973 shared_ptr<FilmViewer> _viewer;
975 boost::shared_ptr<Film> _film;
976 boost::signals2::scoped_connection _config_changed_connection;
977 wxMenuItem* _file_add_ov;
978 wxMenuItem* _file_add_kdm;
979 wxMenuItem* _tools_verify;
980 wxMenuItem* _view_full_screen;
981 wxMenuItem* _view_dual_screen;
984 static const wxCmdLineEntryDesc command_line_description[] = {
985 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
986 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
989 class PlayServer : public Server
992 explicit PlayServer (DOMFrame* frame)
993 : Server (PLAYER_PLAY_PORT)
997 void handle (shared_ptr<Socket> socket)
1000 int const length = socket->read_uint32 ();
1001 scoped_array<char> buffer (new char[length]);
1002 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1003 string s (buffer.get());
1004 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1005 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1016 * @brief The magic App class for wxWidgets.
1018 class App : public wxApp
1031 wxInitAllImageHandlers ();
1033 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1034 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1036 wxSplashScreen* splash = maybe_show_splash ();
1038 SetAppName (_("DCP-o-matic Player"));
1040 if (!wxApp::OnInit()) {
1044 #ifdef DCPOMATIC_LINUX
1045 unsetenv ("UBUNTU_MENUPROXY");
1049 ProcessSerialNumber serial;
1050 GetCurrentProcess (&serial);
1051 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1054 dcpomatic_setup_path_encoding ();
1056 /* Enable i18n; this will create a Config object
1057 to look for a force-configured language. This Config
1058 object will be wrong, however, because dcpomatic_setup
1059 hasn't yet been called and there aren't any filters etc.
1062 dcpomatic_setup_i18n ();
1064 /* Set things up, including filters etc.
1065 which will now be internationalised correctly.
1069 /* Force the configuration to be re-loaded correctly next
1074 signal_manager = new wxSignalManager (this);
1076 _frame = new DOMFrame ();
1077 SetTopWindow (_frame);
1078 _frame->Maximize ();
1084 PlayServer* server = new PlayServer (_frame);
1085 new thread (boost::bind (&PlayServer::run, server));
1087 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1089 _frame->load_dcp (_dcp_to_load);
1090 } catch (exception& e) {
1091 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1095 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1097 if (Config::instance()->check_for_updates ()) {
1098 UpdateChecker::instance()->run ();
1103 catch (exception& e)
1105 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1109 void OnInitCmdLine (wxCmdLineParser& parser)
1111 parser.SetDesc (command_line_description);
1112 parser.SetSwitchChars (wxT ("-"));
1115 bool OnCmdLineParsed (wxCmdLineParser& parser)
1117 if (parser.GetParamCount() > 0) {
1118 _dcp_to_load = wx_to_std (parser.GetParam (0));
1124 void report_exception ()
1128 } catch (FileError& e) {
1132 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1133 std_to_wx (e.what()),
1134 std_to_wx (e.file().string().c_str ())
1137 } catch (exception& e) {
1141 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1142 std_to_wx (e.what ())
1146 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1150 /* An unhandled exception has occurred inside the main event loop */
1151 bool OnExceptionInMainLoop ()
1153 report_exception ();
1154 /* This will terminate the program */
1158 void OnUnhandledException ()
1160 report_exception ();
1165 signal_manager->ui_idle ();
1168 void config_failed_to_load ()
1170 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1173 void config_warning (string m)
1175 message_dialog (_frame, std_to_wx (m));
1179 string _dcp_to_load;