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"
53 #include <wx/stdpaths.h>
54 #include <wx/splash.h>
55 #include <wx/cmdline.h>
56 #include <wx/preferences.h>
57 #include <wx/progdlg.h>
58 #include <wx/display.h>
60 #include <ApplicationServices/ApplicationServices.h>
62 #include <boost/bind.hpp>
76 using boost::shared_ptr;
77 using boost::scoped_array;
78 using boost::optional;
79 using boost::dynamic_pointer_cast;
88 /* Allow spare IDs after _history for the recent files list */
91 /* Allow spare IDs for CPLs */
92 ID_view_full_screen = 200,
94 ID_view_closed_captions,
95 ID_view_scale_appropriate,
98 ID_view_scale_quarter,
99 ID_help_report_a_problem,
101 ID_tools_check_for_updates,
102 /* IDs for shortcuts (with no associated menu item) */
108 class DOMFrame : public wxFrame
112 : wxFrame (0, -1, _("DCP-o-matic Player"))
114 , _update_news_requested (false)
116 , _mode (Config::instance()->player_mode())
120 , _history_position (0)
121 , _history_separator (0)
122 , _view_full_screen (0)
123 , _view_dual_screen (0)
126 #if defined(DCPOMATIC_WINDOWS)
127 maybe_open_console ();
128 cout << "DCP-o-matic Player is starting." << "\n";
131 wxMenuBar* bar = new wxMenuBar;
133 set_menu_sensitivity ();
136 #ifdef DCPOMATIC_WINDOWS
137 SetIcon (wxIcon (std_to_wx ("id")));
140 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
141 update_from_config ();
143 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
144 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
145 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
159 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
160 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
162 /* Use a panel as the only child of the Frame so that we avoid
163 the dark-grey background on Windows.
165 _overall_panel = new wxPanel (this, wxID_ANY);
167 _viewer.reset (new FilmViewer (_overall_panel));
168 _controls = new Controls (_overall_panel, _viewer, false);
169 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
170 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
171 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
172 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
173 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
174 _info = new PlayerInformation (_overall_panel, _viewer);
175 setup_main_sizer (Config::instance()->player_mode());
177 int accelerators = 4;
179 int accelerators = 3;
182 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
183 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
184 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
185 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
187 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
189 wxAcceleratorTable accel_table (accelerators, accel);
190 SetAcceleratorTable (accel_table);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
194 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
195 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
197 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
198 _controls->SPLChanged.connect (boost::bind(&DOMFrame::set_spl, this, _1));
199 #ifdef DCPOMATIC_VARIANT_SWAROOP
200 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
201 MonitorChecker::instance()->run ();
206 void monitor_checker_state_changed ()
208 if (!MonitorChecker::instance()->ok()) {
209 error_dialog (this, _("The required display devices are not connected correctly."));
214 void setup_main_sizer (Config::PlayerMode mode)
216 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
217 if (mode != Config::PLAYER_MODE_DUAL) {
218 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
220 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
221 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
222 _overall_panel->SetSizer (main_sizer);
223 _overall_panel->Layout ();
226 bool playback_permitted ()
228 #ifdef DCPOMATIC_VARIANT_SWAROOP
229 if (!MonitorChecker::instance()->ok()) {
230 error_dialog (this, _("The required display devices are not connected correctly."));
234 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
239 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
240 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
241 if (d && !d->kdm_timing_window_valid()) {
247 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
253 void playback_started (DCPTime time)
255 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
260 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
261 DCPOMATIC_ASSERT (dcp);
262 DCPExaminer ex (dcp);
263 shared_ptr<dcp::CPL> playing_cpl;
264 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
265 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
269 DCPOMATIC_ASSERT (playing_cpl)
271 FILE* f = fopen_boost(*log, "a");
274 "%s playback-started %s %s %s\n",
275 dcp::LocalTime().as_string().c_str(),
276 time.timecode(_film->video_frame_rate()).c_str(),
277 dcp->directories().front().string().c_str(),
278 playing_cpl->annotation_text().c_str()
283 void playback_seeked (DCPTime time)
285 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
290 FILE* f = fopen_boost(*log, "a");
291 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
295 void playback_stopped (DCPTime time)
297 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
302 FILE* f = fopen_boost(*log, "a");
303 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
307 void set_decode_reduction (optional<int> reduction)
309 _viewer->set_dcp_decode_reduction (reduction);
310 _info->triggered_update ();
311 Config::instance()->set_decode_reduction (reduction);
314 void load_dcp (boost::filesystem::path dir)
319 BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
320 spl.push_back (SPLEntry(j, dir));
323 Config::instance()->add_to_player_history (dir);
326 #ifdef DCPOMATIC_VARIANT_SWAROOP
327 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
329 ScopedTemporary temp;
330 string url = Config::instance()->kdm_server_url();
331 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
332 optional<dcp::EncryptedKDM> kdm;
333 if (dcp->cpl() && !get_from_url(url, false, temp)) {
335 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
336 if (kdm->cpl_id() != dcp->cpl()) {
339 } catch (std::exception& e) {
347 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
349 using namespace boost::filesystem;
350 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
352 return optional<dcp::EncryptedKDM>();
354 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
356 if (file_size(i->path()) < MAX_KDM_SIZE) {
357 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
358 if (kdm.cpl_id() == dcp->cpl()) {
362 } catch (std::exception& e) {
366 return optional<dcp::EncryptedKDM>();
369 void set_spl (list<SPLEntry> spl)
371 if (_viewer->playing ()) {
375 _film.reset (new Film (optional<boost::filesystem::path>()));
378 _viewer->set_film (_film);
379 _info->triggered_update ();
383 /* Start off as Flat */
384 _film->set_container (Ratio::from_id("185"));
387 shared_ptr<DCPContent> first;
389 BOOST_FOREACH (SPLEntry i, spl) {
390 shared_ptr<DCPContent> dcp;
392 dcp.reset (new DCPContent (_film, i.directory));
393 } catch (boost::filesystem::filesystem_error& e) {
394 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
402 _film->examine_and_add_content (dcp, true);
403 bool const ok = progress (_("Loading DCP"));
404 if (!ok || !report_errors_from_last_job()) {
408 dcp->set_position (position + i.black_before);
409 position += dcp->length_after_trim() + i.black_before;
411 /* This DCP has been examined and loaded */
413 if (dcp->needs_kdm()) {
414 optional<dcp::EncryptedKDM> kdm;
415 #ifdef DCPOMATIC_VARIANT_SWAROOP
416 kdm = get_kdm_from_url (dcp);
419 get_kdm_from_directory (dcp);
424 dcp->examine (shared_ptr<Job>());
428 BOOST_FOREACH (shared_ptr<TextContent> j, dcp->text) {
433 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
434 if (r->id() == "239") {
435 /* Any scope content means we use scope */
436 _film->set_container(r);
440 /* Any 3D content means we use 3D mode */
441 if (dcp->three_d()) {
442 _film->set_three_d (true);
445 _viewer->set_film (_film);
446 _viewer->seek (DCPTime(), true);
447 _info->triggered_update ();
449 set_menu_sensitivity ();
450 _controls->log (wxString::Format(_("Load DCP %s"), i.directory.filename().string().c_str()));
453 wxMenuItemList old = _cpl_menu->GetMenuItems();
454 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
455 _cpl_menu->Remove (*i);
458 if (spl.size() == 1) {
459 /* Offer a CPL menu */
460 DCPExaminer ex (first);
461 int id = ID_view_cpl;
462 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
463 wxMenuItem* j = _cpl_menu->AppendRadioItem(
465 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
467 j->Check(!first->cpl() || i->id() == *first->cpl());
475 void setup_menu (wxMenuBar* m)
477 _file_menu = new wxMenu;
478 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
479 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
480 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
482 _history_position = _file_menu->GetMenuItems().GetCount();
484 _file_menu->AppendSeparator ();
485 _file_menu->Append (ID_file_close, _("&Close"));
486 _file_menu->AppendSeparator ();
489 _file_menu->Append (wxID_EXIT, _("&Exit"));
491 _file_menu->Append (wxID_EXIT, _("&Quit"));
495 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
497 wxMenu* edit = new wxMenu;
498 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
501 prefs->Enable (Config::instance()->have_write_permission());
503 _cpl_menu = new wxMenu;
505 wxMenu* view = new wxMenu;
506 optional<int> c = Config::instance()->decode_reduction();
507 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
508 view->AppendSeparator();
509 #ifndef DCPOMATIC_VARIANT_SWAROOP
510 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
511 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
514 view->AppendSeparator();
515 view->Append(ID_view_closed_captions, _("Closed captions..."));
516 view->AppendSeparator();
517 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
518 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
519 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
520 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
522 wxMenu* tools = new wxMenu;
523 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
524 tools->AppendSeparator ();
525 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
527 wxMenu* help = new wxMenu;
529 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
531 help->Append (wxID_ABOUT, _("About"));
533 help->Append (ID_help_report_a_problem, _("Report a problem..."));
535 m->Append (_file_menu, _("&File"));
537 m->Append (edit, _("&Edit"));
539 m->Append (view, _("&View"));
540 m->Append (tools, _("&Tools"));
541 m->Append (help, _("&Help"));
546 wxString d = wxStandardPaths::Get().GetDocumentsDir();
547 if (Config::instance()->last_player_load_directory()) {
548 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
551 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
556 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
557 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
564 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
566 Config::instance()->set_last_player_load_directory (dcp.parent_path());
574 wxDirDialog* c = new wxDirDialog (
576 _("Select DCP to open as OV"),
577 wxStandardPaths::Get().GetDocumentsDir(),
578 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
584 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
585 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
592 DCPOMATIC_ASSERT (_film);
593 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
594 DCPOMATIC_ASSERT (dcp);
595 dcp->add_ov (wx_to_std(c->GetPath()));
596 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
597 bool const ok = progress (_("Loading DCP"));
598 if (!ok || !report_errors_from_last_job()) {
601 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
605 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
607 _film->set_container(r);
613 _info->triggered_update ();
618 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
620 if (d->ShowModal() == wxID_OK) {
621 DCPOMATIC_ASSERT (_film);
622 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
623 DCPOMATIC_ASSERT (dcp);
625 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
626 dcp->examine (shared_ptr<Job>());
627 } catch (exception& e) {
628 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
635 _info->triggered_update ();
638 void file_history (wxCommandEvent& event)
640 vector<boost::filesystem::path> history = Config::instance()->player_history ();
641 int n = event.GetId() - ID_file_history;
642 if (n >= 0 && n < static_cast<int> (history.size ())) {
643 load_dcp (history[n]);
649 _viewer->set_film (shared_ptr<Film>());
651 _info->triggered_update ();
652 set_menu_sensitivity ();
660 void edit_preferences ()
662 if (!Config::instance()->have_write_permission()) {
666 if (!_config_dialog) {
667 _config_dialog = create_player_config_dialog ();
669 _config_dialog->Show (this);
672 void view_cpl (wxCommandEvent& ev)
674 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
675 DCPOMATIC_ASSERT (dcp);
676 DCPExaminer ex (dcp);
677 int id = ev.GetId() - ID_view_cpl;
678 DCPOMATIC_ASSERT (id >= 0);
679 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
680 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
681 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
687 dcp->set_cpl ((*i)->id());
688 dcp->examine (shared_ptr<Job>());
691 void view_full_screen ()
693 if (_mode == Config::PLAYER_MODE_FULL) {
694 _mode = Config::PLAYER_MODE_WINDOW;
696 _mode = Config::PLAYER_MODE_FULL;
702 void view_dual_screen ()
704 if (_mode == Config::PLAYER_MODE_DUAL) {
705 _mode = Config::PLAYER_MODE_WINDOW;
707 _mode = Config::PLAYER_MODE_DUAL;
715 if (_view_full_screen) {
716 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
718 if (_view_dual_screen) {
719 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
725 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
726 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
727 _info->Show (_mode != Config::PLAYER_MODE_FULL);
728 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
729 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
731 if (_mode == Config::PLAYER_MODE_DUAL) {
732 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
733 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
734 _dual_screen->ShowFullScreen (true);
735 _viewer->panel()->Reparent (_dual_screen);
736 _dual_screen->Show ();
737 if (wxDisplay::GetCount() > 1) {
738 switch (Config::instance()->image_display()) {
740 _dual_screen->Move (0, 0);
741 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
744 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
745 // (0, 0) doesn't seem to work for some strange reason
752 _viewer->panel()->Reparent (_overall_panel);
753 _dual_screen->Destroy ();
758 setup_main_sizer (_mode);
761 void view_closed_captions ()
763 _viewer->show_closed_captions ();
768 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
769 DCPOMATIC_ASSERT (dcp);
771 JobManager* jm = JobManager::instance ();
772 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
773 bool const ok = progress (_("Verifying DCP"));
778 DCPOMATIC_ASSERT (!jm->get().empty());
779 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
780 DCPOMATIC_ASSERT (last);
782 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
787 void tools_check_for_updates ()
789 UpdateChecker::instance()->run ();
790 _update_news_requested = true;
795 AboutDialog* d = new AboutDialog (this);
800 void help_report_a_problem ()
802 ReportProblemDialog* d = new ReportProblemDialog (this);
803 if (d->ShowModal () == wxID_OK) {
809 void update_checker_state_changed ()
811 UpdateChecker* uc = UpdateChecker::instance ();
813 bool const announce =
814 _update_news_requested ||
815 (uc->stable() && Config::instance()->check_for_updates()) ||
816 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
818 _update_news_requested = false;
824 if (uc->state() == UpdateChecker::YES) {
825 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
826 dialog->ShowModal ();
828 } else if (uc->state() == UpdateChecker::FAILED) {
829 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
831 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
834 _update_news_requested = false;
837 void config_changed ()
839 /* Instantly save any config changes when using the player GUI */
841 Config::instance()->write_config();
842 } catch (FileError& e) {
846 _("Could not write to config file at %s. Your changes have not been saved."),
847 std_to_wx(e.file().string())
850 } catch (exception& e) {
853 _("Could not write to config file. Your changes have not been saved.")
857 update_from_config ();
860 void update_from_config ()
862 for (int i = 0; i < _history_items; ++i) {
863 delete _file_menu->Remove (ID_file_history + i);
866 if (_history_separator) {
867 _file_menu->Remove (_history_separator);
869 delete _history_separator;
870 _history_separator = 0;
872 int pos = _history_position;
874 vector<boost::filesystem::path> history = Config::instance()->player_history ();
876 if (!history.empty ()) {
877 _history_separator = _file_menu->InsertSeparator (pos++);
880 for (size_t i = 0; i < history.size(); ++i) {
883 s = String::compose ("&%1 %2", i + 1, history[i].string());
885 s = history[i].string();
887 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
890 _history_items = history.size ();
893 void set_menu_sensitivity ()
895 _tools_verify->Enable (static_cast<bool>(_film));
896 _file_add_ov->Enable (static_cast<bool>(_film));
897 _file_add_kdm->Enable (static_cast<bool>(_film));
898 _view_cpl->Enable (static_cast<bool>(_film));
901 void start_stop_pressed ()
903 if (_viewer->playing()) {
912 _viewer->seek_by (-_viewer->one_video_frame(), true);
915 void forward_frame ()
917 _viewer->seek_by (_viewer->one_video_frame(), true);
922 /** @return false if the task was cancelled */
923 bool progress (wxString task)
925 JobManager* jm = JobManager::instance ();
927 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
931 while (jm->work_to_do() || signal_manager->ui_idle()) {
933 if (!progress->Pulse()) {
934 /* user pressed cancel */
935 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
943 progress->Destroy ();
947 bool report_errors_from_last_job ()
949 JobManager* jm = JobManager::instance ();
951 DCPOMATIC_ASSERT (!jm->get().empty());
953 shared_ptr<Job> last = jm->get().back();
954 if (last->finished_in_error()) {
955 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
962 wxFrame* _dual_screen;
963 bool _update_news_requested;
964 PlayerInformation* _info;
965 Config::PlayerMode _mode;
966 wxPreferencesEditor* _config_dialog;
967 wxPanel* _overall_panel;
969 wxMenuItem* _view_cpl;
972 int _history_position;
973 wxMenuItem* _history_separator;
974 shared_ptr<FilmViewer> _viewer;
976 boost::shared_ptr<Film> _film;
977 boost::signals2::scoped_connection _config_changed_connection;
978 wxMenuItem* _file_add_ov;
979 wxMenuItem* _file_add_kdm;
980 wxMenuItem* _tools_verify;
981 wxMenuItem* _view_full_screen;
982 wxMenuItem* _view_dual_screen;
985 static const wxCmdLineEntryDesc command_line_description[] = {
986 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
987 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
990 class PlayServer : public Server
993 explicit PlayServer (DOMFrame* frame)
994 : Server (PLAYER_PLAY_PORT)
998 void handle (shared_ptr<Socket> socket)
1001 int const length = socket->read_uint32 ();
1002 scoped_array<char> buffer (new char[length]);
1003 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1004 string s (buffer.get());
1005 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1006 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1017 * @brief The magic App class for wxWidgets.
1019 class App : public wxApp
1032 wxInitAllImageHandlers ();
1034 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1035 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1037 wxSplashScreen* splash = maybe_show_splash ();
1039 SetAppName (_("DCP-o-matic Player"));
1041 if (!wxApp::OnInit()) {
1045 #ifdef DCPOMATIC_LINUX
1046 unsetenv ("UBUNTU_MENUPROXY");
1050 ProcessSerialNumber serial;
1051 GetCurrentProcess (&serial);
1052 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1055 dcpomatic_setup_path_encoding ();
1057 /* Enable i18n; this will create a Config object
1058 to look for a force-configured language. This Config
1059 object will be wrong, however, because dcpomatic_setup
1060 hasn't yet been called and there aren't any filters etc.
1063 dcpomatic_setup_i18n ();
1065 /* Set things up, including filters etc.
1066 which will now be internationalised correctly.
1070 /* Force the configuration to be re-loaded correctly next
1075 _frame = new DOMFrame ();
1076 SetTopWindow (_frame);
1077 _frame->Maximize ();
1083 signal_manager = new wxSignalManager (this);
1085 PlayServer* server = new PlayServer (_frame);
1086 new thread (boost::bind (&PlayServer::run, server));
1088 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1090 _frame->load_dcp (_dcp_to_load);
1091 } catch (exception& e) {
1092 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1096 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1098 if (Config::instance()->check_for_updates ()) {
1099 UpdateChecker::instance()->run ();
1104 catch (exception& e)
1106 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1110 void OnInitCmdLine (wxCmdLineParser& parser)
1112 parser.SetDesc (command_line_description);
1113 parser.SetSwitchChars (wxT ("-"));
1116 bool OnCmdLineParsed (wxCmdLineParser& parser)
1118 if (parser.GetParamCount() > 0) {
1119 _dcp_to_load = wx_to_std (parser.GetParam (0));
1125 void report_exception ()
1129 } catch (FileError& e) {
1133 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1134 std_to_wx (e.what()),
1135 std_to_wx (e.file().string().c_str ())
1138 } catch (exception& e) {
1142 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1143 std_to_wx (e.what ())
1147 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1151 /* An unhandled exception has occurred inside the main event loop */
1152 bool OnExceptionInMainLoop ()
1154 report_exception ();
1155 /* This will terminate the program */
1159 void OnUnhandledException ()
1161 report_exception ();
1166 signal_manager->ui_idle ();
1169 void config_failed_to_load ()
1171 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1174 void config_warning (string m)
1176 message_dialog (_frame, std_to_wx (m));
1180 string _dcp_to_load;