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/update_checker.h"
35 #include "lib/compose.hpp"
36 #include "lib/dcp_content.h"
37 #include "lib/job_manager.h"
40 #include "lib/video_content.h"
41 #include "lib/text_content.h"
42 #include "lib/ratio.h"
43 #include "lib/verify_dcp_job.h"
44 #include "lib/dcp_examiner.h"
45 #include "lib/examine_content_job.h"
46 #include "lib/server.h"
47 #include "lib/dcpomatic_socket.h"
49 #include <wx/stdpaths.h>
50 #include <wx/splash.h>
51 #include <wx/cmdline.h>
52 #include <wx/preferences.h>
53 #include <wx/progdlg.h>
54 #include <wx/display.h>
56 #include <ApplicationServices/ApplicationServices.h>
58 #include <boost/bind.hpp>
72 using boost::shared_ptr;
73 using boost::scoped_array;
74 using boost::optional;
75 using boost::dynamic_pointer_cast;
84 /* Allow spare IDs after _history for the recent files list */
87 /* Allow spare IDs for CPLs */
88 ID_view_full_screen = 200,
90 ID_view_closed_captions,
91 ID_view_scale_appropriate,
94 ID_view_scale_quarter,
95 ID_help_report_a_problem,
97 ID_tools_check_for_updates,
98 /* IDs for shortcuts (with no associated menu item) */
104 class DOMFrame : public wxFrame
108 : wxFrame (0, -1, _("DCP-o-matic Player"))
110 , _update_news_requested (false)
112 , _mode (Config::instance()->player_mode())
116 , _history_position (0)
117 , _history_separator (0)
120 #if defined(DCPOMATIC_WINDOWS)
121 maybe_open_console ();
122 cout << "DCP-o-matic Player is starting." << "\n";
125 wxMenuBar* bar = new wxMenuBar;
127 set_menu_sensitivity ();
130 #ifdef DCPOMATIC_WINDOWS
131 SetIcon (wxIcon (std_to_wx ("id")));
134 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this));
137 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
138 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
139 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
140 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
141 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
142 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
143 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
144 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
145 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
146 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
147 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
148 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
149 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
150 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
151 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
152 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
153 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
154 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
156 /* Use a panel as the only child of the Frame so that we avoid
157 the dark-grey background on Windows.
159 _overall_panel = new wxPanel (this, wxID_ANY);
161 _viewer.reset (new FilmViewer (_overall_panel));
162 _controls = new Controls (_overall_panel, _viewer);
163 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
164 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
165 _viewer->Started.connect (bind(&DOMFrame::playback_started, this));
166 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this));
167 _info = new PlayerInformation (_overall_panel, _viewer);
168 setup_main_sizer (true);
170 int accelerators = 4;
172 int accelerators = 3;
175 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
176 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
177 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
178 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
180 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
182 wxAcceleratorTable accel_table (accelerators, accel);
183 SetAcceleratorTable (accel_table);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
190 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
195 void setup_main_sizer (bool with_viewer)
197 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
199 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
201 main_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
202 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
203 _overall_panel->SetSizer (main_sizer);
204 _overall_panel->Layout ();
207 bool playback_permitted ()
209 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
214 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
215 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
216 if (d && !d->kdm_timing_window_valid()) {
222 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
228 void playback_started ()
230 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
235 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
236 DCPOMATIC_ASSERT (dcp);
237 DCPExaminer ex (dcp);
238 shared_ptr<dcp::CPL> playing_cpl;
239 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
240 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
244 DCPOMATIC_ASSERT (playing_cpl)
246 FILE* f = fopen_boost(*log, "a");
249 "%s playback-started %s %s\n",
250 dcp::LocalTime().as_string().c_str(),
251 dcp->directories().front().string().c_str(),
252 playing_cpl->annotation_text().c_str()
257 void playback_stopped ()
259 optional<boost::filesystem::path> log = Config::instance()->player_log_file();
264 FILE* f = fopen_boost(*log, "a");
265 fprintf (f, "%s playback-stopped\n", dcp::LocalTime().as_string().c_str());
269 void set_decode_reduction (optional<int> reduction)
271 _viewer->set_dcp_decode_reduction (reduction);
272 _info->triggered_update ();
273 Config::instance()->set_decode_reduction (reduction);
276 void load_dcp (boost::filesystem::path dir)
278 _film.reset (new Film (optional<boost::filesystem::path>()));
279 shared_ptr<DCPContent> dcp;
281 dcp.reset (new DCPContent (_film, dir));
282 } catch (boost::filesystem::filesystem_error& e) {
283 error_dialog (this, _("Could not load DCP"), std_to_wx (e.what()));
287 _film->examine_and_add_content (dcp, true);
288 bool const ok = progress (_("Loading DCP"));
289 if (!ok || !report_errors_from_last_job()) {
293 setup_from_dcp (dcp);
295 if (dcp->three_d()) {
296 _film->set_three_d (true);
299 _viewer->set_film (_film);
300 _viewer->seek (DCPTime(), true);
301 _info->triggered_update ();
303 Config::instance()->add_to_player_history (dir);
305 set_menu_sensitivity ();
307 wxMenuItemList old = _cpl_menu->GetMenuItems();
308 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
309 _cpl_menu->Remove (*i);
312 DCPExaminer ex (dcp);
313 int id = ID_view_cpl;
314 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
315 wxMenuItem* j = _cpl_menu->AppendRadioItem(
317 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
319 j->Check(!dcp->cpl() || i->id() == *dcp->cpl());
326 void setup_menu (wxMenuBar* m)
328 _file_menu = new wxMenu;
329 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
330 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
331 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("&Add KDM..."));
333 _history_position = _file_menu->GetMenuItems().GetCount();
335 _file_menu->AppendSeparator ();
336 _file_menu->Append (ID_file_close, _("&Close"));
337 _file_menu->AppendSeparator ();
340 _file_menu->Append (wxID_EXIT, _("&Exit"));
342 _file_menu->Append (wxID_EXIT, _("&Quit"));
346 _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
348 wxMenu* edit = new wxMenu;
349 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
352 _cpl_menu = new wxMenu;
354 wxMenu* view = new wxMenu;
355 optional<int> c = Config::instance()->decode_reduction();
356 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
357 view->AppendSeparator();
358 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
359 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
361 view->AppendSeparator();
362 view->Append(ID_view_closed_captions, _("Closed captions..."));
363 view->AppendSeparator();
364 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
365 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
366 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
367 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
369 wxMenu* tools = new wxMenu;
370 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
371 tools->AppendSeparator ();
372 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
374 wxMenu* help = new wxMenu;
376 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
378 help->Append (wxID_ABOUT, _("About"));
380 help->Append (ID_help_report_a_problem, _("Report a problem..."));
382 m->Append (_file_menu, _("&File"));
384 m->Append (edit, _("&Edit"));
386 m->Append (view, _("&View"));
387 m->Append (tools, _("&Tools"));
388 m->Append (help, _("&Help"));
393 wxString d = wxStandardPaths::Get().GetDocumentsDir();
394 if (Config::instance()->last_player_load_directory()) {
395 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
398 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
403 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
404 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
411 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
413 Config::instance()->set_last_player_load_directory (dcp.parent_path());
421 wxDirDialog* c = new wxDirDialog (
423 _("Select DCP to open as OV"),
424 wxStandardPaths::Get().GetDocumentsDir(),
425 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
431 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
432 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
439 DCPOMATIC_ASSERT (_film);
440 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
441 DCPOMATIC_ASSERT (dcp);
442 dcp->add_ov (wx_to_std(c->GetPath()));
443 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
444 bool const ok = progress (_("Loading DCP"));
445 if (!ok || !report_errors_from_last_job()) {
448 setup_from_dcp (dcp);
452 _info->triggered_update ();
457 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
459 if (d->ShowModal() == wxID_OK) {
460 DCPOMATIC_ASSERT (_film);
461 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
462 DCPOMATIC_ASSERT (dcp);
464 dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
465 dcp->examine (shared_ptr<Job>());
466 } catch (exception& e) {
467 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
474 _info->triggered_update ();
477 void file_history (wxCommandEvent& event)
479 vector<boost::filesystem::path> history = Config::instance()->player_history ();
480 int n = event.GetId() - ID_file_history;
481 if (n >= 0 && n < static_cast<int> (history.size ())) {
482 load_dcp (history[n]);
488 _viewer->set_film (shared_ptr<Film>());
490 _info->triggered_update ();
491 set_menu_sensitivity ();
499 void edit_preferences ()
501 if (!_config_dialog) {
502 _config_dialog = create_player_config_dialog ();
504 _config_dialog->Show (this);
507 void view_cpl (wxCommandEvent& ev)
509 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
510 DCPOMATIC_ASSERT (dcp);
511 DCPExaminer ex (dcp);
512 int id = ev.GetId() - ID_view_cpl;
513 DCPOMATIC_ASSERT (id >= 0);
514 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
515 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
516 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
522 dcp->set_cpl ((*i)->id());
523 dcp->examine (shared_ptr<Job>());
526 void view_full_screen ()
528 if (_mode == Config::PLAYER_MODE_FULL) {
529 _mode = Config::PLAYER_MODE_WINDOW;
531 _mode = Config::PLAYER_MODE_FULL;
537 void view_dual_screen ()
539 if (_mode == Config::PLAYER_MODE_DUAL) {
540 _mode = Config::PLAYER_MODE_WINDOW;
542 _mode = Config::PLAYER_MODE_DUAL;
550 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
551 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
556 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
557 _info->Show (_mode != Config::PLAYER_MODE_FULL);
558 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
559 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
561 if (_mode == Config::PLAYER_MODE_DUAL) {
562 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
563 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
564 _dual_screen->ShowFullScreen (true);
565 _viewer->panel()->Reparent (_dual_screen);
566 _dual_screen->Show ();
567 if (wxDisplay::GetCount() > 1) {
568 switch (Config::instance()->image_display()) {
570 _dual_screen->Move (0, 0);
571 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
574 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
575 // (0, 0) doesn't seem to work for some strange reason
582 _viewer->panel()->Reparent (_overall_panel);
583 _dual_screen->Destroy ();
588 setup_main_sizer (_mode != Config::PLAYER_MODE_DUAL);
591 void view_closed_captions ()
593 _viewer->show_closed_captions ();
598 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
599 DCPOMATIC_ASSERT (dcp);
601 JobManager* jm = JobManager::instance ();
602 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
603 bool const ok = progress (_("Verifying DCP"));
608 DCPOMATIC_ASSERT (!jm->get().empty());
609 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
610 DCPOMATIC_ASSERT (last);
612 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
617 void tools_check_for_updates ()
619 UpdateChecker::instance()->run ();
620 _update_news_requested = true;
625 AboutDialog* d = new AboutDialog (this);
630 void help_report_a_problem ()
632 ReportProblemDialog* d = new ReportProblemDialog (this);
633 if (d->ShowModal () == wxID_OK) {
639 void update_checker_state_changed ()
641 UpdateChecker* uc = UpdateChecker::instance ();
643 bool const announce =
644 _update_news_requested ||
645 (uc->stable() && Config::instance()->check_for_updates()) ||
646 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
648 _update_news_requested = false;
654 if (uc->state() == UpdateChecker::YES) {
655 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
656 dialog->ShowModal ();
658 } else if (uc->state() == UpdateChecker::FAILED) {
659 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
661 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
664 _update_news_requested = false;
667 void config_changed ()
669 /* Instantly save any config changes when using the player GUI */
671 Config::instance()->write_config();
672 } catch (exception& e) {
676 _("Could not write to config file at %s. Your changes have not been saved."),
677 std_to_wx (Config::instance()->cinemas_file().string()).data()
682 for (int i = 0; i < _history_items; ++i) {
683 delete _file_menu->Remove (ID_file_history + i);
686 if (_history_separator) {
687 _file_menu->Remove (_history_separator);
689 delete _history_separator;
690 _history_separator = 0;
692 int pos = _history_position;
694 vector<boost::filesystem::path> history = Config::instance()->player_history ();
696 if (!history.empty ()) {
697 _history_separator = _file_menu->InsertSeparator (pos++);
700 for (size_t i = 0; i < history.size(); ++i) {
703 s = String::compose ("&%1 %2", i + 1, history[i].string());
705 s = history[i].string();
707 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
710 _history_items = history.size ();
713 void set_menu_sensitivity ()
715 _tools_verify->Enable (static_cast<bool>(_film));
716 _file_add_ov->Enable (static_cast<bool>(_film));
717 _file_add_kdm->Enable (static_cast<bool>(_film));
718 _view_cpl->Enable (static_cast<bool>(_film));
721 void start_stop_pressed ()
723 if (_viewer->playing()) {
732 _viewer->seek_by (-_viewer->one_video_frame(), true);
735 void forward_frame ()
737 _viewer->seek_by (_viewer->one_video_frame(), true);
742 /** @return false if the task was cancelled */
743 bool progress (wxString task)
745 JobManager* jm = JobManager::instance ();
747 wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic Player"), task, 100, 0, wxPD_CAN_ABORT);
751 while (jm->work_to_do() || signal_manager->ui_idle()) {
753 if (!progress->Pulse()) {
754 /* user pressed cancel */
755 BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
763 progress->Destroy ();
767 bool report_errors_from_last_job ()
769 JobManager* jm = JobManager::instance ();
771 DCPOMATIC_ASSERT (!jm->get().empty());
773 shared_ptr<Job> last = jm->get().back();
774 if (last->finished_in_error()) {
775 error_dialog(this, std_to_wx(last->error_summary()) + ".\n", std_to_wx(last->error_details()));
782 void setup_from_dcp (shared_ptr<DCPContent> dcp)
784 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
789 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
791 _film->set_container(r);
796 wxFrame* _dual_screen;
797 bool _update_news_requested;
798 PlayerInformation* _info;
799 Config::PlayerMode _mode;
800 wxPreferencesEditor* _config_dialog;
801 wxPanel* _overall_panel;
803 wxMenuItem* _view_cpl;
806 int _history_position;
807 wxMenuItem* _history_separator;
808 shared_ptr<FilmViewer> _viewer;
810 boost::shared_ptr<Film> _film;
811 boost::signals2::scoped_connection _config_changed_connection;
812 wxMenuItem* _file_add_ov;
813 wxMenuItem* _file_add_kdm;
814 wxMenuItem* _tools_verify;
815 wxMenuItem* _view_full_screen;
816 wxMenuItem* _view_dual_screen;
819 static const wxCmdLineEntryDesc command_line_description[] = {
820 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
821 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
824 class PlayServer : public Server
827 explicit PlayServer (DOMFrame* frame)
828 : Server (PLAYER_PLAY_PORT)
832 void handle (shared_ptr<Socket> socket)
835 int const length = socket->read_uint32 ();
836 scoped_array<char> buffer (new char[length]);
837 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
838 string s (buffer.get());
839 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
840 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
851 * @brief The magic App class for wxWidgets.
853 class App : public wxApp
866 wxInitAllImageHandlers ();
868 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
869 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
871 wxSplashScreen* splash = maybe_show_splash ();
873 SetAppName (_("DCP-o-matic Player"));
875 if (!wxApp::OnInit()) {
879 #ifdef DCPOMATIC_LINUX
880 unsetenv ("UBUNTU_MENUPROXY");
884 ProcessSerialNumber serial;
885 GetCurrentProcess (&serial);
886 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
889 dcpomatic_setup_path_encoding ();
891 /* Enable i18n; this will create a Config object
892 to look for a force-configured language. This Config
893 object will be wrong, however, because dcpomatic_setup
894 hasn't yet been called and there aren't any filters etc.
897 dcpomatic_setup_i18n ();
899 /* Set things up, including filters etc.
900 which will now be internationalised correctly.
904 /* Force the configuration to be re-loaded correctly next
909 _frame = new DOMFrame ();
910 SetTopWindow (_frame);
917 signal_manager = new wxSignalManager (this);
919 PlayServer* server = new PlayServer (_frame);
920 new thread (boost::bind (&PlayServer::run, server));
922 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
924 _frame->load_dcp (_dcp_to_load);
925 } catch (exception& e) {
926 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
930 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
932 if (Config::instance()->check_for_updates ()) {
933 UpdateChecker::instance()->run ();
940 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
944 void OnInitCmdLine (wxCmdLineParser& parser)
946 parser.SetDesc (command_line_description);
947 parser.SetSwitchChars (wxT ("-"));
950 bool OnCmdLineParsed (wxCmdLineParser& parser)
952 if (parser.GetParamCount() > 0) {
953 _dcp_to_load = wx_to_std (parser.GetParam (0));
959 void report_exception ()
963 } catch (FileError& e) {
967 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
968 std_to_wx (e.what()),
969 std_to_wx (e.file().string().c_str ())
972 } catch (exception& e) {
976 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
977 std_to_wx (e.what ())
981 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
985 /* An unhandled exception has occurred inside the main event loop */
986 bool OnExceptionInMainLoop ()
989 /* This will terminate the program */
993 void OnUnhandledException ()
1000 signal_manager->ui_idle ();
1003 void config_failed_to_load ()
1005 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1008 void config_warning (string m)
1010 message_dialog (_frame, std_to_wx (m));
1014 string _dcp_to_load;