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"
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 _info = new PlayerInformation (_overall_panel, _viewer);
177 setup_main_sizer (Config::instance()->player_mode());
179 int accelerators = 4;
181 int accelerators = 3;
184 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
185 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
186 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
187 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
189 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
191 wxAcceleratorTable accel_table (accelerators, accel);
192 SetAcceleratorTable (accel_table);
195 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
196 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
197 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
199 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
200 _controls->SPLChanged.connect (boost::bind(&DOMFrame::set_spl, this, _1));
201 #ifdef DCPOMATIC_VARIANT_SWAROOP
202 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
203 MonitorChecker::instance()->run ();
208 void monitor_checker_state_changed ()
210 if (!MonitorChecker::instance()->ok()) {
211 error_dialog (this, _("The required display devices are not connected correctly."));
216 void setup_main_sizer (Config::PlayerMode mode)
218 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
219 if (mode != Config::PLAYER_MODE_DUAL) {
220 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
222 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
223 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
224 _overall_panel->SetSizer (main_sizer);
225 _overall_panel->Layout ();
228 bool playback_permitted ()
230 #ifdef DCPOMATIC_VARIANT_SWAROOP
231 if (!MonitorChecker::instance()->ok()) {
232 error_dialog (this, _("The required display devices are not connected correctly."));
236 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
241 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
242 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
243 if (d && !d->kdm_timing_window_valid()) {
249 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
255 void playback_started (DCPTime time)
257 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
262 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
263 DCPOMATIC_ASSERT (dcp);
264 DCPExaminer ex (dcp);
265 shared_ptr<dcp::CPL> playing_cpl;
266 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
267 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
271 DCPOMATIC_ASSERT (playing_cpl)
273 FILE* f = fopen_boost(*log, "a");
276 "%s playback-started %s %s %s\n",
277 dcp::LocalTime().as_string().c_str(),
278 time.timecode(_film->video_frame_rate()).c_str(),
279 dcp->directories().front().string().c_str(),
280 playing_cpl->annotation_text().c_str()
285 void playback_seeked (DCPTime time)
287 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
292 FILE* f = fopen_boost(*log, "a");
293 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
297 void playback_stopped (DCPTime time)
299 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
304 FILE* f = fopen_boost(*log, "a");
305 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
309 void set_decode_reduction (optional<int> reduction)
311 _viewer->set_dcp_decode_reduction (reduction);
312 _info->triggered_update ();
313 Config::instance()->set_decode_reduction (reduction);
316 void load_dcp (boost::filesystem::path dir)
321 BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
322 spl.playlist.push_back (SPLEntry(j, dir));
325 Config::instance()->add_to_player_history (dir);
328 #ifdef DCPOMATIC_VARIANT_SWAROOP
329 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
331 ScopedTemporary temp;
332 string url = Config::instance()->kdm_server_url();
333 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
334 optional<dcp::EncryptedKDM> kdm;
335 if (dcp->cpl() && !get_from_url(url, false, temp)) {
337 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
338 if (kdm->cpl_id() != dcp->cpl()) {
341 } catch (std::exception& e) {
349 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
351 using namespace boost::filesystem;
352 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
354 return optional<dcp::EncryptedKDM>();
356 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
358 if (file_size(i->path()) < MAX_KDM_SIZE) {
359 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
360 if (kdm.cpl_id() == dcp->cpl()) {
364 } catch (std::exception& e) {
368 return optional<dcp::EncryptedKDM>();
371 void set_spl (SPL spl)
373 if (_viewer->playing ()) {
377 _film.reset (new Film (optional<boost::filesystem::path>()));
379 if (spl.playlist.empty ()) {
380 _viewer->set_film (_film);
381 _info->triggered_update ();
385 /* Start off as Flat */
386 _film->set_container (Ratio::from_id("185"));
388 /* Put 1 frame of black at the start so when we seek to 0 we don't see anything */
389 DCPTime position = DCPTime::from_frames(1, _film->video_frame_rate());
390 shared_ptr<DCPContent> first;
392 BOOST_FOREACH (SPLEntry i, spl.playlist) {
393 shared_ptr<DCPContent> dcp;
395 dcp.reset (new DCPContent (_film, i.directory));
396 } catch (boost::filesystem::filesystem_error& e) {
397 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
405 _film->examine_and_add_content (dcp, true);
406 bool const ok = progress (_("Loading DCP"));
407 if (!ok || !report_errors_from_last_job()) {
411 dcp->set_position (position + i.black_before);
412 position += dcp->length_after_trim() + i.black_before;
414 /* This DCP has been examined and loaded */
416 if (dcp->needs_kdm()) {
417 optional<dcp::EncryptedKDM> kdm;
418 #ifdef DCPOMATIC_VARIANT_SWAROOP
419 kdm = get_kdm_from_url (dcp);
422 get_kdm_from_directory (dcp);
427 dcp->examine (shared_ptr<Job>());
431 BOOST_FOREACH (shared_ptr<TextContent> j, dcp->text) {
436 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
437 if (r->id() == "239") {
438 /* Any scope content means we use scope */
439 _film->set_container(r);
443 /* Any 3D content means we use 3D mode */
444 if (dcp->three_d()) {
445 _film->set_three_d (true);
448 _viewer->set_film (_film);
449 _viewer->seek (DCPTime(), true);
450 _info->triggered_update ();
452 set_menu_sensitivity ();
453 _controls->log (wxString::Format(_("Load DCP %s"), i.directory.filename().string().c_str()));
456 wxMenuItemList old = _cpl_menu->GetMenuItems();
457 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
458 _cpl_menu->Remove (*i);
461 if (spl.playlist.size() == 1) {
462 /* Offer a CPL menu */
463 DCPExaminer ex (first);
464 int id = ID_view_cpl;
465 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
466 wxMenuItem* j = _cpl_menu->AppendRadioItem(
468 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
470 j->Check(!first->cpl() || i->id() == *first->cpl());
478 void setup_menu (wxMenuBar* m)
480 _file_menu = new wxMenu;
481 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
482 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
483 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
485 _history_position = _file_menu->GetMenuItems().GetCount();
487 _file_menu->AppendSeparator ();
488 _file_menu->Append (ID_file_close, _("&Close"));
489 _file_menu->AppendSeparator ();
492 _file_menu->Append (wxID_EXIT, _("&Exit"));
494 _file_menu->Append (wxID_EXIT, _("&Quit"));
498 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
500 wxMenu* edit = new wxMenu;
501 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
504 prefs->Enable (Config::instance()->have_write_permission());
506 _cpl_menu = new wxMenu;
508 wxMenu* view = new wxMenu;
509 optional<int> c = Config::instance()->decode_reduction();
510 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
511 view->AppendSeparator();
512 #ifndef DCPOMATIC_VARIANT_SWAROOP
513 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
514 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
517 view->AppendSeparator();
518 view->Append(ID_view_closed_captions, _("Closed captions..."));
519 view->AppendSeparator();
520 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
521 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
522 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
523 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
525 wxMenu* tools = new wxMenu;
526 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
527 tools->AppendSeparator ();
528 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
530 wxMenu* help = new wxMenu;
532 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
534 help->Append (wxID_ABOUT, _("About"));
536 help->Append (ID_help_report_a_problem, _("Report a problem..."));
538 m->Append (_file_menu, _("&File"));
540 m->Append (edit, _("&Edit"));
542 m->Append (view, _("&View"));
543 m->Append (tools, _("&Tools"));
544 m->Append (help, _("&Help"));
549 wxString d = wxStandardPaths::Get().GetDocumentsDir();
550 if (Config::instance()->last_player_load_directory()) {
551 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
554 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
559 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
560 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
567 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
569 Config::instance()->set_last_player_load_directory (dcp.parent_path());
577 wxDirDialog* c = new wxDirDialog (
579 _("Select DCP to open as OV"),
580 wxStandardPaths::Get().GetDocumentsDir(),
581 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
587 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
588 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
595 DCPOMATIC_ASSERT (_film);
596 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
597 DCPOMATIC_ASSERT (dcp);
598 dcp->add_ov (wx_to_std(c->GetPath()));
599 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
600 bool const ok = progress (_("Loading DCP"));
601 if (!ok || !report_errors_from_last_job()) {
604 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
608 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
610 _film->set_container(r);
616 _info->triggered_update ();
621 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
623 if (d->ShowModal() == wxID_OK) {
624 DCPOMATIC_ASSERT (_film);
625 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
626 DCPOMATIC_ASSERT (dcp);
628 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
629 dcp->examine (shared_ptr<Job>());
630 } catch (exception& e) {
631 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
638 _info->triggered_update ();
641 void file_history (wxCommandEvent& event)
643 vector<boost::filesystem::path> history = Config::instance()->player_history ();
644 int n = event.GetId() - ID_file_history;
645 if (n >= 0 && n < static_cast<int> (history.size ())) {
646 load_dcp (history[n]);
652 _viewer->set_film (shared_ptr<Film>());
654 _info->triggered_update ();
655 set_menu_sensitivity ();
663 void edit_preferences ()
665 if (!Config::instance()->have_write_permission()) {
669 if (!_config_dialog) {
670 _config_dialog = create_player_config_dialog ();
672 _config_dialog->Show (this);
675 void view_cpl (wxCommandEvent& ev)
677 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
678 DCPOMATIC_ASSERT (dcp);
679 DCPExaminer ex (dcp);
680 int id = ev.GetId() - ID_view_cpl;
681 DCPOMATIC_ASSERT (id >= 0);
682 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
683 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
684 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
690 dcp->set_cpl ((*i)->id());
691 dcp->examine (shared_ptr<Job>());
694 void view_full_screen ()
696 if (_mode == Config::PLAYER_MODE_FULL) {
697 _mode = Config::PLAYER_MODE_WINDOW;
699 _mode = Config::PLAYER_MODE_FULL;
705 void view_dual_screen ()
707 if (_mode == Config::PLAYER_MODE_DUAL) {
708 _mode = Config::PLAYER_MODE_WINDOW;
710 _mode = Config::PLAYER_MODE_DUAL;
718 if (_view_full_screen) {
719 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
721 if (_view_dual_screen) {
722 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
728 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
729 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
730 _info->Show (_mode != Config::PLAYER_MODE_FULL);
731 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
732 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
734 if (_mode == Config::PLAYER_MODE_DUAL) {
735 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
736 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
737 _dual_screen->ShowFullScreen (true);
738 _viewer->panel()->Reparent (_dual_screen);
739 _dual_screen->Show ();
740 if (wxDisplay::GetCount() > 1) {
741 switch (Config::instance()->image_display()) {
743 _dual_screen->Move (0, 0);
744 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
747 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
748 // (0, 0) doesn't seem to work for some strange reason
755 _viewer->panel()->Reparent (_overall_panel);
756 _dual_screen->Destroy ();
761 setup_main_sizer (_mode);
764 void view_closed_captions ()
766 _viewer->show_closed_captions ();
771 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
772 DCPOMATIC_ASSERT (dcp);
774 JobManager* jm = JobManager::instance ();
775 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
776 bool const ok = progress (_("Verifying DCP"));
781 DCPOMATIC_ASSERT (!jm->get().empty());
782 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
783 DCPOMATIC_ASSERT (last);
785 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
790 void tools_check_for_updates ()
792 UpdateChecker::instance()->run ();
793 _update_news_requested = true;
798 AboutDialog* d = new AboutDialog (this);
803 void help_report_a_problem ()
805 ReportProblemDialog* d = new ReportProblemDialog (this);
806 if (d->ShowModal () == wxID_OK) {
812 void update_checker_state_changed ()
814 UpdateChecker* uc = UpdateChecker::instance ();
816 bool const announce =
817 _update_news_requested ||
818 (uc->stable() && Config::instance()->check_for_updates()) ||
819 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
821 _update_news_requested = false;
827 if (uc->state() == UpdateChecker::YES) {
828 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
829 dialog->ShowModal ();
831 } else if (uc->state() == UpdateChecker::FAILED) {
832 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
834 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
837 _update_news_requested = false;
840 void config_changed (Config::Property prop)
842 /* Instantly save any config changes when using the player GUI */
844 Config::instance()->write_config();
845 } catch (FileError& e) {
846 if (prop != Config::HISTORY) {
850 _("Could not write to config file at %s. Your changes have not been saved."),
851 std_to_wx(e.file().string())
855 } catch (exception& e) {
858 _("Could not write to config file. Your changes have not been saved.")
862 update_from_config ();
865 void update_from_config ()
867 for (int i = 0; i < _history_items; ++i) {
868 delete _file_menu->Remove (ID_file_history + i);
871 if (_history_separator) {
872 _file_menu->Remove (_history_separator);
874 delete _history_separator;
875 _history_separator = 0;
877 int pos = _history_position;
879 vector<boost::filesystem::path> history = Config::instance()->player_history ();
881 if (!history.empty ()) {
882 _history_separator = _file_menu->InsertSeparator (pos++);
885 for (size_t i = 0; i < history.size(); ++i) {
888 s = String::compose ("&%1 %2", i + 1, history[i].string());
890 s = history[i].string();
892 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
895 _history_items = history.size ();
898 void set_menu_sensitivity ()
900 _tools_verify->Enable (static_cast<bool>(_film));
901 _file_add_ov->Enable (static_cast<bool>(_film));
902 _file_add_kdm->Enable (static_cast<bool>(_film));
903 _view_cpl->Enable (static_cast<bool>(_film));
906 void start_stop_pressed ()
908 if (_viewer->playing()) {
917 _viewer->seek_by (-_viewer->one_video_frame(), true);
920 void forward_frame ()
922 _viewer->seek_by (_viewer->one_video_frame(), true);
927 /** @return false if the task was cancelled */
928 bool progress (wxString task)
930 JobManager* jm = JobManager::instance ();
932 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
936 while (jm->work_to_do() || signal_manager->ui_idle()) {
938 if (!progress->Pulse()) {
939 /* user pressed cancel */
940 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
948 progress->Destroy ();
952 bool report_errors_from_last_job ()
954 JobManager* jm = JobManager::instance ();
956 DCPOMATIC_ASSERT (!jm->get().empty());
958 shared_ptr<Job> last = jm->get().back();
959 if (last->finished_in_error()) {
960 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
967 wxFrame* _dual_screen;
968 bool _update_news_requested;
969 PlayerInformation* _info;
970 Config::PlayerMode _mode;
971 wxPreferencesEditor* _config_dialog;
972 wxPanel* _overall_panel;
974 wxMenuItem* _view_cpl;
977 int _history_position;
978 wxMenuItem* _history_separator;
979 shared_ptr<FilmViewer> _viewer;
981 boost::shared_ptr<Film> _film;
982 boost::signals2::scoped_connection _config_changed_connection;
983 wxMenuItem* _file_add_ov;
984 wxMenuItem* _file_add_kdm;
985 wxMenuItem* _tools_verify;
986 wxMenuItem* _view_full_screen;
987 wxMenuItem* _view_dual_screen;
990 static const wxCmdLineEntryDesc command_line_description[] = {
991 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
992 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
995 class PlayServer : public Server
998 explicit PlayServer (DOMFrame* frame)
999 : Server (PLAYER_PLAY_PORT)
1003 void handle (shared_ptr<Socket> socket)
1006 int const length = socket->read_uint32 ();
1007 scoped_array<char> buffer (new char[length]);
1008 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1009 string s (buffer.get());
1010 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1011 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1022 * @brief The magic App class for wxWidgets.
1024 class App : public wxApp
1037 wxInitAllImageHandlers ();
1039 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1040 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1042 wxSplashScreen* splash = maybe_show_splash ();
1044 SetAppName (_("DCP-o-matic Player"));
1046 if (!wxApp::OnInit()) {
1050 #ifdef DCPOMATIC_LINUX
1051 unsetenv ("UBUNTU_MENUPROXY");
1055 ProcessSerialNumber serial;
1056 GetCurrentProcess (&serial);
1057 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1060 dcpomatic_setup_path_encoding ();
1062 /* Enable i18n; this will create a Config object
1063 to look for a force-configured language. This Config
1064 object will be wrong, however, because dcpomatic_setup
1065 hasn't yet been called and there aren't any filters etc.
1068 dcpomatic_setup_i18n ();
1070 /* Set things up, including filters etc.
1071 which will now be internationalised correctly.
1075 /* Force the configuration to be re-loaded correctly next
1080 _frame = new DOMFrame ();
1081 SetTopWindow (_frame);
1082 _frame->Maximize ();
1088 signal_manager = new wxSignalManager (this);
1090 PlayServer* server = new PlayServer (_frame);
1091 new thread (boost::bind (&PlayServer::run, server));
1093 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1095 _frame->load_dcp (_dcp_to_load);
1096 } catch (exception& e) {
1097 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1101 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1103 if (Config::instance()->check_for_updates ()) {
1104 UpdateChecker::instance()->run ();
1109 catch (exception& e)
1111 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1115 void OnInitCmdLine (wxCmdLineParser& parser)
1117 parser.SetDesc (command_line_description);
1118 parser.SetSwitchChars (wxT ("-"));
1121 bool OnCmdLineParsed (wxCmdLineParser& parser)
1123 if (parser.GetParamCount() > 0) {
1124 _dcp_to_load = wx_to_std (parser.GetParam (0));
1130 void report_exception ()
1134 } catch (FileError& e) {
1138 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1139 std_to_wx (e.what()),
1140 std_to_wx (e.file().string().c_str ())
1143 } catch (exception& e) {
1147 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1148 std_to_wx (e.what ())
1152 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1156 /* An unhandled exception has occurred inside the main event loop */
1157 bool OnExceptionInMainLoop ()
1159 report_exception ();
1160 /* This will terminate the program */
1164 void OnUnhandledException ()
1166 report_exception ();
1171 signal_manager->ui_idle ();
1174 void config_failed_to_load ()
1176 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1179 void config_warning (string m)
1181 message_dialog (_frame, std_to_wx (m));
1185 string _dcp_to_load;