summaryrefslogtreecommitdiff
path: root/src/librygel-ruih
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2014-10-31 22:34:58 +0100
committerJens Georg <mail@jensge.org>2014-11-08 13:20:56 +0100
commit59754509650b67dab3a7b4e97d8637a1f509bbbd (patch)
tree879e4e81609f487165703d4a0a85bf4d2aae606b /src/librygel-ruih
parentcb35a67fa77531d25b81115c8ada7fab07dfc97e (diff)
downloadrygel-59754509650b67dab3a7b4e97d8637a1f509bbbd.tar.gz
ruih: Watch config directory
Dynamically disable/enable the plugin if the config file disappears/appears. Signed-off-by: Jens Georg <mail@jensge.org>
Diffstat (limited to 'src/librygel-ruih')
-rw-r--r--src/librygel-ruih/rygel-ruih-service.vala12
-rw-r--r--src/librygel-ruih/rygel-ruih-servicemanager.vala36
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 6dfde58c..970905f2 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 b51e324d..1ca23471 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;
}