Give a better error if the user tries to load a non-KDM as a DKDM into the KDM creator.
[dcpomatic.git] / src / tools / dcpomatic_kdm.cc
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);