[rygel] tracker: Update category containers on change



commit cfa0583bd6bf7f78450cc16dc6887495e182668c
Author: Jens Georg <mail jensge org>
Date:   Thu Jul 21 12:53:50 2011 +0200

    tracker: Update category containers on change
    
    With this change the tracker plugin now recalculates the contents of
    special containers if the CategoryAll container changes due to
    GraphUpdated signal.

 .../tracker/rygel-tracker-category-container.vala  |   32 ++++++++++++++++++++
 .../tracker/rygel-tracker-metadata-values.vala     |   10 +++++-
 .../tracker/rygel-tracker-search-container.vala    |    2 +-
 3 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-category-container.vala b/src/plugins/tracker/rygel-tracker-category-container.vala
index 95d0402..c6ea211 100644
--- a/src/plugins/tracker/rygel-tracker-category-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-container.vala
@@ -45,9 +45,41 @@ public abstract class Rygel.Tracker.CategoryContainer : Rygel.SimpleContainer {
         this.add_child_container (new Tags (this, item_factory));
         this.add_child_container (new Titles (this, this.item_factory));
         this.add_child_container (new New (this, this.item_factory));
+        ulong signal_id = 0;
+
+        signal_id = this.all_container.container_updated.connect( () => {
+            // ingore first update
+            this.all_container.container_updated.connect
+                                        (this.on_all_container_updated);
+            this.all_container.disconnect (signal_id);
+        });
     }
 
     public void add_create_class (string create_class) {
         this.all_container.create_classes.add (create_class);
     }
+
+    private void trigger_child_update (MediaObjects children) {
+        foreach (var container in children) {
+            if (container == this.all_container ||
+                container == null) {
+                continue;
+            }
+
+            if (container is MetadataValues) {
+                (container as MetadataValues).fetch_metadata_values ();
+            } else if (container is SearchContainer) {
+                (container as SearchContainer).get_children_count ();
+            }
+        }
+    }
+
+    private void on_all_container_updated (MediaContainer other) {
+        if (other != this.all_container) {
+            // otherwise we'd do a recursive update
+            return;
+        }
+
+        this.trigger_child_update (this.get_all_children ());
+    }
 }
diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala
index 0f41db1..6b80bf6 100644
--- a/src/plugins/tracker/rygel-tracker-metadata-values.vala
+++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala
@@ -33,6 +33,7 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer {
     private const string RESOURCES_PATH = "/org/freedesktop/Tracker1/Resources";
 
     private ItemFactory item_factory;
+    private bool update_in_progress = false;
 
     // In tracker 0.7, we might don't get values of keys in place so you need a
     // chain of keys to reach to final destination. For instances:
@@ -66,7 +67,12 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer {
         this.fetch_metadata_values.begin ();
     }
 
-    private async void fetch_metadata_values () {
+    internal async void fetch_metadata_values () {
+        if (this.update_in_progress) {
+            return;
+        }
+
+        this.update_in_progress = true;
         // First thing, clear the existing hierarchy, if any
         this.clear ();
 
@@ -112,6 +118,7 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer {
             critical (_("Error getting all values for '%s': %s"),
                       string.joinv (" -> ", this.key_chain),
                       error.message);
+            this.update_in_progress = false;
 
             return;
         }
@@ -157,6 +164,7 @@ public abstract class Rygel.Tracker.MetadataValues : Rygel.SimpleContainer {
         }
 
         this.updated ();
+        this.update_in_progress = false;
     }
 
     public override async MediaObject? find_object (string       id,
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 9017fe8..5473871 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -188,7 +188,7 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer {
         }
     }
 
-    protected async void get_children_count () {
+    internal async void get_children_count () {
         try {
             var query = new SelectionQuery.clone (this.query);
 



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