[rygel] media-export: React to config changes



commit 2fa271bf913a5ce009bb69367ce96389dcdaa978
Author: Jens Georg <jensg openismus com>
Date:   Wed Dec 19 22:57:22 2012 +0100

    media-export: React to config changes
    
    Disable change monitoring. For now, don't disable the actual submonitors in
    case it gets re-enabled. Otherwise we'd need to crawl and add the monitors
    again.

 .../rygel-media-export-recursive-file-monitor.vala |   30 +++++++++++++------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-recursive-file-monitor.vala b/src/plugins/media-export/rygel-media-export-recursive-file-monitor.vala
index 75035ab..ff1477d 100644
--- a/src/plugins/media-export/rygel-media-export-recursive-file-monitor.vala
+++ b/src/plugins/media-export/rygel-media-export-recursive-file-monitor.vala
@@ -28,13 +28,9 @@ public class Rygel.MediaExport.RecursiveFileMonitor : Object {
 
     public RecursiveFileMonitor (Cancellable? cancellable) {
         this.monitor_changes = true;
-        try {
-            var config = MetaConfig.get_default ();
-            this.monitor_changes = config.get_bool ("MediaExport",
-                                                    "monitor-changes");
-        } catch (Error error) {
-            this.monitor_changes = true;
-        }
+        var config = MetaConfig.get_default ();
+        config.setting_changed.connect (this.on_config_changed);
+        this.on_config_changed (config, Plugin.NAME, "monitor-changes");
 
         if (!this.monitor_changes) {
             message (_("Will not monitor file changes"));
@@ -51,7 +47,9 @@ public class Rygel.MediaExport.RecursiveFileMonitor : Object {
     public void on_monitor_changed (File             file,
                                     File?            other_file,
                                     FileMonitorEvent event_type) {
-        this.changed (file, other_file, event_type);
+        if (this.monitor_changes) {
+            this.changed (file, other_file, event_type);
+        }
 
         switch (event_type) {
             case FileMonitorEvent.CREATED:
@@ -76,8 +74,7 @@ public class Rygel.MediaExport.RecursiveFileMonitor : Object {
     }
 
     public async void add (File file) {
-        if (!this.monitor_changes ||
-             this.monitors.has_key (file)) {
+        if (this.monitors.has_key (file)) {
             return;
         }
 
@@ -110,4 +107,17 @@ public class Rygel.MediaExport.RecursiveFileMonitor : Object {
     public signal void changed (File             file,
                                 File?            other_file,
                                 FileMonitorEvent event_type);
+
+    private void on_config_changed (Configuration config,
+                                    string section,
+                                    string key) {
+        if (section != Plugin.NAME || key != "monitor-changes") {
+            return;
+        }
+
+        try {
+            this.monitor_changes = config.get_bool (Plugin.NAME,
+                                                    "monitor-changes");
+        } catch (Error error) { }
+    }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]