Enable audio by default.
[dcpomatic.git] / src / lib / config.cc
index 2a8a3cc89c6efb1f7733b3d3cb660643d0835459..6ae850bfff209f6f1d5a04a47ddb79bda357a0b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -31,6 +31,7 @@
 #include "cross.h"
 #include "film.h"
 #include "dkdm_wrapper.h"
+#include "compose.hpp"
 #include <dcp/raw_convert.h>
 #include <dcp/name_format.h>
 #include <dcp/certificate_chain.h>
@@ -65,6 +66,7 @@ using dcp::raw_convert;
 Config* Config::_instance = 0;
 boost::signals2::signal<void ()> Config::FailedToLoad;
 boost::signals2::signal<void (string)> Config::Warning;
+boost::optional<boost::filesystem::path> Config::test_path;
 
 /** Construct default configuration */
 Config::Config ()
@@ -99,6 +101,7 @@ Config::set_defaults ()
        _default_j2k_bandwidth = 100000000;
        _default_audio_delay = 0;
        _default_interop = true;
+       _default_upload_after_make_dcp = false;
        _mail_server = "";
        _mail_port = 25;
        _mail_user = "";
@@ -126,7 +129,7 @@ Config::set_defaults ()
        for (int i = 0; i < NAG_COUNT; ++i) {
                _nagged[i] = false;
        }
-       _sound = false;
+       _sound = true;
        _sound_output = optional<string> ();
        _last_kdm_write_type = KDM_WRITE_FLAT;
 
@@ -261,6 +264,7 @@ try
                _dcp_issuer = f.string_child ("DCPIssuer");
        }
 
+       _default_upload_after_make_dcp = f.optional_bool_child("DefaultUploadAfterMakeDCP").get_value_or (false);
        _dcp_creator = f.optional_string_child ("DCPCreator").get_value_or ("");
 
        if (version && version.get() >= 2) {
@@ -305,11 +309,14 @@ try
        _win32_console = f.optional_bool_child ("Win32Console").get_value_or (false);
 #endif
 
-       list<cxml::NodePtr> his = f.node_children ("History");
        BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("History")) {
                _history.push_back (i->content ());
        }
 
+       BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("PlayerHistory")) {
+               _player_history.push_back (i->content ());
+       }
+
        cxml::NodePtr signer = f.optional_node_child ("Signer");
        if (signer) {
                shared_ptr<dcp::CertificateChain> c (new dcp::CertificateChain ());
@@ -361,7 +368,7 @@ try
                }
        }
        /* The variable was renamed but not the XML tag */
-       _sound = f.optional_bool_child("PreviewSound").get_value_or (false);
+       _sound = f.optional_bool_child("PreviewSound").get_value_or (true);
        _sound_output = f.optional_string_child("PreviewSoundOutput");
        if (f.optional_string_child("CoverSheet")) {
                _cover_sheet = f.optional_string_child("CoverSheet").get();
@@ -390,8 +397,13 @@ catch (...) {
 
                /* Make a copy of the configuration */
                try {
-                       boost::filesystem::copy_file (path ("config.xml", false), path ("config.xml.backup", false));
-                       boost::filesystem::copy_file (path ("cinemas.xml", false), path ("cinemas.xml.backup", false));
+                       int n = 1;
+                       while (n < 100 && boost::filesystem::exists(path(String::compose("config.xml.%1", n)))) {
+                               ++n;
+                       }
+
+                       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));
                } catch (...) {}
 
                /* We have a config file but it didn't load */
@@ -410,16 +422,20 @@ boost::filesystem::path
 Config::path (string file, bool create_directories)
 {
        boost::filesystem::path p;
+       if (test_path) {
+               p = test_path.get();
+       } else {
 #ifdef DCPOMATIC_OSX
-       p /= g_get_home_dir ();
-       p /= "Library";
-       p /= "Preferences";
-       p /= "com.dcpomatic";
-       p /= "2";
+               p /= g_get_home_dir ();
+               p /= "Library";
+               p /= "Preferences";
+               p /= "com.dcpomatic";
+               p /= "2";
 #else
-       p /= g_get_user_config_dir ();
-       p /= "dcpomatic2";
+               p /= g_get_user_config_dir ();
+               p /= "dcpomatic2";
 #endif
+       }
        boost::system::error_code ec;
        if (create_directories) {
                boost::filesystem::create_directories (p, ec);
@@ -528,6 +544,7 @@ Config::write_config () const
        root->add_child("DCPIssuer")->add_child_text (_dcp_issuer);
        /* [XML] DCPIssuer Creator text to write into CPL files. */
        root->add_child("DCPCreator")->add_child_text (_dcp_creator);
+       root->add_child("DefaultUploadAfterMakeDCP")->add_child_text (_default_upload_after_make_dcp ? "1" : "0");
 
        /* [XML] ISDCFMetadata Default ISDCF metadata to use for new films; child tags are <code>&lt;ContentVersion&gt;</code>,
           <code>&lt;AudioLanguage&gt;</code>, <code>&lt;SubtitleLanguage&gt;</code>, <code>&lt;Territory&gt;</code>,
@@ -618,6 +635,10 @@ Config::write_config () const
                root->add_child("History")->add_child_text (i.string ());
        }
 
+       BOOST_FOREACH (boost::filesystem::path i, _player_history) {
+               root->add_child("PlayerHistory")->add_child_text (i.string ());
+       }
+
        /* [XML] DKDMGroup A group of DKDMs, each with a <code>Name</code> attribute, containing other <code>&lt;DKDMGroup&gt;</code>
           or <code>&lt;DKDM&gt;</code> tags.
        */
@@ -784,13 +805,25 @@ Config::set_cover_sheet_to_default ()
 
 void
 Config::add_to_history (boost::filesystem::path p)
+{
+       add_to_history_internal (_history, p);
+}
+
+void
+Config::add_to_player_history (boost::filesystem::path p)
+{
+       add_to_history_internal (_player_history, p);
+}
+
+void
+Config::add_to_history_internal (vector<boost::filesystem::path>& h, boost::filesystem::path p)
 {
        /* Remove existing instances of this path in the history */
-       _history.erase (remove (_history.begin(), _history.end(), p), _history.end ());
+       h.erase (remove (h.begin(), h.end(), p), h.end ());
 
-       _history.insert (_history.begin (), p);
-       if (_history.size() > HISTORY_SIZE) {
-               _history.pop_back ();
+       h.insert (h.begin (), p);
+       if (h.size() > HISTORY_SIZE) {
+               h.pop_back ();
        }
 
        changed ();