Nag users to backup config.xml if they make a DKDM.
authorCarl Hetherington <cth@carlh.net>
Thu, 4 May 2017 09:55:53 +0000 (10:55 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 4 May 2017 09:55:53 +0000 (10:55 +0100)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc
src/wx/nag_dialog.cc [new file with mode: 0644]
src/wx/nag_dialog.h [new file with mode: 0644]
src/wx/wscript

index 896445f0c866847c62efd7606ce88cd998e49f31..dc1f3f7a04285c65c95637441c181c8721754ca4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-04  Carl Hetherington  <cth@carlh.net>
+
+       * Nag users to backup config.xml if they make a DKDM.
+
 2017-05-03  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.11.3 released.
index 9fdf572070b79eee467d7b0613f46b4e8fe224e6..c0ab44923a4d8b9344de0b77a294ee12a0066e3d 100644 (file)
@@ -117,6 +117,9 @@ Config::set_defaults ()
        _dcp_metadata_filename_format = dcp::NameFormat ("%t");
        _dcp_asset_filename_format = dcp::NameFormat ("%t");
        _jump_to_selected = true;
+       for (int i = 0; i < NAG_COUNT; ++i) {
+               _nagged[i] = false;
+       }
        _preview_sound = false;
        _preview_sound_output = optional<string> ();
 
@@ -318,6 +321,12 @@ try
        _dcp_metadata_filename_format = dcp::NameFormat (f.optional_string_child("DCPMetadataFilenameFormat").get_value_or ("%t"));
        _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t"));
        _jump_to_selected = f.optional_bool_child("JumpToSelected").get_value_or (true);
+       BOOST_FOREACH (cxml::NodePtr i, f.node_children("Nagged")) {
+               int const id = i->number_attribute<int>("Id");
+               if (id >= 0 && id < NAG_COUNT) {
+                       _nagged[id] = raw_convert<int>(i->content());
+               }
+       }
        _preview_sound = f.optional_bool_child("PreviewSound").get_value_or (false);
        _preview_sound_output = f.optional_string_child("PreviewSoundOutput");
 
@@ -496,6 +505,11 @@ Config::write_config () const
        root->add_child("DCPMetadataFilenameFormat")->add_child_text (_dcp_metadata_filename_format.specification ());
        root->add_child("DCPAssetFilenameFormat")->add_child_text (_dcp_asset_filename_format.specification ());
        root->add_child("JumpToSelected")->add_child_text (_jump_to_selected ? "1" : "0");
+       for (int i = 0; i < NAG_COUNT; ++i) {
+               xmlpp::Element* e = root->add_child ("Nagged");
+               e->set_attribute ("Id", raw_convert<string>(i));
+               e->add_child_text (_nagged[i] ? "1" : "0");
+       }
        root->add_child("PreviewSound")->add_child_text (_preview_sound ? "1" : "0");
        if (_preview_sound_output) {
                root->add_child("PreviewSoundOutput")->add_child_text (_preview_sound_output.get());
@@ -686,3 +700,10 @@ Config::delete_template (string name) const
 {
        boost::filesystem::remove (template_path (name));
 }
+
+/** @return Path to the config.xml, for telling the user what it is */
+boost::filesystem::path
+Config::config_path ()
+{
+       return path("config.xml", false);
+}
index 40380f825f3247e7e545be4c4f5a12c4c3d6a79c..f2d224898fce5e3f45ff2bf0d7862c9f0be51aac 100644 (file)
@@ -313,6 +313,15 @@ public:
                return _jump_to_selected;
        }
 
+       enum Nag {
+               NAG_DKDM_CONFIG,
+               NAG_COUNT
+       };
+
+       bool nagged (Nag nag) const {
+               return _nagged[nag];
+       }
+
        bool preview_sound () const {
                return _preview_sound;
        }
@@ -585,6 +594,10 @@ public:
                maybe_set (_jump_to_selected, j);
        }
 
+       void set_nagged (Nag nag, bool nagged) {
+               maybe_set (_nagged[nag], nagged);
+       }
+
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> Changed;
        /** Emitted if read() failed on an existing Config file.  There is nothing
@@ -607,6 +620,7 @@ public:
        static void drop ();
        static void restore_defaults ();
        static bool have_existing (std::string);
+       static boost::filesystem::path config_path ();
 
 private:
        Config ();
@@ -718,6 +732,7 @@ private:
        dcp::NameFormat _dcp_metadata_filename_format;
        dcp::NameFormat _dcp_asset_filename_format;
        bool _jump_to_selected;
+       bool _nagged[NAG_COUNT];
        bool _preview_sound;
        /** name of a specific sound output stream to use for preview, or empty to use the default */
        boost::optional<std::string> _preview_sound_output;
index e9a1f652cea81ef535369e8cb82604b855316a06..1ced8923b9e3a033c80c4bc361590d2847c6c058 100644 (file)
@@ -40,6 +40,7 @@
 #include "wx/video_waveform_dialog.h"
 #include "wx/save_template_dialog.h"
 #include "wx/templates_dialog.h"
+#include "wx/nag_dialog.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -597,6 +598,17 @@ private:
                        return;
                }
 
+               NagDialog::maybe_nag (
+                       this,
+                       Config::NAG_DKDM_CONFIG,
+                       wxString::Format (
+                               _("You are making a DKDM which is encrypted by a private key held in"
+                                 "\n\n<tt>%s</tt>\n\nIt is <span weight=\"bold\" size=\"larger\">VITALLY IMPORTANT</span> "
+                                 "that you <span weight=\"bold\" size=\"larger\">BACK UP THIS FILE</span> since if it is lost "
+                                 "your DKDMs (and the DCPs they protect) will become useless."), std_to_wx(Config::config_path().string()).data()
+                               )
+                       );
+
                optional<dcp::EncryptedKDM> kdm;
                try {
                        kdm = _film->make_kdm (
diff --git a/src/wx/nag_dialog.cc b/src/wx/nag_dialog.cc
new file mode 100644 (file)
index 0000000..69b64cb
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "nag_dialog.h"
+#include "wx_util.h"
+#include <wx/richtext/richtextctrl.h>
+#include <boost/foreach.hpp>
+
+using boost::shared_ptr;
+
+NagDialog::NagDialog (wxWindow* parent, Config::Nag nag, wxString message)
+       : wxDialog (parent, wxID_ANY, _("Important notice"))
+       , _nag (nag)
+{
+       wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
+       _text = new wxStaticText (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (400, 300));
+       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 ();
+
+       SetSizer (sizer);
+       sizer->Layout ();
+       sizer->SetSizeHints (this);
+
+       _text->SetLabelMarkup (message);
+}
+
+void
+NagDialog::shut_up (wxCommandEvent& ev)
+{
+       Config::instance()->set_nagged (_nag, ev.IsChecked());
+}
+
+void
+NagDialog::maybe_nag (wxWindow* parent, Config::Nag nag, wxString message)
+{
+       if (!Config::instance()->nagged (nag)) {
+               NagDialog* d = new NagDialog (parent, nag, message);
+               d->ShowModal ();
+               d->Destroy ();
+       }
+}
diff --git a/src/wx/nag_dialog.h b/src/wx/nag_dialog.h
new file mode 100644 (file)
index 0000000..06f98d9
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "lib/config.h"
+#include <wx/wx.h>
+
+class wxRichTextCtrl;
+
+class NagDialog : public wxDialog
+{
+public:
+       static void maybe_nag (wxWindow* parent, Config::Nag nag, wxString message);
+
+private:
+       NagDialog (wxWindow* parent, Config::Nag nag, wxString message);
+       void shut_up (wxCommandEvent& ev);
+
+       wxStaticText* _text;
+       Config::Nag _nag;
+};
index c545bf4828a4dbe152d44f4b3241862757c369b3..332a04ac58b6a576282658a9a95fc22fb9b5cf7b 100644 (file)
@@ -68,6 +68,7 @@ sources = """
           key_dialog.cc
           make_chain_dialog.cc
           move_to_dialog.cc
+          nag_dialog.cc
           name_format_editor.cc
           new_film_dialog.cc
           normal_job_view.cc