diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-02-17 19:25:33 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-02-17 19:25:33 +0000 |
| commit | 4228cb5b5323e9dc4bc87182b27427e48bb59d91 (patch) | |
| tree | 42b0222c333c7bb27f7ae68196837d9dbfa6b65a /src | |
| parent | 4f19455332f1f4cc4c313338b7fb0b6fc508d5b4 (diff) | |
Use a separate file (in a configurable location) to store cinema / screen certificates (#796).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/config.cc | 86 | ||||
| -rw-r--r-- | src/lib/config.h | 10 | ||||
| -rw-r--r-- | src/wx/config_dialog.cc | 20 | ||||
| -rw-r--r-- | src/wx/file_picker_ctrl.cc | 3 | ||||
| -rw-r--r-- | src/wx/wx_util.cc | 14 | ||||
| -rw-r--r-- | src/wx/wx_util.h | 4 |
6 files changed, 109 insertions, 28 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index d157207d0..cf47bba8e 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -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 */ @@ -344,6 +346,13 @@ Config::instance () 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); +} diff --git a/src/lib/config.h b/src/lib/config.h index 806853083..109f7b603 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -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; diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index 8af125a97..696f7a65f 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -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; diff --git a/src/wx/file_picker_ctrl.cc b/src/wx/file_picker_ctrl.cc index 8de1596a9..9b52fc1cf 100644 --- a/src/wx/file_picker_ctrl.cc +++ b/src/wx/file_picker_ctrl.cc @@ -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 ()); } diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 1e990c495..d7620eff4 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -21,12 +21,12 @@ * @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())); } } diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h index aaa59c4ac..112289c78 100644 --- a/src/wx/wx_util.h +++ b/src/wx/wx_util.h @@ -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); |
