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_picker_ctrl.h"
26 #include "wx/full_config_dialog.h"
27 #include "wx/job_view_dialog.h"
28 #include "wx/kdm_output_panel.h"
29 #include "wx/kdm_timing_panel.h"
30 #include "wx/nag_dialog.h"
31 #include "wx/new_dkdm_folder_dialog.h"
32 #include "wx/report_problem_dialog.h"
33 #include "wx/screens_panel.h"
34 #include "wx/static_text.h"
35 #include "wx/wx_signal_manager.h"
36 #include "wx/wx_util.h"
37 #include "lib/cinema.h"
38 #include "lib/collator.h"
39 #include "lib/compose.hpp"
40 #include "lib/constants.h"
41 #include "lib/config.h"
42 #include "lib/cross.h"
43 #include "lib/dcpomatic_log.h"
44 #include "lib/dkdm_wrapper.h"
45 #include "lib/exceptions.h"
46 #include "lib/file_log.h"
47 #include "lib/job_manager.h"
48 #include "lib/kdm_with_metadata.h"
49 #include "lib/scope_guard.h"
50 #include "lib/screen.h"
51 #include "lib/send_kdm_email_job.h"
52 #include <dcp/encrypted_kdm.h>
53 #include <dcp/decrypted_kdm.h>
54 #include <dcp/exceptions.h>
55 #include <dcp/warnings.h>
56 LIBDCP_DISABLE_WARNINGS
57 #include <wx/filepicker.h>
58 #include <wx/preferences.h>
59 #include <wx/splash.h>
60 #include <wx/srchctrl.h>
61 #include <wx/treectrl.h>
63 LIBDCP_ENABLE_WARNINGS
65 #include <ApplicationServices/ApplicationServices.h>
67 #include <boost/bind/bind.hpp>
68 #include <unordered_set>
77 using std::make_shared;
80 using std::shared_ptr;
82 using std::unordered_set;
85 using boost::optional;
87 using std::dynamic_pointer_cast;
88 #if BOOST_VERSION >= 106100
89 using namespace boost::placeholders;
91 using namespace dcpomatic;
95 ID_help_report_a_problem = 1,
99 class DOMFrame : public wxFrame
102 explicit DOMFrame (wxString const & title)
103 : wxFrame (nullptr, -1, title)
104 , _config_dialog (nullptr)
105 , _job_view (nullptr)
107 #if defined(DCPOMATIC_WINDOWS)
108 if (Config::instance()->win32_console ()) {
111 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
112 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
113 FILE* hf_out = _fdopen(hCrt, "w");
114 setvbuf(hf_out, NULL, _IONBF, 1);
117 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
118 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
119 FILE* hf_in = _fdopen(hCrt, "r");
120 setvbuf(hf_in, NULL, _IONBF, 128);
123 std::cout << "DCP-o-matic KDM creator is starting." << "\n";
127 auto bar = new wxMenuBar;
131 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
132 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
133 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
134 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
136 /* Use a panel as the only child of the Frame so that we avoid
137 the dark-grey background on Windows.
139 auto overall_panel = new wxPanel (this, wxID_ANY);
140 auto main_sizer = new wxBoxSizer (wxHORIZONTAL);
142 auto horizontal = new wxBoxSizer (wxHORIZONTAL);
143 auto left = new wxBoxSizer (wxVERTICAL);
144 auto right = new wxBoxSizer (wxVERTICAL);
146 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 2);
147 horizontal->Add (right, 1, wxEXPAND);
149 wxFont subheading_font (*wxNORMAL_FONT);
150 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
152 auto h = new StaticText (overall_panel, _("Screens"));
153 h->SetFont (subheading_font);
154 left->Add (h, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
155 _screens = new ScreensPanel (overall_panel);
156 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
158 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
159 h = new StaticText (overall_panel, S_("KDM|Timing"));
160 h->SetFont (subheading_font);
162 _timing = new KDMTimingPanel (overall_panel);
163 right->Add (_timing, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
165 h = new StaticText (overall_panel, _("DKDM"));
166 h->SetFont (subheading_font);
167 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
169 _dkdm_search = new wxSearchCtrl(overall_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, search_ctrl_height()));
171 /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */
172 _dkdm_search->ShowCancelButton (true);
175 right->Add(_dkdm_search, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
177 auto dkdm_sizer = new wxBoxSizer (wxHORIZONTAL);
178 _dkdm = new wxTreeCtrl (
179 overall_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT
181 dkdm_sizer->Add(_dkdm, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
182 wxBoxSizer* dkdm_buttons = new wxBoxSizer(wxVERTICAL);
183 _add_dkdm = new Button (overall_panel, _("Add..."));
184 dkdm_buttons->Add (_add_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
185 _add_dkdm_folder = new Button (overall_panel, _("Add folder..."));
186 dkdm_buttons->Add (_add_dkdm_folder, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
187 _remove_dkdm = new Button (overall_panel, _("Remove"));
188 dkdm_buttons->Add (_remove_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
189 _export_dkdm = new Button (overall_panel, _("Export..."));
190 dkdm_buttons->Add (_export_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
191 dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
192 right->Add (dkdm_sizer, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
196 h = new StaticText (overall_panel, _("Output"));
197 h->SetFont (subheading_font);
198 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
199 _output = new KDMOutputPanel (overall_panel);
200 right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
202 _create = new Button (overall_panel, _("Create KDMs"));
203 right->Add (_create, 0, wxALL, DCPOMATIC_SIZER_GAP);
205 main_sizer->Add (horizontal, 1, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER);
206 overall_panel->SetSizer (main_sizer);
208 /* Instantly save any config changes when using a DCP-o-matic GUI */
209 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
211 _screens->ScreensChanged.connect (boost::bind (&DOMFrame::setup_sensitivity, this));
212 _create->Bind (wxEVT_BUTTON, bind (&DOMFrame::create_kdms, this));
213 _dkdm->Bind(wxEVT_TREE_SEL_CHANGED, boost::bind(&DOMFrame::dkdm_selection_changed, this));
214 _dkdm->Bind (wxEVT_TREE_BEGIN_DRAG, boost::bind (&DOMFrame::dkdm_begin_drag, this, _1));
215 _dkdm->Bind (wxEVT_TREE_END_DRAG, boost::bind (&DOMFrame::dkdm_end_drag, this, _1));
216 _dkdm->Bind(wxEVT_TREE_ITEM_EXPANDED, boost::bind(&DOMFrame::dkdm_expanded, this, _1));
217 _dkdm->Bind(wxEVT_TREE_ITEM_COLLAPSED, boost::bind(&DOMFrame::dkdm_collapsed, this, _1));
218 _add_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_clicked, this));
219 _add_dkdm_folder->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_folder_clicked, this));
220 _remove_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::remove_dkdm_clicked, this));
221 _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
222 _dkdm_search->Bind(wxEVT_TEXT, boost::bind(&DOMFrame::dkdm_search_changed, this));
224 setup_sensitivity ();
226 dcpomatic_log = make_shared<FileLog>(State::write_path("kdm.log"));
232 /* false here allows the close handler to veto the close request */
236 void edit_preferences ()
238 if (!_config_dialog) {
239 _config_dialog = create_full_config_dialog ();
241 _config_dialog->Show (this);
246 auto d = new AboutDialog (this);
251 void help_report_a_problem ()
253 auto d = new ReportProblemDialog (this, shared_ptr<Film>());
254 if (d->ShowModal () == wxID_OK) {
260 void setup_menu (wxMenuBar* m)
262 auto file = new wxMenu;
265 file->Append (wxID_EXIT, _("&Exit"));
267 file->Append (wxID_EXIT, _("&Quit"));
271 file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
273 wxMenu* edit = new wxMenu;
274 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
277 wxMenu* help = new wxMenu;
279 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
281 help->Append (wxID_ABOUT, _("About"));
283 help->Append (ID_help_report_a_problem, _("Report a problem..."));
285 m->Append (file, _("&File"));
287 m->Append (edit, _("&Edit"));
289 m->Append (help, _("&Help"));
292 bool confirm_overwrite (boost::filesystem::path path)
294 return confirm_dialog (
296 wxString::Format (_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
300 /** @id if not nullptr this is filled in with the wxTreeItemId of the selection */
301 shared_ptr<DKDMBase> selected_dkdm (wxTreeItemId* id = nullptr) const
303 wxArrayTreeItemIds selections;
304 _dkdm->GetSelections (selections);
305 if (selections.GetCount() != 1) {
316 auto i = _dkdm_id.find (selections[0]);
317 if (i == _dkdm_id.end()) {
327 auto dkdm_base = selected_dkdm ();
332 list<KDMWithMetadataPtr> kdms;
335 auto dkdm = std::dynamic_pointer_cast<DKDM>(dkdm_base);
338 /* Decrypt the DKDM */
339 dcp::DecryptedKDM decrypted (dkdm->dkdm(), Config::instance()->decryption_chain()->key().get());
340 title = decrypted.content_title_text ();
342 /* This is the signer for our new KDMs */
343 auto signer = Config::instance()->signer_chain ();
344 if (!signer->valid ()) {
345 throw InvalidSignerError ();
348 for (auto i: _screens->screens()) {
354 dcp::LocalTime begin(_timing->from(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
355 dcp::LocalTime end(_timing->until(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
357 /* Make an empty KDM */
358 dcp::DecryptedKDM kdm (
361 decrypted.annotation_text().get_value_or (""),
363 dcp::LocalTime().as_string()
366 /* Add keys from the DKDM */
367 for (auto const& j: decrypted.keys()) {
371 auto const encrypted = kdm.encrypt(
372 signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
373 !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
376 dcp::NameFormat::Map name_values;
377 name_values['c'] = i->cinema->name;
378 name_values['s'] = i->name;
379 name_values['f'] = title;
380 name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
381 name_values['e'] = end.date() + " " + end.time_of_day(true, false);
382 name_values['i'] = encrypted.cpl_id ();
385 kdms.push_back (make_shared<KDMWithMetadata>(name_values, i->cinema.get(), i->cinema->emails, encrypted));
393 auto result = _output->make (
394 kdms, title, bind (&DOMFrame::confirm_overwrite, this, _1)
398 JobManager::instance()->add (result.first);
400 _job_view->Destroy ();
403 _job_view = new JobViewDialog (this, _("Send KDM emails"), result.first);
404 _job_view->ShowModal ();
407 if (result.second > 0) {
408 /* XXX: proper plural form support in wxWidgets? */
409 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
412 wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())
415 } catch (dcp::NotEncryptedError& e) {
416 error_dialog (this, _("CPL's content is not encrypted."));
417 } catch (exception& e) {
418 error_dialog (this, std_to_wx(e.what()));
420 error_dialog (this, _("An unknown exception occurred."));
424 void setup_sensitivity ()
426 _screens->setup_sensitivity ();
427 _output->setup_sensitivity ();
428 wxArrayTreeItemIds sel;
429 _dkdm->GetSelections (sel);
430 auto group = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
431 auto dkdm = dynamic_pointer_cast<DKDM>(selected_dkdm());
432 _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0 && dkdm);
433 _remove_dkdm->Enable (sel.GetCount() > 0 && (!group || group->name() != "root"));
434 _export_dkdm->Enable (sel.GetCount() > 0 && dkdm);
437 void dkdm_selection_changed()
439 _selected_dkdm = selected_dkdm();
443 void dkdm_expanded(wxTreeEvent& ev)
445 if (_ignore_expand) {
449 auto iter = _dkdm_id.find(ev.GetItem());
450 if (iter != _dkdm_id.end()) {
451 _expanded_dkdm_groups.insert(iter->second);
455 void dkdm_collapsed(wxTreeEvent& ev)
457 auto iter = _dkdm_id.find(ev.GetItem());
458 if (iter != _dkdm_id.end()) {
459 _expanded_dkdm_groups.erase(iter->second);
463 void dkdm_begin_drag (wxTreeEvent& ev)
468 void dkdm_end_drag (wxTreeEvent& ev)
470 auto from = _dkdm_id.find (_dkdm->GetSelection ());
471 auto to = _dkdm_id.find (ev.GetItem ());
472 if (from == _dkdm_id.end() || to == _dkdm_id.end() || from->first == to->first) {
476 auto group = dynamic_pointer_cast<DKDMGroup> (to->second);
478 group = to->second->parent();
481 DCPOMATIC_ASSERT (group);
482 DCPOMATIC_ASSERT (from->second->parent ());
484 from->second->parent()->remove (from->second);
485 add_dkdm(from->second, group, dynamic_pointer_cast<DKDM>(to->second));
490 void add_dkdm_clicked ()
492 auto d = new wxFileDialog(
494 _("Select DKDM file"),
497 wxT("XML files|*.xml|All files|*.*"),
501 ScopeGuard sg = [d]() { d->Destroy(); };
503 if (d->ShowModal() != wxID_OK) {
507 auto chain = Config::instance()->decryption_chain();
508 DCPOMATIC_ASSERT (chain->key());
512 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
514 dcp::EncryptedKDM ekdm(dcp::file_to_string(wx_to_std(paths[i]), MAX_KDM_SIZE));
515 /* Decrypt the DKDM to make sure that we can */
516 dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
518 auto new_dkdm = make_shared<DKDM>(ekdm);
519 auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
521 group = Config::instance()->dkdms ();
523 add_dkdm(new_dkdm, group);
524 } catch (dcp::KDMFormatError& e) {
527 _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all."),
531 } catch (dcp::KDMDecryptionError &) {
534 _("Could not decrypt the DKDM. Perhaps it was not created with the correct certificate.")
536 } catch (dcp::MiscError& e) {
539 _("Could not read file as a KDM. It is much too large. Make sure you are loading a DKDM (XML) file."),
547 void add_dkdm_folder_clicked ()
549 auto d = new NewDKDMFolderDialog (this);
550 if (d->ShowModal() == wxID_OK) {
551 auto new_dkdm = make_shared<DKDMGroup>(wx_to_std(d->get()));
552 auto parent = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
554 parent = Config::instance()->dkdms ();
556 add_dkdm(new_dkdm, parent);
562 void update_dkdm_view()
564 _dkdm->DeleteAllItems();
566 add_dkdm_to_view(Config::instance()->dkdms());
567 if (_selected_dkdm) {
568 auto selection_in_id_map = std::find_if(_dkdm_id.begin(), _dkdm_id.end(), [this](pair<wxTreeItemId, shared_ptr<DKDMBase>> const& entry) {
569 return entry.second == _selected_dkdm;
571 if (selection_in_id_map != _dkdm_id.end()) {
572 _dkdm->SelectItem(selection_in_id_map->first);
577 /** @return true if this thing or any of its children match a search string */
578 bool matches(shared_ptr<DKDMBase> base, string const& search)
580 if (search.empty()) {
584 auto name = base->name();
585 transform(name.begin(), name.end(), name.begin(), ::tolower);
586 if (name.find(search) != string::npos) {
590 auto group = dynamic_pointer_cast<DKDMGroup>(base);
595 auto const children = group->children();
596 return std::any_of(children.begin(), children.end(), [this, search](shared_ptr<DKDMBase> child) {
597 return matches(child, search);
601 /** Add DKDMs to the view that match the current search */
602 void add_dkdm_to_view(shared_ptr<DKDMBase> base)
604 auto search = wx_to_std(_dkdm_search->GetValue());
605 transform(search.begin(), search.end(), search.begin(), ::tolower);
607 optional<wxTreeItemId> group_to_expand;
609 if (!base->parent()) {
610 /* This is the root group */
611 _dkdm_id[_dkdm->AddRoot("root")] = base;
613 /* Add base to the view */
615 auto parent_id = dkdm_to_id(base->parent());
616 added = _dkdm->AppendItem(parent_id, std_to_wx(base->name()));
617 /* Expand the group (later) if it matches the search or it was manually expanded */
618 if (!search.empty() || _expanded_dkdm_groups.find(base) != _expanded_dkdm_groups.end()) {
619 group_to_expand = added;
621 _dkdm_id[added] = base;
625 auto group = dynamic_pointer_cast<DKDMGroup>(base);
627 auto children = group->children();
629 [this](shared_ptr<DKDMBase> a, shared_ptr<DKDMBase> b) { return _collator.compare(a->name(), b->name()) < 0; }
632 for (auto i: children) {
633 if (matches(i, search)) {
639 if (group_to_expand) {
640 _ignore_expand = true;
641 _dkdm->Expand(*group_to_expand);
642 _ignore_expand = false;
646 /** @param group Group to add dkdm to */
647 void add_dkdm(shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group, shared_ptr<DKDM> previous = shared_ptr<DKDM>())
649 group->add (dkdm, previous);
650 /* We're messing with a Config-owned object here, so tell it that something has changed.
653 Config::instance()->changed ();
656 wxTreeItemId dkdm_to_id (shared_ptr<DKDMBase> dkdm)
658 for (auto const& i: _dkdm_id) {
659 if (i.second == dkdm) {
663 DCPOMATIC_ASSERT (false);
666 void remove_dkdm_clicked ()
668 auto removed = selected_dkdm ();
673 if (NagDialog::maybe_nag (
674 this, Config::NAG_DELETE_DKDM,
675 _("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. "
681 _dkdm->Delete (dkdm_to_id (removed));
682 auto dkdms = Config::instance()->dkdms ();
683 dkdms->remove (removed);
684 Config::instance()->changed ();
687 void export_dkdm_clicked ()
689 auto removed = selected_dkdm ();
694 auto dkdm = dynamic_pointer_cast<DKDM>(removed);
699 auto d = new wxFileDialog (
700 this, _("Select DKDM File"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"),
701 wxFD_SAVE | wxFD_OVERWRITE_PROMPT
704 if (d->ShowModal() == wxID_OK) {
705 dkdm->dkdm().as_xml(wx_to_std(d->GetPath()));
710 void dkdm_search_changed()
715 wxPreferencesEditor* _config_dialog;
716 ScreensPanel* _screens;
717 KDMTimingPanel* _timing;
719 wxSearchCtrl* _dkdm_search;
720 typedef std::map<wxTreeItemId, std::shared_ptr<DKDMBase>> DKDMMap;
722 /* Keep a separate track of the selected DKDM so that when a search happens, and some things
723 * get removed from the view, we can restore the selection when they are re-added.
725 shared_ptr<DKDMBase> _selected_dkdm;
726 /* Keep expanded groups for the same reason */
727 unordered_set<shared_ptr<DKDMBase>> _expanded_dkdm_groups;
728 /* true if we are "artificially" expanding a group because it contains something found
731 bool _ignore_expand = false;
733 wxButton* _add_dkdm_folder;
734 wxButton* _remove_dkdm;
735 wxButton* _export_dkdm;
737 KDMOutputPanel* _output;
738 JobViewDialog* _job_view;
744 * @brief The magic App class for wxWidgets.
746 class App : public wxApp
756 bool OnInit () override
758 wxSplashScreen* splash = nullptr;
761 wxInitAllImageHandlers ();
763 Config::FailedToLoad.connect(boost::bind(&App::config_failed_to_load, this, _1));
764 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
766 splash = maybe_show_splash ();
768 SetAppName (_("DCP-o-matic KDM Creator"));
770 if (!wxApp::OnInit()) {
774 #ifdef DCPOMATIC_LINUX
775 unsetenv ("UBUNTU_MENUPROXY");
779 make_foreground_application ();
782 dcpomatic_setup_path_encoding ();
784 /* Enable i18n; this will create a Config object
785 to look for a force-configured language. This Config
786 object will be wrong, however, because dcpomatic_setup
787 hasn't yet been called and there aren't any filters etc.
790 dcpomatic_setup_i18n ();
792 /* Set things up, including filters etc.
793 which will now be internationalised correctly.
797 /* Force the configuration to be re-loaded correctly next
802 _frame = new DOMFrame (_("DCP-o-matic KDM Creator"));
803 SetTopWindow (_frame);
811 signal_manager = new wxSignalManager (this);
812 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
819 error_dialog (0, _("DCP-o-matic could not start"), std_to_wx(e.what()));
825 /* An unhandled exception has occurred inside the main event loop */
826 bool OnExceptionInMainLoop () override
830 } catch (FileError& e) {
834 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
835 std_to_wx (e.what()),
836 std_to_wx (e.file().string().c_str ())
839 } catch (exception& e) {
843 _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
848 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
851 /* This will terminate the program */
855 void OnUnhandledException () override
857 error_dialog (nullptr, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
862 signal_manager->ui_idle ();
865 void config_failed_to_load(Config::LoadFailure what)
867 report_config_load_failure(_frame, what);
870 void config_warning (string m)
872 message_dialog (_frame, std_to_wx(m));