Add configuration options for DKDMs.
authorCarl Hetherington <cth@carlh.net>
Wed, 6 May 2020 21:58:36 +0000 (23:58 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 6 May 2020 21:58:36 +0000 (23:58 +0200)
src/lib/config.cc
src/lib/config.h

index 7364a122c4998c877a7970331840e240c50ec146..ebb6ece931f0bed3899e734f17c0baefdb2f4dad 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -32,6 +32,7 @@
 #include "dkdm_wrapper.h"
 #include "compose.hpp"
 #include "crypto.h"
+#include "dkdm_recipient.h"
 #include <dcp/raw_convert.h>
 #include <dcp/name_format.h>
 #include <dcp/certificate_chain.h>
@@ -127,10 +128,12 @@ Config::set_defaults ()
        _win32_console = false;
 #endif
        _cinemas_file = path ("cinemas.xml");
+       _dkdm_recipients_file = path ("dkdm_recipients.xml");
        _show_hints_before_make_dcp = true;
        _confirm_kdm_email = true;
        _kdm_container_name_format = dcp::NameFormat ("KDM %f %c");
        _kdm_filename_format = dcp::NameFormat ("KDM %f %c %s");
+       _dkdm_filename_format = dcp::NameFormat ("DKDM %f %c %s");
        _dcp_metadata_filename_format = dcp::NameFormat ("%t");
        _dcp_asset_filename_format = dcp::NameFormat ("%t");
        _jump_to_selected = true;
@@ -232,6 +235,7 @@ Config::backup ()
 
                boost::filesystem::copy_file(path("config.xml", false), path(String::compose("config.xml.%1", n), false));
                boost::filesystem::copy_file(path("cinemas.xml", false), path(String::compose("cinemas.xml.%1", n), false));
+               boost::filesystem::copy_file(path("dkdm_recipients.xml", false), path(String::compose("dkdm_recipients.xml.%1", n), false));
        } catch (...) {}
 }
 
@@ -334,7 +338,9 @@ try
        _default_interop = f.optional_bool_child("DefaultInterop").get_value_or (false);
        _default_kdm_directory = f.optional_string_child("DefaultKDMDirectory");
 
-       /* Load any cinemas from config.xml */
+       /* Read any cinemas that are still lying around in the config file
+        * from an old version.
+        */
        read_cinemas (f);
 
        _mail_server = f.string_child ("MailServer");
@@ -513,10 +519,12 @@ try
                }
        }
        _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ());
+       _dkdm_recipients_file = f.optional_string_child("DKDMRecipientsFile").get_value_or (path("dkdm_recipients.xml").string());
        _show_hints_before_make_dcp = f.optional_bool_child("ShowHintsBeforeMakeDCP").get_value_or (true);
        _confirm_kdm_email = f.optional_bool_child("ConfirmKDMEmail").get_value_or (true);
        _kdm_container_name_format = dcp::NameFormat (f.optional_string_child("KDMContainerNameFormat").get_value_or ("KDM %f %c"));
        _kdm_filename_format = dcp::NameFormat (f.optional_string_child("KDMFilenameFormat").get_value_or ("KDM %f %c %s"));
+       _dkdm_filename_format = dcp::NameFormat (f.optional_string_child("DKDMFilenameFormat").get_value_or("DKDM %f %c %s"));
        _dcp_metadata_filename_format = dcp::NameFormat (f.optional_string_child("DCPMetadataFilenameFormat").get_value_or ("%t"));
        _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t"));
        _jump_to_selected = f.optional_bool_child("JumpToSelected").get_value_or (true);
@@ -608,12 +616,17 @@ try
        _player_lock_file = f.optional_string_child("PlayerLockFile");
 #endif
 
-       /* 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);
        }
+
+       if (boost::filesystem::exists (_dkdm_recipients_file)) {
+               cxml::Document f ("DKDMRecipients");
+               f.read_file (_dkdm_recipients_file);
+               read_dkdm_recipients (f);
+       }
 }
 catch (...) {
        if (have_existing ("config.xml")) {
@@ -647,6 +660,7 @@ Config::write () const
 {
        write_config ();
        write_cinemas ();
+       write_dkdm_recipients ();
 }
 
 void
@@ -883,12 +897,16 @@ Config::write_config () const
 
        /* [XML] CinemasFile Filename of cinemas list file. */
        root->add_child("CinemasFile")->add_child_text (_cinemas_file.string());
+       /* [XML] DKDMRecipientsFile Filename of DKDM recipients list file. */
+       root->add_child("DKDMRecipientsFile")->add_child_text (_dkdm_recipients_file.string());
        /* [XML] ShowHintsBeforeMakeDCP 1 to show hints in the GUI before making a DCP, otherwise 0. */
        root->add_child("ShowHintsBeforeMakeDCP")->add_child_text (_show_hints_before_make_dcp ? "1" : "0");
        /* [XML] ConfirmKDMEmail 1 to confirm before sending KDM emails in the GUI, otherwise 0. */
        root->add_child("ConfirmKDMEmail")->add_child_text (_confirm_kdm_email ? "1" : "0");
        /* [XML] KDMFilenameFormat Format for KDM filenames. */
        root->add_child("KDMFilenameFormat")->add_child_text (_kdm_filename_format.specification ());
+       /* [XML] KDMFilenameFormat Format for DKDM filenames. */
+       root->add_child("DKDMFilenameFormat")->add_child_text(_dkdm_filename_format.specification());
        /* [XML] KDMContainerNameFormat Format for KDM containers (directories or ZIP files). */
        root->add_child("KDMContainerNameFormat")->add_child_text (_kdm_container_name_format.specification ());
        /* [XML] DCPMetadataFilenameFormat Format for DCP metadata filenames. */
@@ -1080,28 +1098,45 @@ Config::write_config () const
        }
 }
 
+
+template <class T>
 void
-Config::write_cinemas () const
+write_file (string root_node, string node, string version, list<shared_ptr<T> > things, boost::filesystem::path file)
 {
        xmlpp::Document doc;
-       xmlpp::Element* root = doc.create_root_node ("Cinemas");
-       root->add_child("Version")->add_child_text ("1");
+       xmlpp::Element* root = doc.create_root_node (root_node);
+       root->add_child("Version")->add_child_text(version);
 
-       BOOST_FOREACH (shared_ptr<Cinema> i, _cinemas) {
-               i->as_xml (root->add_child ("Cinema"));
+       BOOST_FOREACH (shared_ptr<T> i, things) {
+               i->as_xml (root->add_child(node));
        }
 
        try {
-               doc.write_to_file_formatted (_cinemas_file.string() + ".tmp");
-               boost::filesystem::remove (_cinemas_file);
-               boost::filesystem::rename (_cinemas_file.string() + ".tmp", _cinemas_file);
+               doc.write_to_file_formatted (file.string() + ".tmp");
+               boost::filesystem::remove (file);
+               boost::filesystem::rename (file.string() + ".tmp", file);
        } catch (xmlpp::exception& e) {
                string s = e.what ();
                trim (s);
-               throw FileError (s, _cinemas_file);
+               throw FileError (s, file);
        }
 }
 
+
+void
+Config::write_cinemas () const
+{
+       write_file ("Cinemas", "Cinema", "1", _cinemas, _cinemas_file);
+}
+
+
+void
+Config::write_dkdm_recipients () const
+{
+       write_file ("DKDMRecipients", "DKDMRecipient", "1", _dkdm_recipients, _dkdm_recipients_file);
+}
+
+
 boost::filesystem::path
 Config::default_directory_or (boost::filesystem::path a) const
 {
@@ -1293,6 +1328,37 @@ Config::set_cinemas_file (boost::filesystem::path file)
        changed (OTHER);
 }
 
+
+void
+Config::read_dkdm_recipients (cxml::Document const & f)
+{
+       _dkdm_recipients.clear ();
+       list<cxml::NodePtr> cin = f.node_children ("DKDMRecipient");
+       BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("DKDMRecipient")) {
+               _dkdm_recipients.push_back (shared_ptr<DKDMRecipient>(new DKDMRecipient(i)));
+       }
+}
+
+void
+Config::set_dkdm_recipients_file (boost::filesystem::path file)
+{
+       if (file == _dkdm_recipients_file) {
+               return;
+       }
+
+       _dkdm_recipients_file = file;
+
+       if (boost::filesystem::exists (_dkdm_recipients_file)) {
+               /* Existing file; read it in */
+               cxml::Document f ("DKDMRecipients");
+               f.read_file (_dkdm_recipients_file);
+               read_dkdm_recipients (f);
+       }
+
+       changed (OTHER);
+}
+
+
 void
 Config::save_template (shared_ptr<const Film> film, string name) const
 {
index 7494074036c0fb01772d0c25cb4a0749a1b3ed50..f54ca3814043abf5c8fa51c619c975cf87591113 100644 (file)
@@ -44,6 +44,7 @@ class Ratio;
 class Cinema;
 class Film;
 class DKDMGroup;
+class DKDMRecipient;
 
 /** @class Config
  *  @brief A singleton class holding configuration.
@@ -76,6 +77,7 @@ public:
                USE_ANY_SERVERS,
                SERVERS,
                CINEMAS,
+               DKDM_RECIPIENTS,
                SOUND,
                SOUND_OUTPUT,
                INTERFACE_COMPLEXITY,
@@ -148,6 +150,10 @@ public:
                return _cinemas;
        }
 
+       std::list<boost::shared_ptr<DKDMRecipient> > dkdm_recipients () const {
+               return _dkdm_recipients;
+       }
+
        std::list<int> allowed_dcp_frame_rates () const {
                return _allowed_dcp_frame_rates;
        }
@@ -342,6 +348,10 @@ public:
                return _cinemas_file;
        }
 
+       boost::filesystem::path dkdm_recipients_file () const {
+               return _dkdm_recipients_file;
+       }
+
        bool show_hints_before_make_dcp () const {
                return _show_hints_before_make_dcp;
        }
@@ -358,6 +368,10 @@ public:
                return _kdm_filename_format;
        }
 
+       dcp::NameFormat dkdm_filename_format () const {
+               return _dkdm_filename_format;
+       }
+
        dcp::NameFormat dcp_metadata_filename_format () const {
                return _dcp_metadata_filename_format;
        }
@@ -617,6 +631,16 @@ public:
                changed (CINEMAS);
        }
 
+       void add_dkdm_recipient (boost::shared_ptr<DKDMRecipient> c) {
+               _dkdm_recipients.push_back (c);
+               changed (DKDM_RECIPIENTS);
+       }
+
+       void remove_dkdm_recipient (boost::shared_ptr<DKDMRecipient> c) {
+               _dkdm_recipients.remove (c);
+               changed (DKDM_RECIPIENTS);
+       }
+
        void set_allowed_dcp_frame_rates (std::list<int> const & r) {
                maybe_set (_allowed_dcp_frame_rates, r);
        }
@@ -814,6 +838,8 @@ public:
 
        void set_cinemas_file (boost::filesystem::path file);
 
+       void set_dkdm_recipients_file (boost::filesystem::path file);
+
        void set_show_hints_before_make_dcp (bool s) {
                maybe_set (_show_hints_before_make_dcp, s);
        }
@@ -859,6 +885,10 @@ public:
                maybe_set (_kdm_filename_format, n);
        }
 
+       void set_dkdm_filename_format (dcp::NameFormat n) {
+               maybe_set (_dkdm_filename_format, n);
+       }
+
        void set_dcp_metadata_filename_format (dcp::NameFormat n) {
                maybe_set (_dcp_metadata_filename_format, n);
        }
@@ -1111,6 +1141,7 @@ public:
        void write () const;
        void write_config () const;
        void write_cinemas () const;
+       void write_dkdm_recipients () const;
        void link (boost::filesystem::path new_file) const;
        void copy_and_link (boost::filesystem::path new_file) const;
        bool have_write_permission () const;
@@ -1136,6 +1167,7 @@ private:
        void set_notification_email_to_default ();
        void set_cover_sheet_to_default ();
        void read_cinemas (cxml::Document const & f);
+       void read_dkdm_recipients (cxml::Document const & f);
        boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
        boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const;
        void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p);
@@ -1215,6 +1247,7 @@ private:
        boost::optional<boost::filesystem::path> _default_kdm_directory;
        bool _default_upload_after_make_dcp;
        std::list<boost::shared_ptr<Cinema> > _cinemas;
+       std::list<boost::shared_ptr<DKDMRecipient> > _dkdm_recipients;
        std::string _mail_server;
        int _mail_port;
        EmailProtocol _mail_protocol;
@@ -1257,9 +1290,11 @@ private:
        std::vector<boost::filesystem::path> _player_history;
        boost::shared_ptr<DKDMGroup> _dkdms;
        boost::filesystem::path _cinemas_file;
+       boost::filesystem::path _dkdm_recipients_file;
        bool _show_hints_before_make_dcp;
        bool _confirm_kdm_email;
        dcp::NameFormat _kdm_filename_format;
+       dcp::NameFormat _dkdm_filename_format;
        dcp::NameFormat _kdm_container_name_format;
        dcp::NameFormat _dcp_metadata_filename_format;
        dcp::NameFormat _dcp_asset_filename_format;