Make certificate re-creation cancellable and default nags
authorCarl Hetherington <cth@carlh.net>
Sun, 7 Jan 2018 00:02:00 +0000 (00:02 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 7 Jan 2018 00:02:00 +0000 (00:02 +0000)
to not going away (#1158).

ChangeLog
src/wx/config_dialog.cc
src/wx/config_dialog.h
src/wx/nag_dialog.cc
src/wx/nag_dialog.h

index 809cf70964ed1f4f15e1bebda05ef10daaf53af4..565c26763716a87404d0ff70668b733fe1203fcc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-07  Carl Hetherington  <cth@carlh.net>
+
+       * Make certificate re-creation cancellable and default nags
+       to not going away (#1158).
+
 2018-01-06  Carl Hetherington  <cth@carlh.net>
 
        * Check that we can decrypt a DKDM when it is loaded into
index 8d10fb9eb757d0aa87144a2a0015ed1c05763491..fb80963f4c31c37d1dc07d81085f7ab26e8ba045 100644 (file)
@@ -32,10 +32,10 @@ using boost::shared_ptr;
 using boost::function;
 
 static
-void
+bool
 do_nothing ()
 {
-
+       return false;
 }
 
 Page::Page (wxSize panel_size, int border)
@@ -329,7 +329,7 @@ CertificateChainEditor::CertificateChainEditor (
        int border,
        function<void (shared_ptr<dcp::CertificateChain>)> set,
        function<shared_ptr<const dcp::CertificateChain> (void)> get,
-       function<void (void)> nag_remake
+       function<bool (void)> nag_remake
        )
        : wxDialog (parent, wxID_ANY, title)
        , _set (set)
@@ -604,7 +604,10 @@ CertificateChainEditor::remake_certificates ()
                intermediate_common_name = i->subject_common_name ();
        }
 
-       _nag_remake ();
+       if (_nag_remake()) {
+               /* Cancel was clicked */
+               return;
+       }
 
        MakeChainDialog* d = new MakeChainDialog (
                this,
@@ -847,13 +850,14 @@ KeysPage::import_decryption_chain_and_key ()
        d->Destroy ();
 }
 
-void
+bool
 KeysPage::nag_remake_decryption_chain ()
 {
-       NagDialog::maybe_nag (
+       return NagDialog::maybe_nag (
                _panel,
                Config::NAG_REMAKE_DECRYPTION_CHAIN,
-               _("If you continue with this operation you will no longer be able to use any DKDMs that you have created.  Also, any KDMs that have been sent to you will become useless.  Proceed with caution!")
+               _("If you continue with this operation you will no longer be able to use any DKDMs that you have created.  Also, any KDMs that have been sent to you will become useless.  Proceed with caution!"),
+               true
                );
 }
 
index 9a73d4e614722445c87e6ea11bad1e351493b5c8..b76f8bc355fa9d597b2dbc4b217d19615122d4e4 100644 (file)
@@ -120,7 +120,7 @@ public:
                int border,
                boost::function<void (boost::shared_ptr<dcp::CertificateChain>)> set,
                boost::function<boost::shared_ptr<const dcp::CertificateChain> (void)> get,
-               boost::function<void (void)> nag_remake
+               boost::function<bool (void)> nag_remake
                );
 
        void add_button (wxWindow* button);
@@ -149,7 +149,7 @@ private:
        wxBoxSizer* _button_sizer;
        boost::function<void (boost::shared_ptr<dcp::CertificateChain>)> _set;
        boost::function<boost::shared_ptr<const dcp::CertificateChain> (void)> _get;
-       boost::function<void (void)> _nag_remake;
+       boost::function<bool (void)> _nag_remake;
 };
 
 class KeysPage : public StandardPage
@@ -176,7 +176,7 @@ private:
        void export_decryption_certificate ();
        void export_decryption_chain ();
        void config_changed () {}
-       void nag_remake_decryption_chain ();
+       bool nag_remake_decryption_chain ();
        void decryption_advanced ();
        void signing_advanced ();
        void export_decryption_chain_and_key ();
index 69b64cb400a9c79c7c454c7b77c82c251b5a1900..b7efb43db45953fa35a85d1af24f827dc9e74458 100644 (file)
@@ -25,7 +25,7 @@
 
 using boost::shared_ptr;
 
-NagDialog::NagDialog (wxWindow* parent, Config::Nag nag, wxString message)
+NagDialog::NagDialog (wxWindow* parent, Config::Nag nag, wxString message, bool can_cancel)
        : wxDialog (parent, wxID_ANY, _("Important notice"))
        , _nag (nag)
 {
@@ -34,15 +34,17 @@ NagDialog::NagDialog (wxWindow* parent, Config::Nag nag, wxString message)
        sizer->Add (_text, 1, wxEXPAND | wxALL, 6);
 
        wxCheckBox* b = new wxCheckBox (this, wxID_ANY, _("Don't show this message again"));
-       b->SetValue (true);
-       Config::instance()->set_nagged (_nag, true);
        sizer->Add (b, 0, wxALL, 6);
        b->Bind (wxEVT_CHECKBOX, bind (&NagDialog::shut_up, this, _1));
 
-       wxStdDialogButtonSizer* buttons = CreateStdDialogButtonSizer (0);
-       sizer->Add (CreateSeparatedSizer(buttons), wxSizerFlags().Expand().DoubleBorder());
-       buttons->SetAffirmativeButton (new wxButton (this, wxID_OK));
-       buttons->Realize ();
+       int flags = wxOK;
+       if (can_cancel) {
+               flags |= wxCANCEL;
+       }
+       wxSizer* buttons = CreateSeparatedButtonSizer (flags);
+       if (buttons) {
+               sizer->Add(buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
 
        SetSizer (sizer);
        sizer->Layout ();
@@ -57,12 +59,17 @@ NagDialog::shut_up (wxCommandEvent& ev)
        Config::instance()->set_nagged (_nag, ev.IsChecked());
 }
 
-void
-NagDialog::maybe_nag (wxWindow* parent, Config::Nag nag, wxString message)
+/** @return true if the user clicked Cancel */
+bool
+NagDialog::maybe_nag (wxWindow* parent, Config::Nag nag, wxString message, bool can_cancel)
 {
-       if (!Config::instance()->nagged (nag)) {
-               NagDialog* d = new NagDialog (parent, nag, message);
-               d->ShowModal ();
-               d->Destroy ();
+       if (Config::instance()->nagged(nag)) {
+               return false;
        }
+
+       NagDialog* d = new NagDialog (parent, nag, message, can_cancel);
+       int const r = d->ShowModal();
+       d->Destroy ();
+
+       return r == wxID_CANCEL;
 }
index 06f98d967c75766daa6bbb800c717a9c8a3b80f6..83d681fefcac8d2471d3995fd7e628cdceeb23df 100644 (file)
@@ -26,10 +26,10 @@ class wxRichTextCtrl;
 class NagDialog : public wxDialog
 {
 public:
-       static void maybe_nag (wxWindow* parent, Config::Nag nag, wxString message);
+       static bool maybe_nag (wxWindow* parent, Config::Nag nag, wxString message, bool can_cancel = false);
 
 private:
-       NagDialog (wxWindow* parent, Config::Nag nag, wxString message);
+       NagDialog (wxWindow* parent, Config::Nag nag, wxString message, bool can_cancel);
        void shut_up (wxCommandEvent& ev);
 
        wxStaticText* _text;