X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_kdm.cc;h=65326efb3e52139cfda31536c63b5f0bf02c3102;hb=c6871fe8617b3de03662b7630355059393bf8043;hp=072cc2b0ebc8afa70dacfe1cef2bf23143a45512;hpb=aaf1d809a0ebbc2eb7dcd9ea7146cfe7bb4702f1;p=dcpomatic.git diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 072cc2b0e..65326efb3 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -18,7 +18,7 @@ */ -#include "wx/config_dialog.h" +#include "wx/full_config_dialog.h" #include "wx/about_dialog.h" #include "wx/report_problem_dialog.h" #include "wx/file_picker_ctrl.h" @@ -42,11 +42,13 @@ #include "lib/compose.hpp" #include "lib/cinema.h" #include "lib/dkdm_wrapper.h" +#include "lib/cross.h" #include #include #include #include #include +#include #include #ifdef __WXOSX__ #include @@ -77,7 +79,7 @@ enum { class DOMFrame : public wxFrame { public: - DOMFrame (wxString const & title) + explicit DOMFrame (wxString const & title) : wxFrame (0, -1, title) , _config_dialog (0) , _job_view (0) @@ -158,7 +160,7 @@ public: dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP); right->Add (dkdm_sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP); - add_dkdm_view (Config::instance()->dkdms(), shared_ptr ()); + add_dkdm_view (Config::instance()->dkdms()); h = new wxStaticText (overall_panel, wxID_ANY, _("Output")); h->SetFont (subheading_font); @@ -179,6 +181,8 @@ public: _screens->ScreensChanged.connect (boost::bind (&DOMFrame::setup_sensitivity, this)); _create->Bind (wxEVT_BUTTON, bind (&DOMFrame::create_kdms, this)); _dkdm->Bind (wxEVT_TREE_SEL_CHANGED, boost::bind (&DOMFrame::setup_sensitivity, this)); + _dkdm->Bind (wxEVT_TREE_BEGIN_DRAG, boost::bind (&DOMFrame::dkdm_begin_drag, this, _1)); + _dkdm->Bind (wxEVT_TREE_END_DRAG, boost::bind (&DOMFrame::dkdm_end_drag, this, _1)); _add_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_clicked, this)); _add_dkdm_folder->Bind (wxEVT_BUTTON, bind (&DOMFrame::add_dkdm_folder_clicked, this)); _remove_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::remove_dkdm_clicked, this)); @@ -196,7 +200,7 @@ private: void edit_preferences () { if (!_config_dialog) { - _config_dialog = create_config_dialog (); + _config_dialog = create_full_config_dialog (); } _config_dialog->Show (this); } @@ -324,7 +328,14 @@ private: } /* Encrypt */ - screen_kdms.push_back (ScreenKDM (i, kdm.encrypt (signer, i->recipient.get(), i->trusted_devices, _output->formulation()))); + screen_kdms.push_back ( + ScreenKDM ( + i, + kdm.encrypt ( + signer, i->recipient.get(), i->trusted_devices, _output->formulation(), true, 0 + ) + ) + ); } pair, int> result = _output->make ( @@ -352,7 +363,7 @@ private: } catch (dcp::NotEncryptedError& e) { error_dialog (this, _("CPL's content is not encrypted.")); } catch (exception& e) { - error_dialog (this, e.what ()); + error_dialog (this, std_to_wx(e.what())); } catch (...) { error_dialog (this, _("An unknown exception occurred.")); } @@ -367,32 +378,68 @@ private: _create->Enable (!_screens->screens().empty() && sel.GetCount() > 0); } + void dkdm_begin_drag (wxTreeEvent& ev) + { + ev.Allow (); + } + + void dkdm_end_drag (wxTreeEvent& ev) + { + DKDMMap::iterator from = _dkdm_id.find (_dkdm->GetSelection ()); + DKDMMap::iterator to = _dkdm_id.find (ev.GetItem ()); + if (from == _dkdm_id.end() || to == _dkdm_id.end() || from->first == to->first) { + return; + } + + shared_ptr group = dynamic_pointer_cast (to->second); + if (!group) { + group = to->second->parent(); + } + + DCPOMATIC_ASSERT (group); + DCPOMATIC_ASSERT (from->second->parent ()); + + from->second->parent()->remove (from->second); + add_dkdm_model (from->second, group, dynamic_pointer_cast(to->second)); + + _dkdm->Delete (from->first); + _dkdm_id.erase (from->first); + add_dkdm_view (from->second, dynamic_pointer_cast(to->second) ? to->first : optional()); + } + void add_dkdm_clicked () { wxFileDialog* d = new wxFileDialog (this, _("Select DKDM file")); if (d->ShowModal() == wxID_OK) { shared_ptr new_dkdm; try { - new_dkdm.reset ( - new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE))) - ); + dcp::EncryptedKDM ekdm(dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)); + + /* Decrypt the DKDM to make sure that we can */ + shared_ptr chain = Config::instance()->decryption_chain(); + DCPOMATIC_ASSERT (chain->key()); + dcp::DecryptedKDM dkdm(ekdm, chain->key().get()); + + new_dkdm.reset(new DKDM(ekdm)); + shared_ptr group = dynamic_pointer_cast (selected_dkdm ()); + if (!group) { + group = Config::instance()->dkdms (); + } + add_dkdm_model (new_dkdm, group); + add_dkdm_view (new_dkdm); } catch (dcp::KDMFormatError& e) { error_dialog ( this, - wxString::Format ( - _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all.\n\n%s"), - std_to_wx(e.what()).data() - ) + _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all."), + std_to_wx(e.what()) ); return; + } catch (dcp::KDMDecryptionError) { + error_dialog ( + this, + _("Could not decrypt the DKDM. Perhaps it was not created with the correct certificate.") + ); } - - shared_ptr group = dynamic_pointer_cast (selected_dkdm ()); - if (!group) { - group = Config::instance()->dkdms (); - } - add_dkdm_model (new_dkdm, group); - add_dkdm_view (new_dkdm, group); } d->Destroy (); } @@ -407,7 +454,7 @@ private: parent = Config::instance()->dkdms (); } add_dkdm_model (new_dkdm, parent); - add_dkdm_view (new_dkdm, parent); + add_dkdm_view (new_dkdm); } d->Destroy (); } @@ -415,29 +462,35 @@ private: /** @param dkdm Thing to add. * @param parent Parent group, or 0. */ - void add_dkdm_view (shared_ptr base, shared_ptr parent) + void add_dkdm_view (shared_ptr base, optional previous = optional()) { - if (!parent) { + if (!base->parent()) { /* This is the root group */ _dkdm_id[_dkdm->AddRoot("root")] = base; } else { /* Add base to the view */ - _dkdm_id[_dkdm->AppendItem(dkdm_to_id(parent), std_to_wx(base->name()))] = base; + wxTreeItemId added; + if (previous) { + added = _dkdm->InsertItem(dkdm_to_id(base->parent()), *previous, std_to_wx(base->name())); + } else { + added = _dkdm->AppendItem(dkdm_to_id(base->parent()), std_to_wx(base->name())); + } + _dkdm_id[added] = base; } /* Add children */ shared_ptr g = dynamic_pointer_cast (base); if (g) { BOOST_FOREACH (shared_ptr i, g->children()) { - add_dkdm_view (i, g); + add_dkdm_view (i); } } } /** @param group Group to add dkdm to */ - void add_dkdm_model (shared_ptr dkdm, shared_ptr group) + void add_dkdm_model (shared_ptr dkdm, shared_ptr group, shared_ptr previous = shared_ptr ()) { - group->add (dkdm); + group->add (dkdm, previous); /* We're messing with a Config-owned object here, so tell it that something has changed. This isn't nice. */ @@ -499,6 +552,11 @@ private: { wxInitAllImageHandlers (); + Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this)); + Config::Warning.connect (boost::bind (&App::config_warning, this, _1)); + + wxSplashScreen* splash = maybe_show_splash (); + SetAppName (_("DCP-o-matic KDM Creator")); if (!wxApp::OnInit()) { @@ -538,6 +596,9 @@ private: _frame = new DOMFrame (_("DCP-o-matic KDM Creator")); SetTopWindow (_frame); _frame->Maximize (); + if (splash) { + splash->Destroy (); + } _frame->Show (); signal_manager = new wxSignalManager (this); @@ -547,7 +608,7 @@ private: } catch (exception& e) { - error_dialog (0, wxString::Format ("DCP-o-matic could not start: %s", e.what ())); + error_dialog (0, _("DCP-o-matic could not start"), std_to_wx(e.what())); return true; } @@ -591,6 +652,16 @@ private: signal_manager->ui_idle (); } + void config_failed_to_load () + { + message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create.")); + } + + void config_warning (string m) + { + message_dialog (_frame, std_to_wx (m)); + } + DOMFrame* _frame; };