[rygel] tracker: Only ask for relavent metadata



commit de879dc1541d81743f332e357a870f14d3ba6c46
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Dec 1 01:43:58 2009 +0200

    tracker: Only ask for relavent metadata
    
    This is not just smart thing to do anyways as it will decrease D-Bus
    traffic but is also necessary due to a bug in tracker.

 .../tracker/rygel-tracker-image-item-factory.vala  |   31 +++++++++++---
 .../tracker/rygel-tracker-item-factory.vala        |   26 +------------
 .../tracker/rygel-tracker-music-item-factory.vala  |   41 +++++++++++++++----
 .../tracker/rygel-tracker-search-container.vala    |    2 +-
 .../tracker/rygel-tracker-video-item-factory.vala  |   35 ++++++++++++++---
 5 files changed, 87 insertions(+), 48 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-image-item-factory.vala b/src/plugins/tracker/rygel-tracker-image-item-factory.vala
index f355779..243006c 100644
--- a/src/plugins/tracker/rygel-tracker-image-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-image-item-factory.vala
@@ -28,6 +28,13 @@ using DBus;
  * Tracker image item factory.
  */
 public class Rygel.TrackerImageItemFactory : Rygel.TrackerItemFactory {
+    private enum ImageMetadata {
+        HEIGHT = Metadata.LAST_KEY,
+        WIDTH,
+
+        LAST_KEY
+    }
+
     private const string CATEGORY = "nmm:Photo";
 
     public TrackerImageItemFactory () {
@@ -41,17 +48,27 @@ public class Rygel.TrackerImageItemFactory : Rygel.TrackerItemFactory {
                                       throws GLib.Error {
         var item = base.create (id, path, parent, metadata);
 
-        if (metadata[Metadata.WIDTH] != "")
-            item.width = metadata[Metadata.WIDTH].to_int ();
+        if (metadata[ImageMetadata.WIDTH] != "")
+            item.width = metadata[ImageMetadata.WIDTH].to_int ();
 
-        if (metadata[Metadata.HEIGHT] != "")
-            item.height = metadata[Metadata.HEIGHT].to_int ();
+        if (metadata[ImageMetadata.HEIGHT] != "")
+            item.height = metadata[ImageMetadata.HEIGHT].to_int ();
 
-        if (metadata[Metadata.DATE] != "") {
-            item.date = seconds_to_iso8601 (metadata[Metadata.DATE]);
+        return item;
+    }
+
+    public override string[] get_metadata_keys () {
+        var base_keys = base.get_metadata_keys ();
+
+        var keys = new string[ImageMetadata.LAST_KEY];
+        for (var i = 0; i < base_keys.length; i++) {
+            keys[i] = base_keys[i];
         }
 
-        return item;
+        keys[ImageMetadata.WIDTH] = "nfo:width";
+        keys[ImageMetadata.HEIGHT] = "nfo:height";
+
+        return keys;
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-item-factory.vala b/src/plugins/tracker/rygel-tracker-item-factory.vala
index a199141..2c5c804 100644
--- a/src/plugins/tracker/rygel-tracker-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-item-factory.vala
@@ -35,18 +35,6 @@ public abstract class Rygel.TrackerItemFactory {
         SIZE,
         DATE,
 
-        // Image and Video
-        HEIGHT,
-        WIDTH,
-
-        // Audio and Video
-        DURATION,
-
-        // Audio
-        AUDIO_ALBUM,
-        AUDIO_ARTIST,
-        AUDIO_TRACK_NUM,
-
         LAST_KEY
     }
 
@@ -85,7 +73,7 @@ public abstract class Rygel.TrackerItemFactory {
         return item;
     }
 
-    public static string[] get_metadata_keys () {
+    public virtual string[] get_metadata_keys () {
         string[] keys = new string[Metadata.LAST_KEY];
         keys[Metadata.FILE_NAME] = "nfo:fileName";
         keys[Metadata.TITLE] = "nie:title";
@@ -93,18 +81,6 @@ public abstract class Rygel.TrackerItemFactory {
         keys[Metadata.SIZE] = "nfo:fileSize";
         keys[Metadata.DATE] = "dc:date";
 
-        // Image and Video metadata
-        keys[Metadata.WIDTH] = "nfo:width";
-        keys[Metadata.HEIGHT] = "nfo:height";
-
-        // Audio and Video metadata
-        keys[Metadata.DURATION] = "nmm:length";
-
-        // Audio metadata
-        keys[Metadata.AUDIO_ARTIST] = "nmm:performer";
-        keys[Metadata.AUDIO_ALBUM] = "nmm:musicAlbum";
-        keys[Metadata.AUDIO_TRACK_NUM] = "nmm:trackNumber";
-
         return keys;
     }
 
diff --git a/src/plugins/tracker/rygel-tracker-music-item-factory.vala b/src/plugins/tracker/rygel-tracker-music-item-factory.vala
index 86c4b96..3941fd9 100644
--- a/src/plugins/tracker/rygel-tracker-music-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-music-item-factory.vala
@@ -28,6 +28,15 @@ using DBus;
  * Tracker music item factory.
  */
 public class Rygel.TrackerMusicItemFactory : Rygel.TrackerItemFactory {
+    private enum MusicMetadata {
+        DURATION = Metadata.LAST_KEY,
+        AUDIO_ALBUM,
+        AUDIO_ARTIST,
+        AUDIO_TRACK_NUM,
+
+        LAST_KEY
+    }
+
     private const string CATEGORY = "nmm:MusicPiece";
 
     public TrackerMusicItemFactory () {
@@ -41,20 +50,34 @@ public class Rygel.TrackerMusicItemFactory : Rygel.TrackerItemFactory {
                                       throws GLib.Error {
         var item = base.create (id, path, parent, metadata);
 
-        if (metadata[Metadata.DURATION] != "")
-            item.duration = metadata[Metadata.DURATION].to_int ();
+        if (metadata[MusicMetadata.DURATION] != "")
+            item.duration = metadata[MusicMetadata.DURATION].to_int ();
 
-        if (metadata[Metadata.AUDIO_TRACK_NUM] != "")
-            item.track_number = metadata[Metadata.AUDIO_TRACK_NUM].to_int ();
-
-        if (metadata[Metadata.DATE] != "") {
-            item.date = seconds_to_iso8601 (metadata[Metadata.DATE]);
+        if (metadata[MusicMetadata.AUDIO_TRACK_NUM] != "") {
+            var track_number = metadata[MusicMetadata.AUDIO_TRACK_NUM];
+            item.track_number = track_number.to_int ();
         }
 
-        item.author = metadata[Metadata.AUDIO_ARTIST];
-        item.album = metadata[Metadata.AUDIO_ALBUM];
+        item.author = metadata[MusicMetadata.AUDIO_ARTIST];
+        item.album = metadata[MusicMetadata.AUDIO_ALBUM];
 
         return item;
     }
+
+    public override string[] get_metadata_keys () {
+        var base_keys = base.get_metadata_keys ();
+
+        var keys = new string[MusicMetadata.LAST_KEY];
+        for (var i = 0; i < base_keys.length; i++) {
+            keys[i] = base_keys[i];
+        }
+
+        keys[MusicMetadata.DURATION] = "nmm:length";
+        keys[MusicMetadata.AUDIO_ARTIST] = "nmm:performer";
+        keys[MusicMetadata.AUDIO_ALBUM] = "nmm:musicAlbum";
+        keys[MusicMetadata.AUDIO_TRACK_NUM] = "nmm:trackNumber";
+
+        return keys;
+    }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 41bb3c0..aab80da 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -66,7 +66,7 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
                                                     false));
 
         var optional = new TrackerQueryTriplets ();
-        foreach (var key in TrackerItemFactory.get_metadata_keys ()) {
+        foreach (var key in this.item_factory.get_metadata_keys ()) {
             var variable = "?" + key.replace (":", "_");
 
             variables.add (variable);
diff --git a/src/plugins/tracker/rygel-tracker-video-item-factory.vala b/src/plugins/tracker/rygel-tracker-video-item-factory.vala
index 95ca114..8004029 100644
--- a/src/plugins/tracker/rygel-tracker-video-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-video-item-factory.vala
@@ -28,6 +28,14 @@ using DBus;
  * Tracker video item factory.
  */
 public class Rygel.TrackerVideoItemFactory : Rygel.TrackerItemFactory {
+    private enum VideoMetadata {
+        HEIGHT = Metadata.LAST_KEY,
+        WIDTH,
+        DURATION,
+
+        LAST_KEY
+    }
+
     private const string CATEGORY = "nmm:Video";
 
     public TrackerVideoItemFactory () {
@@ -41,16 +49,31 @@ public class Rygel.TrackerVideoItemFactory : Rygel.TrackerItemFactory {
                                       throws GLib.Error {
         var item = base.create (id, path, parent, metadata);
 
-        if (metadata[Metadata.WIDTH] != "")
-            item.width = metadata[Metadata.WIDTH].to_int ();
+        if (metadata[VideoMetadata.WIDTH] != "")
+            item.width = metadata[VideoMetadata.WIDTH].to_int ();
 
-        if (metadata[Metadata.HEIGHT] != "")
-            item.height = metadata[Metadata.HEIGHT].to_int ();
+        if (metadata[VideoMetadata.HEIGHT] != "")
+            item.height = metadata[VideoMetadata.HEIGHT].to_int ();
 
-        if (metadata[Metadata.DURATION] != "")
-            item.duration = metadata[Metadata.DURATION].to_int ();
+        if (metadata[VideoMetadata.DURATION] != "")
+            item.duration = metadata[VideoMetadata.DURATION].to_int ();
 
         return item;
     }
+
+    public override string[] get_metadata_keys () {
+        var base_keys = base.get_metadata_keys ();
+
+        var keys = new string[VideoMetadata.LAST_KEY];
+        for (var i = 0; i < base_keys.length; i++) {
+            keys[i] = base_keys[i];
+        }
+
+        keys[VideoMetadata.WIDTH] = "nfo:width";
+        keys[VideoMetadata.HEIGHT] = "nfo:height";
+        keys[VideoMetadata.DURATION] = "nmm:length";
+
+        return keys;
+    }
 }
 



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