[rygel] core: Implement filtered-browse.



commit fe415775b969ba21b80a10d6d1684e9e8b8f44a1
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Jun 22 18:56:04 2009 +0300

    core: Implement filtered-browse.
    
    Currently we are not handling "res" properties.

 src/rygel/rygel-browse.vala           |    4 +-
 src/rygel/rygel-didl-lite-writer.vala |   90 ++++++++++++++++++++++-----------
 2 files changed, 63 insertions(+), 31 deletions(-)
---
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 60b868c..5722211 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -128,7 +128,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         }
 
         try {
-            this.didl_writer.serialize (this.media_object);
+            this.didl_writer.serialize (this.media_object, this.filter);
         } catch (Error err) {
             this.handle_error (err);
             return;
@@ -247,7 +247,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         /* serialize all children */
         for (int i = 0; i < children.size; i++) {
             try {
-                this.didl_writer.serialize (children[i]);
+                this.didl_writer.serialize (children[i], this.filter);
             } catch (Error err) {
                 this.handle_error (err);
                 return;
diff --git a/src/rygel/rygel-didl-lite-writer.vala b/src/rygel/rygel-didl-lite-writer.vala
index 04b0429..460dda9 100644
--- a/src/rygel/rygel-didl-lite-writer.vala
+++ b/src/rygel/rygel-didl-lite-writer.vala
@@ -38,18 +38,22 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter {
         this.http_server = http_server;
     }
 
-    public void serialize (MediaObject media_object) throws Error {
+    public void serialize (MediaObject media_object,
+                           string      filter_str)
+                           throws Error {
+        var filter = new Filter (filter_str);
+
         if (media_object is MediaItem) {
-            this.serialize_item ((MediaItem) media_object);
+            this.serialize_item ((MediaItem) media_object, filter);
         } else if (media_object is MediaContainer) {
-            this.serialize_container ((MediaContainer) media_object);
+            this.serialize_container ((MediaContainer) media_object, filter);
         } else {
             throw new DIDLLiteWriterError.UNSUPPORTED_OBJECT (
                 "Unable to serialize unsupported object");
         }
     }
 
-    private void serialize_item (MediaItem item) throws Error {
+    private void serialize_item (MediaItem item, Filter filter) throws Error {
         this.start_item (item.id,
                          item.parent.id,
                          null,
@@ -61,23 +65,29 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter {
                          null,
                          item.title);
 
-        this.add_string ("class",
-                         GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
-                         null,
-                         item.upnp_class);
+        if ("class" in filter) {
+            this.add_string ("class",
+                             GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
+                             null,
+                             item.upnp_class);
+        }
 
         if (item.author != null && item.author != "") {
-            this.add_string ("creator",
-                             GUPnP.DIDLLiteWriter.NAMESPACE_DC,
-                             null,
-                             item.author);
+            if ("creator" in filter) {
+                this.add_string ("creator",
+                                 GUPnP.DIDLLiteWriter.NAMESPACE_DC,
+                                 null,
+                                 item.author);
+            }
 
-            if (item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
+            if (item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS) &&
+                "author" in filter) {
                 this.add_string ("author",
                                  GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
                                  null,
                                  item.author);
-            } else if (item.upnp_class.has_prefix (MediaItem.MUSIC_CLASS)) {
+            } else if (item.upnp_class.has_prefix (MediaItem.MUSIC_CLASS) &&
+                       "artist" in filter) {
                 this.add_string ("artist",
                                  GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
                                  null,
@@ -85,42 +95,46 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter {
             }
         }
 
-        if (item.track_number >= 0) {
+        if (item.track_number >= 0 && "originalTrackNumber" in filter) {
             this.add_int ("originalTrackNumber",
                           GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
                           null,
                           item.track_number);
         }
 
-        if (item.album != null && item.album != "") {
+        if (item.album != null && item.album != "" && "album" in filter) {
             this.add_string ("album",
                              GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
                              null,
                              item.album);
         }
 
-        if (item.date != null && item.date != "") {
+        if (item.date != null && item.date != "" && "date" in filter) {
             this.add_string ("date",
                              GUPnP.DIDLLiteWriter.NAMESPACE_DC,
                              null,
                              item.date);
         }
 
-        /* Add resource data */
-        var resources = this.get_original_resources (item);
+        if ("res" in filter) {
+            /* Add resource data */
+            var resources = this.get_original_resources (item);
 
-        /* Now get the transcoded/proxy URIs */
-        this.http_server.add_resources (resources, item);
+            /* Now get the transcoded/proxy URIs */
+            this.http_server.add_resources (resources, item);
 
-        foreach (DIDLLiteResource res in resources) {
-            this.add_res (res);
+            foreach (DIDLLiteResource res in resources) {
+                this.add_res (res);
+            }
         }
 
         /* End of item */
         this.end_item ();
     }
 
-    private void serialize_container (MediaContainer container) throws Error {
+    private void serialize_container (MediaContainer container,
+                                      Filter         filter)
+                                      throws Error {
         string parent_id;
 
         if (container.parent != null) {
@@ -134,11 +148,12 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter {
                               (int) container.child_count,
                               false,
                               false);
-
-        this.add_string ("class",
-                         GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
-                         null,
-                         "object.container.storageFolder");
+        if ("class" in filter) {
+            this.add_string ("class",
+                             GUPnP.DIDLLiteWriter.NAMESPACE_UPNP,
+                             null,
+                             "object.container.storageFolder");
+        }
 
         this.add_string ("title",
                          GUPnP.DIDLLiteWriter.NAMESPACE_DC,
@@ -162,3 +177,20 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter {
         return resources;
     }
 }
+
+private class Rygel.Filter : ArrayList<string> {
+    public Filter (string filter_str) {
+        base ((GLib.EqualFunc) Filter.filter_equal_func);
+
+        var tokens = filter_str.split (",", -1);
+
+        foreach (var token in tokens) {
+            this.add (token);
+        }
+    }
+
+    private static bool filter_equal_func (string a, string b) {
+        return a == "*" || a == b;
+    }
+}
+



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