[rygel] core,media-export: Implement find_object() in MediaContainer



commit e5eb6bf69a295e9619b9ff612f93e09d58c2dc9a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Nov 11 00:05:05 2009 +0200

    core,media-export: Implement find_object() in MediaContainer
    
    Plugins no longer need to provide MediaContainer.find_object() since we
    now provide an implementation based on MediaContainer.search().

 .../rygel-media-export-null-container.vala         |    7 ---
 src/rygel/rygel-media-container.vala               |   26 ++++++++++--
 src/rygel/rygel-media-db-container.vala            |    6 ---
 src/rygel/rygel-simple-container.vala              |   40 --------------------
 4 files changed, 21 insertions(+), 58 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-null-container.vala b/src/plugins/media-export/rygel-media-export-null-container.vala
index cf835aa..b74e8c7 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -37,11 +37,4 @@ internal class Rygel.NullContainer : MediaContainer {
                                         throws Error {
         return new Gee.ArrayList<MediaObject>();
     }
-
-    public override async MediaObject? find_object (string       id,
-                                                    Cancellable? cancellable)
-                                                    throws Error {
-        return null;
-    }
-
 }
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index 26f39a2..568dc10 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -26,8 +26,7 @@ using Gee;
 /**
  * Represents a container (folder) for media items and containers. Provides
  * basic serialization (to DIDLLiteWriter) implementation. Deriving classes
- * are supposed to provide working implementations of get_children and
- * find_object.
+ * are supposed to provide working implementations of get_children.
  */
 public abstract class Rygel.MediaContainer : MediaObject {
     /**
@@ -84,9 +83,26 @@ public abstract class Rygel.MediaContainer : MediaObject {
     *
     * return the found media object.
     */
-    public async abstract MediaObject? find_object (string       id,
-                                                    Cancellable? cancellable)
-                                                    throws Error;
+    public async virtual MediaObject? find_object (string       id,
+                                                   Cancellable? cancellable)
+                                                   throws Error {
+        var expression = new RelationalExpression ();
+        expression.op = SearchCriteriaOp.EQ;
+        expression.operand1 = "@id";
+        expression.operand2 = id;
+
+        uint total_matches;
+        var results = yield this.search (expression,
+                                         0,
+                                         1,
+                                         out total_matches,
+                                         cancellable);
+        if (results.size > 0) {
+            return results[0];
+        } else {
+            return null;
+        }
+    }
 
     /**
      * Recursively searches for all media objects the satisfy the given search
diff --git a/src/rygel/rygel-media-db-container.vala b/src/rygel/rygel-media-db-container.vala
index a478daa..a27f01c 100644
--- a/src/rygel/rygel-media-db-container.vala
+++ b/src/rygel/rygel-media-db-container.vala
@@ -63,12 +63,6 @@ public class Rygel.MediaDBContainer : MediaContainer {
 
         return children;
     }
-
-    public override async MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws GLib.Error {
-        return media_db.get_object (id);
-    }
 }
 
 
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index 46fb191..2f24f68 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -66,44 +66,4 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
 
         return this.children.slice ((int) offset, (int) stop);
     }
-
-    public override async MediaObject? find_object (string       id,
-                                                    Cancellable? cancellable)
-                                                    throws Error {
-        MediaObject child = null;
-
-        foreach (var tmp in this.children) {
-            if (id == tmp.id) {
-                child = tmp;
-
-                break;
-            }
-        }
-
-        if (child == null) {
-            child = yield this.find_object_in_children (id, cancellable);
-        }
-
-        return child;
-    }
-
-    public async MediaObject? find_object_in_children (string       id,
-                                                       Cancellable? cancellable)
-                                                       throws Error {
-        MediaObject child = null;
-
-        // Recurse into the child containers
-        foreach (var tmp in this.children) {
-            if (tmp is MediaContainer) {
-                var container = tmp as MediaContainer;
-
-                child = yield container.find_object (id, cancellable);
-                if (child != null) {
-                    break;
-                }
-            }
-        }
-
-        return child;
-    }
 }



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