Merge master.
[dcpomatic.git] / src / lib / config.cc
index 354940b1c4239327ded876436f62b0e0065e7338..6fbd34d05e5f772f4cb8872b7aa3190bc33c705b 100644 (file)
@@ -27,6 +27,8 @@
 #include "server.h"
 #include "scaler.h"
 #include "filter.h"
+#include "ratio.h"
+#include "dcp_content_type.h"
 #include "sound_processor.h"
 
 #include "i18n.h"
@@ -37,6 +39,7 @@ using std::string;
 using std::ofstream;
 using std::list;
 using boost::shared_ptr;
+using boost::lexical_cast;
 using boost::optional;
 
 Config* Config::_instance = 0;
@@ -48,6 +51,9 @@ Config::Config ()
        , _reference_scaler (Scaler::from_id (N_("bicubic")))
        , _tms_path (N_("."))
        , _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
+       , _default_still_length (10)
+       , _default_container (0)
+       , _default_dcp_content_type (0)
 {
        _allowed_dcp_frame_rates.push_back (24);
        _allowed_dcp_frame_rates.push_back (25);
@@ -55,7 +61,11 @@ Config::Config ()
        _allowed_dcp_frame_rates.push_back (48);
        _allowed_dcp_frame_rates.push_back (50);
        _allowed_dcp_frame_rates.push_back (60);
+}
 
+void
+Config::read ()
+{
        if (!boost::filesystem::exists (file (false))) {
                read_old_metadata ();
                return;
@@ -93,7 +103,22 @@ Config::Config ()
        }
 
        _language = f.optional_string_child ("Language");
+
+       c = f.optional_string_child ("DefaultContainer");
+       if (c) {
+               _default_container = Ratio::from_id (c.get ());
+       }
+
+       c = f.optional_string_child ("DefaultDCPContentType");
+       if (c) {
+               _default_dcp_content_type = DCPContentType::from_dci_name (c.get ());
+       }
+
+       _dcp_metadata.issuer = f.optional_string_child ("DCPMetadataIssuer").get_value_or ("");
+       _dcp_metadata.creator = f.optional_string_child ("DCPMetadataCreator").get_value_or ("");
+
        _default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
+       _default_still_length = f.optional_number_child<int>("DefaultStillLength").get_value_or (10);
 }
 
 void
@@ -142,6 +167,16 @@ Config::read_old_metadata ()
                        _sound_processor = SoundProcessor::from_id (v);
                } else if (k == "language") {
                        _language = v;
+               } else if (k == "default_container") {
+                       _default_container = Ratio::from_id (v);
+               } else if (k == "default_dcp_content_type") {
+                       _default_dcp_content_type = DCPContentType::from_dci_name (v);
+               } else if (k == "dcp_metadata_issuer") {
+                       _dcp_metadata.issuer = v;
+               } else if (k == "dcp_metadata_creator") {
+                       _dcp_metadata.creator = v;
+               } else if (k == "dcp_metadata_issue_date") {
+                       _dcp_metadata.issue_date = v;
                }
 
                _default_dci_metadata.read_old_metadata (k, v);
@@ -154,8 +189,10 @@ Config::file (bool old) const
 {
        boost::filesystem::path p;
        p /= g_get_user_config_dir ();
+       boost::system::error_code ec;
+       boost::filesystem::create_directory (p, ec);
        if (old) {
-               p /= ".dcpomatic";
+               p /= ".dvdomatic";
        } else {
                p /= ".dcpomatic.xml";
        }
@@ -168,6 +205,13 @@ Config::instance ()
 {
        if (_instance == 0) {
                _instance = new Config;
+               try {
+                       _instance->read ();
+               } catch (...) {
+                       /* configuration load failed; never mind, just
+                          stick with the default.
+                       */
+               }
        }
 
        return _instance;
@@ -180,9 +224,9 @@ Config::write () const
        xmlpp::Document doc;
        xmlpp::Element* root = doc.create_root_node ("Config");
 
-       root->add_child("NumLocalEncodingThreads")->add_child_text (boost::lexical_cast<string> (_num_local_encoding_threads));
+       root->add_child("NumLocalEncodingThreads")->add_child_text (lexical_cast<string> (_num_local_encoding_threads));
        root->add_child("DefaultDirectory")->add_child_text (_default_directory);
-       root->add_child("ServerPort")->add_child_text (boost::lexical_cast<string> (_server_port));
+       root->add_child("ServerPort")->add_child_text (lexical_cast<string> (_server_port));
        if (_reference_scaler) {
                root->add_child("ReferenceScaler")->add_child_text (_reference_scaler->id ());
        }
@@ -205,9 +249,19 @@ Config::write () const
        if (_language) {
                root->add_child("Language")->add_child_text (_language.get());
        }
+       if (_default_container) {
+               root->add_child("DefaultContainer")->add_child_text (_default_container->id ());
+       }
+       if (_default_dcp_content_type) {
+               root->add_child("DefaultDCPContentType")->add_child_text (_default_dcp_content_type->dci_name ());
+       }
+       root->add_child("DCPMetadataIssuer")->add_child_text (_dcp_metadata.issuer);
+       root->add_child("DCPMetadataCreator")->add_child_text (_dcp_metadata.creator);
 
        _default_dci_metadata.as_xml (root->add_child ("DCIMetadata"));
 
+       root->add_child("DefaultStillLength")->add_child_text (lexical_cast<string> (_default_still_length));
+
        doc.write_to_file_formatted (file (false));
 }