Tracker items fetch metadata at contruction time.
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Thu, 25 Dec 2008 11:59:15 +0000 (11:59 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Thu, 25 Dec 2008 11:59:15 +0000 (11:59 +0000)
svn path=/trunk/; revision=364

src/plugins/tracker/rygel-tracker-container.vala
src/plugins/tracker/rygel-tracker-image-item.vala
src/plugins/tracker/rygel-tracker-item.vala
src/plugins/tracker/rygel-tracker-music-item.vala
src/plugins/tracker/rygel-tracker-video-item.vala

index bfdd342..162aa4e 100644 (file)
@@ -160,18 +160,20 @@ public class Rygel.TrackerContainer : MediaContainer {
                                    string         path) {
         MediaItem item;
 
-        if (this.child_class == MediaItem.VIDEO_CLASS) {
-            item = new TrackerVideoItem (path,
-                                         path,
-                                         this);
-        } else if (this.child_class == MediaItem.IMAGE_CLASS) {
-            item = new TrackerImageItem (path,
-                                         path,
-                                         this);
-        } else {
-            item = new TrackerMusicItem (path,
-                                         path,
-                                         this);
+        try {
+            if (this.child_class == MediaItem.VIDEO_CLASS) {
+                item = new TrackerVideoItem (path, path, this);
+            } else if (this.child_class == MediaItem.IMAGE_CLASS) {
+                item = new TrackerImageItem (path, path, this);
+            } else {
+                item = new TrackerMusicItem (path, path, this);
+            }
+        } catch (GLib.Error error) {
+            critical ("Failed to fetch item %s. Reason: %s",
+                      item.id,
+                      error.message);
+
+            return false;
         }
 
         try {
index d826725..f8ec031 100644 (file)
@@ -33,9 +33,7 @@ using DBus;
 public class Rygel.TrackerImageItem : TrackerItem {
     public TrackerImageItem (string              id,
                              string              path,
-                             TrackerContainer    parent) {
-        base (id, path, parent);
-
+                             TrackerContainer    parent) throws GLib.Error {
         keys = new string[] {"File:Name",
                              "File:Mime",
                              "Image:Title",
@@ -45,10 +43,11 @@ public class Rygel.TrackerImageItem : TrackerItem {
                              "Image:Album",
                              "Image:Date",
                              "DC:Date"};
+
+        base (id, path, parent);
     }
 
-    public override void serialize (DIDLLiteWriter didl_writer)
-                                    throws GLib.Error {
+    public override void fetch_metadata () throws GLib.Error {
         string[] values = null;
 
         /* TODO: make this async */
@@ -84,8 +83,6 @@ public class Rygel.TrackerImageItem : TrackerItem {
         this.author = values[3];
         this.album = values[6];
         this.uri = this.uri_from_path (path);
-
-        base.serialize (didl_writer);
     }
 }
 
index ad4c49e..6f637fc 100644 (file)
@@ -38,11 +38,13 @@ public abstract class Rygel.TrackerItem : MediaItem {
 
     public TrackerItem (string           id,
                         string           path,
-                        TrackerContainer parent) {
+                        TrackerContainer parent) throws GLib.Error {
         base (id, parent.id, "", parent.child_class, parent.streamer);
 
         this.path = path;
         this.parent = parent;
+
+        this.fetch_metadata ();
     }
 
     protected string seconds_to_iso8601 (string seconds) {
@@ -65,5 +67,7 @@ public abstract class Rygel.TrackerItem : MediaItem {
     protected string uri_from_path (string path) {
         return "file://%s".printf (path);
     }
+
+    protected abstract void fetch_metadata () throws GLib.Error;
 }
 
index f6619fe..91fe115 100644 (file)
@@ -33,9 +33,7 @@ using DBus;
 public class Rygel.TrackerMusicItem : TrackerItem {
     public TrackerMusicItem (string              id,
                              string              path,
-                             TrackerContainer    parent) {
-        base (id, path, parent);
-
+                             TrackerContainer    parent) throws GLib.Error {
         keys = new string[] {"File:Name",
                              "File:Mime",
                              "Audio:Title",
@@ -45,10 +43,11 @@ public class Rygel.TrackerMusicItem : TrackerItem {
                              "Audio:ReleaseDate",
                              "Audio:DateAdded",
                              "DC:Date"};
+
+        base (id, path, parent);
     }
 
-    public override void serialize (DIDLLiteWriter didl_writer)
-                                    throws GLib.Error {
+    public override void fetch_metadata () throws GLib.Error {
         string[] values = null;
 
         /* TODO: make this async */
@@ -83,8 +82,6 @@ public class Rygel.TrackerMusicItem : TrackerItem {
         this.author = values[3];
         this.album = values[5];
         this.uri = this.uri_from_path (path);
-
-        base.serialize (didl_writer);
     }
 }
 
index 426b301..554f266 100644 (file)
@@ -33,9 +33,7 @@ using DBus;
 public class Rygel.TrackerVideoItem : TrackerItem {
     public TrackerVideoItem (string              id,
                              string              path,
-                             TrackerContainer    parent) {
-        base (id, path, parent);
-
+                             TrackerContainer    parent) throws GLib.Error {
         keys = new string[] {"File:Name",
                              "File:Mime",
                              "Video:Title",
@@ -43,10 +41,11 @@ public class Rygel.TrackerVideoItem : TrackerItem {
                              "Video:Width",
                              "Video:Height",
                              "DC:Date"};
+
+        base (id, path, parent);
     }
 
-    public override void serialize (DIDLLiteWriter didl_writer)
-                                    throws GLib.Error {
+    public override void fetch_metadata () throws GLib.Error {
         string[] values = null;
 
         /* TODO: make this async */
@@ -76,8 +75,6 @@ public class Rygel.TrackerVideoItem : TrackerItem {
         this.mime = values[1];
         this.author = values[3];
         this.uri = this.uri_from_path (path);
-
-        base.serialize (didl_writer);
     }
 }