[rygel/wip/ruih: 9/10] ruih: Watch config directory



commit e044c3cb35494afe97152ec6e05a07a8dc751e4f
Author: Jens Georg <mail jensge org>
Date:   Fri Oct 31 22:34:58 2014 +0100

    ruih: Watch config directory
    
    Dynamically disable/enable the plugin if the config file disappears/appears.
    
    Signed-off-by: Jens Georg <mail jensge org>

 src/librygel-ruih/rygel-ruih-service.vala        |   12 +++++++
 src/librygel-ruih/rygel-ruih-servicemanager.vala |   36 +++++++++++++--------
 2 files changed, 34 insertions(+), 14 deletions(-)
---
diff --git a/src/librygel-ruih/rygel-ruih-service.vala b/src/librygel-ruih/rygel-ruih-service.vala
index 6dfde58..970905f 100644
--- a/src/librygel-ruih/rygel-ruih-service.vala
+++ b/src/librygel-ruih/rygel-ruih-service.vala
@@ -48,6 +48,10 @@ internal class Rygel.RuihService: Service {
 
         this.action_invoked["GetCompatibleUIs"].connect
                                         (this.get_compatible_uis_cb);
+
+        var manager = RuihServiceManager.get_default ();
+        manager.updated.connect (this.update_plugin_availability);
+        this.update_plugin_availability ();
     }
 
     /* Browse action implementation */
@@ -78,4 +82,12 @@ internal class Rygel.RuihService: Service {
         value.init (typeof (string));
         value.set_string ("");
     }
+
+    private void update_plugin_availability () {
+        var manager = RuihServiceManager.get_default ();
+        var plugin = this.root_device.resource_factory as Plugin;
+
+
+        plugin.active = manager.ui_list_available ();
+    }
 }
diff --git a/src/librygel-ruih/rygel-ruih-servicemanager.vala 
b/src/librygel-ruih/rygel-ruih-servicemanager.vala
index b51e324..1ca2347 100644
--- a/src/librygel-ruih/rygel-ruih-servicemanager.vala
+++ b/src/librygel-ruih/rygel-ruih-servicemanager.vala
@@ -55,10 +55,11 @@ public class Rygel.RuihServiceManager : Object
     internal Cancellable cancellable;
     private string ui_listing_full_path;
     private FileMonitor ui_file_monitor;
-    private RuihServiceManager ruih_manager;
 
     public const string UI_LISTING_FILE_NAME = "UIList.xml";
 
+    public signal void updated ();
+
     public static RuihServiceManager get_default () {
         if (instance == null) {
             instance = new RuihServiceManager ();
@@ -82,18 +83,23 @@ public class Rygel.RuihServiceManager : Object
         try {
             this.set_ui_list (ui_listing_full_path);
             var ui_file = File.new_for_path (ui_listing_full_path);
-            this.ui_file_monitor = ui_file.monitor_file (FileMonitorFlags.NONE,
-                                                         cancellable);
+            var config_dir_file = File.new_for_path (ui_listing_directory);
+            this.ui_file_monitor = config_dir_file.monitor_directory
+                                        (FileMonitorFlags.NONE,
+                                         cancellable);
             this.ui_file_monitor.changed.connect ((src, dest, event) => {
-                debug ("File monitor for %s triggered with %s",
-                       this.ui_listing_full_path,
-                       event.to_string ());
-                try {
-                    ruih_manager.set_ui_list (ui_listing_full_path);
-                } catch (RuihServiceError e) {
-                    warning (_("Failed to set UIList for file %s - %s"),
-                             ui_listing_full_path,
-                             e.message);
+                if (ui_file.equal (src)) {
+                    try {
+                        this.set_ui_list (ui_listing_full_path);
+                    } catch (RuihServiceError e) {
+                        warning (_("Failed to set UIList for file %s - %s"),
+                                 ui_listing_full_path,
+                                 e.message);
+                    }
+
+                    // Always signal update as the first thing set_ui_list
+                    // does is to clear the old list.
+                    this.updated ();
                 }
             });
         } catch (RuihServiceError e) {
@@ -111,6 +117,10 @@ public class Rygel.RuihServiceManager : Object
         this.cancellable.cancel ();
     }
 
+    public bool ui_list_available () {
+        return !this.ui_list.is_empty;
+    }
+
     public void set_ui_list (string ui_list_file_path) throws RuihServiceError {
         this.ui_list.clear ();
         // Empty internal data
@@ -134,8 +144,6 @@ public class Rygel.RuihServiceManager : Object
             }
         }
 
-        this.updated ();
-
         delete doc;
     }
 


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