[rygel] tracker: Deduct place_holder status from rdf:type



commit 8562c79a353a9260fafe73b95defcf19babbe5f9
Author: Jens Georg <mail jensge org>
Date:   Wed May 4 13:55:03 2011 +0200

    tracker: Deduct place_holder status from rdf:type
    
    We create place-holder items as nie:DataObjects now and query for their
    promotion to nfo:FileDataObject through the miner as an indicator that
    a real file exists now.

 .../tracker/rygel-tracker-insertion-query.vala     |    6 +---
 .../tracker/rygel-tracker-item-factory.vala        |    4 ++
 .../tracker/rygel-tracker-key-chain-map.vala       |   35 ++++++++++++++-----
 3 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-insertion-query.vala b/src/plugins/tracker/rygel-tracker-insertion-query.vala
index 7bd1a5f..4f342f3 100644
--- a/src/plugins/tracker/rygel-tracker-insertion-query.vala
+++ b/src/plugins/tracker/rygel-tracker-insertion-query.vala
@@ -35,7 +35,6 @@ public class Rygel.Tracker.InsertionQuery : Query {
         var triplets = new QueryTriplets ();
         triplets.add (new QueryTriplet (QUERY_ID, "a", category));
         triplets.add (new QueryTriplet (QUERY_ID, "a", "nie:DataObject"));
-        triplets.add (new QueryTriplet (QUERY_ID, "a", "nfo:FileDataObject"));
         triplets.add (new QueryTriplet (QUERY_ID, "nmm:uPnPShared", "true"));
         triplets.add (new QueryTriplet (QUERY_ID, "tracker:available", "true"));
         triplets.add (new QueryTriplet (QUERY_ID,
@@ -59,16 +58,13 @@ public class Rygel.Tracker.InsertionQuery : Query {
         if (item.size > 0) {
             triplets.add (new QueryTriplet
                                         (QUERY_ID,
-                                         "nfo:fileSize",
+                                         "nie:byteSize",
                                          "\"" + item.size.to_string () + "\""));
         }
 
         var now = TimeVal ();
         var date = now.to_iso8601 ();
         triplets.add (new QueryTriplet (QUERY_ID,
-                                        "nfo:fileLastModified",
-                                        "\"" + date + "\""));
-        triplets.add (new QueryTriplet (QUERY_ID,
                                         "nie:contentCreated",
                                         "\"" + date + "\""));
 
diff --git a/src/plugins/tracker/rygel-tracker-item-factory.vala b/src/plugins/tracker/rygel-tracker-item-factory.vala
index e6f7283..1958aa3 100644
--- a/src/plugins/tracker/rygel-tracker-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-item-factory.vala
@@ -33,6 +33,7 @@ using Gst;
 public abstract class Rygel.Tracker.ItemFactory {
     protected enum Metadata {
         URL,
+        PLACE_HOLDER,
         FILE_NAME,
         TITLE,
         DLNA_PROFILE,
@@ -69,6 +70,7 @@ public abstract class Rygel.Tracker.ItemFactory {
 
         // These must be the same order as enum Metadata
         this.properties.add ("res");
+        this.properties.add ("place_holder");
         this.properties.add ("fileName");
         this.properties.add ("dc:title");
         this.properties.add ("dlnaProfile");
@@ -100,6 +102,8 @@ public abstract class Rygel.Tracker.ItemFactory {
             // created).
             item.size = 0;
 
+        item.place_holder = bool.parse (metadata[Metadata.PLACE_HOLDER]);
+
         if (metadata[Metadata.DATE] != "")
             item.date = metadata[Metadata.DATE];
 
diff --git a/src/plugins/tracker/rygel-tracker-key-chain-map.vala b/src/plugins/tracker/rygel-tracker-key-chain-map.vala
index 9e5a5b2..8eaf3e2 100644
--- a/src/plugins/tracker/rygel-tracker-key-chain-map.vala
+++ b/src/plugins/tracker/rygel-tracker-key-chain-map.vala
@@ -25,25 +25,34 @@ using Gee;
 /**
  * A map of upnp properties to tracker property key chains
  */
-public class Rygel.Tracker.KeyChainMap : HashMap<string, ArrayList<string>> {
-    private static KeyChainMap key_chain_map;
+public class Rygel.Tracker.KeyChainMap : Object {
+    HashMap<string, ArrayList<string>> key_chain_map;
+    HashMap<string, string> functions;
+    private static KeyChainMap instance;
 
     public static KeyChainMap get_key_chain_map () {
-        if (unlikely (key_chain_map == null)) {
-            key_chain_map = new KeyChainMap ();
+        if (unlikely (instance == null)) {
+            instance = new KeyChainMap ();
         }
 
-        return key_chain_map;
+        return instance;
     }
 
     private KeyChainMap () {
+        this.key_chain_map = new HashMap<string, ArrayList<string>> ();
+        this.functions = new HashMap<string, string> ();
+
         // Item
         add_key_chain ("res", "nie:url");
+        add_function ("place_holder",
+                      "(NOT EXISTS { %s a nfo:FileDataObject })");
         add_key_chain ("fileName", "nfo:fileName");
         add_key_chain ("dc:title", "nie:title");
         add_key_chain ("dlnaProfile", "nmm:dlnaProfile");
         add_key_chain ("mimeType", "nie:mimeType");
-        add_key_chain ("res size", "nfo:fileSize");
+        add_function ("res size",
+                      "tracker:coalesce(nfo:fileSize(%1$s)," +
+                      "nie:byteSize(%1$s),\"\")");
         add_key_chain ("date", "nie:contentCreated");
 
         // Music Item
@@ -66,8 +75,12 @@ public class Rygel.Tracker.KeyChainMap : HashMap<string, ArrayList<string>> {
     public string map_property (string property) {
         var str = SelectionQuery.ITEM_VARIABLE;
 
-        foreach (var key in this[property]) {
-            str = key + "(" + str + ")";
+        if (this.key_chain_map.has_key (property)) {
+            foreach (var key in this.key_chain_map[property]) {
+                str = key + "(" + str + ")";
+            }
+        } else if (this.functions.has_key (property)) {
+            str = this.functions[property].printf (str);
         }
 
         return str;
@@ -85,7 +98,11 @@ public class Rygel.Tracker.KeyChainMap : HashMap<string, ArrayList<string>> {
             key = list.arg ();
         }
 
-        this[property] = key_chain;
+        this.key_chain_map[property] = key_chain;
+    }
+
+    private void add_function (string property, string function) {
+        this.functions[property] = function;
     }
 }
 



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