core,tracker: CategoryContainer.add_child_container -> SimpleContainer
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 21 Dec 2010 20:47:27 +0000 (22:47 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 21 Dec 2010 20:47:27 +0000 (22:47 +0200)
Move add_child_container method of Tracker.CategoryContainer to parent
SimpleContainer in core so that all plugins can make use of it.

src/plugins/tracker/rygel-tracker-category-container.vala
src/rygel/rygel-simple-container.vala

index 4e24d9f..0dc6b2a 100644 (file)
@@ -29,8 +29,6 @@ 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,
@@ -38,36 +36,10 @@ 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_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 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 ();
-        }
-    }
 }
index 36fab0d..e05fd4e 100644 (file)
@@ -33,12 +33,15 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
                                      Rygel.SearchableContainer {
     public MediaObjects children;
 
+    private MediaObjects empty_children;
+
     public SimpleContainer (string          id,
                             MediaContainer? parent,
                             string          title) {
         base (id, parent, title, 0);
 
         this.children = new MediaObjects ();
+        this.empty_children = new MediaObjects ();
     }
 
     public SimpleContainer.root (string title) {
@@ -51,6 +54,15 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
         this.child_count++;
     }
 
+    public 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);
+        }
+    }
+
     public void remove_child (MediaObject child) {
         this.children.remove (child);
 
@@ -108,4 +120,20 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
                                          out total_matches,
                                          cancellable);
     }
+
+    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 ();
+        }
+    }
 }