+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
/*
- 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
#ifdef DCPOMATIC_WINDOWS
_win32_console = false;
#endif
+ _cinemas_file = path ("cinemas.xml");
_allowed_dcp_frame_rates.clear ();
_allowed_dcp_frame_rates.push_back (24);
_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);
_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 */
/** 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");
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);
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) {
}
}
+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
{
{
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);
+}
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);
changed ();
}
+ void set_cinemas_file (boost::filesystem::path file);
+
void clear_history () {
_history.clear ();
changed ();
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>
#endif
std::vector<boost::filesystem::path> _history;
std::vector<dcp::EncryptedKDM> _dkdms;
+ boost::filesystem::path _cinemas_file;
/** Singleton instance, or 0 */
static Config* _instance;
#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"
#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>
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;
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));
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 ();
}
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;
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);
FilePickerCtrl::browse_clicked ()
{
wxFileDialog* d = new wxFileDialog (this, _prompt, wxEmptyString, wxEmptyString, _wildcard);
+ d->SetPath (_path);
if (d->ShowModal () == wxID_OK) {
SetPath (d->GetPath ());
}
* @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;
}
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()));
}
}
#include <gtk/gtk.h>
#endif
-class wxFilePickerCtrl;
+class FilePickerCtrl;
class wxSpinCtrl;
class wxSpinCtrlDouble;
class wxGridBagSizer;
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);