Add a load of explicit keywords.
[dcpomatic.git] / src / tools / dcpomatic_kdm.cc
index 0ee8a07862a7f49ca57582a9912ddf569102d2f9..65326efb3e52139cfda31536c63b5f0bf02c3102 100644 (file)
@@ -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"
 #include "lib/compose.hpp"
 #include "lib/cinema.h"
 #include "lib/dkdm_wrapper.h"
+#include "lib/cross.h"
 #include <dcp/encrypted_kdm.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/exceptions.h>
 #include <wx/wx.h>
 #include <wx/preferences.h>
+#include <wx/splash.h>
 #include <wx/filepicker.h>
 #ifdef __WXOSX__
 #include <ApplicationServices/ApplicationServices.h>
@@ -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)
@@ -198,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);
        }
@@ -326,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<shared_ptr<Job>, int> result = _output->make (
@@ -354,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."));
                }
@@ -378,7 +387,7 @@ private:
        {
                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()) {
+               if (from == _dkdm_id.end() || to == _dkdm_id.end() || from->first == to->first) {
                        return;
                }
 
@@ -391,7 +400,7 @@ private:
                DCPOMATIC_ASSERT (from->second->parent ());
 
                from->second->parent()->remove (from->second);
-               add_dkdm_model (from->second, group);
+               add_dkdm_model (from->second, group, dynamic_pointer_cast<DKDM>(to->second));
 
                _dkdm->Delete (from->first);
                _dkdm_id.erase (from->first);
@@ -404,26 +413,33 @@ private:
                if (d->ShowModal() == wxID_OK) {
                        shared_ptr<DKDMBase> 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<const dcp::CertificateChain> chain = Config::instance()->decryption_chain();
+                               DCPOMATIC_ASSERT (chain->key());
+                               dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
+
+                               new_dkdm.reset(new DKDM(ekdm));
+                               shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (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<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
-                       if (!group) {
-                               group = Config::instance()->dkdms ();
-                       }
-                       add_dkdm_model (new_dkdm, group);
-                       add_dkdm_view (new_dkdm);
                }
                d->Destroy ();
        }
@@ -472,9 +488,9 @@ private:
        }
 
        /** @param group Group to add dkdm to */
-       void add_dkdm_model (shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group)
+       void add_dkdm_model (shared_ptr<DKDMBase> dkdm, shared_ptr<DKDMGroup> group, shared_ptr<DKDM> previous = shared_ptr<DKDM> ())
        {
-               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.
                */
@@ -536,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()) {
@@ -575,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);
@@ -584,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;
        }
 
@@ -628,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;
 };