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_ptr.h"
37 #include "wx/wx_signal_manager.h"
38 #include "wx/wx_util.h"
39 #include "lib/cinema.h"
40 #include "lib/collator.h"
41 #include "lib/compose.hpp"
42 #include "lib/constants.h"
43 #include "lib/config.h"
44 #include "lib/cross.h"
45 #include "lib/dcpomatic_log.h"
46 #include "lib/dkdm_wrapper.h"
47 #include "lib/exceptions.h"
48 #include "lib/file_log.h"
49 #include "lib/job_manager.h"
50 #include "lib/kdm_with_metadata.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
59 #include <wx/filepicker.h>
60 #include <wx/preferences.h>
61 #include <wx/splash.h>
62 #include <wx/srchctrl.h>
63 #include <wx/treectrl.h>
65 LIBDCP_ENABLE_WARNINGS
67 #include <ApplicationServices/ApplicationServices.h>
69 #include <boost/bind/bind.hpp>
70 #include <unordered_set>
79 using std::make_shared;
82 using std::shared_ptr;
84 using std::unordered_set;
87 using boost::optional;
89 using std::dynamic_pointer_cast;
90 #if BOOST_VERSION >= 106100
91 using namespace boost::placeholders;
93 using namespace dcpomatic;
97 ID_help_report_a_problem = 1,
101 class DOMFrame : public wxFrame
104 explicit DOMFrame (wxString const & title)
105 : wxFrame (nullptr, -1, title)
106 , _config_dialog (nullptr)
107 , _job_view (nullptr)
109 #if defined(DCPOMATIC_WINDOWS)
110 if (Config::instance()->win32_console ()) {
113 HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
114 int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
115 FILE* hf_out = _fdopen(hCrt, "w");
116 setvbuf(hf_out, NULL, _IONBF, 1);
119 HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
120 hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
121 FILE* hf_in = _fdopen(hCrt, "r");
122 setvbuf(hf_in, NULL, _IONBF, 128);
125 std::cout << "DCP-o-matic KDM creator is starting." << "\n";
129 auto bar = new wxMenuBar;
133 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
134 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
135 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
136 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
138 /* Use a panel as the only child of the Frame so that we avoid
139 the dark-grey background on Windows.
141 auto overall_panel = new wxPanel (this, wxID_ANY);
142 auto main_sizer = new wxBoxSizer (wxHORIZONTAL);
144 auto horizontal = new wxBoxSizer (wxHORIZONTAL);
145 auto left = new wxBoxSizer (wxVERTICAL);
146 auto right = new wxBoxSizer (wxVERTICAL);
148 horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 2);
149 horizontal->Add (right, 1, wxEXPAND);
151 wxFont subheading_font (*wxNORMAL_FONT);
152 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
154 auto h = new StaticText (overall_panel, _("Screens"));
155 h->SetFont (subheading_font);
156 left->Add (h, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
157 _screens = new ScreensPanel (overall_panel);
158 left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
160 /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
161 h = new StaticText (overall_panel, S_("KDM|Timing"));
162 h->SetFont (subheading_font);
164 _timing = new KDMTimingPanel (overall_panel);
165 right->Add (_timing, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
167 h = new StaticText (overall_panel, _("DKDM"));
168 h->SetFont (subheading_font);
169 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
171 _dkdm_search = new wxSearchCtrl(overall_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, search_ctrl_height()));
173 /* The cancel button seems to be strangely broken in GTK3; clicking on it twice sometimes works */
174 _dkdm_search->ShowCancelButton (true);
177 right->Add(_dkdm_search, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
179 class DKDMDropTarget : public wxFileDropTarget
182 DKDMDropTarget(DOMFrame* frame)
186 bool OnDropFiles(wxCoord, wxCoord, wxArrayString const& filenames) override
188 for (size_t i = 0; i < filenames.GetCount(); ++i) {
189 _frame->add_dkdm(boost::filesystem::path(wx_to_std(filenames[0])));
199 auto dkdm_sizer = new wxBoxSizer (wxHORIZONTAL);
200 _dkdm = new wxTreeCtrl (
201 overall_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT
203 _dkdm->SetDropTarget(new DKDMDropTarget(this));
204 dkdm_sizer->Add(_dkdm, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
205 auto dkdm_buttons = new wxBoxSizer(wxVERTICAL);
206 _add_dkdm = new Button (overall_panel, _("Add..."));
207 dkdm_buttons->Add (_add_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
208 _add_dkdm_folder = new Button (overall_panel, _("Add folder..."));
209 dkdm_buttons->Add (_add_dkdm_folder, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
210 _remove_dkdm = new Button (overall_panel, _("Remove"));
211 dkdm_buttons->Add (_remove_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
212 _export_dkdm = new Button (overall_panel, _("Export..."));
213 dkdm_buttons->Add (_export_dkdm, 0, wxALL | wxEXPAND, DCPOMATIC_BUTTON_STACK_GAP);
214 dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
215 right->Add (dkdm_sizer, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
219 h = new StaticText (overall_panel, _("Output"));
220 h->SetFont (subheading_font);
221 right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
222 _output = new KDMOutputPanel (overall_panel);
223 right->Add (_output, 0, wxALL, DCPOMATIC_SIZER_Y_GAP);
225 _create = new Button (overall_panel, _("Create KDMs"));
226 right->Add (_create, 0, wxALL, DCPOMATIC_SIZER_GAP);
228 main_sizer->Add (horizontal, 1, wxALL | wxEXPAND, DCPOMATIC_DIALOG_BORDER);
229 overall_panel->SetSizer (main_sizer);
231 /* Instantly save any config changes when using a DCP-o-matic GUI */
232 Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
234 _screens->ScreensChanged.connect (boost::bind (&DOMFrame::setup_sensitivity, this));
235 _create->Bind (wxEVT_BUTTON, bind (&DOMFrame::create_kdms, this));
236 _dkdm->Bind(wxEVT_TREE_SEL_CHANGED, boost::bind(&DOMFrame::dkdm_selection_changed, this));
237 _dkdm->Bind (wxEVT_TREE_BEGIN_DRAG, boost::bind (&DOMFrame::dkdm_begin_drag, this, _1));
238 _dkdm->Bind (wxEVT_TREE_END_DRAG, boost::bind (&DOMFrame::dkdm_end_drag, this, _1));
239 _dkdm->Bind(wxEVT_TREE_ITEM_EXPANDED, boost::bind(&DOMFrame::dkdm_expanded, this, _1));
240 _dkdm->Bind(wxEVT_TREE_ITEM_COLLAPSED, boost::bind(&DOMFrame::dkdm_collapsed, this, _1));
241 _add_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_clicked, this));
242 _add_dkdm_folder->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_folder_clicked, this));
243 _remove_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::remove_dkdm_clicked, this));
244 _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
245 _dkdm_search->Bind(wxEVT_TEXT, boost::bind(&DOMFrame::dkdm_search_changed, this));
247 setup_sensitivity ();
249 dcpomatic_log = make_shared<FileLog>(State::write_path("kdm.log"));
255 /* false here allows the close handler to veto the close request */
259 void edit_preferences ()
261 if (!_config_dialog) {
262 _config_dialog = create_full_config_dialog ();
264 _config_dialog->Show (this);
269 auto d = make_wx<AboutDialog>(this);
273 void help_report_a_problem ()
275 auto d = make_wx<ReportProblemDialog>(this, shared_ptr<Film>());
276 if (d->ShowModal () == wxID_OK) {
281 void setup_menu (wxMenuBar* m)
283 auto file = new wxMenu;
286 file->Append (wxID_EXIT, _("&Exit"));
288 file->Append (wxID_EXIT, _("&Quit"));
292 file->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
294 wxMenu* edit = new wxMenu;
295 edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
298 wxMenu* help = new wxMenu;
300 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
302 help->Append (wxID_ABOUT, _("About"));
304 help->Append (ID_help_report_a_problem, _("Report a problem..."));
306 m->Append (file, _("&File"));
308 m->Append (edit, _("&Edit"));
310 m->Append (help, _("&Help"));
313 bool confirm_overwrite (boost::filesystem::path path)
315 return confirm_dialog (
317 wxString::Format (_("File %s already exists. Do you want to overwrite it?"), std_to_wx(path.string()).data())
321 /** @id if not nullptr this is filled in with the wxTreeItemId of the selection */
322 shared_ptr<DKDMBase> selected_dkdm (wxTreeItemId* id = nullptr) const
324 wxArrayTreeItemIds selections;
325 _dkdm->GetSelections (selections);
326 if (selections.GetCount() != 1) {
337 auto i = _dkdm_id.find (selections[0]);
338 if (i == _dkdm_id.end()) {
348 auto dkdm_base = selected_dkdm ();
353 list<KDMWithMetadataPtr> kdms;
356 auto dkdm = std::dynamic_pointer_cast<DKDM>(dkdm_base);
359 /* Decrypt the DKDM */
360 dcp::DecryptedKDM decrypted (dkdm->dkdm(), Config::instance()->decryption_chain()->key().get());
361 title = decrypted.content_title_text ();
363 /* This is the signer for our new KDMs */
364 auto signer = Config::instance()->signer_chain ();
365 if (!signer->valid ()) {
366 throw InvalidSignerError ();
369 for (auto i: _screens->screens()) {
375 dcp::LocalTime begin(_timing->from(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
376 dcp::LocalTime end(_timing->until(), dcp::UTCOffset(i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()));
378 /* Make an empty KDM */
379 dcp::DecryptedKDM kdm (
382 decrypted.annotation_text().get_value_or (""),
384 dcp::LocalTime().as_string()
387 /* Add keys from the DKDM */
388 for (auto const& j: decrypted.keys()) {
392 auto const encrypted = kdm.encrypt(
393 signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
394 !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
397 dcp::NameFormat::Map name_values;
398 name_values['c'] = i->cinema->name;
399 name_values['s'] = i->name;
400 name_values['f'] = title;
401 name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
402 name_values['e'] = end.date() + " " + end.time_of_day(true, false);
403 name_values['i'] = encrypted.cpl_id ();
406 kdms.push_back (make_shared<KDMWithMetadata>(name_values, i->cinema.get(), i->cinema->emails, encrypted));
414 auto result = _output->make (
415 kdms, title, bind (&DOMFrame::confirm_overwrite, this, _1)
419 JobManager::instance()->add (result.first);
421 _job_view->Destroy ();
424 _job_view = new JobViewDialog (this, _("Send KDM emails"), result.first);
425 _job_view->ShowModal ();
428 if (result.second > 0) {
429 /* XXX: proper plural form support in wxWidgets? */
430 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
433 wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())
436 } catch (dcp::NotEncryptedError& e) {
437 error_dialog (this, _("CPL's content is not encrypted."));
438 } catch (exception& e) {
439 error_dialog (this, std_to_wx(e.what()));
441 error_dialog (this, _("An unknown exception occurred."));
445 void setup_sensitivity ()
447 _screens->setup_sensitivity ();
448 _output->setup_sensitivity ();
449 wxArrayTreeItemIds sel;
450 _dkdm->GetSelections (sel);
451 auto group = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
452 auto dkdm = dynamic_pointer_cast<DKDM>(selected_dkdm());
453 _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0 && dkdm);
454 _remove_dkdm->Enable (sel.GetCount() > 0 && (!group || group->name() != "root"));
455 _export_dkdm->Enable (sel.GetCount() > 0 && dkdm);
458 void dkdm_selection_changed()
460 _selected_dkdm = selected_dkdm();
464 void dkdm_expanded(wxTreeEvent& ev)
466 if (_ignore_expand) {
470 auto iter = _dkdm_id.find(ev.GetItem());
471 if (iter != _dkdm_id.end()) {
472 _expanded_dkdm_groups.insert(iter->second);
476 void dkdm_collapsed(wxTreeEvent& ev)
478 auto iter = _dkdm_id.find(ev.GetItem());
479 if (iter != _dkdm_id.end()) {
480 _expanded_dkdm_groups.erase(iter->second);
484 void dkdm_begin_drag (wxTreeEvent& ev)
489 void dkdm_end_drag (wxTreeEvent& ev)
491 auto from = _dkdm_id.find (_dkdm->GetSelection ());
492 auto to = _dkdm_id.find (ev.GetItem ());
493 if (from == _dkdm_id.end() || to == _dkdm_id.end() || from->first == to->first) {
497 auto group = dynamic_pointer_cast<DKDMGroup> (to->second);
499 group = to->second->parent();
502 DCPOMATIC_ASSERT (group);
503 DCPOMATIC_ASSERT (from->second->parent ());
505 from->second->parent()->remove (from->second);
506 add_dkdm(from->second, group, dynamic_pointer_cast<DKDM>(to->second));
511 void add_dkdm_clicked ()
513 auto dialog = make_wx<FileDialog>(this, _("Select DKDM file"), wxT("XML files|*.xml|All files|*.*"), wxFD_MULTIPLE, "AddDKDMPath");
514 if (!dialog->show()) {
518 for (auto path: dialog->paths()) {
523 void add_dkdm(boost::filesystem::path path)
525 auto chain = Config::instance()->decryption_chain();
526 DCPOMATIC_ASSERT (chain->key());
529 dcp::EncryptedKDM ekdm(dcp::file_to_string(path, MAX_KDM_SIZE));
530 /* Decrypt the DKDM to make sure that we can */
531 dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
533 auto new_dkdm = make_shared<DKDM>(ekdm);
534 auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
536 group = Config::instance()->dkdms ();
538 add_dkdm(new_dkdm, group);
539 } catch (dcp::KDMFormatError& e) {
542 _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all."),
546 } catch (dcp::KDMDecryptionError &) {
549 _("Could not decrypt the DKDM. Perhaps it was not created with the correct certificate.")
551 } catch (dcp::MiscError& e) {
554 _("Could not read file as a KDM. It is much too large. Make sure you are loading a DKDM (XML) file."),
562 void add_dkdm_folder_clicked ()
564 auto d = make_wx<NewDKDMFolderDialog>(this);
565 if (d->ShowModal() != wxID_OK) {
569 auto new_dkdm = make_shared<DKDMGroup>(wx_to_std(d->get()));
570 auto parent = dynamic_pointer_cast<DKDMGroup>(selected_dkdm());
572 parent = Config::instance()->dkdms ();
574 add_dkdm(new_dkdm, parent);
578 void update_dkdm_view()
580 _dkdm->DeleteAllItems();
582 add_dkdm_to_view(Config::instance()->dkdms());
583 if (_selected_dkdm) {
584 auto selection_in_id_map = std::find_if(_dkdm_id.begin(), _dkdm_id.end(), [this](pair<wxTreeItemId, shared_ptr<DKDMBase>> const& entry) {
585 return entry.second == _selected_dkdm;
587 if (selection_in_id_map != _dkdm_id.end()) {
588 _dkdm->SelectItem(selection_in_id_map->first);
593 /** @return true if this thing or any of its children match a search string */
594 bool matches(shared_ptr<DKDMBase> base, string const& search)
596 if (search.empty()) {
600 auto name = base->name();
601 transform(name.begin(), name.end(), name.begin(), ::tolower);
602 if (name.find(search) != string::npos) {
606 auto group = dynamic_pointer_cast<DKDMGroup>(base);
611 auto const children = group->children();
612 return std::any_of(children.begin(), children.end(), [this, search](shared_ptr<DKDMBase> child) {
613 return matches(child, search);
617 /** Add DKDMs to the view that match the current search */
618 void add_dkdm_to_view(shared_ptr<DKDMBase> base)
620 auto search = wx_to_std(_dkdm_search->GetValue());
621 transform(search.begin(), search.end(), search.begin(), ::tolower);
623 optional<wxTreeItemId> group_to_expand;
625 if (!base->parent()) {
626 /* This is the root group */
627 _dkdm_id[_dkdm->AddRoot("root")] = base;
629 /* Add base to the view */
631 auto parent_id = dkdm_to_id(base->parent());
632 added = _dkdm->AppendItem(parent_id, std_to_wx(base->name()));
633 /* Expand the group (later) if it matches the search or it was manually expanded */
634 if (!search.empty() || _expanded_dkdm_groups.find(base) != _expanded_dkdm_groups.end()) {
635 group_to_expand = added;
637 _dkdm_id[added] = base;
641 auto group = dynamic_pointer_cast<DKDMGroup>(base);
643 auto children = group->children();
645 [this](shared_ptr<DKDMBase> a, shared_ptr<DKDMBase> b) { return _collator.compare(a->name(), b->name()) < 0; }
648 for (auto i: children) {
649 if (matches(i, search)) {
655 if (group_to_expand) {
656 _ignore_expand = true;
657 _dkdm->Expand(*group_to_expand);
658 _ignore_expand = false;
662 /** @param group Group to add dkdm to */
663 void add_dkdm(shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group, shared_ptr<DKDM> previous = shared_ptr<DKDM>())
665 group->add (dkdm, previous);
666 /* We're messing with a Config-owned object here, so tell it that something has changed.
669 Config::instance()->changed ();
672 wxTreeItemId dkdm_to_id (shared_ptr<DKDMBase> dkdm)
674 for (auto const& i: _dkdm_id) {
675 if (i.second == dkdm) {
679 DCPOMATIC_ASSERT (false);
682 void remove_dkdm_clicked ()
684 auto removed = selected_dkdm ();
689 if (NagDialog::maybe_nag (
690 this, Config::NAG_DELETE_DKDM,
691 _("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. "
697 _dkdm->Delete (dkdm_to_id (removed));
698 auto dkdms = Config::instance()->dkdms ();
699 dkdms->remove (removed);
700 Config::instance()->changed ();
703 void export_dkdm_clicked ()
705 auto removed = selected_dkdm ();
710 auto dkdm = dynamic_pointer_cast<DKDM>(removed);
715 auto d = make_wx<wxFileDialog>(
716 this, _("Select DKDM File"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"),
717 wxFD_SAVE | wxFD_OVERWRITE_PROMPT
720 if (d->ShowModal() == wxID_OK) {
721 dkdm->dkdm().as_xml(wx_to_std(d->GetPath()));
725 void dkdm_search_changed()
730 wxPreferencesEditor* _config_dialog;
731 ScreensPanel* _screens;
732 KDMTimingPanel* _timing;
734 wxSearchCtrl* _dkdm_search;
735 typedef std::map<wxTreeItemId, std::shared_ptr<DKDMBase>> DKDMMap;
737 /* Keep a separate track of the selected DKDM so that when a search happens, and some things
738 * get removed from the view, we can restore the selection when they are re-added.
740 shared_ptr<DKDMBase> _selected_dkdm;
741 /* Keep expanded groups for the same reason */
742 unordered_set<shared_ptr<DKDMBase>> _expanded_dkdm_groups;
743 /* true if we are "artificially" expanding a group because it contains something found
746 bool _ignore_expand = false;
748 wxButton* _add_dkdm_folder;
749 wxButton* _remove_dkdm;
750 wxButton* _export_dkdm;
752 KDMOutputPanel* _output;
753 JobViewDialog* _job_view;
759 * @brief The magic App class for wxWidgets.
761 class App : public wxApp
771 bool OnInit () override
773 wx_ptr<wxSplashScreen> splash;
776 wxInitAllImageHandlers ();
778 Config::FailedToLoad.connect(boost::bind(&App::config_failed_to_load, this, _1));
779 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
781 splash = maybe_show_splash ();
783 SetAppName (_("DCP-o-matic KDM Creator"));
785 if (!wxApp::OnInit()) {
789 #ifdef DCPOMATIC_LINUX
790 unsetenv ("UBUNTU_MENUPROXY");
794 make_foreground_application ();
797 dcpomatic_setup_path_encoding ();
799 /* Enable i18n; this will create a Config object
800 to look for a force-configured language. This Config
801 object will be wrong, however, because dcpomatic_setup
802 hasn't yet been called and there aren't any filters etc.
805 dcpomatic_setup_i18n ();
807 /* Set things up, including filters etc.
808 which will now be internationalised correctly.
812 /* Force the configuration to be re-loaded correctly next
817 _frame = new DOMFrame (_("DCP-o-matic KDM Creator"));
818 SetTopWindow (_frame);
826 signal_manager = new wxSignalManager (this);
827 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
834 error_dialog (0, _("DCP-o-matic could not start"), std_to_wx(e.what()));
840 /* An unhandled exception has occurred inside the main event loop */
841 bool OnExceptionInMainLoop () override
845 } catch (FileError& e) {
849 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
850 std_to_wx (e.what()),
851 std_to_wx (e.file().string().c_str ())
854 } catch (exception& e) {
858 _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
863 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
866 /* This will terminate the program */
870 void OnUnhandledException () override
872 error_dialog (nullptr, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
877 signal_manager->ui_idle ();
880 void config_failed_to_load(Config::LoadFailure what)
882 report_config_load_failure(_frame, what);
885 void config_warning (string m)
887 message_dialog (_frame, std_to_wx(m));