[rygel] tracker: Avoid exposing empty containers



commit e8ef12f599b5ddd09617570b29d6fb13a53ef647
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Dec 21 18:15:14 2010 +0200

    tracker: Avoid exposing empty containers
    
    Very often it happens that we don't have enough metadata available from tracker
    to populate our hierarchies and we end-up exposing empty containers. Not only
    empty containers are contrary to user's expectations but apparently DLNA CTT
    isn't able to digest them.
    
    This patch makes category containers delay addition of child containers to
    actual (exposed) hierarchy until they produce some offspring.

 .../tracker/rygel-tracker-category-container.vala  |   37 +++++++++++++++++---
 src/plugins/tracker/rygel-tracker-music.vala       |    6 ++--
 src/plugins/tracker/rygel-tracker-pictures.vala    |    2 +-
 src/plugins/tracker/rygel-tracker-videos.vala      |    2 +-
 4 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-category-container.vala b/src/plugins/tracker/rygel-tracker-category-container.vala
index 747cdb9..947a97b 100644
--- a/src/plugins/tracker/rygel-tracker-category-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-container.vala
@@ -29,6 +29,8 @@ using Gee;
 public abstract class Rygel.Tracker.CategoryContainer : Rygel.SimpleContainer {
     public ItemFactory item_factory;
 
+    private MediaObjects empty_children;
+
     public CategoryContainer (string         id,
                               MediaContainer parent,
                               string         title,
@@ -36,11 +38,36 @@ public abstract class Rygel.Tracker.CategoryContainer : Rygel.SimpleContainer {
         base (id, parent, title);
 
         this.item_factory = item_factory;
+        this.empty_children = new MediaObjects ();
 
-        this.add_child (new CategoryAllContainer (this));
-        this.add_child (new Tags (this, item_factory));
-        this.add_child (new Titles (this, this.item_factory));
-        this.add_child (new New (this, this.item_factory));
+        this.add_child_container (new CategoryAllContainer (this));
+        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));
     }
-}
 
+    protected async void add_child_container (MediaContainer child) {
+        if (child.child_count > 0) {
+            this.add_child (child);
+        } else {
+            this.empty_children.add (child);
+            child.container_updated.connect (this.on_container_updated);
+        }
+    }
+
+    private void on_container_updated (MediaContainer source,
+                                       MediaContainer updated) {
+        if (!(updated in this.empty_children)) {
+            return;
+        }
+
+        if (updated.child_count > 0) {
+            this.empty_children.remove (updated);
+            updated.container_updated.disconnect (this.on_container_updated);
+
+            this.add_child (updated);
+
+            this.updated ();
+        }
+    }
+}
diff --git a/src/plugins/tracker/rygel-tracker-music.vala b/src/plugins/tracker/rygel-tracker-music.vala
index 3be9cf5..142add6 100644
--- a/src/plugins/tracker/rygel-tracker-music.vala
+++ b/src/plugins/tracker/rygel-tracker-music.vala
@@ -30,9 +30,9 @@ public class Rygel.Tracker.Music : CategoryContainer {
     public Music (string id, MediaContainer parent, string title) {
         base (id, parent, title, new MusicItemFactory ());
 
-        this.add_child (new Artists (this));
-        this.add_child (new Albums (this));
-        this.add_child (new Genre (this));
+        this.add_child_container (new Artists (this));
+        this.add_child_container (new Albums (this));
+        this.add_child_container (new Genre (this));
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-pictures.vala b/src/plugins/tracker/rygel-tracker-pictures.vala
index a06362a..eac5344 100644
--- a/src/plugins/tracker/rygel-tracker-pictures.vala
+++ b/src/plugins/tracker/rygel-tracker-pictures.vala
@@ -30,7 +30,7 @@ public class Rygel.Tracker.Pictures : CategoryContainer {
     public Pictures (string id, MediaContainer parent, string title) {
         base (id, parent, title, new PictureItemFactory ());
 
-        this.add_child (new Years (this, this.item_factory));
+        this.add_child_container (new Years (this, this.item_factory));
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-videos.vala b/src/plugins/tracker/rygel-tracker-videos.vala
index 42c9da6..3a69bb5 100644
--- a/src/plugins/tracker/rygel-tracker-videos.vala
+++ b/src/plugins/tracker/rygel-tracker-videos.vala
@@ -30,7 +30,7 @@ public class Rygel.Tracker.Videos : CategoryContainer {
     public Videos (string id, MediaContainer parent, string title) {
         base (id, parent, title, new VideoItemFactory ());
 
-        this.add_child (new Years (this, this.item_factory));
+        this.add_child_container (new Years (this, this.item_factory));
     }
 }
 



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