[rygel/wip/track-changes: 2/6] WIP: Changed MediaContainer's updated() and container_updated signal.



commit 9ec7782b9d580d8342d4c51b0af932dd53ce6301
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Tue Sep 11 16:34:57 2012 +0200

    WIP: Changed MediaContainer's updated() and container_updated signal.

 src/librygel-server/rygel-content-directory.vala   |    6 ++-
 src/librygel-server/rygel-media-container.vala     |   56 ++++++++++++++++---
 src/librygel-server/rygel-media-server-plugin.vala |    5 ++-
 src/librygel-server/rygel-simple-container.vala    |   10 +++-
 4 files changed, 63 insertions(+), 14 deletions(-)
---
diff --git a/src/librygel-server/rygel-content-directory.vala b/src/librygel-server/rygel-content-directory.vala
index 8aed373..67bee6a 100644
--- a/src/librygel-server/rygel-content-directory.vala
+++ b/src/librygel-server/rygel-content-directory.vala
@@ -372,8 +372,12 @@ internal class Rygel.ContentDirectory: Service {
      * @param updated_container the container that just got updated
      */
     private void on_container_updated (MediaContainer root_container,
-                                       MediaContainer updated_container) {
+                                       MediaContainer updated_container,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         this.system_update_id++;
+        updated_container.update_id = this.system_update_id++;
 
         if (this.clear_updated_containers) {
             this.updated_containers.clear ();
diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala
index 535f628..59d6b67 100644
--- a/src/librygel-server/rygel-media-container.vala
+++ b/src/librygel-server/rygel-media-container.vala
@@ -26,6 +26,12 @@
 using GUPnP;
 using Gee;
 
+public enum Rygel.ObjectEventType {
+    ADDED = 0,
+    MODIFIED = 1,
+    DELETED = 2
+}
+
 /**
  * Represents a container (folder) for media items and containers. Provides
  * basic serialization (to DIDLLiteWriter) implementation. Deriving classes
@@ -45,12 +51,30 @@ public abstract class Rygel.MediaContainer : MediaObject {
                                               "+dc:title";
 
     /**
-     * container_updated signal that is emitted if a child container under the
-     * tree of this container gets updated.
+     * container_updated signal that is emitted if a child container
+     * under the tree of this container gets updated. object is set to
+     * the MediaObject being the source of container update. Note that
+     * it may be even set to container itself.
      *
      * @param container the container that just got updated.
+     * @param object the object that got changed.
+     * @param event_type describes what actually happened to object.
+     * @param sub_tree_update whether the modification is part of
+     * sub-tree update.
+     */
+    public signal void container_updated (MediaContainer container,
+                                          MediaObject object,
+                                          ObjectEventType event_type,
+                                          bool sub_tree_update);
+
+    /**
+     * sub_tree_updates_finished signal is emitted when all of
+     * sub-tree operations are finished.
+     *
+     * @param sub_tree_root - root of a sub-tree where all operations
+     * were performed.
      */
-    public signal void container_updated (MediaContainer container);
+    public signal void sub_tree_updates_finished (MediaObject sub_tree_root);
 
     public int child_count;
     public uint32 update_id;
@@ -102,6 +126,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
         this.upnp_class = STORAGE_FOLDER;
 
         this.container_updated.connect (on_container_updated);
+        this.sub_tree_updates_finished.connect (on_sub_tree_updates_finished);
     }
 
     public MediaContainer.root (string title,
@@ -144,11 +169,11 @@ public abstract class Rygel.MediaContainer : MediaObject {
      * metadata changes etc).
      *
      */
-    public void updated () {
-        this.update_id++;
-
+    public void updated (MediaObject object,
+                         ObjectEventType event_type,
+                         bool sub_tree_update) {
         // Emit the signal that will start the bump-up process for this event.
-        this.container_updated (this);
+        this.container_updated (this, object, event_type, sub_tree_update);
     }
 
     internal override DIDLLiteObject serialize (DIDLLiteWriter writer,
@@ -197,9 +222,22 @@ public abstract class Rygel.MediaContainer : MediaObject {
      * @param updated_container the container that just got updated
      */
     private void on_container_updated (MediaContainer container,
-                                       MediaContainer updated_container) {
+                                       MediaContainer updated_container,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
+        if (this.parent != null) {
+            this.parent.container_updated (updated_container,
+                                           object,
+                                           event_type,
+                                           sub_tree_update);
+        }
+    }
+
+    private void on_sub_tree_updates_finished (MediaContainer container,
+                                               MediaObject sub_tree_root) {
         if (this.parent != null) {
-            this.parent.container_updated (updated_container);
+            this.parent.sub_tree_updates_finished (sub_tree_root);
         }
     }
 }
diff --git a/src/librygel-server/rygel-media-server-plugin.vala b/src/librygel-server/rygel-media-server-plugin.vala
index 28a4e84..c7428bf 100644
--- a/src/librygel-server/rygel-media-server-plugin.vala
+++ b/src/librygel-server/rygel-media-server-plugin.vala
@@ -81,7 +81,10 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin {
     }
 
     private void on_container_updated (MediaContainer root_container,
-                                       MediaContainer updated) {
+                                       MediaContainer updated,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         if (updated != root_container || updated.child_count == 0) {
             return;
         }
diff --git a/src/librygel-server/rygel-simple-container.vala b/src/librygel-server/rygel-simple-container.vala
index bb7d18b..9eef9d1 100644
--- a/src/librygel-server/rygel-simple-container.vala
+++ b/src/librygel-server/rygel-simple-container.vala
@@ -91,6 +91,7 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
     }
 
     public void clear () {
+        // TODO: this will have to emit sub-tree events of object being deleted.
         this.children.clear ();
 
         this.child_count = 0;
@@ -213,7 +214,10 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
     }
 
     private void on_container_updated (MediaContainer source,
-                                       MediaContainer updated) {
+                                       MediaContainer updated,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         if (updated.child_count > 0) {
             if (!(updated in this.empty_children)) {
                 return;
@@ -223,7 +227,7 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
 
             this.add_child (updated);
 
-            this.updated ();
+            this.updated (updated, ObjectEventType.ADDED, false);
 
             debug ("Container '%s' now non-empty, added it to hierarchy now.",
                    updated.id);
@@ -235,7 +239,7 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
             this.remove_child (updated);
             this.empty_children.add (updated);
 
-            this.updated ();
+            this.updated (updated, ObjectEventType.DELETED, false);
 
             debug ("Container '%s' now empty, removing it from hierarchy now.",
                    updated.id);



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