Support basic drag-and-drop of DKDMs.
[dcpomatic.git] / src / tools / dcpomatic_kdm.cc
1 /*
2     Copyright (C) 2015-2017 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/config_dialog.h"
22 #include "wx/about_dialog.h"
23 #include "wx/report_problem_dialog.h"
24 #include "wx/file_picker_ctrl.h"
25 #include "wx/wx_util.h"
26 #include "wx/wx_signal_manager.h"
27 #include "wx/screens_panel.h"
28 #include "wx/kdm_timing_panel.h"
29 #include "wx/kdm_output_panel.h"
30 #include "wx/job_view_dialog.h"
31 #include "wx/file_dialog_wrapper.h"
32 #include "wx/new_dkdm_folder_dialog.h"
33 #include "wx/editable_list.h"
34 #include "lib/config.h"
35 #include "lib/util.h"
36 #include "lib/screen.h"
37 #include "lib/job_manager.h"
38 #include "lib/screen_kdm.h"
39 #include "lib/exceptions.h"
40 #include "lib/cinema_kdms.h"
41 #include "lib/send_kdm_email_job.h"
42 #include "lib/compose.hpp"
43 #include "lib/cinema.h"
44 #include "lib/dkdm_wrapper.h"
45 #include <dcp/encrypted_kdm.h>
46 #include <dcp/decrypted_kdm.h>
47 #include <dcp/exceptions.h>
48 #include <wx/wx.h>
49 #include <wx/preferences.h>
50 #include <wx/filepicker.h>
51 #ifdef __WXOSX__
52 #include <ApplicationServices/ApplicationServices.h>
53 #endif
54 #include <boost/bind.hpp>
55 #include <boost/foreach.hpp>
56
57 #ifdef check
58 #undef check
59 #endif
60
61 using std::exception;
62 using std::list;
63 using std::string;
64 using std::vector;
65 using std::pair;
66 using std::map;
67 using boost::shared_ptr;
68 using boost::bind;
69 using boost::optional;
70 using boost::ref;
71 using boost::dynamic_pointer_cast;
72
73 enum {
74         ID_help_report_a_problem = 1,
75 };
76
77 class DOMFrame : public wxFrame
78 {
79 public:
80         DOMFrame (wxString const & title)
81                 : wxFrame (0, -1, title)
82                 , _config_dialog (0)
83                 , _job_view (0)
84         {
85 #if defined(DCPOMATIC_WINDOWS)
86                 if (Config::instance()->win32_console ()) {
87                         AllocConsole();
88
89                         HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
90                         int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
91                         FILE* hf_out = _fdopen(hCrt, "w");
92                         setvbuf(hf_out, NULL, _IONBF, 1);
93                         *stdout = *hf_out;
94
95                         HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
96                         hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
97                         FILE* hf_in = _fdopen(hCrt, "r");
98                         setvbuf(hf_in, NULL, _IONBF, 128);
99                         *stdin = *hf_in;
100
101                         std::cout << "DCP-o-matic KDM creator is starting." << "\n";
102                 }
103 #endif
104
105                 wxMenuBar* bar = new wxMenuBar;
106                 setup_menu (bar);
107                 SetMenuBar (bar);
108
109                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this),             wxID_EXIT);
110                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this),      wxID_PREFERENCES);
111                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this),            wxID_ABOUT);
112                 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
113
114                 /* Use a panel as the only child of the Frame so that we avoid
115                    the dark-grey background on Windows.
116                 */
117                 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
118                 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
119
120                 wxBoxSizer* horizontal = new wxBoxSizer (wxHORIZONTAL);
121                 wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
122                 wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
123
124                 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 2);
125                 horizontal->Add (right, 1, wxEXPAND);
126
127                 wxFont subheading_font (*wxNORMAL_FONT);
128                 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
129
130                 wxStaticText* h = new wxStaticText (overall_panel, wxID_ANY, _("Screens"));
131                 h->SetFont (subheading_font);
132                 left->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
133                 _screens = new ScreensPanel (overall_panel);
134                 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
135
136                 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
137                 h = new wxStaticText (overall_panel, wxID_ANY, S_("KDM|Timing"));
138                 h->SetFont (subheading_font);
139                 right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
140                 _timing = new KDMTimingPanel (overall_panel);
141                 right->Add (_timing, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
142
143                 h = new wxStaticText (overall_panel, wxID_ANY, _("DKDM"));
144                 h->SetFont (subheading_font);
145                 right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
146                 wxBoxSizer* dkdm_sizer = new wxBoxSizer (wxHORIZONTAL);
147                 _dkdm = new wxTreeCtrl (
148                         overall_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT
149                 );
150                 dkdm_sizer->Add (_dkdm, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
151                 wxBoxSizer* dkdm_buttons = new wxBoxSizer(wxVERTICAL);
152                 _add_dkdm = new wxButton (overall_panel, wxID_ANY, _("Add..."));
153                 dkdm_buttons->Add (_add_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
154                 _add_dkdm_folder = new wxButton (overall_panel, wxID_ANY, _("Add folder..."));
155                 dkdm_buttons->Add (_add_dkdm_folder, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
156                 _remove_dkdm = new wxButton (overall_panel, wxID_ANY, _("Remove"));
157                 dkdm_buttons->Add (_remove_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
158                 dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
159                 right->Add (dkdm_sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
160
161                 add_dkdm_view (Config::instance()->dkdms());
162
163                 h = new wxStaticText (overall_panel, wxID_ANY, _("Output"));
164                 h->SetFont (subheading_font);
165                 right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
166                 /* XXX: hard-coded non-interop here */
167                 _output = new KDMOutputPanel (overall_panel, false);
168                 right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
169
170                 _create = new wxButton (overall_panel, wxID_ANY, _("Create KDMs"));
171                 right->Add (_create, 0, wxALL, DCPOMATIC_SIZER_GAP);
172
173                 main_sizer->Add (horizontal, 1, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER);
174                 overall_panel->SetSizer (main_sizer);
175
176                 /* Instantly save any config changes when using a DCP-o-matic GUI */
177                 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
178
179                 _screens->ScreensChanged.connect (boost::bind (&DOMFrame::setup_sensitivity, this));
180                 _create->Bind (wxEVT_BUTTON, bind (&DOMFrame::create_kdms, this));
181                 _dkdm->Bind (wxEVT_TREE_SEL_CHANGED, boost::bind (&DOMFrame::setup_sensitivity, this));
182                 _dkdm->Bind (wxEVT_TREE_BEGIN_DRAG, boost::bind (&DOMFrame::dkdm_begin_drag, this, _1));
183                 _dkdm->Bind (wxEVT_TREE_END_DRAG, boost::bind (&DOMFrame::dkdm_end_drag, this, _1));
184                 _add_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_clicked, this));
185                 _add_dkdm_folder->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_folder_clicked, this));
186                 _remove_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::remove_dkdm_clicked, this));
187
188                 setup_sensitivity ();
189         }
190
191 private:
192         void file_exit ()
193         {
194                 /* false here allows the close handler to veto the close request */
195                 Close (false);
196         }
197
198         void edit_preferences ()
199         {
200                 if (!_config_dialog) {
201                         _config_dialog = create_config_dialog ();
202                 }
203                 _config_dialog->Show (this);
204         }
205
206         void help_about ()
207         {
208                 AboutDialog* d = new AboutDialog (this);
209                 d->ShowModal ();
210                 d->Destroy ();
211         }
212
213         void help_report_a_problem ()
214         {
215                 ReportProblemDialog* d = new ReportProblemDialog (this, shared_ptr<Film> ());
216                 if (d->ShowModal () == wxID_OK) {
217                         d->report ();
218                 }
219                 d->Destroy ();
220         }
221
222         void setup_menu (wxMenuBar* m)
223         {
224                 wxMenu* file = new wxMenu;
225
226 #ifdef __WXOSX__
227                 file->Append (wxID_EXIT, _("&Exit"));
228 #else
229                 file->Append (wxID_EXIT, _("&Quit"));
230 #endif
231
232 #ifdef __WXOSX__
233                 file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
234 #else
235                 wxMenu* edit = new wxMenu;
236                 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
237 #endif
238
239                 wxMenu* help = new wxMenu;
240 #ifdef __WXOSX__
241                 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
242 #else
243                 help->Append (wxID_ABOUT, _("About"));
244 #endif
245                 help->Append (ID_help_report_a_problem, _("Report a problem..."));
246
247                 m->Append (file, _("&File"));
248 #ifndef __WXOSX__
249                 m->Append (edit, _("&Edit"));
250 #endif
251                 m->Append (help, _("&Help"));
252         }
253
254         bool confirm_overwrite (boost::filesystem::path path)
255         {
256                 return confirm_dialog (
257                         this,
258                         wxString::Format (_("File %s already exists.  Do you want to overwrite it?"), std_to_wx(path.string()).data())
259                         );
260         }
261
262         /** @id if not 0 this is filled in with the wxTreeItemId of the selection */
263         shared_ptr<DKDMBase> selected_dkdm (wxTreeItemId* id = 0) const
264         {
265                 wxArrayTreeItemIds selections;
266                 _dkdm->GetSelections (selections);
267                 if (selections.GetCount() != 1) {
268                         if (id) {
269                                 *id = 0;
270                         }
271                         return shared_ptr<DKDMBase> ();
272                 }
273
274                 if (id) {
275                         *id = selections[0];
276                 }
277
278                 DKDMMap::const_iterator i = _dkdm_id.find (selections[0]);
279                 if (i == _dkdm_id.end()) {
280                         return shared_ptr<DKDMBase> ();
281                 }
282
283                 return i->second;
284         }
285
286         void create_kdms ()
287         {
288                 try {
289                         shared_ptr<DKDMBase> dkdm_base = selected_dkdm ();
290                         if (!dkdm_base) {
291                                 return;
292                         }
293                         shared_ptr<DKDM> dkdm = boost::dynamic_pointer_cast<DKDM> (dkdm_base);
294                         if (!dkdm) {
295                                 return;
296                         }
297
298                         /* Decrypt the DKDM */
299                         dcp::DecryptedKDM decrypted (dkdm->dkdm(), Config::instance()->decryption_chain()->key().get());
300
301                         /* This is the signer for our new KDMs */
302                         shared_ptr<const dcp::CertificateChain> signer = Config::instance()->signer_chain ();
303                         if (!signer->valid ()) {
304                                 throw InvalidSignerError ();
305                         }
306
307                         list<ScreenKDM> screen_kdms;
308                         BOOST_FOREACH (shared_ptr<Screen> i, _screens->screens()) {
309
310                                 if (!i->recipient) {
311                                         continue;
312                                 }
313
314                                 /* Make an empty KDM */
315                                 dcp::DecryptedKDM kdm (
316                                         dcp::LocalTime (_timing->from(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()),
317                                         dcp::LocalTime (_timing->until(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()),
318                                         decrypted.annotation_text().get_value_or (""),
319                                         decrypted.content_title_text(),
320                                         dcp::LocalTime().as_string()
321                                         );
322
323                                 /* Add keys from the DKDM */
324                                 BOOST_FOREACH (dcp::DecryptedKDMKey const & j, decrypted.keys()) {
325                                         kdm.add_key (j);
326                                 }
327
328                                 /* Encrypt */
329                                 screen_kdms.push_back (ScreenKDM (i, kdm.encrypt (signer, i->recipient.get(), i->trusted_devices, _output->formulation())));
330                         }
331
332                         pair<shared_ptr<Job>, int> result = _output->make (
333                                 screen_kdms, decrypted.content_title_text(), _timing, bind (&DOMFrame::confirm_overwrite, this, _1), shared_ptr<Log> ()
334                                 );
335
336                         if (result.first) {
337                                 JobManager::instance()->add (result.first);
338                                 if (_job_view) {
339                                         _job_view->Destroy ();
340                                         _job_view = 0;
341                                 }
342                                 _job_view = new JobViewDialog (this, _("Send KDM emails"), result.first);
343                                 _job_view->ShowModal ();
344                         }
345
346                         if (result.second > 0) {
347                                 /* XXX: proper plural form support in wxWidgets? */
348                                 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
349                                 message_dialog (
350                                         this,
351                                         wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())
352                                         );
353                         }
354                 } catch (dcp::NotEncryptedError& e) {
355                         error_dialog (this, _("CPL's content is not encrypted."));
356                 } catch (exception& e) {
357                         error_dialog (this, e.what ());
358                 } catch (...) {
359                         error_dialog (this, _("An unknown exception occurred."));
360                 }
361         }
362
363         void setup_sensitivity ()
364         {
365                 _screens->setup_sensitivity ();
366                 _output->setup_sensitivity ();
367                 wxArrayTreeItemIds sel;
368                 _dkdm->GetSelections (sel);
369                 _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0);
370         }
371
372         void dkdm_begin_drag (wxTreeEvent& ev)
373         {
374                 ev.Allow ();
375         }
376
377         void dkdm_end_drag (wxTreeEvent& ev)
378         {
379                 DKDMMap::iterator from = _dkdm_id.find (_dkdm->GetSelection ());
380                 DKDMMap::iterator to = _dkdm_id.find (ev.GetItem ());
381                 if (from == _dkdm_id.end() || to == _dkdm_id.end()) {
382                         return;
383                 }
384
385                 shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (to->second);
386                 if (!group) {
387                         group = to->second->parent();
388                 }
389
390                 DCPOMATIC_ASSERT (group);
391                 DCPOMATIC_ASSERT (from->second->parent ());
392
393                 from->second->parent()->remove (from->second);
394                 add_dkdm_model (from->second, group);
395
396                 _dkdm->Delete (from->first);
397                 _dkdm_id.erase (from->first);
398                 add_dkdm_view (from->second);
399         }
400
401         void add_dkdm_clicked ()
402         {
403                 wxFileDialog* d = new wxFileDialog (this, _("Select DKDM file"));
404                 if (d->ShowModal() == wxID_OK) {
405                         shared_ptr<DKDMBase> new_dkdm;
406                         try {
407                                 new_dkdm.reset (
408                                         new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)))
409                                         );
410                         } catch (dcp::KDMFormatError& e) {
411                                 error_dialog (
412                                         this,
413                                         wxString::Format (
414                                                 _("Could not read file as a KDM.  Perhaps it is badly formatted, or not a KDM at all.\n\n%s"),
415                                                 std_to_wx(e.what()).data()
416                                                 )
417                                         );
418                                 return;
419                         }
420
421                         shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
422                         if (!group) {
423                                 group = Config::instance()->dkdms ();
424                         }
425                         add_dkdm_model (new_dkdm, group);
426                         add_dkdm_view (new_dkdm);
427                 }
428                 d->Destroy ();
429         }
430
431         void add_dkdm_folder_clicked ()
432         {
433                 NewDKDMFolderDialog* d = new NewDKDMFolderDialog (this);
434                 if (d->ShowModal() == wxID_OK) {
435                         shared_ptr<DKDMBase> new_dkdm (new DKDMGroup (wx_to_std (d->get ())));
436                         shared_ptr<DKDMGroup> parent = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
437                         if (!parent) {
438                                 parent = Config::instance()->dkdms ();
439                         }
440                         add_dkdm_model (new_dkdm, parent);
441                         add_dkdm_view (new_dkdm);
442                 }
443                 d->Destroy ();
444         }
445
446         /** @param dkdm Thing to add.
447          *  @param parent Parent group, or 0.
448          */
449         void add_dkdm_view (shared_ptr<DKDMBase> base)
450         {
451                 if (!base->parent()) {
452                         /* This is the root group */
453                         _dkdm_id[_dkdm->AddRoot("root")] = base;
454                 } else {
455                         /* Add base to the view */
456                         _dkdm_id[_dkdm->AppendItem(dkdm_to_id(base->parent()), std_to_wx(base->name()))] = base;
457                 }
458
459                 /* Add children */
460                 shared_ptr<DKDMGroup> g = dynamic_pointer_cast<DKDMGroup> (base);
461                 if (g) {
462                         BOOST_FOREACH (shared_ptr<DKDMBase> i, g->children()) {
463                                 add_dkdm_view (i);
464                         }
465                 }
466         }
467
468         /** @param group Group to add dkdm to */
469         void add_dkdm_model (shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group)
470         {
471                 group->add (dkdm);
472                 /* We're messing with a Config-owned object here, so tell it that something has changed.
473                    This isn't nice.
474                 */
475                 Config::instance()->changed ();
476         }
477
478         wxTreeItemId dkdm_to_id (shared_ptr<DKDMBase> dkdm)
479         {
480                 for (DKDMMap::iterator i = _dkdm_id.begin(); i != _dkdm_id.end(); ++i) {
481                         if (i->second == dkdm) {
482                                 return i->first;
483                         }
484                 }
485                 DCPOMATIC_ASSERT (false);
486         }
487
488         void remove_dkdm_clicked ()
489         {
490                 shared_ptr<DKDMBase> removed = selected_dkdm ();
491                 if (!removed) {
492                         return;
493                 }
494
495                 _dkdm->Delete (dkdm_to_id (removed));
496                 shared_ptr<DKDMGroup> dkdms = Config::instance()->dkdms ();
497                 dkdms->remove (removed);
498                 Config::instance()->changed ();
499         }
500
501         wxPreferencesEditor* _config_dialog;
502         ScreensPanel* _screens;
503         KDMTimingPanel* _timing;
504         wxTreeCtrl* _dkdm;
505         typedef std::map<wxTreeItemId, boost::shared_ptr<DKDMBase> > DKDMMap;
506         DKDMMap _dkdm_id;
507         wxButton* _add_dkdm;
508         wxButton* _add_dkdm_folder;
509         wxButton* _remove_dkdm;
510         wxButton* _create;
511         KDMOutputPanel* _output;
512         JobViewDialog* _job_view;
513 };
514
515 /** @class App
516  *  @brief The magic App class for wxWidgets.
517  */
518 class App : public wxApp
519 {
520 public:
521         App ()
522                 : wxApp ()
523                 , _frame (0)
524         {}
525
526 private:
527
528         bool OnInit ()
529         try
530         {
531                 wxInitAllImageHandlers ();
532
533                 SetAppName (_("DCP-o-matic KDM Creator"));
534
535                 if (!wxApp::OnInit()) {
536                         return false;
537                 }
538
539 #ifdef DCPOMATIC_LINUX
540                 unsetenv ("UBUNTU_MENUPROXY");
541 #endif
542
543 #ifdef __WXOSX__
544                 ProcessSerialNumber serial;
545                 GetCurrentProcess (&serial);
546                 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
547 #endif
548
549                 dcpomatic_setup_path_encoding ();
550
551                 /* Enable i18n; this will create a Config object
552                    to look for a force-configured language.  This Config
553                    object will be wrong, however, because dcpomatic_setup
554                    hasn't yet been called and there aren't any filters etc.
555                    set up yet.
556                 */
557                 dcpomatic_setup_i18n ();
558
559                 /* Set things up, including filters etc.
560                    which will now be internationalised correctly.
561                 */
562                 dcpomatic_setup ();
563
564                 /* Force the configuration to be re-loaded correctly next
565                    time it is needed.
566                 */
567                 Config::drop ();
568
569                 _frame = new DOMFrame (_("DCP-o-matic KDM Creator"));
570                 SetTopWindow (_frame);
571                 _frame->Maximize ();
572                 _frame->Show ();
573
574                 signal_manager = new wxSignalManager (this);
575                 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
576
577                 return true;
578         }
579         catch (exception& e)
580         {
581                 error_dialog (0, wxString::Format ("DCP-o-matic could not start: %s", e.what ()));
582                 return true;
583         }
584
585         /* An unhandled exception has occurred inside the main event loop */
586         bool OnExceptionInMainLoop ()
587         {
588                 try {
589                         throw;
590                 } catch (FileError& e) {
591                         error_dialog (
592                                 0,
593                                 wxString::Format (
594                                         _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
595                                         std_to_wx (e.what()),
596                                         std_to_wx (e.file().string().c_str ())
597                                         )
598                                 );
599                 } catch (exception& e) {
600                         error_dialog (
601                                 0,
602                                 wxString::Format (
603                                         _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
604                                         std_to_wx (e.what ())
605                                         )
606                                 );
607                 } catch (...) {
608                         error_dialog (0, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
609                 }
610
611                 /* This will terminate the program */
612                 return false;
613         }
614
615         void OnUnhandledException ()
616         {
617                 error_dialog (0, _("An unknown exception occurred.") + "  " + REPORT_PROBLEM);
618         }
619
620         void idle ()
621         {
622                 signal_manager->ui_idle ();
623         }
624
625         DOMFrame* _frame;
626 };
627
628 IMPLEMENT_APP (App)