Move stress testing code into a separate class and always build it.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
1 /*
2     Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
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/standard_controls.h"
31 #include "wx/playlist_controls.h"
32 #ifdef DCPOMATIC_VARIANT_SWAROOP
33 #include "wx/swaroop_controls.h"
34 #endif
35 #include "wx/timer_display.h"
36 #include "wx/system_information_dialog.h"
37 #include "wx/player_stress_tester.h"
38 #include "lib/cross.h"
39 #include "lib/config.h"
40 #include "lib/util.h"
41 #include "lib/internet.h"
42 #include "lib/update_checker.h"
43 #include "lib/compose.hpp"
44 #include "lib/dcp_content.h"
45 #include "lib/job_manager.h"
46 #include "lib/job.h"
47 #include "lib/film.h"
48 #include "lib/null_log.h"
49 #include "lib/video_content.h"
50 #include "lib/text_content.h"
51 #include "lib/ratio.h"
52 #include "lib/verify_dcp_job.h"
53 #include "lib/dcp_examiner.h"
54 #include "lib/examine_content_job.h"
55 #include "lib/server.h"
56 #include "lib/dcpomatic_socket.h"
57 #include "lib/scoped_temporary.h"
58 #include "lib/monitor_checker.h"
59 #include "lib/lock_file_checker.h"
60 #include "lib/ffmpeg_content.h"
61 #include "lib/dcpomatic_log.h"
62 #include "lib/file_log.h"
63 #include <dcp/dcp.h>
64 #include <dcp/raw_convert.h>
65 #include <dcp/exceptions.h>
66 #include <wx/wx.h>
67 #include <wx/stdpaths.h>
68 #include <wx/splash.h>
69 #include <wx/cmdline.h>
70 #include <wx/preferences.h>
71 #include <wx/progdlg.h>
72 #include <wx/display.h>
73 #ifdef __WXGTK__
74 #include <X11/Xlib.h>
75 #endif
76 #ifdef __WXOSX__
77 #include <ApplicationServices/ApplicationServices.h>
78 #endif
79 #include <boost/bind.hpp>
80 #include <boost/algorithm/string.hpp>
81 #include <iostream>
82
83 #ifdef check
84 #undef check
85 #endif
86
87 #define MAX_CPLS 32
88
89 using std::string;
90 using std::cout;
91 using std::list;
92 using std::exception;
93 using std::vector;
94 using boost::shared_ptr;
95 using boost::weak_ptr;
96 using boost::scoped_array;
97 using boost::optional;
98 using boost::dynamic_pointer_cast;
99 using boost::thread;
100 using boost::bind;
101 using dcp::raw_convert;
102 using namespace dcpomatic;
103
104 enum {
105         ID_file_open = 1,
106         ID_file_add_ov,
107         ID_file_add_kdm,
108         ID_file_history,
109         /* Allow spare IDs after _history for the recent files list */
110         ID_file_close = 100,
111         ID_view_cpl,
112         /* Allow spare IDs for CPLs */
113         ID_view_full_screen = 200,
114         ID_view_dual_screen,
115         ID_view_closed_captions,
116         ID_view_scale_appropriate,
117         ID_view_scale_full,
118         ID_view_scale_half,
119         ID_view_scale_quarter,
120         ID_help_report_a_problem,
121         ID_tools_verify,
122         ID_tools_check_for_updates,
123         ID_tools_timing,
124         ID_tools_system_information,
125         /* IDs for shortcuts (with no associated menu item) */
126         ID_start_stop,
127         ID_back_frame,
128         ID_forward_frame
129 };
130
131 class DOMFrame : public wxFrame
132 {
133 public:
134         DOMFrame ()
135                 : wxFrame (0, -1, _("DCP-o-matic Player"))
136                 , _dual_screen (0)
137                 , _update_news_requested (false)
138                 , _info (0)
139                 , _mode (Config::instance()->player_mode())
140                 , _config_dialog (0)
141                 , _file_menu (0)
142                 , _history_items (0)
143                 , _history_position (0)
144                 , _history_separator (0)
145                 , _system_information_dialog (0)
146                 , _view_full_screen (0)
147                 , _view_dual_screen (0)
148 {
149                 dcpomatic_log.reset (new NullLog());
150
151 #if defined(DCPOMATIC_WINDOWS)
152                 maybe_open_console ();
153                 cout << "DCP-o-matic Player is starting." << "\n";
154 #endif
155
156                 wxMenuBar* bar = new wxMenuBar;
157                 setup_menu (bar);
158                 set_menu_sensitivity ();
159                 SetMenuBar (bar);
160
161 #ifdef DCPOMATIC_WINDOWS
162                 SetIcon (wxIcon (std_to_wx ("id")));
163 #endif
164
165                 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
166                 update_from_config (Config::PLAYER_DEBUG_LOG);
167
168                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
169                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
170                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
171                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
172                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
173                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
174                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
175                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
176                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
177                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
178                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
179                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
180                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
181                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
182                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
183                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
184                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
185                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
186                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
187                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
188
189                 /* Use a panel as the only child of the Frame so that we avoid
190                    the dark-grey background on Windows.
191                 */
192                 _overall_panel = new wxPanel (this, wxID_ANY);
193
194                 _viewer.reset (new FilmViewer (_overall_panel));
195 #ifdef DCPOMATIC_VARIANT_SWAROOP
196                 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
197                 _controls = sc;
198                 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
199 #else
200                 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
201                         PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
202                         _controls = pc;
203                         pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
204                 } else {
205                         _controls = new StandardControls (_overall_panel, _viewer, false);
206                 }
207 #endif
208                 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
209                 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
210                 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
211                 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
212                 _info = new PlayerInformation (_overall_panel, _viewer);
213                 setup_main_sizer (Config::instance()->player_mode());
214 #ifdef __WXOSX__
215                 int accelerators = 4;
216 #else
217                 int accelerators = 3;
218 #endif
219
220                 _stress.setup (this, _controls);
221
222                 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
223                 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
224                 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
225                 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
226 #ifdef __WXOSX__
227                 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
228 #endif
229                 wxAcceleratorTable accel_table (accelerators, accel);
230                 SetAcceleratorTable (accel_table);
231                 delete[] accel;
232
233                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
234                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
235                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
236
237                 reset_film ();
238
239                 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
240 #ifdef DCPOMATIC_VARIANT_SWAROOP
241                 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
242                 MonitorChecker::instance()->run ();
243                 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
244                 LockFileChecker::instance()->run ();
245 #endif
246                 setup_screen ();
247
248                 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
249
250 #ifdef DCPOMATIC_VARIANT_SWAROOP
251                 sc->check_restart ();
252 #endif
253         }
254
255 #ifdef DCPOMATIC_VARIANT_SWAROOP
256         void monitor_checker_state_changed ()
257         {
258                 if (!MonitorChecker::instance()->ok()) {
259                         _viewer->stop ();
260                         error_dialog (this, _("The required display devices are not connected correctly."));
261                 }
262         }
263
264         void lock_checker_state_changed ()
265         {
266                 if (!LockFileChecker::instance()->ok()) {
267                         _viewer->stop ();
268                         error_dialog (this, _("The lock file is not present."));
269                 }
270         }
271 #endif
272
273         void setup_main_sizer (Config::PlayerMode mode)
274         {
275                 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
276                 if (mode != Config::PLAYER_MODE_DUAL) {
277                         main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
278                 }
279                 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
280                 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
281                 _overall_panel->SetSizer (main_sizer);
282                 _overall_panel->Layout ();
283         }
284
285         bool playback_permitted ()
286         {
287 #ifdef DCPOMATIC_VARIANT_SWAROOP
288                 if (!MonitorChecker::instance()->ok()) {
289                         error_dialog (this, _("The required display devices are not connected correctly."));
290                         return false;
291                 }
292                 if (!LockFileChecker::instance()->ok()) {
293                         error_dialog (this, _("The lock file is not present."));
294                         return false;
295                 }
296 #endif
297                 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
298                         return true;
299                 }
300
301                 bool ok = true;
302                 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
303                         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
304                         if (d && !d->kdm_timing_window_valid()) {
305                                 ok = false;
306                         }
307                 }
308
309 #ifdef DCPOMATIC_VARIANT_SWAROOP
310                 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
311                         shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
312                         if (c && !c->kdm_timing_window_valid()) {
313                                 ok = false;
314                         }
315                 }
316 #endif
317
318                 if (!ok) {
319                         error_dialog (this, _("The KDM does not allow playback of this content at this time."));
320                 }
321
322                 return ok;
323         }
324
325         void playback_started (DCPTime time)
326         {
327                 /* XXX: this only logs the first piece of content; probably should be each piece? */
328                 if (_film->content().empty()) {
329                         return;
330                 }
331
332                 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
333                 if (dcp) {
334                         DCPExaminer ex (dcp, true);
335                         shared_ptr<dcp::CPL> playing_cpl;
336                         BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
337                                 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
338                                         playing_cpl = i;
339                                 }
340                         }
341                         DCPOMATIC_ASSERT (playing_cpl);
342
343                         _controls->log (
344                                 wxString::Format(
345                                         "playback-started %s %s %s",
346                                         time.timecode(_film->video_frame_rate()).c_str(),
347                                         dcp->directories().front().string().c_str(),
348                                         playing_cpl->annotation_text().c_str()
349                                         )
350                                 );
351                 }
352
353                 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
354                 if (ffmpeg) {
355                         _controls->log (
356                                 wxString::Format(
357                                         "playback-started %s %s",
358                                         time.timecode(_film->video_frame_rate()).c_str(),
359                                         ffmpeg->path(0).string().c_str()
360                                         )
361                                 );
362                 }
363         }
364
365         void playback_stopped (DCPTime time)
366         {
367 #ifdef DCPOMATIC_VARIANT_SWAROOP
368                 try {
369                         boost::filesystem::remove (Config::path("position"));
370                 } catch (...) {
371                         /* Never mind */
372                 }
373 #endif
374
375                 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
376         }
377
378         void set_decode_reduction (optional<int> reduction)
379         {
380                 _viewer->set_dcp_decode_reduction (reduction);
381                 _info->triggered_update ();
382                 Config::instance()->set_decode_reduction (reduction);
383         }
384
385         void load_dcp (boost::filesystem::path dir)
386         {
387                 DCPOMATIC_ASSERT (_film);
388
389                 reset_film ();
390                 try {
391                         _stress.set_suspended (true);
392                         shared_ptr<DCPContent> dcp (new DCPContent(dir));
393                         shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
394                         _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
395                         JobManager::instance()->add (job);
396                         bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
397                         if (!ok || !report_errors_from_last_job(this)) {
398                                 return;
399                         }
400 #ifndef DCPOMATIC_VARIANT_SWAROOP
401                         Config::instance()->add_to_player_history (dir);
402 #endif
403                 } catch (dcp::DCPReadError& e) {
404                         error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
405                 }
406         }
407
408         void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
409         {
410                 shared_ptr<Job> job = weak_job.lock ();
411                 if (!job || !job->finished_ok()) {
412                         return;
413                 }
414
415                 shared_ptr<Content> content = weak_content.lock ();
416                 if (!content) {
417                         return;
418                 }
419
420                 _film->add_content (content);
421                 _stress.set_suspended (false);
422         }
423
424         void reset_film_weak (weak_ptr<Film> weak_film)
425         {
426                 shared_ptr<Film> film = weak_film.lock ();
427                 if (film) {
428                         reset_film (film);
429                 }
430         }
431
432         void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
433         {
434                 _film = film;
435                 _film->set_tolerant (true);
436                 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
437                 _viewer->set_film (_film);
438                 _controls->set_film (_film);
439                 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
440                 _info->triggered_update ();
441         }
442
443         void film_changed (ChangeType type, Film::Property property)
444         {
445                 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
446                         return;
447                 }
448
449                 if (_viewer->playing ()) {
450                         _viewer->stop ();
451                 }
452
453                 /* Start off as Flat */
454                 _film->set_container (Ratio::from_id("185"));
455
456                 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
457                         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
458
459                         BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
460                                 j->set_use (true);
461                         }
462
463                         if (i->video) {
464                                 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
465                                 if (r->id() == "239") {
466                                         /* Any scope content means we use scope */
467                                         _film->set_container(r);
468                                 }
469                         }
470
471                         /* Any 3D content means we use 3D mode */
472                         if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
473                                 _film->set_three_d (true);
474                         }
475                 }
476
477                 _viewer->seek (DCPTime(), true);
478                 _info->triggered_update ();
479
480                 set_menu_sensitivity ();
481
482                 wxMenuItemList old = _cpl_menu->GetMenuItems();
483                 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
484                         _cpl_menu->Remove (*i);
485                 }
486
487                 if (_film->content().size() == 1) {
488                         /* Offer a CPL menu */
489                         shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
490                         if (first) {
491                                 DCPExaminer ex (first, true);
492                                 int id = ID_view_cpl;
493                                 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
494                                         wxMenuItem* j = _cpl_menu->AppendRadioItem(
495                                                 id,
496                                                 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
497                                                 );
498                                         j->Check(!first->cpl() || i->id() == *first->cpl());
499                                         ++id;
500                                 }
501                         }
502                 }
503         }
504
505         void load_stress_script (boost::filesystem::path path)
506         {
507                 _stress.load_script (path);
508         }
509
510 private:
511
512         bool report_errors_from_last_job (wxWindow* parent) const
513         {
514                 JobManager* jm = JobManager::instance ();
515
516                 DCPOMATIC_ASSERT (!jm->get().empty());
517
518                 shared_ptr<Job> last = jm->get().back();
519                 if (last->finished_in_error()) {
520                         error_dialog(parent, wxString::Format(_("Could not load DCP.\n\n%s."), std_to_wx(last->error_summary()).data()), std_to_wx(last->error_details()));
521                         return false;
522                 }
523
524                 return true;
525         }
526
527         void setup_menu (wxMenuBar* m)
528         {
529                 _file_menu = new wxMenu;
530                 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
531                 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
532                 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
533
534                 _history_position = _file_menu->GetMenuItems().GetCount();
535
536                 _file_menu->AppendSeparator ();
537                 _file_menu->Append (ID_file_close, _("&Close"));
538                 _file_menu->AppendSeparator ();
539
540 #ifdef __WXOSX__
541                 _file_menu->Append (wxID_EXIT, _("&Exit"));
542 #else
543                 _file_menu->Append (wxID_EXIT, _("&Quit"));
544 #endif
545
546 #ifdef __WXOSX__
547                 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
548 #else
549                 wxMenu* edit = new wxMenu;
550                 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
551 #endif
552
553                 prefs->Enable (Config::instance()->have_write_permission());
554
555                 _cpl_menu = new wxMenu;
556
557                 wxMenu* view = new wxMenu;
558                 optional<int> c = Config::instance()->decode_reduction();
559                 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
560                 view->AppendSeparator();
561 #ifndef DCPOMATIC_VARIANT_SWAROOP
562                 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
563                 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
564 #endif
565                 setup_menu ();
566                 view->AppendSeparator();
567                 view->Append(ID_view_closed_captions, _("Closed captions..."));
568                 view->AppendSeparator();
569                 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
570                 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
571                 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
572                 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
573
574                 wxMenu* tools = new wxMenu;
575                 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
576                 tools->AppendSeparator ();
577                 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
578                 tools->Append (ID_tools_timing, _("Timing..."));
579                 tools->Append (ID_tools_system_information, _("System information..."));
580
581                 wxMenu* help = new wxMenu;
582 #ifdef __WXOSX__
583                 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
584 #else
585                 help->Append (wxID_ABOUT, _("About"));
586 #endif
587                 help->Append (ID_help_report_a_problem, _("Report a problem..."));
588
589                 m->Append (_file_menu, _("&File"));
590 #ifndef __WXOSX__
591                 m->Append (edit, _("&Edit"));
592 #endif
593                 m->Append (view, _("&View"));
594                 m->Append (tools, _("&Tools"));
595                 m->Append (help, _("&Help"));
596         }
597
598         void file_open ()
599         {
600                 wxString d = wxStandardPaths::Get().GetDocumentsDir();
601                 if (Config::instance()->last_player_load_directory()) {
602                         d = std_to_wx (Config::instance()->last_player_load_directory()->string());
603                 }
604
605                 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
606
607                 int r;
608                 while (true) {
609                         r = c->ShowModal ();
610                         if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
611                                 error_dialog (this, _("You did not select a folder.  Make sure that you select a folder before clicking Open."));
612                         } else {
613                                 break;
614                         }
615                 }
616
617                 if (r == wxID_OK) {
618                         boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
619                         load_dcp (dcp);
620                         Config::instance()->set_last_player_load_directory (dcp.parent_path());
621                 }
622
623                 c->Destroy ();
624         }
625
626         void file_add_ov ()
627         {
628                 wxDirDialog* c = new wxDirDialog (
629                         this,
630                         _("Select DCP to open as OV"),
631                         wxStandardPaths::Get().GetDocumentsDir(),
632                         wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
633                         );
634
635                 int r;
636                 while (true) {
637                         r = c->ShowModal ();
638                         if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
639                                 error_dialog (this, _("You did not select a folder.  Make sure that you select a folder before clicking Open."));
640                         } else {
641                                 break;
642                         }
643                 }
644
645                 if (r == wxID_OK) {
646                         DCPOMATIC_ASSERT (_film);
647                         shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
648                         DCPOMATIC_ASSERT (dcp);
649                         dcp->add_ov (wx_to_std(c->GetPath()));
650                         JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
651                         bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
652                         if (!ok || !report_errors_from_last_job(this)) {
653                                 return;
654                         }
655                         BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
656                                 i->set_use (true);
657                         }
658                         if (dcp->video) {
659                                 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
660                                 if (r) {
661                                         _film->set_container(r);
662                                 }
663                         }
664                 }
665
666                 c->Destroy ();
667                 _info->triggered_update ();
668         }
669
670         void file_add_kdm ()
671         {
672                 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
673
674                 if (d->ShowModal() == wxID_OK) {
675                         DCPOMATIC_ASSERT (_film);
676 #ifdef DCPOMATIC_VARIANT_SWAROOP
677                         shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
678                         if (ffmpeg) {
679                                 try {
680                                         ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
681                                 } catch (exception& e) {
682                                         error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
683                                         d->Destroy();
684                                         return;
685                                 }
686                         }
687 #endif
688                         shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
689 #ifndef DCPOMATIC_VARIANT_SWAROOP
690                         DCPOMATIC_ASSERT (dcp);
691 #endif
692                         try {
693                                 if (dcp) {
694                                         dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
695                                         dcp->examine (_film, shared_ptr<Job>());
696                                 }
697                         } catch (exception& e) {
698                                 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
699                                 d->Destroy ();
700                                 return;
701                         }
702                 }
703
704                 d->Destroy ();
705                 _info->triggered_update ();
706         }
707
708         void file_history (wxCommandEvent& event)
709         {
710                 vector<boost::filesystem::path> history = Config::instance()->player_history ();
711                 int n = event.GetId() - ID_file_history;
712                 if (n >= 0 && n < static_cast<int> (history.size ())) {
713                         try {
714                                 load_dcp (history[n]);
715                         } catch (exception& e) {
716                                 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
717                         }
718                 }
719         }
720
721         void file_close ()
722         {
723                 reset_film ();
724                 _info->triggered_update ();
725                 set_menu_sensitivity ();
726         }
727
728         void file_exit ()
729         {
730                 Close ();
731         }
732
733         void edit_preferences ()
734         {
735                 if (!Config::instance()->have_write_permission()) {
736                         return;
737                 }
738
739                 if (!_config_dialog) {
740                         _config_dialog = create_player_config_dialog ();
741                 }
742                 _config_dialog->Show (this);
743         }
744
745         void view_cpl (wxCommandEvent& ev)
746         {
747                 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
748                 DCPOMATIC_ASSERT (dcp);
749                 DCPExaminer ex (dcp, true);
750                 int id = ev.GetId() - ID_view_cpl;
751                 DCPOMATIC_ASSERT (id >= 0);
752                 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
753                 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
754                 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
755                 while (id > 0) {
756                         ++i;
757                         --id;
758                 }
759
760                 dcp->set_cpl ((*i)->id());
761                 dcp->examine (_film, shared_ptr<Job>());
762         }
763
764         void view_full_screen ()
765         {
766                 if (_mode == Config::PLAYER_MODE_FULL) {
767                         _mode = Config::PLAYER_MODE_WINDOW;
768                 } else {
769                         _mode = Config::PLAYER_MODE_FULL;
770                 }
771                 setup_screen ();
772                 setup_menu ();
773         }
774
775         void view_dual_screen ()
776         {
777                 if (_mode == Config::PLAYER_MODE_DUAL) {
778                         _mode = Config::PLAYER_MODE_WINDOW;
779                 } else {
780                         _mode = Config::PLAYER_MODE_DUAL;
781                 }
782                 setup_screen ();
783                 setup_menu ();
784         }
785
786         void setup_menu ()
787         {
788                 if (_view_full_screen) {
789                         _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
790                 }
791                 if (_view_dual_screen) {
792                         _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
793                 }
794         }
795
796         void setup_screen ()
797         {
798                 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
799                 _info->Show (_mode != Config::PLAYER_MODE_FULL);
800                 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
801                 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
802                 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
803
804                 if (_mode == Config::PLAYER_MODE_DUAL) {
805                         _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
806                         _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
807                         _dual_screen->ShowFullScreen (true);
808                         _viewer->panel()->Reparent (_dual_screen);
809                         _dual_screen->Show ();
810                         if (wxDisplay::GetCount() > 1) {
811                                 switch (Config::instance()->image_display()) {
812                                 case 0:
813                                         _dual_screen->Move (0, 0);
814                                         Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
815                                         break;
816                                 case 1:
817                                         _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
818                                         // (0, 0) doesn't seem to work for some strange reason
819                                         Move (8, 8);
820                                         break;
821                                 }
822                         }
823                 } else {
824                         if (_dual_screen) {
825                                 _viewer->panel()->Reparent (_overall_panel);
826                                 _dual_screen->Destroy ();
827                                 _dual_screen = 0;
828                         }
829                 }
830
831                 setup_main_sizer (_mode);
832         }
833
834         void view_closed_captions ()
835         {
836                 _viewer->show_closed_captions ();
837         }
838
839         void tools_verify ()
840         {
841                 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
842                 DCPOMATIC_ASSERT (dcp);
843
844                 JobManager* jm = JobManager::instance ();
845                 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
846                 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
847                 if (!ok) {
848                         return;
849                 }
850
851                 DCPOMATIC_ASSERT (!jm->get().empty());
852                 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
853                 DCPOMATIC_ASSERT (last);
854
855                 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
856                 d->ShowModal ();
857                 d->Destroy ();
858         }
859
860         void tools_check_for_updates ()
861         {
862                 UpdateChecker::instance()->run ();
863                 _update_news_requested = true;
864         }
865
866         void tools_timing ()
867         {
868                 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
869                 d->ShowModal ();
870                 d->Destroy ();
871         }
872
873         void tools_system_information ()
874         {
875                 if (!_system_information_dialog) {
876                         _system_information_dialog = new SystemInformationDialog (this, _viewer);
877                 }
878
879                 _system_information_dialog->Show ();
880         }
881
882         void help_about ()
883         {
884                 AboutDialog* d = new AboutDialog (this);
885                 d->ShowModal ();
886                 d->Destroy ();
887         }
888
889         void help_report_a_problem ()
890         {
891                 ReportProblemDialog* d = new ReportProblemDialog (this);
892                 if (d->ShowModal () == wxID_OK) {
893                         d->report ();
894                 }
895                 d->Destroy ();
896         }
897
898         void update_checker_state_changed ()
899         {
900                 UpdateChecker* uc = UpdateChecker::instance ();
901
902                 bool const announce =
903                         _update_news_requested ||
904                         (uc->stable() && Config::instance()->check_for_updates()) ||
905                         (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
906
907                 _update_news_requested = false;
908
909                 if (!announce) {
910                         return;
911                 }
912
913                 if (uc->state() == UpdateChecker::YES) {
914                         UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
915                         dialog->ShowModal ();
916                         dialog->Destroy ();
917                 } else if (uc->state() == UpdateChecker::FAILED) {
918                         error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
919                 } else {
920                         error_dialog (this, _("There are no new versions of DCP-o-matic available."));
921                 }
922
923                 _update_news_requested = false;
924         }
925
926         void config_changed (Config::Property prop)
927         {
928                 /* Instantly save any config changes when using the player GUI */
929                 try {
930                         Config::instance()->write_config();
931                 } catch (FileError& e) {
932                         if (prop != Config::HISTORY) {
933                                 error_dialog (
934                                         this,
935                                         wxString::Format(
936                                                 _("Could not write to config file at %s.  Your changes have not been saved."),
937                                                 std_to_wx(e.file().string())
938                                                 )
939                                         );
940                         }
941                 } catch (exception& e) {
942                         error_dialog (
943                                 this,
944                                 _("Could not write to config file.  Your changes have not been saved.")
945                                 );
946                 }
947
948                 update_from_config (prop);
949         }
950
951         void update_from_config (Config::Property prop)
952         {
953                 for (int i = 0; i < _history_items; ++i) {
954                         delete _file_menu->Remove (ID_file_history + i);
955                 }
956
957                 if (_history_separator) {
958                         _file_menu->Remove (_history_separator);
959                 }
960                 delete _history_separator;
961                 _history_separator = 0;
962
963                 int pos = _history_position;
964
965                 /* Clear out non-existant history items before we re-build the menu */
966                 Config::instance()->clean_player_history ();
967                 vector<boost::filesystem::path> history = Config::instance()->player_history ();
968
969                 if (!history.empty ()) {
970                         _history_separator = _file_menu->InsertSeparator (pos++);
971                 }
972
973                 for (size_t i = 0; i < history.size(); ++i) {
974                         string s;
975                         if (i < 9) {
976                                 s = String::compose ("&%1 %2", i + 1, history[i].string());
977                         } else {
978                                 s = history[i].string();
979                         }
980                         _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
981                 }
982
983                 _history_items = history.size ();
984
985                 if (prop == Config::PLAYER_DEBUG_LOG) {
986                         optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
987                         if (p) {
988                                 dcpomatic_log.reset (new FileLog(*p));
989                         } else {
990                                 dcpomatic_log.reset (new NullLog());
991                         }
992                         dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
993                 }
994         }
995
996         void set_menu_sensitivity ()
997         {
998                 _tools_verify->Enable (static_cast<bool>(_film));
999                 _file_add_ov->Enable (static_cast<bool>(_film));
1000                 _file_add_kdm->Enable (static_cast<bool>(_film));
1001                 _view_cpl->Enable (static_cast<bool>(_film));
1002         }
1003
1004         void start_stop_pressed ()
1005         {
1006                 if (_viewer->playing()) {
1007                         _viewer->stop();
1008                 } else {
1009                         _viewer->start();
1010                 }
1011         }
1012
1013         void back_frame ()
1014         {
1015                 _viewer->seek_by (-_viewer->one_video_frame(), true);
1016         }
1017
1018         void forward_frame ()
1019         {
1020                 _viewer->seek_by (_viewer->one_video_frame(), true);
1021         }
1022
1023         wxFrame* _dual_screen;
1024         bool _update_news_requested;
1025         PlayerInformation* _info;
1026         Config::PlayerMode _mode;
1027         wxPreferencesEditor* _config_dialog;
1028         wxPanel* _overall_panel;
1029         wxMenu* _file_menu;
1030         wxMenuItem* _view_cpl;
1031         wxMenu* _cpl_menu;
1032         int _history_items;
1033         int _history_position;
1034         wxMenuItem* _history_separator;
1035         shared_ptr<FilmViewer> _viewer;
1036         Controls* _controls;
1037         SystemInformationDialog* _system_information_dialog;
1038         boost::shared_ptr<Film> _film;
1039         boost::signals2::scoped_connection _config_changed_connection;
1040         boost::signals2::scoped_connection _examine_job_connection;
1041         wxMenuItem* _file_add_ov;
1042         wxMenuItem* _file_add_kdm;
1043         wxMenuItem* _tools_verify;
1044         wxMenuItem* _view_full_screen;
1045         wxMenuItem* _view_dual_screen;
1046         PlayerStressTester _stress;
1047 };
1048
1049 static const wxCmdLineEntryDesc command_line_description[] = {
1050         { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1051         { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1052         { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1053         { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1054 };
1055
1056 class PlayServer : public Server
1057 {
1058 public:
1059         explicit PlayServer (DOMFrame* frame)
1060                 : Server (PLAYER_PLAY_PORT)
1061                 , _frame (frame)
1062         {}
1063
1064         void handle (shared_ptr<Socket> socket)
1065         {
1066                 try {
1067                         int const length = socket->read_uint32 ();
1068                         scoped_array<char> buffer (new char[length]);
1069                         socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1070                         string s (buffer.get());
1071                         signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1072                         socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1073                 } catch (...) {
1074
1075                 }
1076         }
1077
1078 private:
1079         DOMFrame* _frame;
1080 };
1081
1082 /** @class App
1083  *  @brief The magic App class for wxWidgets.
1084  */
1085 class App : public wxApp
1086 {
1087 public:
1088         App ()
1089                 : wxApp ()
1090                 , _frame (0)
1091         {
1092 #ifdef DCPOMATIC_LINUX
1093                 XInitThreads ();
1094 #endif
1095         }
1096
1097 private:
1098
1099         bool OnInit ()
1100         {
1101                 wxSplashScreen* splash = 0;
1102                 try {
1103                         wxInitAllImageHandlers ();
1104
1105                         Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1106                         Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1107
1108                         splash = maybe_show_splash ();
1109
1110                         SetAppName (_("DCP-o-matic Player"));
1111
1112                         if (!wxApp::OnInit()) {
1113                                 return false;
1114                         }
1115
1116 #ifdef DCPOMATIC_LINUX
1117                         unsetenv ("UBUNTU_MENUPROXY");
1118 #endif
1119
1120 #ifdef __WXOSX__
1121                         ProcessSerialNumber serial;
1122                         GetCurrentProcess (&serial);
1123                         TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1124 #endif
1125
1126                         dcpomatic_setup_path_encoding ();
1127
1128                         /* Enable i18n; this will create a Config object
1129                            to look for a force-configured language.  This Config
1130                            object will be wrong, however, because dcpomatic_setup
1131                            hasn't yet been called and there aren't any filters etc.
1132                            set up yet.
1133                         */
1134                         dcpomatic_setup_i18n ();
1135
1136                         /* Set things up, including filters etc.
1137                            which will now be internationalised correctly.
1138                         */
1139                         dcpomatic_setup ();
1140
1141                         /* Force the configuration to be re-loaded correctly next
1142                            time it is needed.
1143                         */
1144                         Config::drop ();
1145
1146                         signal_manager = new wxSignalManager (this);
1147
1148                         _frame = new DOMFrame ();
1149                         SetTopWindow (_frame);
1150                         _frame->Maximize ();
1151                         if (splash) {
1152                                 splash->Destroy ();
1153                                 splash = 0;
1154                         }
1155                         _frame->Show ();
1156
1157                         PlayServer* server = new PlayServer (_frame);
1158                         new thread (boost::bind (&PlayServer::run, server));
1159
1160                         if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1161                                 try {
1162                                         _frame->load_dcp (_dcp_to_load);
1163                                 } catch (exception& e) {
1164                                         error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1165                                 }
1166                         }
1167
1168                         if (_stress) {
1169                                 try {
1170                                         _frame->load_stress_script (*_stress);
1171                                 } catch (exception& e) {
1172                                         error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1173                                 }
1174                         }
1175
1176                         Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1177
1178                         if (Config::instance()->check_for_updates ()) {
1179                                 UpdateChecker::instance()->run ();
1180                         }
1181                 }
1182                 catch (exception& e)
1183                 {
1184                         if (splash) {
1185                                 splash->Destroy ();
1186                         }
1187                         error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1188                 }
1189
1190                 return true;
1191         }
1192
1193         void OnInitCmdLine (wxCmdLineParser& parser)
1194         {
1195                 parser.SetDesc (command_line_description);
1196                 parser.SetSwitchChars (wxT ("-"));
1197         }
1198
1199         bool OnCmdLineParsed (wxCmdLineParser& parser)
1200         {
1201                 if (parser.GetParamCount() > 0) {
1202                         _dcp_to_load = wx_to_std (parser.GetParam (0));
1203                 }
1204
1205                 wxString config;
1206                 if (parser.Found("c", &config)) {
1207                         Config::override_path = wx_to_std (config);
1208                 }
1209                 wxString stress;
1210                 if (parser.Found("s", &stress)) {
1211                         _stress = wx_to_std (stress);
1212                 }
1213
1214                 return true;
1215         }
1216
1217         void report_exception ()
1218         {
1219                 try {
1220                         throw;
1221                 } catch (FileError& e) {
1222                         error_dialog (
1223                                 0,
1224                                 wxString::Format (
1225                                         _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1226                                         std_to_wx (e.what()),
1227                                         std_to_wx (e.file().string().c_str ())
1228                                         )
1229                                 );
1230                 } catch (exception& e) {
1231                         error_dialog (
1232                                 0,
1233                                 wxString::Format (
1234                                         _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1235                                         std_to_wx (e.what ())
1236                                         )
1237                                 );
1238                 } catch (...) {
1239                         error_dialog (0, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
1240                 }
1241         }
1242
1243         /* An unhandled exception has occurred inside the main event loop */
1244         bool OnExceptionInMainLoop ()
1245         {
1246                 report_exception ();
1247                 /* This will terminate the program */
1248                 return false;
1249         }
1250
1251         void OnUnhandledException ()
1252         {
1253                 report_exception ();
1254         }
1255
1256         void idle ()
1257         {
1258                 signal_manager->ui_idle ();
1259         }
1260
1261         void config_failed_to_load ()
1262         {
1263                 message_dialog (_frame, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
1264         }
1265
1266         void config_warning (string m)
1267         {
1268                 message_dialog (_frame, std_to_wx (m));
1269         }
1270
1271         DOMFrame* _frame;
1272         string _dcp_to_load;
1273         boost::optional<string> _stress;
1274 };
1275
1276 IMPLEMENT_APP (App)