Give a better error if the user tries to load a non-KDM as a DKDM into the KDM creator.
authorCarl Hetherington <cth@carlh.net>
Thu, 20 Oct 2016 10:42:14 +0000 (11:42 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 20 Oct 2016 10:42:14 +0000 (11:42 +0100)
14 files changed:
src/lib/util.cc
src/lib/util.h
src/tools/dcpomatic_kdm.cc
src/wx/cinema_dialog.cc
src/wx/config_dialog.cc
src/wx/editable_list.cc [deleted file]
src/wx/editable_list.h
src/wx/email_dialog.cc
src/wx/email_dialog.h
src/wx/file_dialog_wrapper.h
src/wx/screen_dialog.cc
src/wx/server_dialog.cc
src/wx/server_dialog.h
src/wx/wscript

index 00f36f2178b495b85e480b7d1188f8a03d1d1281..38451e9314e9bbd67da2afeb9a226115727ead83 100644 (file)
@@ -675,9 +675,3 @@ relaxed_string_to_float (string s)
                return lexical_cast<float> (s);
        }
 }
-
-bool
-string_not_empty (string s)
-{
-       return !s.empty ();
-}
index f9b4d0e0541a250dc7f8afba456e5aa0c022bd22..5e1780d727acc495d5f902b627e3ee840dd5670c 100644 (file)
@@ -79,6 +79,5 @@ extern std::map<std::string, std::string> split_get_request (std::string url);
 extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
 extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
 extern float relaxed_string_to_float (std::string);
-extern bool string_not_empty (std::string);
 
 #endif
index 362d8105f0c862d4d7ea824e52de7b773994a2df..21dd019403dfaad9a185efd3db03bad06804501b 100644 (file)
@@ -62,6 +62,7 @@ using std::string;
 using std::vector;
 using boost::shared_ptr;
 using boost::bind;
+using boost::optional;
 
 enum {
        ID_help_report_a_problem = 1,
@@ -75,6 +76,17 @@ public:
        {
 
        }
+
+       optional<dcp::EncryptedKDM> get ()
+       {
+               try {
+                       return dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (_dialog->GetPath ())));
+               } catch (cxml::Error& e) {
+                       error_dialog (_parent, wxString::Format ("This file does not look like a KDM (%s)", std_to_wx (e.what()).data()));
+               }
+
+               return optional<dcp::EncryptedKDM> ();
+       }
 };
 
 static string
@@ -156,7 +168,7 @@ public:
                vector<string> columns;
                columns.push_back (wx_to_std (_("CPL")));
                _dkdm = new EditableList<dcp::EncryptedKDM, KDMFileDialogWrapper> (
-                       overall_panel, columns, bind (&DOMFrame::dkdms, this), bind (&DOMFrame::set_dkdms, this, _1), bind (&always_valid), bind (&column, _1), false
+                       overall_panel, columns, bind (&DOMFrame::dkdms, this), bind (&DOMFrame::set_dkdms, this, _1), bind (&column, _1), false
                        );
                right->Add (_dkdm, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
 
index 264b046d1f5923f73b14ab29bb32435817fd6360..87fcb443e7c201e168e291d2f6ac64ef3dba3870 100644 (file)
@@ -70,7 +70,7 @@ CinemaDialog::CinemaDialog (wxWindow* parent, wxString title, string name, list<
        vector<string> columns;
        columns.push_back (wx_to_std (_("Address")));
        _email_list = new EditableList<string, EmailDialog> (
-               this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&string_not_empty, _1), bind (&column, _1)
+               this, columns, bind (&CinemaDialog::get_emails, this), bind (&CinemaDialog::set_emails, this, _1), bind (&column, _1)
                );
 
        sizer->Add (_email_list, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
index 0369070a7c32edd900588ec56a6b5568e775a33b..5b7dc1cc41390e5f63406c201857e0b8f5d7ce08 100644 (file)
@@ -624,7 +624,6 @@ private:
                        columns,
                        boost::bind (&Config::servers, Config::instance()),
                        boost::bind (&Config::set_servers, Config::instance(), _1),
-                       boost::bind (&always_valid),
                        boost::bind (&EncodingServersPage::server_column, this, _1)
                        );
 
@@ -1276,7 +1275,6 @@ private:
                        columns,
                        bind (&Config::kdm_cc, Config::instance()),
                        bind (&Config::set_kdm_cc, Config::instance(), _1),
-                       bind (&string_not_empty, _1),
                        bind (&column, _1)
                        );
                table->Add (_kdm_cc, 1, wxEXPAND | wxALL);
diff --git a/src/wx/editable_list.cc b/src/wx/editable_list.cc
deleted file mode 100644 (file)
index 34471b6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-    Copyright (C) 2016 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/>.
-
-*/
-
-bool
-always_valid ()
-{
-       return true;
-}
index 8226c9cac813e5eefb2eca1a88370e417d3ad0ac..681588215f539a28457caed75a4250218b2b7316 100644 (file)
@@ -27,8 +27,6 @@
 #include <boost/function.hpp>
 #include <vector>
 
-bool always_valid ();
-
 /** @param T type of things being edited.
  *  @param S dialog to edit a thing.
  */
@@ -41,7 +39,6 @@ public:
                std::vector<std::string> columns,
                boost::function<std::vector<T> ()> get,
                boost::function<void (std::vector<T>)> set,
-               boost::function<bool (T)> valid,
                boost::function<std::string (T, int)> column,
                bool can_edit = true,
                bool title = true
@@ -49,7 +46,6 @@ public:
                : wxPanel (parent)
                , _get (get)
                , _set (set)
-               , _valid (valid)
                , _columns (columns.size ())
                , _column (column)
                , _edit (0)
@@ -159,11 +155,11 @@ private:
                S* dialog = new S (this);
 
                if (dialog->ShowModal() == wxID_OK) {
-                       T const v = dialog->get ();
-                       if (_valid (v)) {
-                               add_to_control (v);
+                       boost::optional<T> const v = dialog->get ();
+                       if (v) {
+                               add_to_control (v.get ());
                                std::vector<T> all = _get ();
-                               all.push_back (v);
+                               all.push_back (v.get ());
                                _set (all);
                        }
                }
@@ -184,12 +180,12 @@ private:
                S* dialog = new S (this);
                dialog->set (all[item]);
                if (dialog->ShowModal() == wxID_OK) {
-                       T const v = dialog->get ();
-                       if (!_valid (v)) {
+                       boost::optional<T> const v = dialog->get ();
+                       if (!v) {
                                return;
                        }
 
-                       all[item] = v;
+                       all[item] = v.get ();
                }
                dialog->Destroy ();
 
@@ -226,7 +222,6 @@ private:
 
        boost::function <std::vector<T> ()> _get;
        boost::function <void (std::vector<T>)> _set;
-       boost::function <bool (T)> _valid;
        int _columns;
        boost::function<std::string (T, int)> _column;
 
index 97f974a90050a17699c0bcb22d2eacacf815e6d3..b95d79b03ba83174c72e091eb21635d9b83ff28b 100644 (file)
@@ -23,6 +23,7 @@
 
 using std::string;
 using boost::shared_ptr;
+using boost::optional;
 
 EmailDialog::EmailDialog (wxWindow* parent)
        : TableDialog (parent, _("Email address"), 2, 1, true)
@@ -39,8 +40,14 @@ EmailDialog::set (string address)
        _email->SetValue (std_to_wx (address));
 }
 
-string
+optional<string>
 EmailDialog::get () const
 {
-       return wx_to_std (_email->GetValue ());
+       string s = wx_to_std (_email->GetValue ());
+       if (s.empty ()) {
+               /* Invalid email address */
+               return optional<string> ();
+       }
+
+       return s;
 }
index 4fb08d28b848a30ef262abcec9cf0b9fc9be4abd..40a6fdb741f5743a6dd3ae100e0875370ea90301 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "table_dialog.h"
+#include <boost/optional.hpp>
 
 class EmailDialog : public TableDialog
 {
@@ -26,7 +27,7 @@ public:
        EmailDialog (wxWindow *);
 
        void set (std::string);
-       std::string get () const;
+       boost::optional<std::string> get () const;
 
 private:
        wxTextCtrl* _email;
index 251d1b71d15711462cd0be9cee6a0f038bbb6c9a..dd63ff2dae447bfdaccd6a9842e0f02092fd8d20 100644 (file)
@@ -32,7 +32,7 @@ public:
 
        void set (T) {}
 
-       T get ()
+       boost::optional<T> get ()
        {
                return T (dcp::file_to_string (wx_to_std (_dialog->GetPath ())));
        }
@@ -49,7 +49,7 @@ public:
                delete this;
        }
 
-private:
+protected:
        wxWindow* _parent;
        wxFileDialog* _dialog;
 };
index 0ecf223e69e1c99a500f55d2fc35df47684db6fe..e5b254346329f1ab308ff5ac51a6df1838be1f50 100644 (file)
@@ -105,7 +105,6 @@ ScreenDialog::ScreenDialog (
                columns,
                bind (&ScreenDialog::trusted_devices, this),
                bind (&ScreenDialog::set_trusted_devices, this, _1),
-               bind (&always_valid),
                bind (&column, _1),
                false
                );
index f5983b4cdfbb534c2681036fce008b4136c87c65..abad589891231e0de8e876039df6b03424e43855 100644 (file)
@@ -24,6 +24,7 @@
 
 using std::string;
 using boost::shared_ptr;
+using boost::optional;
 
 ServerDialog::ServerDialog (wxWindow* parent)
        : TableDialog (parent, _("Server"), 2, 1, true)
@@ -48,7 +49,7 @@ ServerDialog::set (string server)
        _host->SetValue (std_to_wx (server));
 }
 
-string
+optional<string>
 ServerDialog::get () const
 {
        return wx_to_std (_host->GetValue ());
index 0f1352ed037d9e25d37fefe77120265832b93a6a..ed109c6974c7dc8b8b84eafbf0d7a3d29cb71414 100644 (file)
@@ -26,7 +26,7 @@ public:
        ServerDialog (wxWindow *);
 
        void set (std::string);
-       std::string get () const;
+       boost::optional<std::string> get () const;
 
 private:
        wxTextCtrl* _host;
index fd1528b276a62e9ca9316c792ab652b912e526ef..4543be09f9e318600937673901907bc3913d7d05 100644 (file)
@@ -42,7 +42,6 @@ sources = """
           content_properties_dialog.cc
           content_sub_panel.cc
           dcp_panel.cc
-          editable_list.cc
           email_dialog.cc
           image_sequence_dialog.cc
           image_subtitle_colour_dialog.cc