[rygel] media-export: Use @refID for virtual items



commit ccc6950c54306b2534bb86016730edc0e6413557
Author: Jens Georg <jensg openismus com>
Date:   Thu Jan 17 10:09:28 2013 +0100

    media-export: Use @refID for virtual items
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690770

 .../rygel-media-export-leaf-query-container.vala   |    4 ++
 .../rygel-media-export-query-container.vala        |    1 +
 .../rygel-media-export-root-container.vala         |   31 +++++++++++++++++++-
 3 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-leaf-query-container.vala b/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
index 31c03d4..c42ed0b 100644
--- a/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-leaf-query-container.vala
@@ -39,6 +39,10 @@ internal class Rygel.MediaExport.LeafQueryContainer : QueryContainer {
                                           sort_criteria,
                                           cancellable);
         foreach (var child in children) {
+            var container_id = QueryContainer.ITEM_PREFIX +
+                               this.id.replace (QueryContainer.PREFIX, "");
+            child.ref_id = child.id;
+            child.id = container_id + ":" + child.ref_id;
             child.parent = this;
         }
 
diff --git a/src/plugins/media-export/rygel-media-export-query-container.vala b/src/plugins/media-export/rygel-media-export-query-container.vala
index 49f1e48..97999d1 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -24,6 +24,7 @@ using GUPnP;
 internal abstract class Rygel.MediaExport.QueryContainer : DBContainer {
     // public static members
     public static const string PREFIX = "virtual-container:";
+    public static const string ITEM_PREFIX = "virtual-id:";
 
     // protected members
     protected SearchExpression expression;
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index b7f5b41..6d1ea76 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -90,7 +90,11 @@ public class Rygel.MediaExport.RootContainer : TrackableDbContainer {
                                                     throws Error {
         var object = yield base.find_object (id, cancellable);
 
-        if (object == null && id.has_prefix (QueryContainer.PREFIX)) {
+        if (object != null) {
+            return object;
+        }
+
+        if (id.has_prefix (QueryContainer.PREFIX)) {
             var factory = QueryContainerFactory.get_default ();
             var container = factory.create_from_id (id);
             if (container != null) {
@@ -98,6 +102,31 @@ public class Rygel.MediaExport.RootContainer : TrackableDbContainer {
             }
 
             return container;
+        } else if (id.has_prefix (QueryContainer.ITEM_PREFIX)) {
+            var tmp_id = id.replace (QueryContainer.ITEM_PREFIX, "");
+            var parts = tmp_id.split (":");
+            if (parts.length != 2) {
+                return null;
+            }
+
+            object = yield base.find_object (parts[1], cancellable);
+
+            if (object == null) {
+                return null;
+            }
+
+            object.ref_id = object.id;
+            object.id = id;
+
+            var factory = QueryContainerFactory.get_default ();
+            var container_id = QueryContainer.PREFIX + parts[0];
+            var container = factory.create_from_id (this.media_db,
+                                                    container_id);
+            if (container == null) {
+                return null;
+            }
+
+            object.parent_ref = container;
         }
 
         return object;



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