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"
51 #include <wx/stdpaths.h>
52 #include <wx/splash.h>
53 #include <wx/cmdline.h>
54 #include <wx/preferences.h>
55 #include <wx/progdlg.h>
56 #include <wx/display.h>
58 #include <ApplicationServices/ApplicationServices.h>
60 #include <boost/bind.hpp>
74 using boost::shared_ptr;
75 using boost::scoped_array;
76 using boost::optional;
77 using boost::dynamic_pointer_cast;
86 /* Allow spare IDs after _history for the recent files list */
89 /* Allow spare IDs for CPLs */
90 ID_view_full_screen = 200,
92 ID_view_closed_captions,
93 ID_view_scale_appropriate,
96 ID_view_scale_quarter,
97 ID_help_report_a_problem,
99 ID_tools_check_for_updates,
100 /* IDs for shortcuts (with no associated menu item) */
106 class DOMFrame : public wxFrame
110 : wxFrame (0, -1, _("DCP-o-matic Player"))
112 , _update_news_requested (false)
114 , _mode (Config::instance()->player_mode())
118 , _history_position (0)
119 , _history_separator (0)
120 , _view_full_screen (0)
121 , _view_dual_screen (0)
124 #if defined(DCPOMATIC_WINDOWS)
125 maybe_open_console ();
126 cout << "DCP-o-matic Player is starting." << "\n";
129 wxMenuBar* bar = new wxMenuBar;
131 set_menu_sensitivity ();
134 #ifdef DCPOMATIC_WINDOWS
135 SetIcon (wxIcon (std_to_wx ("id")));
138 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
141 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
142 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
143 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
144 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
145 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
155 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
156 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
157 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
158 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
160 /* Use a panel as the only child of the Frame so that we avoid
161 the dark-grey background on Windows.
163 _overall_panel = new wxPanel (this, wxID_ANY);
165 _viewer.reset (new FilmViewer (_overall_panel));
166 _controls = new Controls (_overall_panel, _viewer, false);
167 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
168 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
169 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
170 _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
171 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
172 _info = new PlayerInformation (_overall_panel, _viewer);
173 setup_main_sizer (Config::instance()->player_mode());
175 int accelerators = 4;
177 int accelerators = 3;
180 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
181 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
182 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
183 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
185 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
187 wxAcceleratorTable accel_table (accelerators, accel);
188 SetAcceleratorTable (accel_table);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
195 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
196 _controls->SPLChanged.connect (boost::bind(&DOMFrame::set_spl, this, _1));
201 void setup_main_sizer (Config::PlayerMode mode)
203 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
204 if (mode != Config::PLAYER_MODE_DUAL) {
205 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
207 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
208 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
209 _overall_panel->SetSizer (main_sizer);
210 _overall_panel->Layout ();
213 bool playback_permitted ()
215 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
220 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
221 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
222 if (d && !d->kdm_timing_window_valid()) {
228 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
234 void playback_started (DCPTime time)
236 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
241 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
242 DCPOMATIC_ASSERT (dcp);
243 DCPExaminer ex (dcp);
244 shared_ptr<dcp::CPL> playing_cpl;
245 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
246 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
250 DCPOMATIC_ASSERT (playing_cpl)
252 FILE* f = fopen_boost(*log, "a");
255 "%s playback-started %s %s %s\n",
256 dcp::LocalTime().as_string().c_str(),
257 time.timecode(_film->video_frame_rate()).c_str(),
258 dcp->directories().front().string().c_str(),
259 playing_cpl->annotation_text().c_str()
264 void playback_seeked (DCPTime time)
266 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
271 FILE* f = fopen_boost(*log, "a");
272 fprintf (f, "%s playback-seeked %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
276 void playback_stopped (DCPTime time)
278 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
283 FILE* f = fopen_boost(*log, "a");
284 fprintf (f, "%s playback-stopped %s\n", dcp::LocalTime().as_string().c_str(), time.timecode(_film->video_frame_rate()).c_str());
288 void set_decode_reduction (optional<int> reduction)
290 _viewer->set_dcp_decode_reduction (reduction);
291 _info->triggered_update ();
292 Config::instance()->set_decode_reduction (reduction);
295 void load_dcp (boost::filesystem::path dir)
298 spl.push_back (SPLEntry(dir));
300 Config::instance()->add_to_player_history (dir);
303 optional<dcp::EncryptedKDM> get_kdm_from_url (shared_ptr<DCPContent> dcp)
305 ScopedTemporary temp;
306 string url = Config::instance()->kdm_server_url();
307 boost::algorithm::replace_all (url, "{CPL}", *dcp->cpl());
308 optional<dcp::EncryptedKDM> kdm;
309 if (dcp->cpl() && !get_from_url(url, false, temp)) {
311 kdm = dcp::EncryptedKDM (dcp::file_to_string(temp.file()));
312 if (kdm->cpl_id() != dcp->cpl()) {
315 } catch (std::exception& e) {
322 optional<dcp::EncryptedKDM> get_kdm_from_directory (shared_ptr<DCPContent> dcp)
324 using namespace boost::filesystem;
325 optional<path> kdm_dir = Config::instance()->player_kdm_directory();
327 return optional<dcp::EncryptedKDM>();
329 for (directory_iterator i = directory_iterator(*kdm_dir); i != directory_iterator(); ++i) {
330 if (file_size(i->path()) < MAX_KDM_SIZE) {
332 dcp::EncryptedKDM kdm (dcp::file_to_string(i->path()));
333 if (kdm.cpl_id() == dcp->cpl()) {
336 } catch (std::exception& e) {
341 return optional<dcp::EncryptedKDM>();
344 void set_spl (list<SPLEntry> spl)
346 if (_viewer->playing ()) {
350 _film.reset (new Film (optional<boost::filesystem::path>()));
353 _viewer->set_film (_film);
354 _info->triggered_update ();
358 /* Start off as Flat */
359 _film->set_container (Ratio::from_id("185"));
362 shared_ptr<DCPContent> first;
364 BOOST_FOREACH (SPLEntry i, spl) {
365 shared_ptr<DCPContent> dcp;
367 dcp.reset (new DCPContent (_film, i.dcp));
368 } catch (boost::filesystem::filesystem_error& e) {
369 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
377 _film->examine_and_add_content (dcp, true);
378 bool const ok = progress (_("Loading DCP"));
379 if (!ok || !report_errors_from_last_job()) {
383 dcp->set_position (position + i.black_before);
384 position += dcp->length_after_trim() + i.black_before;
386 /* This DCP has been examined and loaded */
388 if (dcp->needs_kdm()) {
389 optional<dcp::EncryptedKDM> kdm;
390 #ifdef DCPOMATIC_VARIANT_SWAROOP
391 kdm = get_kdm_from_url (dcp);
394 get_kdm_from_directory (dcp);
399 dcp->examine (shared_ptr<Job>());
403 BOOST_FOREACH (shared_ptr<TextContent> j, dcp->text) {
408 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
409 if (r->id() == "239") {
410 /* Any scope content means we use scope */
411 _film->set_container(r);
415 /* Any 3D content means we use 3D mode */
416 if (dcp->three_d()) {
417 _film->set_three_d (true);
420 _viewer->set_film (_film);
421 _viewer->seek (DCPTime(), true);
422 _info->triggered_update ();
424 set_menu_sensitivity ();
425 _controls->log (wxString::Format(_("Load DCP %s"), i.dcp.filename().string().c_str()));
428 wxMenuItemList old = _cpl_menu->GetMenuItems();
429 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
430 _cpl_menu->Remove (*i);
433 if (spl.size() == 1) {
434 /* Offer a CPL menu */
435 DCPExaminer ex (first);
436 int id = ID_view_cpl;
437 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
438 wxMenuItem* j = _cpl_menu->AppendRadioItem(
440 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
442 j->Check(!first->cpl() || i->id() == *first->cpl());
450 void setup_menu (wxMenuBar* m)
452 _file_menu = new wxMenu;
453 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
454 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
455 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
457 _history_position = _file_menu->GetMenuItems().GetCount();
459 _file_menu->AppendSeparator ();
460 _file_menu->Append (ID_file_close, _("&Close"));
461 _file_menu->AppendSeparator ();
464 _file_menu->Append (wxID_EXIT, _("&Exit"));
466 _file_menu->Append (wxID_EXIT, _("&Quit"));
470 _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
472 wxMenu* edit = new wxMenu;
473 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
476 _cpl_menu = new wxMenu;
478 wxMenu* view = new wxMenu;
479 optional<int> c = Config::instance()->decode_reduction();
480 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
481 view->AppendSeparator();
482 #ifndef DCPOMATIC_VARIANT_SWAROOP
483 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
484 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
487 view->AppendSeparator();
488 view->Append(ID_view_closed_captions, _("Closed captions..."));
489 view->AppendSeparator();
490 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
491 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
492 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
493 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
495 wxMenu* tools = new wxMenu;
496 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
497 tools->AppendSeparator ();
498 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
500 wxMenu* help = new wxMenu;
502 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
504 help->Append (wxID_ABOUT, _("About"));
506 help->Append (ID_help_report_a_problem, _("Report a problem..."));
508 m->Append (_file_menu, _("&File"));
510 m->Append (edit, _("&Edit"));
512 m->Append (view, _("&View"));
513 m->Append (tools, _("&Tools"));
514 m->Append (help, _("&Help"));
519 wxString d = wxStandardPaths::Get().GetDocumentsDir();
520 if (Config::instance()->last_player_load_directory()) {
521 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
524 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
529 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
530 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
537 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
539 Config::instance()->set_last_player_load_directory (dcp.parent_path());
547 wxDirDialog* c = new wxDirDialog (
549 _("Select DCP to open as OV"),
550 wxStandardPaths::Get().GetDocumentsDir(),
551 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
557 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
558 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
565 DCPOMATIC_ASSERT (_film);
566 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
567 DCPOMATIC_ASSERT (dcp);
568 dcp->add_ov (wx_to_std(c->GetPath()));
569 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
570 bool const ok = progress (_("Loading DCP"));
571 if (!ok || !report_errors_from_last_job()) {
574 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
578 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
580 _film->set_container(r);
586 _info->triggered_update ();
591 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
593 if (d->ShowModal() == wxID_OK) {
594 DCPOMATIC_ASSERT (_film);
595 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
596 DCPOMATIC_ASSERT (dcp);
598 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
599 dcp->examine (shared_ptr<Job>());
600 } catch (exception& e) {
601 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
608 _info->triggered_update ();
611 void file_history (wxCommandEvent& event)
613 vector<boost::filesystem::path> history = Config::instance()->player_history ();
614 int n = event.GetId() - ID_file_history;
615 if (n >= 0 && n < static_cast<int> (history.size ())) {
616 load_dcp (history[n]);
622 _viewer->set_film (shared_ptr<Film>());
624 _info->triggered_update ();
625 set_menu_sensitivity ();
633 void edit_preferences ()
635 if (!_config_dialog) {
636 _config_dialog = create_player_config_dialog ();
638 _config_dialog->Show (this);
641 void view_cpl (wxCommandEvent& ev)
643 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
644 DCPOMATIC_ASSERT (dcp);
645 DCPExaminer ex (dcp);
646 int id = ev.GetId() - ID_view_cpl;
647 DCPOMATIC_ASSERT (id >= 0);
648 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
649 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
650 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
656 dcp->set_cpl ((*i)->id());
657 dcp->examine (shared_ptr<Job>());
660 void view_full_screen ()
662 if (_mode == Config::PLAYER_MODE_FULL) {
663 _mode = Config::PLAYER_MODE_WINDOW;
665 _mode = Config::PLAYER_MODE_FULL;
671 void view_dual_screen ()
673 if (_mode == Config::PLAYER_MODE_DUAL) {
674 _mode = Config::PLAYER_MODE_WINDOW;
676 _mode = Config::PLAYER_MODE_DUAL;
684 if (_view_full_screen) {
685 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
687 if (_view_dual_screen) {
688 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
694 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
695 _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
696 _info->Show (_mode != Config::PLAYER_MODE_FULL);
697 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
698 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
700 if (_mode == Config::PLAYER_MODE_DUAL) {
701 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
702 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
703 _dual_screen->ShowFullScreen (true);
704 _viewer->panel()->Reparent (_dual_screen);
705 _dual_screen->Show ();
706 if (wxDisplay::GetCount() > 1) {
707 switch (Config::instance()->image_display()) {
709 _dual_screen->Move (0, 0);
710 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
713 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
714 // (0, 0) doesn't seem to work for some strange reason
721 _viewer->panel()->Reparent (_overall_panel);
722 _dual_screen->Destroy ();
727 setup_main_sizer (_mode);
730 void view_closed_captions ()
732 _viewer->show_closed_captions ();
737 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
738 DCPOMATIC_ASSERT (dcp);
740 JobManager* jm = JobManager::instance ();
741 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
742 bool const ok = progress (_("Verifying DCP"));
747 DCPOMATIC_ASSERT (!jm->get().empty());
748 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
749 DCPOMATIC_ASSERT (last);
751 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
756 void tools_check_for_updates ()
758 UpdateChecker::instance()->run ();
759 _update_news_requested = true;
764 AboutDialog* d = new AboutDialog (this);
769 void help_report_a_problem ()
771 ReportProblemDialog* d = new ReportProblemDialog (this);
772 if (d->ShowModal () == wxID_OK) {
778 void update_checker_state_changed ()
780 UpdateChecker* uc = UpdateChecker::instance ();
782 bool const announce =
783 _update_news_requested ||
784 (uc->stable() && Config::instance()->check_for_updates()) ||
785 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
787 _update_news_requested = false;
793 if (uc->state() == UpdateChecker::YES) {
794 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
795 dialog->ShowModal ();
797 } else if (uc->state() == UpdateChecker::FAILED) {
798 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
800 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
803 _update_news_requested = false;
806 void config_changed ()
808 /* Instantly save any config changes when using the player GUI */
810 Config::instance()->write_config();
811 } catch (exception& e) {
815 _("Could not write to config file at %s. Your changes have not been saved."),
816 std_to_wx (Config::instance()->cinemas_file().string()).data()
821 for (int i = 0; i < _history_items; ++i) {
822 delete _file_menu->Remove (ID_file_history + i);
825 if (_history_separator) {
826 _file_menu->Remove (_history_separator);
828 delete _history_separator;
829 _history_separator = 0;
831 int pos = _history_position;
833 vector<boost::filesystem::path> history = Config::instance()->player_history ();
835 if (!history.empty ()) {
836 _history_separator = _file_menu->InsertSeparator (pos++);
839 for (size_t i = 0; i < history.size(); ++i) {
842 s = String::compose ("&%1 %2", i + 1, history[i].string());
844 s = history[i].string();
846 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
849 _history_items = history.size ();
852 void set_menu_sensitivity ()
854 _tools_verify->Enable (static_cast<bool>(_film));
855 _file_add_ov->Enable (static_cast<bool>(_film));
856 _file_add_kdm->Enable (static_cast<bool>(_film));
857 _view_cpl->Enable (static_cast<bool>(_film));
860 void start_stop_pressed ()
862 if (_viewer->playing()) {
871 _viewer->seek_by (-_viewer->one_video_frame(), true);
874 void forward_frame ()
876 _viewer->seek_by (_viewer->one_video_frame(), true);
881 /** @return false if the task was cancelled */
882 bool progress (wxString task)
884 JobManager* jm = JobManager::instance ();
886 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
890 while (jm->work_to_do() || signal_manager->ui_idle()) {
892 if (!progress->Pulse()) {
893 /* user pressed cancel */
894 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
902 progress->Destroy ();
906 bool report_errors_from_last_job ()
908 JobManager* jm = JobManager::instance ();
910 DCPOMATIC_ASSERT (!jm->get().empty());
912 shared_ptr<Job> last = jm->get().back();
913 if (last->finished_in_error()) {
914 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
921 wxFrame* _dual_screen;
922 bool _update_news_requested;
923 PlayerInformation* _info;
924 Config::PlayerMode _mode;
925 wxPreferencesEditor* _config_dialog;
926 wxPanel* _overall_panel;
928 wxMenuItem* _view_cpl;
931 int _history_position;
932 wxMenuItem* _history_separator;
933 shared_ptr<FilmViewer> _viewer;
935 boost::shared_ptr<Film> _film;
936 boost::signals2::scoped_connection _config_changed_connection;
937 wxMenuItem* _file_add_ov;
938 wxMenuItem* _file_add_kdm;
939 wxMenuItem* _tools_verify;
940 wxMenuItem* _view_full_screen;
941 wxMenuItem* _view_dual_screen;
944 static const wxCmdLineEntryDesc command_line_description[] = {
945 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
946 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
949 class PlayServer : public Server
952 explicit PlayServer (DOMFrame* frame)
953 : Server (PLAYER_PLAY_PORT)
957 void handle (shared_ptr<Socket> socket)
960 int const length = socket->read_uint32 ();
961 scoped_array<char> buffer (new char[length]);
962 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
963 string s (buffer.get());
964 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
965 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
976 * @brief The magic App class for wxWidgets.
978 class App : public wxApp
991 wxInitAllImageHandlers ();
993 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
994 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
996 wxSplashScreen* splash = maybe_show_splash ();
998 SetAppName (_("DCP-o-matic Player"));
1000 if (!wxApp::OnInit()) {
1004 #ifdef DCPOMATIC_LINUX
1005 unsetenv ("UBUNTU_MENUPROXY");
1009 ProcessSerialNumber serial;
1010 GetCurrentProcess (&serial);
1011 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1014 dcpomatic_setup_path_encoding ();
1016 /* Enable i18n; this will create a Config object
1017 to look for a force-configured language. This Config
1018 object will be wrong, however, because dcpomatic_setup
1019 hasn't yet been called and there aren't any filters etc.
1022 dcpomatic_setup_i18n ();
1024 /* Set things up, including filters etc.
1025 which will now be internationalised correctly.
1029 /* Force the configuration to be re-loaded correctly next
1034 _frame = new DOMFrame ();
1035 SetTopWindow (_frame);
1036 _frame->Maximize ();
1042 signal_manager = new wxSignalManager (this);
1044 PlayServer* server = new PlayServer (_frame);
1045 new thread (boost::bind (&PlayServer::run, server));
1047 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1049 _frame->load_dcp (_dcp_to_load);
1050 } catch (exception& e) {
1051 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1055 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1057 if (Config::instance()->check_for_updates ()) {
1058 UpdateChecker::instance()->run ();
1063 catch (exception& e)
1065 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1069 void OnInitCmdLine (wxCmdLineParser& parser)
1071 parser.SetDesc (command_line_description);
1072 parser.SetSwitchChars (wxT ("-"));
1075 bool OnCmdLineParsed (wxCmdLineParser& parser)
1077 if (parser.GetParamCount() > 0) {
1078 _dcp_to_load = wx_to_std (parser.GetParam (0));
1084 void report_exception ()
1088 } catch (FileError& e) {
1092 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1093 std_to_wx (e.what()),
1094 std_to_wx (e.file().string().c_str ())
1097 } catch (exception& e) {
1101 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1102 std_to_wx (e.what ())
1106 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1110 /* An unhandled exception has occurred inside the main event loop */
1111 bool OnExceptionInMainLoop ()
1113 report_exception ();
1114 /* This will terminate the program */
1118 void OnUnhandledException ()
1120 report_exception ();
1125 signal_manager->ui_idle ();
1128 void config_failed_to_load ()
1130 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1133 void config_warning (string m)
1135 message_dialog (_frame, std_to_wx (m));
1139 string _dcp_to_load;