Add a stored list of DKDMs to the creator rather than just a load button (#767).
[dcpomatic.git] / src / lib / config.cc
index fc71a72f3399430a3951c7cdfe01ac94238f13b0..54d42a1b94899b405759673d4acf6e5db01f53f2 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include "config.h"
-#include "server.h"
 #include "filter.h"
 #include "ratio.h"
 #include "types.h"
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
+#include <boost/thread.hpp>
 #include <cstdlib>
 #include <fstream>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -85,18 +86,19 @@ Config::set_defaults ()
        _default_dcp_content_type = DCPContentType::from_isdcf_name ("FTR");
        _default_j2k_bandwidth = 100000000;
        _default_audio_delay = 0;
+       _default_interop = false;
        _mail_server = "";
        _mail_port = 25;
        _mail_user = "";
        _mail_password = "";
-       _kdm_subject = _("KDM delivery");
        _kdm_from = "";
        _kdm_cc = "";
        _kdm_bcc = "";
        _check_for_updates = false;
        _check_for_test_updates = false;
        _maximum_j2k_bandwidth = 250000000;
-       _log_types = Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR;
+       _log_types = LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR;
+       _automatic_audio_analysis = false;
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = false;
 #endif
@@ -119,14 +121,29 @@ Config::restore_defaults ()
        Config::instance()->changed ();
 }
 
+shared_ptr<dcp::CertificateChain>
+Config::create_certificate_chain ()
+{
+       return shared_ptr<dcp::CertificateChain> (
+               new dcp::CertificateChain (
+                       openssl_path(),
+                       "dcpomatic.com",
+                       "dcpomatic.com",
+                       ".dcpomatic.smpte-430-2.ROOT",
+                       ".dcpomatic.smpte-430-2.INTERMEDIATE",
+                       "CS.dcpomatic.smpte-430-2.LEAF"
+                       )
+               );
+}
+
 void
 Config::read ()
 {
        if (!have_existing ()) {
                /* Make a new set of signing certificates and key */
-               _signer_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _signer_chain = create_certificate_chain ();
                /* And similar for decryption of KDMs */
-               _decryption_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _decryption_chain = create_certificate_chain ();
                write ();
                return;
        }
@@ -203,6 +220,7 @@ Config::read ()
        _default_still_length = f.optional_number_child<int>("DefaultStillLength").get_value_or (10);
        _default_j2k_bandwidth = f.optional_number_child<int>("DefaultJ2KBandwidth").get_value_or (200000000);
        _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) {
@@ -228,9 +246,10 @@ Config::read ()
        _check_for_test_updates = f.optional_bool_child("CheckForTestUpdates").get_value_or (false);
 
        _maximum_j2k_bandwidth = f.optional_number_child<int> ("MaximumJ2KBandwidth").get_value_or (250000000);
-       _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate");
+       _allow_any_dcp_frame_rate = f.optional_bool_child ("AllowAnyDCPFrameRate").get_value_or (false);
 
-       _log_types = f.optional_number_child<int> ("LogTypes").get_value_or (Log::TYPE_GENERAL | Log::TYPE_WARNING | Log::TYPE_ERROR);
+       _log_types = f.optional_number_child<int> ("LogTypes").get_value_or (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR);
+       _automatic_audio_analysis = f.optional_bool_child ("AutomaticAudioAnalysis").get_value_or (false);
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = f.optional_bool_child ("Win32Console").get_value_or (false);
 #endif
@@ -251,7 +270,7 @@ Config::read ()
                _signer_chain = c;
        } else {
                /* Make a new set of signing certificates and key */
-               _signer_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _signer_chain = create_certificate_chain ();
        }
 
        cxml::NodePtr decryption = f.optional_node_child ("Decryption");
@@ -263,8 +282,14 @@ Config::read ()
                c->set_key (decryption->string_child ("PrivateKey"));
                _decryption_chain = c;
        } else {
-               _decryption_chain.reset (new dcp::CertificateChain (openssl_path ()));
+               _decryption_chain = create_certificate_chain ();
+       }
+
+       list<cxml::NodePtr> dkdm = f.node_children ("DKDM");
+       BOOST_FOREACH (cxml::NodePtr i, f.node_children ("DKDM")) {
+               _dkdms.push_back (dcp::EncryptedKDM (i->content ()));
        }
+
 }
 
 /** @return Filename to write configuration to */
@@ -354,6 +379,7 @@ Config::write () const
        root->add_child("DefaultStillLength")->add_child_text (raw_convert<string> (_default_still_length));
        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"));
@@ -375,6 +401,7 @@ Config::write () const
        root->add_child("MaximumJ2KBandwidth")->add_child_text (raw_convert<string> (_maximum_j2k_bandwidth));
        root->add_child("AllowAnyDCPFrameRate")->add_child_text (_allow_any_dcp_frame_rate ? "1" : "0");
        root->add_child("LogTypes")->add_child_text (raw_convert<string> (_log_types));
+       root->add_child("AutomaticAudioAnalysis")->add_child_text (_automatic_audio_analysis ? "1" : "0");
 #ifdef DCPOMATIC_WINDOWS
        root->add_child("Win32Console")->add_child_text (_win32_console ? "1" : "0");
 #endif
@@ -395,6 +422,10 @@ Config::write () const
                root->add_child("History")->add_child_text (i->string ());
        }
 
+       BOOST_FOREACH (dcp::EncryptedKDM i, _dkdms) {
+               root->add_child("DKDM")->add_child_text (i.as_xml ());
+       }
+
        try {
                doc.write_to_file_formatted (file().string ());
        } catch (xmlpp::exception& e) {
@@ -436,6 +467,8 @@ Config::changed (Property what)
 void
 Config::set_kdm_email_to_default ()
 {
+       _kdm_subject = _("KDM delivery: $CPL_NAME");
+
        _kdm_email = _(
                "Dear Projectionist\n\n"
                "Please find attached KDMs for $CPL_NAME.\n\n"