swaroop: required monitors checks.
[dcpomatic.git] / src / lib / config.cc
index d7fd74449e4ab59430cd68793b832b5f29ddcfd4..1d83f0a257b48c8b33da3d534930d7afa6c5869e 100644 (file)
@@ -172,7 +172,9 @@ Config::set_defaults ()
 #ifdef DCPOMATIC_VARIANT_SWAROOP
        _player_background_image = boost::none;
        _kdm_server_url = "http://localhost:8000/{CPL}";
-       _player_watermark = boost::none;
+       _player_watermark_theatre = "";
+       _player_watermark_period = 1;
+       _player_watermark_duration = 50;
 #endif
 
        _allowed_dcp_frame_rates.clear ();
@@ -229,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 ());
 
@@ -509,7 +519,12 @@ try
 #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 = f.optional_string_child("PlayerWatermark");
+       _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);
+       BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("RequiredMonitor")) {
+               _required_monitors.push_back(Monitor(i));
+       }
 #endif
 
        /* Replace any cinemas from config.xml with those from the configured file */
@@ -913,8 +928,11 @@ Config::write_config () const
                root->add_child("PlayerBackgroundImage")->add_child_text(_player_background_image->string());
        }
        root->add_child("KDMServerURL")->add_child_text(_kdm_server_url);
-       if (_player_watermark) {
-               root->add_child("PlayerWatermark")->add_child_text(_player_watermark->string());
+       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));
+       BOOST_FOREACH (Monitor i, _required_monitors) {
+               i.as_xml(root->add_child("RequiredMonitor"));
        }
 #endif
 
@@ -1201,3 +1219,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;
+}