Set up new watermark config.
[dcpomatic.git] / src / lib / config.cc
index b61b1d054db99b9badb5299d4fb2449750399fa1..6e06f78e4b85e42d6f8c146aa89fa6a3629a7e3a 100644 (file)
@@ -171,6 +171,10 @@ Config::set_defaults ()
        _player_kdm_directory = boost::none;
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        _player_background_image = boost::none;
+       _kdm_server_url = "http://localhost:8000/{CPL}";
+       _player_watermark_theatre = "";
+       _player_watermark_period = 1;
+       _player_watermark_duration = 50;
 #endif
 
        _allowed_dcp_frame_rates.clear ();
@@ -227,6 +231,14 @@ void
 Config::read ()
 try
 {
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+       if (geteuid() == 0) {
+               /* Take ownership of the config file if we're root */
+               chown (config_file().string().c_str(), 0, 0);
+               chmod (config_file().string().c_str(), 0644);
+       }
+#endif
+
        cxml::Document f ("Config");
        f.read_file (config_file ());
 
@@ -506,6 +518,10 @@ try
        _player_kdm_directory = f.optional_string_child("PlayerKDMDirectory");
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        _player_background_image = f.optional_string_child("PlayerBackgroundImage");
+       _kdm_server_url = f.optional_string_child("KDMServerURL").get_value_or("http://localhost:8000/{CPL}");
+       _player_watermark_theatre = f.optional_string_child("PlayerWatermarkTheatre").get_value_or("");
+       _player_watermark_period = f.optional_number_child<int>("PlayerWatermarkPeriod").get_value_or(1);
+       _player_watermark_duration = f.optional_number_child<int>("PlayerWatermarkDuration").get_value_or(150);
 #endif
 
        /* Replace any cinemas from config.xml with those from the configured file */
@@ -908,6 +924,10 @@ Config::write_config () const
        if (_player_background_image) {
                root->add_child("PlayerBackgroundImage")->add_child_text(_player_background_image->string());
        }
+       root->add_child("KDMServerURL")->add_child_text(_kdm_server_url);
+       root->add_child("PlayerWatermarkTheatre")->add_child_text(_player_watermark_theatre);
+       root->add_child("PlayerWatermarkPeriod")->add_child_text(raw_convert<string>(_player_watermark_period));
+       root->add_child("PlayerWatermarkDuration")->add_child_text(raw_convert<string>(_player_watermark_duration));
 #endif
 
        try {
@@ -1193,3 +1213,15 @@ Config::copy_and_link (boost::filesystem::path new_file) const
        boost::filesystem::copy_file (config_file(), new_file, boost::filesystem::copy_option::overwrite_if_exists);
        link (new_file);
 }
+
+bool
+Config::have_write_permission () const
+{
+       FILE* f = fopen_boost (config_file(), "r+");
+       if (!f) {
+               return false;
+       }
+
+       fclose (f);
+       return true;
+}