Add a 'Make DKDM' dialogue box to simplify and (hopefully) clarify DKDM creation...
[dcpomatic.git] / src / tools / dcpomatic.cc
1 /*
2     Copyright (C) 2012-2019 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 /** @file  src/tools/dcpomatic.cc
22  *  @brief The main DCP-o-matic GUI.
23  */
24
25 #include "wx/standard_controls.h"
26 #include "wx/film_viewer.h"
27 #include "wx/film_editor.h"
28 #include "wx/job_manager_view.h"
29 #include "wx/full_config_dialog.h"
30 #include "wx/wx_util.h"
31 #include "wx/film_name_location_dialog.h"
32 #include "wx/wx_signal_manager.h"
33 #include "wx/recreate_chain_dialog.h"
34 #include "wx/about_dialog.h"
35 #include "wx/kdm_dialog.h"
36 #include "wx/dkdm_dialog.h"
37 #include "wx/self_dkdm_dialog.h"
38 #include "wx/servers_list_dialog.h"
39 #include "wx/hints_dialog.h"
40 #include "wx/update_dialog.h"
41 #include "wx/content_panel.h"
42 #include "wx/report_problem_dialog.h"
43 #include "wx/video_waveform_dialog.h"
44 #include "wx/system_information_dialog.h"
45 #include "wx/save_template_dialog.h"
46 #include "wx/templates_dialog.h"
47 #include "wx/nag_dialog.h"
48 #include "wx/export_dialog.h"
49 #include "wx/paste_dialog.h"
50 #include "wx/focus_manager.h"
51 #include "wx/html_dialog.h"
52 #include "wx/initial_setup_dialog.h"
53 #include "wx/send_i18n_dialog.h"
54 #include "wx/i18n_hook.h"
55 #include "lib/film.h"
56 #include "lib/analytics.h"
57 #include "lib/emailer.h"
58 #include "lib/config.h"
59 #include "lib/util.h"
60 #include "lib/video_content.h"
61 #include "lib/content.h"
62 #include "lib/version.h"
63 #include "lib/signal_manager.h"
64 #include "lib/log.h"
65 #include "lib/screen.h"
66 #include "lib/job_manager.h"
67 #include "lib/exceptions.h"
68 #include "lib/cinema.h"
69 #include "lib/kdm_with_metadata.h"
70 #include "lib/send_kdm_email_job.h"
71 #include "lib/encode_server_finder.h"
72 #include "lib/update_checker.h"
73 #include "lib/cross.h"
74 #include "lib/content_factory.h"
75 #include "lib/compose.hpp"
76 #include "lib/dcpomatic_socket.h"
77 #include "lib/hints.h"
78 #include "lib/dcp_content.h"
79 #include "lib/ffmpeg_encoder.h"
80 #include "lib/transcode_job.h"
81 #include "lib/dkdm_wrapper.h"
82 #include "lib/audio_content.h"
83 #include "lib/check_content_change_job.h"
84 #include "lib/text_content.h"
85 #include "lib/dcpomatic_log.h"
86 #include "lib/subtitle_encoder.h"
87 #include <dcp/exceptions.h>
88 #include <dcp/raw_convert.h>
89 #include <wx/generic/aboutdlgg.h>
90 #include <wx/stdpaths.h>
91 #include <wx/cmdline.h>
92 #include <wx/preferences.h>
93 #include <wx/splash.h>
94 #include <wx/wxhtml.h>
95 #ifdef __WXGTK__
96 #include <X11/Xlib.h>
97 #endif
98 #ifdef __WXMSW__
99 #include <shellapi.h>
100 #endif
101 #ifdef __WXOSX__
102 #include <ApplicationServices/ApplicationServices.h>
103 #endif
104 #include <boost/filesystem.hpp>
105 #include <boost/noncopyable.hpp>
106 #include <boost/foreach.hpp>
107 #include <boost/algorithm/string.hpp>
108 #include <iostream>
109 #include <fstream>
110 /* This is OK as it's only used with DCPOMATIC_WINDOWS */
111 #include <sstream>
112
113 #ifdef check
114 #undef check
115 #endif
116
117 using std::cout;
118 using std::wcout;
119 using std::string;
120 using std::vector;
121 using std::wstring;
122 using std::wstringstream;
123 using std::map;
124 using std::make_pair;
125 using std::list;
126 using std::exception;
127 using boost::shared_ptr;
128 using boost::dynamic_pointer_cast;
129 using boost::optional;
130 using boost::function;
131 using boost::is_any_of;
132 using boost::algorithm::find;
133 using dcp::raw_convert;
134
135 class FilmChangedClosingDialog : public boost::noncopyable
136 {
137 public:
138         explicit FilmChangedClosingDialog (string name)
139         {
140                 _dialog = new wxMessageDialog (
141                         0,
142                         wxString::Format (_("Save changes to film \"%s\" before closing?"), std_to_wx (name).data()),
143                         /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
144                         /// project (Film) has been changed since it was last saved.
145                         _("Film changed"),
146                         wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION
147                         );
148
149                 _dialog->SetYesNoCancelLabels (
150                         _("Save film and close"), _("Close without saving film"), _("Don't close")
151                         );
152         }
153
154         ~FilmChangedClosingDialog ()
155         {
156                 _dialog->Destroy ();
157         }
158
159         int run ()
160         {
161                 return _dialog->ShowModal ();
162         }
163
164 private:
165         wxMessageDialog* _dialog;
166 };
167
168 class FilmChangedDuplicatingDialog : public boost::noncopyable
169 {
170 public:
171         explicit FilmChangedDuplicatingDialog (string name)
172         {
173                 _dialog = new wxMessageDialog (
174                         0,
175                         wxString::Format (_("Save changes to film \"%s\" before duplicating?"), std_to_wx (name).data()),
176                         /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
177                         /// project (Film) has been changed since it was last saved.
178                         _("Film changed"),
179                         wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION
180                         );
181
182                 _dialog->SetYesNoCancelLabels (
183                         _("Save film and duplicate"), _("Duplicate without saving film"), _("Don't duplicate")
184                         );
185         }
186
187         ~FilmChangedDuplicatingDialog ()
188         {
189                 _dialog->Destroy ();
190         }
191
192         int run ()
193         {
194                 return _dialog->ShowModal ();
195         }
196
197 private:
198         wxMessageDialog* _dialog;
199 };
200
201 #define ALWAYS                        0x0
202 #define NEEDS_FILM                    0x1
203 #define NOT_DURING_DCP_CREATION       0x2
204 #define NEEDS_CPL                     0x4
205 #define NEEDS_SINGLE_SELECTED_CONTENT 0x8
206 #define NEEDS_SELECTED_CONTENT        0x10
207 #define NEEDS_SELECTED_VIDEO_CONTENT  0x20
208 #define NEEDS_CLIPBOARD               0x40
209 #define NEEDS_ENCRYPTION              0x80
210
211 map<wxMenuItem*, int> menu_items;
212
213 enum {
214         ID_file_new = 1,
215         ID_file_open,
216         ID_file_save,
217         ID_file_save_as_template,
218         ID_file_duplicate,
219         ID_file_duplicate_and_open,
220         ID_file_history,
221         /* Allow spare IDs after _history for the recent files list */
222         ID_file_close = 100,
223         ID_edit_copy,
224         ID_edit_paste,
225         ID_content_scale_to_fit_width,
226         ID_content_scale_to_fit_height,
227         ID_jobs_make_dcp,
228         ID_jobs_make_dcp_batch,
229         ID_jobs_make_kdms,
230         ID_jobs_make_dkdms,
231         ID_jobs_make_self_dkdm,
232         ID_jobs_export,
233         ID_jobs_send_dcp_to_tms,
234         ID_jobs_show_dcp,
235         ID_jobs_open_dcp_in_player,
236         ID_view_closed_captions,
237         ID_view_video_waveform,
238         ID_tools_hints,
239         ID_tools_encoding_servers,
240         ID_tools_manage_templates,
241         ID_tools_check_for_updates,
242         ID_tools_send_translations,
243         ID_tools_system_information,
244         ID_tools_restore_default_preferences,
245         ID_help_report_a_problem,
246         /* IDs for shortcuts (with no associated menu item) */
247         ID_add_file,
248         ID_remove,
249         ID_start_stop,
250         ID_timeline,
251         ID_back_frame,
252         ID_forward_frame
253 };
254
255 class DOMFrame : public wxFrame
256 {
257 public:
258         explicit DOMFrame (wxString const & title)
259                 : wxFrame (NULL, -1, title)
260                 , _video_waveform_dialog (0)
261                 , _system_information_dialog (0)
262                 , _hints_dialog (0)
263                 , _servers_list_dialog (0)
264                 , _config_dialog (0)
265                 , _kdm_dialog (0)
266                 , _dkdm_dialog (0)
267                 , _templates_dialog (0)
268                 , _file_menu (0)
269                 , _history_items (0)
270                 , _history_position (0)
271                 , _history_separator (0)
272                 , _update_news_requested (false)
273         {
274 #if defined(DCPOMATIC_WINDOWS)
275                 if (Config::instance()->win32_console ()) {
276                         AllocConsole();
277
278                         HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
279                         int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
280                         FILE* hf_out = _fdopen(hCrt, "w");
281                         setvbuf(hf_out, NULL, _IONBF, 1);
282                         *stdout = *hf_out;
283
284                         HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
285                         hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
286                         FILE* hf_in = _fdopen(hCrt, "r");
287                         setvbuf(hf_in, NULL, _IONBF, 128);
288                         *stdin = *hf_in;
289
290                         cout << "DCP-o-matic is starting." << "\n";
291                 }
292 #endif
293
294                 wxMenuBar* bar = new wxMenuBar;
295                 setup_menu (bar);
296                 SetMenuBar (bar);
297
298 #ifdef DCPOMATIC_WINDOWS
299                 SetIcon (wxIcon (std_to_wx ("id")));
300 #endif
301
302                 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
303                 config_changed (Config::OTHER);
304
305                 _analytics_message_connection = Analytics::instance()->Message.connect(boost::bind(&DOMFrame::analytics_message, this, _1, _2));
306
307                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_new, this),                ID_file_new);
308                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this),               ID_file_open);
309                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_save, this),               ID_file_save);
310                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_save_as_template, this),   ID_file_save_as_template);
311                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_duplicate, this),          ID_file_duplicate);
312                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_duplicate_and_open, this), ID_file_duplicate_and_open);
313                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this),              ID_file_close);
314                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1),        ID_file_history, ID_file_history + HISTORY_SIZE);
315                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this),               wxID_EXIT);
316                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_copy, this),               ID_edit_copy);
317                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_paste, this),              ID_edit_paste);
318                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this),        wxID_PREFERENCES);
319                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::content_scale_to_fit_width, this), ID_content_scale_to_fit_width);
320                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::content_scale_to_fit_height, this), ID_content_scale_to_fit_height);
321                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_make_dcp, this),           ID_jobs_make_dcp);
322                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_make_kdms, this),          ID_jobs_make_kdms);
323                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_make_dkdms, this),         ID_jobs_make_dkdms);
324                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_make_dcp_batch, this),     ID_jobs_make_dcp_batch);
325                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_make_self_dkdm, this),     ID_jobs_make_self_dkdm);
326                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_export, this),             ID_jobs_export);
327                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this),    ID_jobs_send_dcp_to_tms);
328                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_show_dcp, this),           ID_jobs_show_dcp);
329                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::jobs_open_dcp_in_player, this), ID_jobs_open_dcp_in_player);
330                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this),    ID_view_closed_captions);
331                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_video_waveform, this),     ID_view_video_waveform);
332                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_hints, this),             ID_tools_hints);
333                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_encoding_servers, this),  ID_tools_encoding_servers);
334                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_manage_templates, this),  ID_tools_manage_templates);
335                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
336                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_send_translations, this), ID_tools_send_translations);
337                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this),ID_tools_system_information);
338                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
339                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this),              wxID_ABOUT);
340                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this),   ID_help_report_a_problem);
341
342                 Bind (wxEVT_CLOSE_WINDOW, boost::bind (&DOMFrame::close, this, _1));
343
344                 /* Use a panel as the only child of the Frame so that we avoid
345                    the dark-grey background on Windows.
346                 */
347                 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
348
349                 _film_viewer.reset (new FilmViewer (overall_panel));
350                 _controls = new StandardControls (overall_panel, _film_viewer, true);
351                 _film_editor = new FilmEditor (overall_panel, _film_viewer);
352                 JobManagerView* job_manager_view = new JobManagerView (overall_panel, false);
353
354                 wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL);
355                 right_sizer->Add (_film_viewer->panel(), 2, wxEXPAND | wxALL, 6);
356                 right_sizer->Add (_controls, 0, wxEXPAND | wxALL, 6);
357                 right_sizer->Add (job_manager_view, 1, wxEXPAND | wxALL, 6);
358
359                 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
360                 main_sizer->Add (_film_editor, 0, wxEXPAND | wxALL, 6);
361                 main_sizer->Add (right_sizer, 1, wxEXPAND | wxALL, 6);
362
363                 set_menu_sensitivity ();
364
365                 _film_editor->FileChanged.connect (bind (&DOMFrame::file_changed, this, _1));
366                 _film_editor->content_panel()->SelectionChanged.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
367                 file_changed ("");
368
369                 JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&DOMFrame::set_menu_sensitivity, this));
370
371                 overall_panel->SetSizer (main_sizer);
372
373                 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
374
375                 FocusManager::instance()->SetFocus.connect (boost::bind (&DOMFrame::remove_accelerators, this));
376                 FocusManager::instance()->KillFocus.connect (boost::bind (&DOMFrame::add_accelerators, this));
377                 add_accelerators ();
378         }
379
380         void add_accelerators ()
381         {
382 #ifdef __WXOSX__
383                 int accelerators = 7;
384 #else
385                 int accelerators = 6;
386 #endif
387                 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
388                 accel[0].Set (wxACCEL_CTRL, static_cast<int>('A'), ID_add_file);
389                 accel[1].Set (wxACCEL_NORMAL, WXK_DELETE, ID_remove);
390                 accel[2].Set (wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
391                 accel[3].Set (wxACCEL_CTRL, static_cast<int>('T'), ID_timeline);
392                 accel[4].Set (wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
393                 accel[5].Set (wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
394 #ifdef __WXOSX__
395                 accel[6].Set (wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
396 #endif
397                 Bind (wxEVT_MENU, boost::bind (&ContentPanel::add_file_clicked, _film_editor->content_panel()), ID_add_file);
398                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::remove_clicked, this, _1), ID_remove);
399                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
400                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::timeline_pressed, this), ID_timeline);
401                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
402                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
403                 wxAcceleratorTable accel_table (accelerators, accel);
404                 SetAcceleratorTable (accel_table);
405                 delete[] accel;
406         }
407
408         void remove_accelerators ()
409         {
410                 SetAcceleratorTable (wxAcceleratorTable ());
411         }
412
413         void remove_clicked (wxCommandEvent& ev)
414         {
415                 if (_film_editor->content_panel()->remove_clicked (true)) {
416                         ev.Skip ();
417                 }
418         }
419
420         void new_film (boost::filesystem::path path, optional<string> template_name)
421         {
422                 shared_ptr<Film> film (new Film (path));
423                 if (template_name) {
424                         film->use_template (template_name.get());
425                 }
426                 film->set_name (path.filename().generic_string());
427                 film->write_metadata ();
428                 set_film (film);
429         }
430
431         void load_film (boost::filesystem::path file)
432         try
433         {
434                 shared_ptr<Film> film (new Film (file));
435                 list<string> const notes = film->read_metadata ();
436
437                 if (film->state_version() == 4) {
438                         error_dialog (
439                                 0,
440                                 _("This film was created with an old version of DVD-o-matic and may not load correctly "
441                                   "in this version.  Please check the film's settings carefully.")
442                                 );
443                 }
444
445                 BOOST_FOREACH (string i, notes) {
446                         error_dialog (0, std_to_wx(i));
447                 }
448
449                 set_film (film);
450
451                 JobManager::instance()->add(shared_ptr<Job>(new CheckContentChangeJob(film)));
452         }
453         catch (FileNotFoundError& e) {
454                 boost::filesystem::path const dir = e.file().parent_path();
455                 if (boost::filesystem::exists(dir / "ASSETMAP") || boost::filesystem::exists(dir / "ASSETMAP.xml")) {
456                         error_dialog (
457                                 this, _("Could not open this folder as a DCP-o-matic project."),
458                                 _("It looks like you are trying to open a DCP.  File -> Open is for loading DCP-o-matic projects, not DCPs.  To import a DCP, create a new project with File -> New and then click the \"Add DCP...\" button.")
459                                 );
460                 } else {
461                         wxString const p = std_to_wx(file.string ());
462                         error_dialog (this, wxString::Format(_("Could not open film at %s"), p.data()), std_to_wx(e.what()));
463                 }
464
465         } catch (std::exception& e) {
466                 wxString const p = std_to_wx (file.string());
467                 error_dialog (this, wxString::Format(_("Could not open film at %s"), p.data()), std_to_wx(e.what()));
468         }
469
470         void set_film (shared_ptr<Film> film)
471         {
472                 _film = film;
473                 _film_viewer->set_film (_film);
474                 _film_editor->set_film (_film);
475                 _controls->set_film (_film);
476                 if (_video_waveform_dialog) {
477                         _video_waveform_dialog->Destroy ();
478                         _video_waveform_dialog = 0;
479                 }
480                 set_menu_sensitivity ();
481                 if (_film && _film->directory()) {
482                         Config::instance()->add_to_history (_film->directory().get());
483                 }
484                 if (_film) {
485                         _film->Change.connect (boost::bind (&DOMFrame::film_change, this, _1));
486                         _film->Message.connect (boost::bind(&DOMFrame::film_message, this, _1));
487                         dcpomatic_log = _film->log ();
488                 }
489         }
490
491         shared_ptr<Film> film () const {
492                 return _film;
493         }
494
495 private:
496
497         void film_message (string m)
498         {
499                 message_dialog (this, std_to_wx(m));
500         }
501
502         void film_change (ChangeType type)
503         {
504                 if (type == CHANGE_TYPE_DONE) {
505                         set_menu_sensitivity ();
506                 }
507         }
508
509         void file_changed (boost::filesystem::path f)
510         {
511                 string s = wx_to_std (_("DCP-o-matic"));
512                 if (!f.empty ()) {
513                         s += " - " + f.string ();
514                 }
515
516                 SetTitle (std_to_wx (s));
517         }
518
519         void file_new ()
520         {
521                 FilmNameLocationDialog* d = new FilmNameLocationDialog (this, _("New Film"), true);
522                 int const r = d->ShowModal ();
523
524                 if (r == wxID_OK && d->check_path() && maybe_save_then_delete_film<FilmChangedClosingDialog>()) {
525                         try {
526                                 new_film (d->path(), d->template_name());
527                         } catch (boost::filesystem::filesystem_error& e) {
528 #ifdef DCPOMATIC_WINDOWS
529                                 string bad_chars = "<>:\"/|?*";
530                                 string const filename = d->path().filename().string();
531                                 string found_bad_chars;
532                                 for (size_t i = 0; i < bad_chars.length(); ++i) {
533                                         if (filename.find(bad_chars[i]) != string::npos && found_bad_chars.find(bad_chars[i]) == string::npos) {
534                                                 found_bad_chars += bad_chars[i];
535                                         }
536                                 }
537                                 wxString message = _("Could not create folder to store film.");
538                                 message += "  ";
539                                 if (!found_bad_chars.empty()) {
540                                         message += wxString::Format (_("Try removing the %s characters from your folder name."), std_to_wx(found_bad_chars).data());
541                                 } else {
542                                         message += _("Please check that you do not have Windows controlled folder access enabled for DCP-o-matic.");
543                                 }
544                                 error_dialog (this, message, std_to_wx(e.what()));
545 #else
546                                 error_dialog (this, _("Could not create folder to store film."), std_to_wx(e.what()));
547 #endif
548                         }
549                 }
550
551                 d->Destroy ();
552         }
553
554         void file_open ()
555         {
556                 wxDirDialog* c = new wxDirDialog (
557                         this,
558                         _("Select film to open"),
559                         std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
560                         wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
561                         );
562
563                 int r;
564                 while (true) {
565                         r = c->ShowModal ();
566                         if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
567                                 error_dialog (this, _("You did not select a folder.  Make sure that you select a folder before clicking Open."));
568                         } else {
569                                 break;
570                         }
571                 }
572
573                 if (r == wxID_OK && maybe_save_then_delete_film<FilmChangedClosingDialog>()) {
574                         load_film (wx_to_std (c->GetPath ()));
575                 }
576
577                 c->Destroy ();
578         }
579
580         void file_save ()
581         {
582                 _film->write_metadata ();
583         }
584
585         void file_save_as_template ()
586         {
587                 SaveTemplateDialog* d = new SaveTemplateDialog (this);
588                 int const r = d->ShowModal ();
589                 if (r == wxID_OK) {
590                         Config::instance()->save_template (_film, d->name ());
591                 }
592                 d->Destroy ();
593         }
594
595         void file_duplicate ()
596         {
597                 FilmNameLocationDialog* d = new FilmNameLocationDialog (this, _("Duplicate Film"), false);
598                 int const r = d->ShowModal ();
599
600                 if (r == wxID_OK && d->check_path() && maybe_save_film<FilmChangedDuplicatingDialog>()) {
601                         shared_ptr<Film> film (new Film (d->path()));
602                         film->copy_from (_film);
603                         film->set_name (d->path().filename().generic_string());
604                         film->write_metadata ();
605                 }
606
607                 d->Destroy ();
608         }
609
610         void file_duplicate_and_open ()
611         {
612                 FilmNameLocationDialog* d = new FilmNameLocationDialog (this, _("Duplicate Film"), false);
613                 int const r = d->ShowModal ();
614
615                 if (r == wxID_OK && d->check_path() && maybe_save_film<FilmChangedDuplicatingDialog>()) {
616                         shared_ptr<Film> film (new Film (d->path()));
617                         film->copy_from (_film);
618                         film->set_name (d->path().filename().generic_string());
619                         film->write_metadata ();
620                         set_film (film);
621                 }
622
623                 d->Destroy ();
624         }
625
626         void file_close ()
627         {
628                 if (_film && _film->dirty ()) {
629
630                         FilmChangedClosingDialog* dialog = new FilmChangedClosingDialog (_film->name ());
631                         int const r = dialog->run ();
632                         delete dialog;
633
634                         switch (r) {
635                         case wxID_NO:
636                                 /* Don't save and carry on to close */
637                                 break;
638                         case wxID_YES:
639                                 /* Save and carry on to close */
640                                 _film->write_metadata ();
641                                 break;
642                         case wxID_CANCEL:
643                                 /* Stop */
644                                 return;
645                         }
646                 }
647
648                 set_film (shared_ptr<Film>());
649         }
650
651         void file_history (wxCommandEvent& event)
652         {
653                 vector<boost::filesystem::path> history = Config::instance()->history ();
654                 int n = event.GetId() - ID_file_history;
655                 if (n >= 0 && n < static_cast<int> (history.size ()) && maybe_save_then_delete_film<FilmChangedClosingDialog>()) {
656                         load_film (history[n]);
657                 }
658         }
659
660         void file_exit ()
661         {
662                 /* false here allows the close handler to veto the close request */
663                 Close (false);
664         }
665
666         void edit_copy ()
667         {
668                 ContentList const sel = _film_editor->content_panel()->selected();
669                 DCPOMATIC_ASSERT (sel.size() == 1);
670                 _clipboard = sel.front()->clone();
671         }
672
673         void edit_paste ()
674         {
675                 DCPOMATIC_ASSERT (_clipboard);
676
677                 PasteDialog* d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty());
678                 if (d->ShowModal() == wxID_OK) {
679                         BOOST_FOREACH (shared_ptr<Content> i, _film_editor->content_panel()->selected()) {
680                                 if (d->video() && i->video) {
681                                         DCPOMATIC_ASSERT (_clipboard->video);
682                                         i->video->take_settings_from (_clipboard->video);
683                                 }
684                                 if (d->audio() && i->audio) {
685                                         DCPOMATIC_ASSERT (_clipboard->audio);
686                                         i->audio->take_settings_from (_clipboard->audio);
687                                 }
688
689                                 if (d->text()) {
690                                         list<shared_ptr<TextContent> >::iterator j = i->text.begin ();
691                                         list<shared_ptr<TextContent> >::const_iterator k = _clipboard->text.begin ();
692                                         while (j != i->text.end() && k != _clipboard->text.end()) {
693                                                 (*j)->take_settings_from (*k);
694                                                 ++j;
695                                                 ++k;
696                                         }
697                                 }
698                         }
699                 }
700                 d->Destroy ();
701         }
702
703         void edit_preferences ()
704         {
705                 if (!_config_dialog) {
706                         _config_dialog = create_full_config_dialog ();
707                 }
708                 _config_dialog->Show (this);
709         }
710
711         void tools_restore_default_preferences ()
712         {
713                 wxMessageDialog* d = new wxMessageDialog (
714                         0,
715                         _("Are you sure you want to restore preferences to their defaults?  This cannot be undone."),
716                         _("Restore default preferences"),
717                         wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
718                         );
719
720                 int const r = d->ShowModal ();
721                 d->Destroy ();
722
723                 if (r == wxID_YES) {
724                         Config::restore_defaults ();
725                 }
726         }
727
728         void jobs_make_dcp ()
729         {
730                 double required;
731                 double available;
732                 bool can_hard_link;
733
734                 if (!_film->should_be_enough_disk_space (required, available, can_hard_link)) {
735                         wxString message;
736                         if (can_hard_link) {
737                                 message = wxString::Format (_("The DCP for this film will take up about %.1f GB, and the disk that you are using only has %.1f GB available.  Do you want to continue anyway?"), required, available);
738                         } else {
739                                 message = wxString::Format (_("The DCP and intermediate files for this film will take up about %.1f GB, and the disk that you are using only has %.1f GB available.  You would need half as much space if the filesystem supported hard links, but it does not.  Do you want to continue anyway?"), required, available);
740                         }
741                         if (!confirm_dialog (this, message)) {
742                                 return;
743                         }
744                 }
745
746                 if (Config::instance()->show_hints_before_make_dcp()) {
747                         HintsDialog* hints = new HintsDialog (this, _film, false);
748                         int const r = hints->ShowModal();
749                         hints->Destroy ();
750                         if (r == wxID_CANCEL) {
751                                 return;
752                         }
753                 }
754
755                 if (_film->encrypted ()) {
756                         NagDialog::maybe_nag (
757                                 this,
758                                 Config::NAG_ENCRYPTED_METADATA,
759                                 _("You are making an encrypted DCP.  It will not be possible to make KDMs for this DCP unless you have copies of "
760                                   "the <tt>metadata.xml</tt> file within the film and the metadata files within the DCP.\n\n"
761                                   "You should ensure that these files are <span weight=\"bold\" size=\"larger\">BACKED UP</span> "
762                                   "if you want to make KDMs for this film.")
763                                 );
764                 }
765
766                 /* Remove any existing DCP if the user agrees */
767                 boost::filesystem::path const dcp_dir = _film->dir (_film->dcp_name(), false);
768                 if (boost::filesystem::exists (dcp_dir)) {
769                         if (!confirm_dialog (this, wxString::Format (_("Do you want to overwrite the existing DCP %s?"), std_to_wx(dcp_dir.string()).data()))) {
770                                 return;
771                         }
772                         boost::filesystem::remove_all (dcp_dir);
773                 }
774
775                 try {
776                         /* It seems to make sense to auto-save metadata here, since the make DCP may last
777                            a long time, and crashes/power failures are moderately likely.
778                         */
779                         _film->write_metadata ();
780                         _film->make_dcp (true);
781                 } catch (BadSettingError& e) {
782                         error_dialog (this, wxString::Format (_("Bad setting for %s."), std_to_wx(e.setting()).data()), std_to_wx(e.what()));
783                 } catch (std::exception& e) {
784                         error_dialog (this, wxString::Format (_("Could not make DCP.")), std_to_wx(e.what()));
785                 }
786         }
787
788         void jobs_make_kdms ()
789         {
790                 if (!_film) {
791                         return;
792                 }
793
794                 if (_kdm_dialog) {
795                         _kdm_dialog->Destroy ();
796                         _kdm_dialog = 0;
797                 }
798
799                 _kdm_dialog = new KDMDialog (this, _film);
800                 _kdm_dialog->Show ();
801         }
802
803         void jobs_make_dkdms ()
804         {
805                 if (!_film) {
806                         return;
807                 }
808
809                 if (_dkdm_dialog) {
810                         _dkdm_dialog->Destroy ();
811                         _dkdm_dialog = 0;
812                 }
813
814                 _dkdm_dialog = new DKDMDialog (this, _film);
815                 _dkdm_dialog->Show ();
816         }
817
818         /** @return false if we succeeded, true if not */
819         bool send_to_other_tool (int port, function<void(boost::filesystem::path)> start, string message)
820         {
821                 /* i = 0; try to connect via socket
822                    i = 1; try again, and then try to start the tool
823                    i = 2 onwards; try again.
824                 */
825                 for (int i = 0; i < 8; ++i) {
826                         try {
827                                 boost::asio::io_service io_service;
828                                 boost::asio::ip::tcp::resolver resolver (io_service);
829                                 boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (port));
830                                 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query);
831                                 Socket socket (5);
832                                 socket.connect (*endpoint_iterator);
833                                 DCPOMATIC_ASSERT (_film->directory ());
834                                 socket.write (message.length() + 1);
835                                 socket.write ((uint8_t *) message.c_str(), message.length() + 1);
836                                 /* OK\0 */
837                                 uint8_t ok[3];
838                                 socket.read (ok, 3);
839                                 return false;
840                         } catch (exception& e) {
841
842                         }
843
844                         if (i == 1) {
845                                 start (wx_to_std (wxStandardPaths::Get().GetExecutablePath()));
846                         }
847
848                         dcpomatic_sleep_seconds (1);
849                 }
850
851                 return true;
852         }
853
854         void jobs_make_dcp_batch ()
855         {
856                 if (!_film) {
857                         return;
858                 }
859
860                 if (Config::instance()->show_hints_before_make_dcp()) {
861                         HintsDialog* hints = new HintsDialog (this, _film, false);
862                         int const r = hints->ShowModal();
863                         hints->Destroy ();
864                         if (r == wxID_CANCEL) {
865                                 return;
866                         }
867                 }
868
869                 _film->write_metadata ();
870
871                 if (send_to_other_tool (BATCH_JOB_PORT, bind (&start_batch_converter, _1), _film->directory()->string())) {
872                         error_dialog (this, _("Could not find batch converter."));
873                 }
874         }
875
876         void jobs_open_dcp_in_player ()
877         {
878                 if (!_film) {
879                         return;
880                 }
881
882                 if (send_to_other_tool (PLAYER_PLAY_PORT, bind (&start_player, _1), _film->dir(_film->dcp_name(false)).string())) {
883                         error_dialog (this, _("Could not find player."));
884                 }
885         }
886
887         void jobs_make_self_dkdm ()
888         {
889                 if (!_film) {
890                         return;
891                 }
892
893                 SelfDKDMDialog* d = new SelfDKDMDialog (this, _film);
894                 if (d->ShowModal () != wxID_OK) {
895                         d->Destroy ();
896                         return;
897                 }
898
899                 NagDialog::maybe_nag (
900                         this,
901                         Config::NAG_DKDM_CONFIG,
902                         wxString::Format (
903                                 _("You are making a DKDM which is encrypted by a private key held in"
904                                   "\n\n<tt>%s</tt>\n\nIt is <span weight=\"bold\" size=\"larger\">VITALLY IMPORTANT</span> "
905                                   "that you <span weight=\"bold\" size=\"larger\">BACK UP THIS FILE</span> since if it is lost "
906                                   "your DKDMs (and the DCPs they protect) will become useless."), std_to_wx(Config::config_file().string()).data()
907                                 )
908                         );
909
910
911                 dcp::LocalTime from (Config::instance()->signer_chain()->leaf().not_before());
912                 from.add_minutes (1);
913                 dcp::LocalTime to (Config::instance()->signer_chain()->leaf().not_after());
914                 to.add_minutes (-1);
915
916                 optional<dcp::EncryptedKDM> kdm;
917                 try {
918                         kdm = _film->make_kdm (
919                                 Config::instance()->decryption_chain()->leaf(),
920                                 vector<string>(),
921                                 d->cpl (),
922                                 from, to,
923                                 dcp::MODIFIED_TRANSITIONAL_1,
924                                 true,
925                                 0
926                                 );
927                 } catch (dcp::NotEncryptedError& e) {
928                         error_dialog (this, _("CPL's content is not encrypted."));
929                 } catch (exception& e) {
930                         error_dialog (this, e.what ());
931                 } catch (...) {
932                         error_dialog (this, _("An unknown exception occurred."));
933                 }
934
935                 if (kdm) {
936                         if (d->internal ()) {
937                                 shared_ptr<DKDMGroup> dkdms = Config::instance()->dkdms ();
938                                 dkdms->add (shared_ptr<DKDM> (new DKDM (kdm.get())));
939                                 Config::instance()->changed ();
940                         } else {
941                                 boost::filesystem::path path = d->directory() / (_film->dcp_name(false) + "_DKDM.xml");
942                                 kdm->as_xml (path);
943                         }
944                 }
945
946                 d->Destroy ();
947         }
948
949         void jobs_export ()
950         {
951                 ExportDialog* d = new ExportDialog (this, _film->isdcf_name(true));
952                 if (d->ShowModal() == wxID_OK) {
953                         if (boost::filesystem::exists(d->path())) {
954                                 bool ok = confirm_dialog(
955                                                 this,
956                                                 wxString::Format (_("File %s already exists.  Do you want to overwrite it?"), std_to_wx(d->path().string()).data())
957                                                 );
958
959                                 if (!ok) {
960                                         d->Destroy ();
961                                         return;
962                                 }
963                         }
964
965                         shared_ptr<TranscodeJob> job (new TranscodeJob (_film));
966                         if (d->format() == EXPORT_FORMAT_SUBTITLES_DCP) {
967                                 job->set_encoder (
968                                         shared_ptr<SubtitleEncoder>(new SubtitleEncoder(_film, job, d->path(), d->split_reels()))
969                                         );
970                         } else {
971                                 job->set_encoder (
972                                         shared_ptr<FFmpegEncoder> (
973                                                 new FFmpegEncoder (_film, job, d->path(), d->format(), d->mixdown_to_stereo(), d->split_reels(), d->x264_crf()
974 #ifdef DCPOMATIC_VARIANT_SWAROOP
975                                                                    , optional<dcp::Key>(), optional<string>()
976 #endif
977                                                         )
978                                                 )
979                                         );
980                         }
981                         JobManager::instance()->add (job);
982                 }
983                 d->Destroy ();
984         }
985
986         void content_scale_to_fit_width ()
987         {
988                 ContentList vc = _film_editor->content_panel()->selected_video ();
989                 for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
990                         (*i)->video->scale_and_crop_to_fit_width (_film);
991                 }
992         }
993
994         void content_scale_to_fit_height ()
995         {
996                 ContentList vc = _film_editor->content_panel()->selected_video ();
997                 for (ContentList::iterator i = vc.begin(); i != vc.end(); ++i) {
998                         (*i)->video->scale_and_crop_to_fit_height (_film);
999                 }
1000         }
1001
1002         void jobs_send_dcp_to_tms ()
1003         {
1004                 _film->send_dcp_to_tms ();
1005         }
1006
1007         void jobs_show_dcp ()
1008         {
1009                 DCPOMATIC_ASSERT (_film->directory ());
1010 #ifdef DCPOMATIC_WINDOWS
1011                 wstringstream args;
1012                 args << "/select," << _film->dir (_film->dcp_name(false));
1013                 ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT);
1014 #endif
1015
1016 #ifdef DCPOMATIC_LINUX
1017                 int r = system ("which nautilus");
1018                 if (WEXITSTATUS (r) == 0) {
1019                         r = system (String::compose("nautilus \"%1\"", _film->directory()->string()).c_str());
1020                         if (WEXITSTATUS (r)) {
1021                                 error_dialog (this, _("Could not show DCP."), _("Could not run nautilus"));
1022                         }
1023                 } else {
1024                         int r = system ("which konqueror");
1025                         if (WEXITSTATUS (r) == 0) {
1026                                 r = system (String::compose ("konqueror \"%1\"", _film->directory()->string()).c_str());
1027                                 if (WEXITSTATUS (r)) {
1028                                         error_dialog (this, _("Could not show DCP"), _("Could not run konqueror"));
1029                                 }
1030                         }
1031                 }
1032 #endif
1033
1034 #ifdef DCPOMATIC_OSX
1035                 int r = system (String::compose ("open -R \"%1\"", _film->dir (_film->dcp_name(false)).string()).c_str());
1036                 if (WEXITSTATUS (r)) {
1037                         error_dialog (this, _("Could not show DCP"));
1038                 }
1039 #endif
1040         }
1041
1042         void view_closed_captions ()
1043         {
1044                 _film_viewer->show_closed_captions ();
1045         }
1046
1047         void view_video_waveform ()
1048         {
1049                 if (!_video_waveform_dialog) {
1050                         _video_waveform_dialog = new VideoWaveformDialog (this, _film, _film_viewer);
1051                 }
1052
1053                 _video_waveform_dialog->Show ();
1054         }
1055
1056         void tools_system_information ()
1057         {
1058                 if (!_system_information_dialog) {
1059                         _system_information_dialog = new SystemInformationDialog (this, _film_viewer);
1060                 }
1061
1062                 _system_information_dialog->Show ();
1063         }
1064
1065         void tools_hints ()
1066         {
1067                 if (!_hints_dialog) {
1068                         _hints_dialog = new HintsDialog (this, _film, true);
1069                 }
1070
1071                 _hints_dialog->Show ();
1072         }
1073
1074         void tools_encoding_servers ()
1075         {
1076                 if (!_servers_list_dialog) {
1077                         _servers_list_dialog = new ServersListDialog (this);
1078                 }
1079
1080                 _servers_list_dialog->Show ();
1081         }
1082
1083         void tools_manage_templates ()
1084         {
1085                 if (!_templates_dialog) {
1086                         _templates_dialog = new TemplatesDialog (this);
1087                 }
1088
1089                 _templates_dialog->Show ();
1090         }
1091
1092         void tools_check_for_updates ()
1093         {
1094                 UpdateChecker::instance()->run ();
1095                 _update_news_requested = true;
1096         }
1097
1098         void tools_send_translations ()
1099         {
1100                 SendI18NDialog* d = new SendI18NDialog (this);
1101                 if (d->ShowModal() == wxID_OK) {
1102                         string body;
1103                         body += d->name() + "\n";
1104                         body += d->language() + "\n";
1105                         body += string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n";
1106                         body += "--\n";
1107                         map<string, string> translations = I18NHook::translations ();
1108                         for (map<string, string>::const_iterator i = translations.begin(); i != translations.end(); ++i) {
1109                                 body += i->first + "\n" + i->second + "\n\n";
1110                         }
1111                         list<string> to;
1112                         to.push_back ("carl@dcpomatic.com");
1113                         Emailer emailer (d->email(), to, "DCP-o-matic translations", body);
1114                         emailer.send ("main.carlh.net", 2525, EMAIL_PROTOCOL_STARTTLS);
1115                 }
1116
1117                 d->Destroy ();
1118         }
1119
1120         void help_about ()
1121         {
1122                 AboutDialog* d = new AboutDialog (this);
1123                 d->ShowModal ();
1124                 d->Destroy ();
1125         }
1126
1127         void help_report_a_problem ()
1128         {
1129                 ReportProblemDialog* d = new ReportProblemDialog (this, _film);
1130                 if (d->ShowModal () == wxID_OK) {
1131                         d->report ();
1132                 }
1133                 d->Destroy ();
1134         }
1135
1136         bool should_close ()
1137         {
1138                 if (!JobManager::instance()->work_to_do ()) {
1139                         return true;
1140                 }
1141
1142                 wxMessageDialog* d = new wxMessageDialog (
1143                         0,
1144                         _("There are unfinished jobs; are you sure you want to quit?"),
1145                         _("Unfinished jobs"),
1146                         wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
1147                         );
1148
1149                 bool const r = d->ShowModal() == wxID_YES;
1150                 d->Destroy ();
1151                 return r;
1152         }
1153
1154         void close (wxCloseEvent& ev)
1155         {
1156                 if (!should_close ()) {
1157                         ev.Veto ();
1158                         return;
1159                 }
1160
1161                 if (_film && _film->dirty ()) {
1162
1163                         FilmChangedClosingDialog* dialog = new FilmChangedClosingDialog (_film->name ());
1164                         int const r = dialog->run ();
1165                         delete dialog;
1166
1167                         switch (r) {
1168                         case wxID_NO:
1169                                 /* Don't save and carry on to close */
1170                                 break;
1171                         case wxID_YES:
1172                                 /* Save and carry on to close */
1173                                 _film->write_metadata ();
1174                                 break;
1175                         case wxID_CANCEL:
1176                                 /* Veto the event and stop */
1177                                 ev.Veto ();
1178                                 return;
1179                         }
1180                 }
1181
1182                 /* We don't want to hear about any more configuration changes, since they
1183                    cause the File menu to be altered, which itself will be deleted around
1184                    now (without, as far as I can see, any way for us to find out).
1185                 */
1186                 _config_changed_connection.disconnect ();
1187
1188                 /* Also stop hearing about analytics-related stuff */
1189                 _analytics_message_connection.disconnect ();
1190
1191                 ev.Skip ();
1192         }
1193
1194         void set_menu_sensitivity ()
1195         {
1196                 list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
1197                 list<shared_ptr<Job> >::iterator i = jobs.begin();
1198                 while (i != jobs.end() && (*i)->json_name() != "transcode") {
1199                         ++i;
1200                 }
1201                 bool const dcp_creation = (i != jobs.end ()) && !(*i)->finished ();
1202                 bool const have_cpl = _film && !_film->cpls().empty ();
1203                 bool const have_single_selected_content = _film_editor->content_panel()->selected().size() == 1;
1204                 bool const have_selected_content = !_film_editor->content_panel()->selected().empty();
1205                 bool const have_selected_video_content = !_film_editor->content_panel()->selected_video().empty();
1206
1207                 for (map<wxMenuItem*, int>::iterator j = menu_items.begin(); j != menu_items.end(); ++j) {
1208
1209                         bool enabled = true;
1210
1211                         if ((j->second & NEEDS_FILM) && !_film) {
1212                                 enabled = false;
1213                         }
1214
1215                         if ((j->second & NOT_DURING_DCP_CREATION) && dcp_creation) {
1216                                 enabled = false;
1217                         }
1218
1219                         if ((j->second & NEEDS_CPL) && !have_cpl) {
1220                                 enabled = false;
1221                         }
1222
1223                         if ((j->second & NEEDS_SELECTED_CONTENT) && !have_selected_content) {
1224                                 enabled = false;
1225                         }
1226
1227                         if ((j->second & NEEDS_SINGLE_SELECTED_CONTENT) && !have_single_selected_content) {
1228                                 enabled = false;
1229                         }
1230
1231                         if ((j->second & NEEDS_SELECTED_VIDEO_CONTENT) && !have_selected_video_content) {
1232                                 enabled = false;
1233                         }
1234
1235                         if ((j->second & NEEDS_CLIPBOARD) && !_clipboard) {
1236                                 enabled = false;
1237                         }
1238
1239                         if ((j->second & NEEDS_ENCRYPTION) && (!_film || !_film->encrypted())) {
1240                                 enabled = false;
1241                         }
1242
1243                         j->first->Enable (enabled);
1244                 }
1245         }
1246
1247         /** @return true if the operation that called this method
1248          *  should continue, false to abort it.
1249          */
1250         template <class T>
1251         bool maybe_save_film ()
1252         {
1253                 if (!_film) {
1254                         return true;
1255                 }
1256
1257                 if (_film->dirty ()) {
1258                         T d (_film->name ());
1259                         switch (d.run ()) {
1260                         case wxID_NO:
1261                                 return true;
1262                         case wxID_YES:
1263                                 _film->write_metadata ();
1264                                 return true;
1265                         case wxID_CANCEL:
1266                                 return false;
1267                         }
1268                 }
1269
1270                 return true;
1271         }
1272
1273         template <class T>
1274         bool maybe_save_then_delete_film ()
1275         {
1276                 bool const r = maybe_save_film<T> ();
1277                 if (r) {
1278                         _film.reset ();
1279                 }
1280                 return r;
1281         }
1282
1283         void add_item (wxMenu* menu, wxString text, int id, int sens)
1284         {
1285                 wxMenuItem* item = menu->Append (id, text);
1286                 menu_items.insert (make_pair (item, sens));
1287         }
1288
1289         void setup_menu (wxMenuBar* m)
1290         {
1291                 _file_menu = new wxMenu;
1292                 add_item (_file_menu, _("New...\tCtrl-N"), ID_file_new, ALWAYS);
1293                 add_item (_file_menu, _("&Open...\tCtrl-O"), ID_file_open, ALWAYS);
1294                 _file_menu->AppendSeparator ();
1295                 add_item (_file_menu, _("&Save\tCtrl-S"), ID_file_save, NEEDS_FILM);
1296                 _file_menu->AppendSeparator ();
1297                 add_item (_file_menu, _("Save as &template..."), ID_file_save_as_template, NEEDS_FILM);
1298                 add_item (_file_menu, _("Duplicate..."), ID_file_duplicate, NEEDS_FILM);
1299                 add_item (_file_menu, _("Duplicate and open..."), ID_file_duplicate_and_open, NEEDS_FILM);
1300
1301                 _history_position = _file_menu->GetMenuItems().GetCount();
1302
1303                 _file_menu->AppendSeparator ();
1304                 add_item (_file_menu, _("&Close\tCtrl-W"), ID_file_close, NEEDS_FILM);
1305
1306 #ifndef __WXOSX__
1307                 _file_menu->AppendSeparator ();
1308 #endif
1309
1310 #ifdef __WXOSX__
1311                 add_item (_file_menu, _("&Exit"), wxID_EXIT, ALWAYS);
1312 #else
1313                 add_item (_file_menu, _("&Quit"), wxID_EXIT, ALWAYS);
1314 #endif
1315
1316                 wxMenu* edit = new wxMenu;
1317                 add_item (edit, _("Copy settings\tCtrl-C"), ID_edit_copy, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_SINGLE_SELECTED_CONTENT);
1318                 add_item (edit, _("Paste settings...\tCtrl-V"), ID_edit_paste, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_SELECTED_CONTENT | NEEDS_CLIPBOARD);
1319
1320 #ifdef __WXOSX__
1321                 add_item (_file_menu, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
1322 #else
1323                 add_item (edit, _("&Preferences...\tCtrl-P"), wxID_PREFERENCES, ALWAYS);
1324 #endif
1325
1326                 wxMenu* content = new wxMenu;
1327                 add_item (content, _("Scale to fit &width"), ID_content_scale_to_fit_width, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
1328                 add_item (content, _("Scale to fit &height"), ID_content_scale_to_fit_height, NEEDS_FILM | NEEDS_SELECTED_VIDEO_CONTENT);
1329
1330                 wxMenu* jobs_menu = new wxMenu;
1331                 add_item (jobs_menu, _("&Make DCP\tCtrl-M"), ID_jobs_make_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION);
1332                 add_item (jobs_menu, _("Make DCP in &batch converter\tCtrl-B"), ID_jobs_make_dcp_batch, NEEDS_FILM | NOT_DURING_DCP_CREATION);
1333                 jobs_menu->AppendSeparator ();
1334                 add_item (jobs_menu, _("Make &KDMs...\tCtrl-K"), ID_jobs_make_kdms, NEEDS_FILM);
1335                 add_item (jobs_menu, _("Make &DKDMs...\tCtrl-D"), ID_jobs_make_dkdms, NEEDS_FILM);
1336                 add_item (jobs_menu, _("Make DKDM for DCP-o-matic..."), ID_jobs_make_self_dkdm, NEEDS_FILM | NEEDS_ENCRYPTION);
1337                 jobs_menu->AppendSeparator ();
1338                 add_item (jobs_menu, _("Export...\tCtrl-E"), ID_jobs_export, NEEDS_FILM);
1339                 jobs_menu->AppendSeparator ();
1340                 add_item (jobs_menu, _("&Send DCP to TMS"), ID_jobs_send_dcp_to_tms, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
1341                 add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
1342                 add_item (jobs_menu, _("Open DCP in &player"), ID_jobs_open_dcp_in_player, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
1343
1344                 wxMenu* view = new wxMenu;
1345                 add_item (view, _("Closed captions..."), ID_view_closed_captions, NEEDS_FILM);
1346                 add_item (view, _("Video waveform..."), ID_view_video_waveform, NEEDS_FILM);
1347
1348                 wxMenu* tools = new wxMenu;
1349                 add_item (tools, _("Hints..."), ID_tools_hints, NEEDS_FILM);
1350                 add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
1351                 add_item (tools, _("Manage templates..."), ID_tools_manage_templates, 0);
1352                 add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
1353                 add_item (tools, _("Send translations..."), ID_tools_send_translations, 0);
1354                 add_item (tools, _("System information..."), ID_tools_system_information, 0);
1355                 tools->AppendSeparator ();
1356                 add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
1357
1358                 wxMenu* help = new wxMenu;
1359 #ifdef __WXOSX__
1360                 add_item (help, _("About DCP-o-matic"), wxID_ABOUT, ALWAYS);
1361 #else
1362                 add_item (help, _("About"), wxID_ABOUT, ALWAYS);
1363 #endif
1364                 add_item (help, _("Report a problem..."), ID_help_report_a_problem, NEEDS_FILM);
1365
1366                 m->Append (_file_menu, _("&File"));
1367                 m->Append (edit, _("&Edit"));
1368                 m->Append (content, _("&Content"));
1369                 m->Append (jobs_menu, _("&Jobs"));
1370                 m->Append (view, _("&View"));
1371                 m->Append (tools, _("&Tools"));
1372                 m->Append (help, _("&Help"));
1373         }
1374
1375         void config_changed (Config::Property what)
1376         {
1377                 /* Instantly save any config changes when using the DCP-o-matic GUI */
1378                 if (what == Config::CINEMAS) {
1379                         try {
1380                                 Config::instance()->write_cinemas();
1381                         } catch (exception& e) {
1382                                 error_dialog (
1383                                         this,
1384                                         wxString::Format (
1385                                                 _("Could not write to cinemas file at %s.  Your changes have not been saved."),
1386                                                 std_to_wx (Config::instance()->cinemas_file().string()).data()
1387                                                 )
1388                                         );
1389                         }
1390                 } else {
1391                         try {
1392                                 Config::instance()->write_config();
1393                         } catch (exception& e) {
1394                                 error_dialog (
1395                                         this,
1396                                         wxString::Format (
1397                                                 _("Could not write to config file at %s.  Your changes have not been saved."),
1398                                                 std_to_wx (Config::instance()->cinemas_file().string()).data()
1399                                                 )
1400                                         );
1401                         }
1402                 }
1403
1404                 for (int i = 0; i < _history_items; ++i) {
1405                         delete _file_menu->Remove (ID_file_history + i);
1406                 }
1407
1408                 if (_history_separator) {
1409                         _file_menu->Remove (_history_separator);
1410                 }
1411                 delete _history_separator;
1412                 _history_separator = 0;
1413
1414                 int pos = _history_position;
1415
1416                 /* Clear out non-existant history items before we re-build the menu */
1417                 Config::instance()->clean_history ();
1418                 vector<boost::filesystem::path> history = Config::instance()->history ();
1419
1420                 if (!history.empty ()) {
1421                         _history_separator = _file_menu->InsertSeparator (pos++);
1422                 }
1423
1424                 for (size_t i = 0; i < history.size(); ++i) {
1425                         string s;
1426                         if (i < 9) {
1427                                 s = String::compose ("&%1 %2", i + 1, history[i].string());
1428                         } else {
1429                                 s = history[i].string();
1430                         }
1431                         _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1432                 }
1433
1434                 _history_items = history.size ();
1435
1436                 dcpomatic_log->set_types (Config::instance()->log_types());
1437         }
1438
1439         void update_checker_state_changed ()
1440         {
1441                 UpdateChecker* uc = UpdateChecker::instance ();
1442
1443                 bool const announce =
1444                         _update_news_requested ||
1445                         (uc->stable() && Config::instance()->check_for_updates()) ||
1446                         (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
1447
1448                 _update_news_requested = false;
1449
1450                 if (!announce) {
1451                         return;
1452                 }
1453
1454                 if (uc->state() == UpdateChecker::YES) {
1455                         UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
1456                         dialog->ShowModal ();
1457                         dialog->Destroy ();
1458                 } else if (uc->state() == UpdateChecker::FAILED) {
1459                         error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1460                 } else {
1461                         error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1462                 }
1463
1464                 _update_news_requested = false;
1465         }
1466
1467         void start_stop_pressed ()
1468         {
1469                 if (_film_viewer->playing()) {
1470                         _film_viewer->stop();
1471                 } else {
1472                         _film_viewer->start();
1473                 }
1474         }
1475
1476         void timeline_pressed ()
1477         {
1478                 _film_editor->content_panel()->timeline_clicked ();
1479         }
1480
1481         void back_frame ()
1482         {
1483                 _film_viewer->seek_by (-_film_viewer->one_video_frame(), true);
1484         }
1485
1486         void forward_frame ()
1487         {
1488                 _film_viewer->seek_by (_film_viewer->one_video_frame(), true);
1489         }
1490
1491         void analytics_message (string title, string html)
1492         {
1493                 HTMLDialog* d = new HTMLDialog(this, std_to_wx(title), std_to_wx(html));
1494                 d->ShowModal();
1495                 d->Destroy();
1496         }
1497
1498         FilmEditor* _film_editor;
1499         boost::shared_ptr<FilmViewer> _film_viewer;
1500         StandardControls* _controls;
1501         VideoWaveformDialog* _video_waveform_dialog;
1502         SystemInformationDialog* _system_information_dialog;
1503         HintsDialog* _hints_dialog;
1504         ServersListDialog* _servers_list_dialog;
1505         wxPreferencesEditor* _config_dialog;
1506         KDMDialog* _kdm_dialog;
1507         DKDMDialog* _dkdm_dialog;
1508         TemplatesDialog* _templates_dialog;
1509         wxMenu* _file_menu;
1510         shared_ptr<Film> _film;
1511         int _history_items;
1512         int _history_position;
1513         wxMenuItem* _history_separator;
1514         boost::signals2::scoped_connection _config_changed_connection;
1515         boost::signals2::scoped_connection _analytics_message_connection;
1516         bool _update_news_requested;
1517         shared_ptr<Content> _clipboard;
1518 };
1519
1520 static const wxCmdLineEntryDesc command_line_description[] = {
1521         { wxCMD_LINE_SWITCH, "n", "new", "create new film", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
1522         { wxCMD_LINE_OPTION, "c", "content", "add content file / directory", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1523         { wxCMD_LINE_OPTION, "d", "dcp", "add content DCP", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1524         { wxCMD_LINE_SWITCH, "v", "version", "show DCP-o-matic version", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
1525         { wxCMD_LINE_OPTION, "", "config", "directory containing config.xml and cinemas.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1526         { wxCMD_LINE_PARAM, 0, 0, "film to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1527         { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1528 };
1529
1530 /** @class App
1531  *  @brief The magic App class for wxWidgets.
1532  */
1533 class App : public wxApp
1534 {
1535 public:
1536         App ()
1537                 : wxApp ()
1538                 , _frame (0)
1539                 , _splash (0)
1540         {
1541 #ifdef DCPOMATIC_LINUX
1542                 XInitThreads ();
1543 #endif
1544         }
1545
1546 private:
1547
1548         bool OnInit ()
1549         {
1550                 try {
1551                         wxInitAllImageHandlers ();
1552
1553                         Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1554                         Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1555
1556                         _splash = maybe_show_splash ();
1557
1558                         SetAppName (_("DCP-o-matic"));
1559
1560                         if (!wxApp::OnInit()) {
1561                                 return false;
1562                         }
1563
1564 #ifdef DCPOMATIC_LINUX
1565                         unsetenv ("UBUNTU_MENUPROXY");
1566 #endif
1567
1568 #ifdef __WXOSX__
1569                         ProcessSerialNumber serial;
1570                         GetCurrentProcess (&serial);
1571                         TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1572 #endif
1573
1574                         dcpomatic_setup_path_encoding ();
1575
1576                         /* Enable i18n; this will create a Config object
1577                            to look for a force-configured language.  This Config
1578                            object will be wrong, however, because dcpomatic_setup
1579                            hasn't yet been called and there aren't any filters etc.
1580                            set up yet.
1581                         */
1582                         dcpomatic_setup_i18n ();
1583
1584                         /* Set things up, including filters etc.
1585                            which will now be internationalised correctly.
1586                         */
1587                         dcpomatic_setup ();
1588
1589                         /* Force the configuration to be re-loaded correctly next
1590                            time it is needed.
1591                         */
1592                         Config::drop ();
1593
1594                         /* We only look out for bad configuration from here on, as before
1595                            dcpomatic_setup() we haven't got OpenSSL ready so there will be
1596                            incorrect certificate chain validity errors.
1597                         */
1598                         Config::Bad.connect (boost::bind(&App::config_bad, this, _1));
1599
1600                         _frame = new DOMFrame (_("DCP-o-matic"));
1601                         SetTopWindow (_frame);
1602                         _frame->Maximize ();
1603                         close_splash ();
1604
1605                         if (!Config::instance()->nagged(Config::NAG_INITIAL_SETUP)) {
1606                                 InitialSetupDialog* d = new InitialSetupDialog ();
1607                                 d->ShowModal ();
1608                                 d->Destroy ();
1609                                 Config::instance()->set_nagged(Config::NAG_INITIAL_SETUP, true);
1610                         }
1611
1612                         if (running_32_on_64 ()) {
1613                                 NagDialog::maybe_nag (
1614                                         _frame, Config::NAG_32_ON_64,
1615                                         _("You are running the 32-bit version of DCP-o-matic on a 64-bit version of Windows.  This will limit the memory available to DCP-o-matic and may cause errors.  You are strongly advised to install the 64-bit version of DCP-o-matic."),
1616                                         false);
1617                         }
1618
1619                         _frame->Show ();
1620
1621                         signal_manager = new wxSignalManager (this);
1622                         Bind (wxEVT_IDLE, boost::bind (&App::idle, this, _1));
1623
1624                         if (!_film_to_load.empty() && boost::filesystem::is_directory (_film_to_load)) {
1625                                 try {
1626                                         _frame->load_film (_film_to_load);
1627                                 } catch (exception& e) {
1628                                         error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), _film_to_load)), std_to_wx(e.what()));
1629                                 }
1630                         }
1631
1632                         if (!_film_to_create.empty ()) {
1633                                 _frame->new_film (_film_to_create, optional<string> ());
1634                                 if (!_content_to_add.empty ()) {
1635                                         BOOST_FOREACH (shared_ptr<Content> i, content_factory(_content_to_add)) {
1636                                                 _frame->film()->examine_and_add_content (i);
1637                                         }
1638                                 }
1639                                 if (!_dcp_to_add.empty ()) {
1640                                         _frame->film()->examine_and_add_content(shared_ptr<DCPContent>(new DCPContent(_dcp_to_add)));
1641                                 }
1642                         }
1643
1644                         Bind (wxEVT_TIMER, boost::bind (&App::check, this));
1645                         _timer.reset (new wxTimer (this));
1646                         _timer->Start (1000);
1647
1648                         if (Config::instance()->check_for_updates ()) {
1649                                 UpdateChecker::instance()->run ();
1650                         }
1651                 }
1652                 catch (exception& e)
1653                 {
1654                         if (_splash) {
1655                                 _splash->Destroy ();
1656                                 _splash = 0;
1657                         }
1658                         error_dialog (0, wxString::Format ("DCP-o-matic could not start."), std_to_wx(e.what()));
1659                 }
1660
1661                 return true;
1662         }
1663
1664         void OnInitCmdLine (wxCmdLineParser& parser)
1665         {
1666                 parser.SetDesc (command_line_description);
1667                 parser.SetSwitchChars (wxT ("-"));
1668         }
1669
1670         bool OnCmdLineParsed (wxCmdLineParser& parser)
1671         {
1672                 if (parser.Found (wxT("version"))) {
1673                         cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
1674                         exit (EXIT_SUCCESS);
1675                 }
1676
1677                 if (parser.GetParamCount() > 0) {
1678                         if (parser.Found (wxT ("new"))) {
1679                                 _film_to_create = wx_to_std (parser.GetParam (0));
1680                         } else {
1681                                 _film_to_load = wx_to_std (parser.GetParam (0));
1682                         }
1683                 }
1684
1685                 wxString content;
1686                 if (parser.Found (wxT ("content"), &content)) {
1687                         _content_to_add = wx_to_std (content);
1688                 }
1689
1690                 wxString dcp;
1691                 if (parser.Found (wxT ("dcp"), &dcp)) {
1692                         _dcp_to_add = wx_to_std (dcp);
1693                 }
1694
1695                 wxString config;
1696                 if (parser.Found (wxT("config"), &config)) {
1697                         State::override_path = wx_to_std (config);
1698                 }
1699
1700                 return true;
1701         }
1702
1703         void report_exception ()
1704         {
1705                 try {
1706                         throw;
1707                 } catch (FileError& e) {
1708                         error_dialog (
1709                                 0,
1710                                 wxString::Format (
1711                                         _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1712                                         std_to_wx (e.what()),
1713                                         std_to_wx (e.file().string().c_str ())
1714                                         )
1715                                 );
1716                 } catch (exception& e) {
1717                         error_dialog (
1718                                 0,
1719                                 wxString::Format (
1720                                         _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1721                                         std_to_wx (e.what ())
1722                                         )
1723                                 );
1724                 } catch (...) {
1725                         error_dialog (0, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
1726                 }
1727         }
1728
1729         /* An unhandled exception has occurred inside the main event loop */
1730         bool OnExceptionInMainLoop ()
1731         {
1732                 report_exception ();
1733                 /* This will terminate the program */
1734                 return false;
1735         }
1736
1737         void OnUnhandledException ()
1738         {
1739                 report_exception ();
1740         }
1741
1742         void idle (wxIdleEvent& ev)
1743         {
1744                 signal_manager->ui_idle ();
1745                 ev.Skip ();
1746         }
1747
1748         void check ()
1749         {
1750                 try {
1751                         EncodeServerFinder::instance()->rethrow ();
1752                 } catch (exception& e) {
1753                         error_dialog (0, std_to_wx (e.what ()));
1754                 }
1755         }
1756
1757         void close_splash ()
1758         {
1759                 if (_splash) {
1760                         _splash->Destroy ();
1761                         _splash = 0;
1762                 }
1763         }
1764
1765         void config_failed_to_load ()
1766         {
1767                 close_splash ();
1768                 message_dialog (_frame, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
1769         }
1770
1771         void config_warning (string m)
1772         {
1773                 close_splash ();
1774                 message_dialog (_frame, std_to_wx (m));
1775         }
1776
1777         bool config_bad (Config::BadReason reason)
1778         {
1779                 /* Destroy the splash screen here, as otherwise bad things seem to happen (for reasons unknown)
1780                    when we open our recreate dialog, close it, *then* try to Destroy the splash (the Destroy fails).
1781                 */
1782                 _splash->Destroy ();
1783                 _splash = 0;
1784
1785                 Config* config = Config::instance();
1786                 switch (reason) {
1787                 case Config::BAD_SIGNER_UTF8_STRINGS:
1788                 {
1789                         if (config->nagged(Config::NAG_BAD_SIGNER_CHAIN)) {
1790                                 return false;
1791                         }
1792                         RecreateChainDialog* d = new RecreateChainDialog (
1793                                 _frame, _("Recreate signing certificates"),
1794                                 _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs contains a small error\n"
1795                                   "which will prevent DCPs from being validated correctly on some systems.  Do you want to re-create\n"
1796                                   "the certificate chain for signing DCPs and KDMs?"),
1797                                 _("Do nothing"),
1798                                 Config::NAG_BAD_SIGNER_CHAIN
1799                                 );
1800                         int const r = d->ShowModal ();
1801                         d->Destroy ();
1802                         return r == wxID_OK;
1803                 }
1804                 case Config::BAD_SIGNER_INCONSISTENT:
1805                 {
1806                         RecreateChainDialog* d = new RecreateChainDialog (
1807                                 _frame, _("Recreate signing certificates"),
1808                                 _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs is inconsistent and\n"
1809                                   "cannot be used.  DCP-o-matic cannot start unless you re-create it.  Do you want to re-create\n"
1810                                   "the certificate chain for signing DCPs and KDMs?"),
1811                                 _("Close DCP-o-matic")
1812                                 );
1813                         int const r = d->ShowModal ();
1814                         d->Destroy ();
1815                         if (r != wxID_OK) {
1816                                 exit (EXIT_FAILURE);
1817                         }
1818                         return true;
1819                 }
1820                 case Config::BAD_DECRYPTION_INCONSISTENT:
1821                 {
1822                         RecreateChainDialog* d = new RecreateChainDialog (
1823                                 _frame, _("Recreate KDM decryption chain"),
1824                                 _("The certificate chain that DCP-o-matic uses for decrypting KDMs is inconsistent and\n"
1825                                   "cannot be used.  DCP-o-matic cannot start unless you re-create it.  Do you want to re-create\n"
1826                                   "the certificate chain for decrypting KDMs?  You may want to say \"No\" here and back up your\n"
1827                                   "configuration before continuing."),
1828                                 _("Close DCP-o-matic")
1829                                 );
1830                         int const r = d->ShowModal ();
1831                         d->Destroy ();
1832                         if (r != wxID_OK) {
1833                                 exit (EXIT_FAILURE);
1834                         }
1835                         return true;
1836                 }
1837                 default:
1838                         DCPOMATIC_ASSERT (false);
1839                 }
1840         }
1841
1842         DOMFrame* _frame;
1843         wxSplashScreen* _splash;
1844         shared_ptr<wxTimer> _timer;
1845         string _film_to_load;
1846         string _film_to_create;
1847         string _content_to_add;
1848         string _dcp_to_add;
1849 };
1850
1851 IMPLEMENT_APP (App)