Use a separate file (in a configurable location) to store cinema / screen certificate...
authorCarl Hetherington <cth@carlh.net>
Wed, 17 Feb 2016 19:25:33 +0000 (19:25 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 17 Feb 2016 19:25:33 +0000 (19:25 +0000)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/wx/config_dialog.cc
src/wx/file_picker_ctrl.cc
src/wx/wx_util.cc
src/wx/wx_util.h

index fce336dfc81c220bb8eb83b92bf226a3b74f7788..9e53166e947a9c2cce97998346dfb411c51504ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-17  Carl Hetherington  <cth@carlh.net>
+
+       * Store cinema / screen certificates in a separate
+       file and allow configuration of its location (#796).
+
 2016-02-16  Carl Hetherington  <cth@carlh.net>
 
        * Add option to dcpomatic_cli to echo the
index d157207d05e8c41b92239ee6736e80cadc1cc197..cf47bba8eaab2b0502962fcad7b0cfe91f527047 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -102,6 +102,7 @@ Config::set_defaults ()
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = false;
 #endif
+       _cinemas_file = path ("cinemas.xml");
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -222,15 +223,8 @@ Config::read ()
        _default_audio_delay = f.optional_number_child<int>("DefaultAudioDelay").get_value_or (0);
        _default_interop = f.optional_bool_child("DefaultInterop").get_value_or (false);
 
-       list<cxml::NodePtr> cin = f.node_children ("Cinema");
-       for (list<cxml::NodePtr>::iterator i = cin.begin(); i != cin.end(); ++i) {
-               /* Slightly grotty two-part construction of Cinema here so that we can use
-                  shared_from_this.
-               */
-               shared_ptr<Cinema> cinema (new Cinema (*i));
-               cinema->read_screens (*i);
-               _cinemas.push_back (cinema);
-       }
+       /* Load any cinemas from config.xml */
+       read_cinemas (f);
 
        _mail_server = f.string_child ("MailServer");
        _mail_port = f.optional_number_child<int> ("MailPort").get_value_or (25);
@@ -294,6 +288,14 @@ Config::read ()
                _dkdms.push_back (dcp::EncryptedKDM (i->content ()));
        }
 
+       _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ());
+
+       /* Replace any cinemas from config.xml with those from the configured file */
+       if (boost::filesystem::exists (_cinemas_file)) {
+               cxml::Document f ("Cinemas");
+               f.read_file (_cinemas_file);
+               read_cinemas (f);
+       }
 }
 
 /** @return Filename to write configuration to */
@@ -343,6 +345,13 @@ Config::instance ()
 /** Write our configuration to disk */
 void
 Config::write () const
+{
+       write_config_xml ();
+       write_cinemas_xml ();
+}
+
+void
+Config::write_config_xml () const
 {
        xmlpp::Document doc;
        xmlpp::Element* root = doc.create_root_node ("Config");
@@ -384,11 +393,6 @@ Config::write () const
        root->add_child("DefaultJ2KBandwidth")->add_child_text (raw_convert<string> (_default_j2k_bandwidth));
        root->add_child("DefaultAudioDelay")->add_child_text (raw_convert<string> (_default_audio_delay));
        root->add_child("DefaultInterop")->add_child_text (_default_interop ? "1" : "0");
-
-       for (list<shared_ptr<Cinema> >::const_iterator i = _cinemas.begin(); i != _cinemas.end(); ++i) {
-               (*i)->as_xml (root->add_child ("Cinema"));
-       }
-
        root->add_child("MailServer")->add_child_text (_mail_server);
        root->add_child("MailPort")->add_child_text (raw_convert<string> (_mail_port));
        root->add_child("MailUser")->add_child_text (_mail_user);
@@ -432,6 +436,8 @@ Config::write () const
                root->add_child("DKDM")->add_child_text (i.as_xml ());
        }
 
+       root->add_child("CinemasFile")->add_child_text (_cinemas_file.string());
+
        try {
                doc.write_to_file_formatted (path("config.xml").string ());
        } catch (xmlpp::exception& e) {
@@ -441,6 +447,26 @@ Config::write () const
        }
 }
 
+void
+Config::write_cinemas_xml () const
+{
+       xmlpp::Document doc;
+       xmlpp::Element* root = doc.create_root_node ("Cinemas");
+       root->add_child("Version")->add_child_text ("1");
+
+       for (list<shared_ptr<Cinema> >::const_iterator i = _cinemas.begin(); i != _cinemas.end(); ++i) {
+               (*i)->as_xml (root->add_child ("Cinema"));
+       }
+
+       try {
+               doc.write_to_file_formatted (_cinemas_file.string ());
+       } catch (xmlpp::exception& e) {
+               string s = e.what ();
+               trim (s);
+               throw FileError (s, _cinemas_file);
+       }
+}
+
 boost::filesystem::path
 Config::default_directory_or (boost::filesystem::path a) const
 {
@@ -511,3 +537,33 @@ Config::have_existing (string file)
 {
        return boost::filesystem::exists (path (file, false));
 }
+
+void
+Config::read_cinemas (cxml::Document const & f)
+{
+       _cinemas.clear ();
+       list<cxml::NodePtr> cin = f.node_children ("Cinema");
+       for (list<cxml::NodePtr>::iterator i = cin.begin(); i != cin.end(); ++i) {
+               /* Slightly grotty two-part construction of Cinema here so that we can use
+                  shared_from_this.
+               */
+               shared_ptr<Cinema> cinema (new Cinema (*i));
+               cinema->read_screens (*i);
+               _cinemas.push_back (cinema);
+       }
+}
+
+void
+Config::set_cinemas_file (boost::filesystem::path file)
+{
+       _cinemas_file = file;
+
+       if (boost::filesystem::exists (_cinemas_file)) {
+               /* Existing file; read it in */
+               cxml::Document f ("Cinemas");
+               f.read_file (_cinemas_file);
+               read_cinemas (f);
+       }
+
+       changed (OTHER);
+}
index 806853083e7e47b6d90752b5b8bdbbebd5dd4e71..109f7b603790bcd43f47a8d10ed6bb62de2679af 100644 (file)
@@ -249,6 +249,10 @@ public:
                return _dkdms;
        }
 
+       boost::filesystem::path cinemas_file () const {
+               return _cinemas_file;
+       }
+
        /** @param n New number of local encoding threads */
        void set_num_local_encoding_threads (int n) {
                maybe_set (_num_local_encoding_threads, n);
@@ -443,6 +447,8 @@ public:
                changed ();
        }
 
+       void set_cinemas_file (boost::filesystem::path file);
+
        void clear_history () {
                _history.clear ();
                changed ();
@@ -466,6 +472,9 @@ private:
        void read ();
        void set_defaults ();
        void set_kdm_email_to_default ();
+       void write_config_xml () const;
+       void write_cinemas_xml () const;
+       void read_cinemas (cxml::Document const & f);
        boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
 
        template <class T>
@@ -543,6 +552,7 @@ private:
 #endif
        std::vector<boost::filesystem::path> _history;
        std::vector<dcp::EncryptedKDM> _dkdms;
+       boost::filesystem::path _cinemas_file;
 
        /** Singleton instance, or 0 */
        static Config* _instance;
index 8af125a97749ce2244f58e0cf3616eed8abb98a7..696f7a65fc9beceefa29c7d33962fa43c37d81d7 100644 (file)
@@ -26,6 +26,7 @@
 #include "editable_list.h"
 #include "filter_dialog.h"
 #include "dir_picker_ctrl.h"
+#include "file_picker_ctrl.h"
 #include "isdcf_metadata_dialog.h"
 #include "server_dialog.h"
 #include "make_chain_dialog.h"
@@ -43,8 +44,8 @@
 #include <dcp/certificate_chain.h>
 #include <wx/stdpaths.h>
 #include <wx/preferences.h>
-#include <wx/filepicker.h>
 #include <wx/spinctrl.h>
+#include <wx/filepicker.h>
 #include <boost/lexical_cast.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
@@ -188,6 +189,11 @@ private:
                table->Add (_num_local_encoding_threads, wxGBPosition (r, 1));
                ++r;
 
+               add_label_to_sizer (table, _panel, _("Cinema and screen database file"), true, wxGBPosition (r, 0));
+               _cinemas_file = new FilePickerCtrl (_panel, _("Select cinema and screen database file"), "*.xml");
+               table->Add (_cinemas_file, wxGBPosition (r, 1));
+               ++r;
+
                _automatic_audio_analysis = new wxCheckBox (_panel, wxID_ANY, _("Automatically analyse content audio"));
                table->Add (_automatic_audio_analysis, wxGBPosition (r, 0), wxGBSpan (1, 2));
                ++r;
@@ -214,8 +220,9 @@ private:
                table->Add (bottom_table, wxGBPosition (r, 0), wxGBSpan (2, 2), wxEXPAND);
                ++r;
 
-               _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::set_language_changed, this));
-               _language->Bind     (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&GeneralPage::language_changed,     this));
+               _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED,   boost::bind (&GeneralPage::set_language_changed, this));
+               _language->Bind     (wxEVT_COMMAND_CHOICE_SELECTED,    boost::bind (&GeneralPage::language_changed,     this));
+               _cinemas_file->Bind (wxEVT_COMMAND_FILEPICKER_CHANGED, boost::bind (&GeneralPage::cinemas_file_changed, this));
 
                _num_local_encoding_threads->SetRange (1, 128);
                _num_local_encoding_threads->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&GeneralPage::num_local_encoding_threads_changed, this));
@@ -268,6 +275,7 @@ private:
                checked_set (_check_for_test_updates, config->check_for_test_updates ());
                checked_set (_issuer, config->dcp_issuer ());
                checked_set (_creator, config->dcp_creator ());
+               checked_set (_cinemas_file, config->cinemas_file());
 
                setup_sensitivity ();
        }
@@ -363,9 +371,15 @@ private:
                Config::instance()->set_dcp_creator (wx_to_std (_creator->GetValue ()));
        }
 
+       void cinemas_file_changed ()
+       {
+               Config::instance()->set_cinemas_file (wx_to_std (_cinemas_file->GetPath ()));
+       }
+
        wxCheckBox* _set_language;
        wxChoice* _language;
        wxSpinCtrl* _num_local_encoding_threads;
+       FilePickerCtrl* _cinemas_file;
        wxCheckBox* _automatic_audio_analysis;
        wxCheckBox* _check_for_updates;
        wxCheckBox* _check_for_test_updates;
index 8de1596a9dc725840f2ab2a6c9fb95fd202ceae1..9b52fc1cf2b6fe8281e681035132de955fc2544e 100644 (file)
@@ -39,7 +39,7 @@ FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wild
         size.SetHeight (-1);
 
        _file = new wxButton (this, wxID_ANY, _("(None)"), wxDefaultPosition, size, wxBU_LEFT);
-       _sizer->Add (_file, 1, wxEXPAND | wxALL, 6);
+       _sizer->Add (_file, 1, wxEXPAND, 0);
 
        SetSizerAndFit (_sizer);
 
@@ -71,6 +71,7 @@ void
 FilePickerCtrl::browse_clicked ()
 {
        wxFileDialog* d = new wxFileDialog (this, _prompt, wxEmptyString, wxEmptyString, _wildcard);
+       d->SetPath (_path);
        if (d->ShowModal () == wxID_OK) {
                SetPath (d->GetPath ());
        }
index 1e990c49515c13393c403c3e7c7680f807e6f3a3..d7620eff40acf0079c53fa858aacca03ab16fd8e 100644 (file)
  *  @brief Some utility functions and classes.
  */
 
-#include <boost/thread.hpp>
-#include <wx/filepicker.h>
-#include <wx/spinctrl.h>
+#include "wx_util.h"
+#include "file_picker_ctrl.h"
 #include "lib/config.h"
 #include "lib/util.h"
-#include "wx_util.h"
+#include <wx/spinctrl.h>
+#include <boost/thread.hpp>
 
 using namespace std;
 using namespace boost;
@@ -136,16 +136,16 @@ string_client_data (wxClientData* o)
 }
 
 void
-checked_set (wxFilePickerCtrl* widget, string value)
+checked_set (FilePickerCtrl* widget, boost::filesystem::path value)
 {
-       if (widget->GetPath() != std_to_wx (value)) {
+       if (widget->GetPath() != std_to_wx (value.string())) {
                if (value.empty()) {
                        /* Hack to make wxWidgets clear the control when we are passed
                           an empty value.
                        */
                        value = " ";
                }
-               widget->SetPath (std_to_wx (value));
+               widget->SetPath (std_to_wx (value.string()));
        }
 }
 
index aaa59c4acac8456d1c688ebd94f8ee423dd94a43..112289c78b3eb8429945055068fb053cf1bbcb87 100644 (file)
@@ -34,7 +34,7 @@
 #include <gtk/gtk.h>
 #endif
 
-class wxFilePickerCtrl;
+class FilePickerCtrl;
 class wxSpinCtrl;
 class wxSpinCtrlDouble;
 class wxGridBagSizer;
@@ -69,7 +69,7 @@ extern wxString context_translation (wxString);
 extern std::string string_client_data (wxClientData* o);
 extern wxString time_to_timecode (DCPTime t, double fps);
 
-extern void checked_set (wxFilePickerCtrl* widget, std::string value);
+extern void checked_set (FilePickerCtrl* widget, boost::filesystem::path value);
 extern void checked_set (wxSpinCtrl* widget, int value);
 extern void checked_set (wxSpinCtrlDouble* widget, double value);
 extern void checked_set (wxChoice* widget, int value);