2 Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "wx/about_dialog.h"
23 #include "wx/dcpomatic_button.h"
24 #include "wx/editable_list.h"
25 #include "wx/file_dialog.h"
26 #include "wx/file_picker_ctrl.h"
27 #include "wx/full_config_dialog.h"
28 #include "wx/job_view_dialog.h"
29 #include "wx/kdm_output_panel.h"
30 #include "wx/kdm_timing_panel.h"
31 #include "wx/nag_dialog.h"
32 #include "wx/new_dkdm_folder_dialog.h"
33 #include "wx/report_problem_dialog.h"
34 #include "wx/screens_panel.h"
35 #include "wx/static_text.h"
36 #include "wx/wx_signal_manager.h"
37 #include "wx/wx_util.h"
38 #include "lib/cinema.h"
39 #include "lib/collator.h"
40 #include "lib/compose.hpp"
41 #include "lib/constants.h"
42 #include "lib/config.h"
43 #include "lib/cross.h"
44 #include "lib/dcpomatic_log.h"
45 #include "lib/dkdm_wrapper.h"
46 #include "lib/exceptions.h"
47 #include "lib/file_log.h"
48 #include "lib/job_manager.h"
49 #include "lib/kdm_with_metadata.h"
50 #include "lib/scope_guard.h"
51 #include "lib/screen.h"
52 #include "lib/send_kdm_email_job.h"
53 #include <dcp/encrypted_kdm.h>
54 #include <dcp/decrypted_kdm.h>
55 #include <dcp/exceptions.h>
56 #include <dcp/warnings.h>
57 LIBDCP_DISABLE_WARNINGS
58 #include <wx/filepicker.h>
59 #include <wx/preferences.h>
60 #include <wx/splash.h>
61 #include <wx/srchctrl.h>
62 #include <wx/treectrl.h>
64 LIBDCP_ENABLE_WARNINGS
66 #include <ApplicationServices/ApplicationServices.h>
68 #include <boost/bind/bind.hpp>
69 #include <unordered_set>
78 using std::make_shared;
81 using std::shared_ptr;
83 using std::unordered_set;
86 using boost::optional;
88 using std::dynamic_pointer_cast;
89 #if BOOST_VERSION >= 106100
90 using namespace boost::placeholders;
92 using namespace dcpomatic;
96 ID_help_report_a_problem = 1,
100 class DOMFrame : public wxFrame
103 explicit DOMFrame (wxString const & title)
104 : wxFrame (nullptr, -1, title)
105 , _config_dialog (nullptr)
106 , _job_view (nullptr)
108 #if defined(DCPOMATIC_WINDOWS)
109 if (Config::instance()->win32_console ()) {
112 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
113 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
114 FILE* hf_out = _fdopen(hCrt, "w");
115 setvbuf(hf_out, NULL, _IONBF, 1);
118 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
119 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
120 FILE* hf_in = _fdopen(hCrt, "r");
121 setvbuf(hf_in, NULL, _IONBF, 128);
124 std::cout << "DCP-o-matic KDM creator is starting." << "\n";
128 auto bar = new wxMenuBar;
132 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
133 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
134 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
135 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
137 /* Use a panel as the only child of the Frame so that we avoid
138 the dark-grey background on Windows.
140 auto overall_panel = new wxPanel (this, wxID_ANY);
141 auto main_sizer = new wxBoxSizer (wxHORIZONTAL);
143 auto horizontal = new wxBoxSizer (wxHORIZONTAL);
144 auto left = new wxBoxSizer (wxVERTICAL);
145 auto right = new wxBoxSizer (wxVERTICAL);
147 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 2);
148 horizontal->Add (right, 1, wxEXPAND);
150 wxFont subheading_font (*wxNORMAL_FONT);
151 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
153 auto h = new StaticText (overall_panel, _("Screens"));
154 h->SetFont (subheading_font);
155 left->Add (h, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
156 _screens = new ScreensPanel (overall_panel);
157 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
159 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
160 h = new StaticText (overall_panel, S_("KDM|Timing"));
161 h->SetFont (subheading_font);
163 _timing = new KDMTimingPanel (overall_panel);
164 right->Add (_timing, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
166 h = new StaticText (overall_panel, _("DKDM"));
167 h->SetFont (subheading_font);
168 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
170 _dkdm_search = new wxSearchCtrl(overall_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, search_ctrl_height()));
172 /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */
173 _dkdm_search->ShowCancelButton (true);
176 right->Add(_dkdm_search, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
178 auto dkdm_sizer = new wxBoxSizer (wxHORIZONTAL);
179 _dkdm = new wxTreeCtrl (
180 overall_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT
182 dkdm_sizer->Add(_dkdm, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
183 auto dkdm_buttons = new wxBoxSizer(wxVERTICAL);
184 _add_dkdm = new Button (overall_panel, _("Add..."));
185 dkdm_buttons->Add (_add_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
186 _add_dkdm_folder = new Button (overall_panel, _("Add folder..."));
187 dkdm_buttons->Add (_add_dkdm_folder, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
188 _remove_dkdm = new Button (overall_panel, _("Remove"));
189 dkdm_buttons->Add (_remove_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
190 _export_dkdm = new Button (overall_panel, _("Export..."));
191 dkdm_buttons->Add (_export_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
192 dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
193 right->Add (dkdm_sizer, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
197 h = new StaticText (overall_panel, _("Output"));
198 h->SetFont (subheading_font);
199 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
200 _output = new KDMOutputPanel (overall_panel);
201 right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
203 _create = new Button (overall_panel, _("Create KDMs"));
204 right->Add (_create, 0, wxALL, DCPOMATIC_SIZER_GAP);
206 main_sizer->Add (horizontal, 1, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER);
207 overall_panel->SetSizer (main_sizer);
209 /* Instantly save any config changes when using a DCP-o-matic GUI */
210 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
212 _screens->ScreensChanged.connect (boost::bind (&DOMFrame::setup_sensitivity, this));
213 _create->Bind (wxEVT_BUTTON, bind (&DOMFrame::create_kdms, this));
214 _dkdm->Bind(wxEVT_TREE_SEL_CHANGED, boost::bind(&DOMFrame::dkdm_selection_changed, this));
215 _dkdm->Bind (wxEVT_TREE_BEGIN_DRAG, boost::bind (&DOMFrame::dkdm_begin_drag, this, _1));
216 _dkdm->Bind (wxEVT_TREE_END_DRAG, boost::bind (&DOMFrame::dkdm_end_drag, this, _1));
217 _dkdm->Bind(wxEVT_TREE_ITEM_EXPANDED, boost::bind(&DOMFrame::dkdm_expanded, this, _1));
218 _dkdm->Bind(wxEVT_TREE_ITEM_COLLAPSED, boost::bind(&DOMFrame::dkdm_collapsed, this, _1));
219 _add_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_clicked, this));
220 _add_dkdm_folder->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_folder_clicked, this));
221 _remove_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::remove_dkdm_clicked, this));
222 _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
223 _dkdm_search->Bind(wxEVT_TEXT, boost::bind(&DOMFrame::dkdm_search_changed, this));
225 setup_sensitivity ();
227 dcpomatic_log = make_shared<FileLog>(State::write_path("kdm.log"));
233 /* false here allows the close handler to veto the close request */
237 void edit_preferences ()
239 if (!_config_dialog) {
240 _config_dialog = create_full_config_dialog ();
242 _config_dialog->Show (this);
247 auto d = new AboutDialog (this);
252 void help_report_a_problem ()
254 auto d = new ReportProblemDialog (this, shared_ptr<Film>());
255 if (d->ShowModal () == wxID_OK) {
261 void setup_menu (wxMenuBar* m)
263 auto file = new wxMenu;
266 file->Append (wxID_EXIT, _("&Exit"));
268 file->Append (wxID_EXIT, _("&Quit"));
272 file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
274 wxMenu* edit = new wxMenu;
275 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
278 wxMenu* help = new wxMenu;
280 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
282 help->Append (wxID_ABOUT, _("About"));
284 help->Append (ID_help_report_a_problem, _("Report a problem..."));
286 m->Append (file, _("&File"));
288 m->Append (edit, _("&Edit"));
290 m->Append (help, _("&Help"));
293 bool confirm_overwrite (boost::filesystem::path path)
295 return confirm_dialog (
297 wxString::Format (_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
301 /** @id if not nullptr this is filled in with the wxTreeItemId of the selection */
302 shared_ptr<DKDMBase> selected_dkdm (wxTreeItemId* id = nullptr) const
304 wxArrayTreeItemIds selections;
305 _dkdm->GetSelections (selections);
306 if (selections.GetCount() != 1) {
317 auto i = _dkdm_id.find (selections[0]);
318 if (i == _dkdm_id.end()) {
328 auto dkdm_base = selected_dkdm ();
333 list<KDMWithMetadataPtr> kdms;
336 auto dkdm = std::dynamic_pointer_cast<DKDM>(dkdm_base);
339 /* Decrypt the DKDM */
340 dcp::DecryptedKDM decrypted (dkdm->dkdm(), Config::instance()->decryption_chain()->key().get());
341 title = decrypted.content_title_text ();
343 /* This is the signer for our new KDMs */
344 auto signer = Config::instance()->signer_chain ();
345 if (!signer->valid ()) {
346 throw InvalidSignerError ();
349 for (auto i: _screens->screens()) {
355 dcp::LocalTime begin(_timing->from(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
356 dcp::LocalTime end(_timing->until(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
358 /* Make an empty KDM */
359 dcp::DecryptedKDM kdm (
362 decrypted.annotation_text().get_value_or (""),
364 dcp::LocalTime().as_string()
367 /* Add keys from the DKDM */
368 for (auto const& j: decrypted.keys()) {
372 auto const encrypted = kdm.encrypt(
373 signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
374 !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
377 dcp::NameFormat::Map name_values;
378 name_values['c'] = i->cinema->name;
379 name_values['s'] = i->name;
380 name_values['f'] = title;
381 name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
382 name_values['e'] = end.date() + " " + end.time_of_day(true, false);
383 name_values['i'] = encrypted.cpl_id ();
386 kdms.push_back (make_shared<KDMWithMetadata>(name_values, i->cinema.get(), i->cinema->emails, encrypted));
394 auto result = _output->make (
395 kdms, title, bind (&DOMFrame::confirm_overwrite, this, _1)
399 JobManager::instance()->add (result.first);
401 _job_view->Destroy ();
404 _job_view = new JobViewDialog (this, _("Send KDM emails"), result.first);
405 _job_view->ShowModal ();
408 if (result.second > 0) {
409 /* XXX: proper plural form support in wxWidgets? */
410 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
413 wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())
416 } catch (dcp::NotEncryptedError& e) {
417 error_dialog (this, _("CPL's content is not encrypted."));
418 } catch (exception& e) {
419 error_dialog (this, std_to_wx(e.what()));
421 error_dialog (this, _("An unknown exception occurred."));
425 void setup_sensitivity ()
427 _screens->setup_sensitivity ();
428 _output->setup_sensitivity ();
429 wxArrayTreeItemIds sel;
430 _dkdm->GetSelections (sel);
431 auto group = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
432 auto dkdm = dynamic_pointer_cast<DKDM>(selected_dkdm());
433 _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0 && dkdm);
434 _remove_dkdm->Enable (sel.GetCount() > 0 && (!group || group->name() != "root"));
435 _export_dkdm->Enable (sel.GetCount() > 0 && dkdm);
438 void dkdm_selection_changed()
440 _selected_dkdm = selected_dkdm();
444 void dkdm_expanded(wxTreeEvent& ev)
446 if (_ignore_expand) {
450 auto iter = _dkdm_id.find(ev.GetItem());
451 if (iter != _dkdm_id.end()) {
452 _expanded_dkdm_groups.insert(iter->second);
456 void dkdm_collapsed(wxTreeEvent& ev)
458 auto iter = _dkdm_id.find(ev.GetItem());
459 if (iter != _dkdm_id.end()) {
460 _expanded_dkdm_groups.erase(iter->second);
464 void dkdm_begin_drag (wxTreeEvent& ev)
469 void dkdm_end_drag (wxTreeEvent& ev)
471 auto from = _dkdm_id.find (_dkdm->GetSelection ());
472 auto to = _dkdm_id.find (ev.GetItem ());
473 if (from == _dkdm_id.end() || to == _dkdm_id.end() || from->first == to->first) {
477 auto group = dynamic_pointer_cast<DKDMGroup> (to->second);
479 group = to->second->parent();
482 DCPOMATIC_ASSERT (group);
483 DCPOMATIC_ASSERT (from->second->parent ());
485 from->second->parent()->remove (from->second);
486 add_dkdm(from->second, group, dynamic_pointer_cast<DKDM>(to->second));
491 void add_dkdm_clicked ()
493 auto dialog = new FileDialog(this, _("Select DKDM file"), wxT("XML files|*.xml|All files|*.*"), wxFD_MULTIPLE, "AddDKDMPath");
495 ScopeGuard sg = [dialog]() { dialog->Destroy(); };
497 if (!dialog->show()) {
501 auto chain = Config::instance()->decryption_chain();
502 DCPOMATIC_ASSERT (chain->key());
504 for (auto path: dialog->paths()) {
506 dcp::EncryptedKDM ekdm(dcp::file_to_string(path, MAX_KDM_SIZE));
507 /* Decrypt the DKDM to make sure that we can */
508 dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
510 auto new_dkdm = make_shared<DKDM>(ekdm);
511 auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
513 group = Config::instance()->dkdms ();
515 add_dkdm(new_dkdm, group);
516 } catch (dcp::KDMFormatError& e) {
519 _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all."),
523 } catch (dcp::KDMDecryptionError &) {
526 _("Could not decrypt the DKDM. Perhaps it was not created with the correct certificate.")
528 } catch (dcp::MiscError& e) {
531 _("Could not read file as a KDM. It is much too large. Make sure you are loading a DKDM (XML) file."),
539 void add_dkdm_folder_clicked ()
541 auto d = new NewDKDMFolderDialog (this);
542 if (d->ShowModal() == wxID_OK) {
543 auto new_dkdm = make_shared<DKDMGroup>(wx_to_std(d->get()));
544 auto parent = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
546 parent = Config::instance()->dkdms ();
548 add_dkdm(new_dkdm, parent);
554 void update_dkdm_view()
556 _dkdm->DeleteAllItems();
558 add_dkdm_to_view(Config::instance()->dkdms());
559 if (_selected_dkdm) {
560 auto selection_in_id_map = std::find_if(_dkdm_id.begin(), _dkdm_id.end(), [this](pair<wxTreeItemId, shared_ptr<DKDMBase>> const& entry) {
561 return entry.second == _selected_dkdm;
563 if (selection_in_id_map != _dkdm_id.end()) {
564 _dkdm->SelectItem(selection_in_id_map->first);
569 /** @return true if this thing or any of its children match a search string */
570 bool matches(shared_ptr<DKDMBase> base, string const& search)
572 if (search.empty()) {
576 auto name = base->name();
577 transform(name.begin(), name.end(), name.begin(), ::tolower);
578 if (name.find(search) != string::npos) {
582 auto group = dynamic_pointer_cast<DKDMGroup>(base);
587 auto const children = group->children();
588 return std::any_of(children.begin(), children.end(), [this, search](shared_ptr<DKDMBase> child) {
589 return matches(child, search);
593 /** Add DKDMs to the view that match the current search */
594 void add_dkdm_to_view(shared_ptr<DKDMBase> base)
596 auto search = wx_to_std(_dkdm_search->GetValue());
597 transform(search.begin(), search.end(), search.begin(), ::tolower);
599 optional<wxTreeItemId> group_to_expand;
601 if (!base->parent()) {
602 /* This is the root group */
603 _dkdm_id[_dkdm->AddRoot("root")] = base;
605 /* Add base to the view */
607 auto parent_id = dkdm_to_id(base->parent());
608 added = _dkdm->AppendItem(parent_id, std_to_wx(base->name()));
609 /* Expand the group (later) if it matches the search or it was manually expanded */
610 if (!search.empty() || _expanded_dkdm_groups.find(base) != _expanded_dkdm_groups.end()) {
611 group_to_expand = added;
613 _dkdm_id[added] = base;
617 auto group = dynamic_pointer_cast<DKDMGroup>(base);
619 auto children = group->children();
621 [this](shared_ptr<DKDMBase> a, shared_ptr<DKDMBase> b) { return _collator.compare(a->name(), b->name()) < 0; }
624 for (auto i: children) {
625 if (matches(i, search)) {
631 if (group_to_expand) {
632 _ignore_expand = true;
633 _dkdm->Expand(*group_to_expand);
634 _ignore_expand = false;
638 /** @param group Group to add dkdm to */
639 void add_dkdm(shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group, shared_ptr<DKDM> previous = shared_ptr<DKDM>())
641 group->add (dkdm, previous);
642 /* We're messing with a Config-owned object here, so tell it that something has changed.
645 Config::instance()->changed ();
648 wxTreeItemId dkdm_to_id (shared_ptr<DKDMBase> dkdm)
650 for (auto const& i: _dkdm_id) {
651 if (i.second == dkdm) {
655 DCPOMATIC_ASSERT (false);
658 void remove_dkdm_clicked ()
660 auto removed = selected_dkdm ();
665 if (NagDialog::maybe_nag (
666 this, Config::NAG_DELETE_DKDM,
667 _("You are about to remove a DKDM. This will make it impossible to decrypt the DCP that the DKDM was made for, and it cannot be undone. "
673 _dkdm->Delete (dkdm_to_id (removed));
674 auto dkdms = Config::instance()->dkdms ();
675 dkdms->remove (removed);
676 Config::instance()->changed ();
679 void export_dkdm_clicked ()
681 auto removed = selected_dkdm ();
686 auto dkdm = dynamic_pointer_cast<DKDM>(removed);
691 auto d = new wxFileDialog (
692 this, _("Select DKDM File"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"),
693 wxFD_SAVE | wxFD_OVERWRITE_PROMPT
696 if (d->ShowModal() == wxID_OK) {
697 dkdm->dkdm().as_xml(wx_to_std(d->GetPath()));
702 void dkdm_search_changed()
707 wxPreferencesEditor* _config_dialog;
708 ScreensPanel* _screens;
709 KDMTimingPanel* _timing;
711 wxSearchCtrl* _dkdm_search;
712 typedef std::map<wxTreeItemId, std::shared_ptr<DKDMBase>> DKDMMap;
714 /* Keep a separate track of the selected DKDM so that when a search happens, and some things
715 * get removed from the view, we can restore the selection when they are re-added.
717 shared_ptr<DKDMBase> _selected_dkdm;
718 /* Keep expanded groups for the same reason */
719 unordered_set<shared_ptr<DKDMBase>> _expanded_dkdm_groups;
720 /* true if we are "artificially" expanding a group because it contains something found
723 bool _ignore_expand = false;
725 wxButton* _add_dkdm_folder;
726 wxButton* _remove_dkdm;
727 wxButton* _export_dkdm;
729 KDMOutputPanel* _output;
730 JobViewDialog* _job_view;
736 * @brief The magic App class for wxWidgets.
738 class App : public wxApp
748 bool OnInit () override
750 wxSplashScreen* splash = nullptr;
753 wxInitAllImageHandlers ();
755 Config::FailedToLoad.connect(boost::bind(&App::config_failed_to_load, this, _1));
756 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
758 splash = maybe_show_splash ();
760 SetAppName (_("DCP-o-matic KDM Creator"));
762 if (!wxApp::OnInit()) {
766 #ifdef DCPOMATIC_LINUX
767 unsetenv ("UBUNTU_MENUPROXY");
771 make_foreground_application ();
774 dcpomatic_setup_path_encoding ();
776 /* Enable i18n; this will create a Config object
777 to look for a force-configured language. This Config
778 object will be wrong, however, because dcpomatic_setup
779 hasn't yet been called and there aren't any filters etc.
782 dcpomatic_setup_i18n ();
784 /* Set things up, including filters etc.
785 which will now be internationalised correctly.
789 /* Force the configuration to be re-loaded correctly next
794 _frame = new DOMFrame (_("DCP-o-matic KDM Creator"));
795 SetTopWindow (_frame);
803 signal_manager = new wxSignalManager (this);
804 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
811 error_dialog (0, _("DCP-o-matic could not start"), std_to_wx(e.what()));
817 /* An unhandled exception has occurred inside the main event loop */
818 bool OnExceptionInMainLoop () override
822 } catch (FileError& e) {
826 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
827 std_to_wx (e.what()),
828 std_to_wx (e.file().string().c_str ())
831 } catch (exception& e) {
835 _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
840 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
843 /* This will terminate the program */
847 void OnUnhandledException () override
849 error_dialog (nullptr, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
854 signal_manager->ui_idle ();
857 void config_failed_to_load(Config::LoadFailure what)
859 report_config_load_failure(_frame, what);
862 void config_warning (string m)
864 message_dialog (_frame, std_to_wx(m));