rygel r282 - in trunk: . src/media-providers/tracker



Author: zeeshanak
Date: Tue Nov 11 17:41:54 2008
New Revision: 282
URL: http://svn.gnome.org/viewvc/rygel?rev=282&view=rev

Log:
Refactor: Separate classes for each item type.

These tracker-specific item classes are responsible for fetching their metadata
and serializing it.

Added:
   trunk/src/media-providers/tracker/rygel-tracker-image-item.vala
   trunk/src/media-providers/tracker/rygel-tracker-music-item.vala
   trunk/src/media-providers/tracker/rygel-tracker-video-item.vala
Modified:
   trunk/ChangeLog
   trunk/src/media-providers/tracker/Makefile.am
   trunk/src/media-providers/tracker/rygel-tracker-container.vala

Modified: trunk/src/media-providers/tracker/Makefile.am
==============================================================================
--- trunk/src/media-providers/tracker/Makefile.am	(original)
+++ trunk/src/media-providers/tracker/Makefile.am	Tue Nov 11 17:41:54 2008
@@ -11,7 +11,13 @@
 		rygel-media-tracker.h \
 		rygel-media-tracker.c \
 		rygel-tracker-container.h \
-		rygel-tracker-container.c
+		rygel-tracker-container.c \
+		rygel-tracker-video-item.h \
+		rygel-tracker-video-item.c \
+		rygel-tracker-music-item.h \
+		rygel-tracker-music-item.c \
+		rygel-tracker-image-item.h \
+		rygel-tracker-image-item.c \
 		rygel-tracker-plugin.h \
 		rygel-tracker-plugin.c
 
@@ -21,6 +27,15 @@
 				    rygel-tracker-container.h \
 			            rygel-tracker-container.c \
 				    rygel-tracker-container.vala \
+                                    rygel-tracker-video-item.h \
+                                    rygel-tracker-video-item.c \
+                                    rygel-tracker-video-item.vala \
+                                    rygel-tracker-music-item.h \
+                                    rygel-tracker-music-item.c \
+                                    rygel-tracker-music-item.vala \
+                                    rygel-tracker-image-item.h \
+                                    rygel-tracker-image-item.c \
+                                    rygel-tracker-image-item.vala \
 				    rygel-tracker-plugin.h \
 			            rygel-tracker-plugin.c \
 				    rygel-tracker-plugin.vala

Modified: trunk/src/media-providers/tracker/rygel-tracker-container.vala
==============================================================================
--- trunk/src/media-providers/tracker/rygel-tracker-container.vala	(original)
+++ trunk/src/media-providers/tracker/rygel-tracker-container.vala	Tue Nov 11 17:41:54 2008
@@ -158,123 +158,27 @@
 
     public bool add_item_from_db (DIDLLiteWriter didl_writer,
                                    string         path) {
+        MediaItem item;
+
         if (this.child_class == MediaItem.VIDEO_CLASS) {
-            return this.add_video_item_from_db (didl_writer, path);
+            item = new TrackerVideoItem (this.root_id + ":" + path,
+                                         path,
+                                         this,
+                                         this.metadata,
+                                         this.context);
         } else if (this.child_class == MediaItem.IMAGE_CLASS) {
-            return this.add_image_item_from_db (didl_writer, path);
+            item = new TrackerImageItem (this.root_id + ":" + path,
+                                         path,
+                                         this,
+                                         this.metadata,
+                                         this.context);
         } else {
-            return this.add_music_item_from_db (didl_writer, path);
+            item = new TrackerMusicItem (this.root_id + ":" + path,
+                                         path,
+                                         this,
+                                         this.metadata,
+                                         this.context);
         }
-    }
-
-    private bool add_video_item_from_db (DIDLLiteWriter didl_writer,
-                                         string         path) {
-        string[] keys = new string[] {"File:Name",
-                                      "File:Mime",
-                                      "Video:Title",
-                                      "Video:Author",
-                                      "Video:Width",
-                                      "Video:Height",
-                                      "DC:Date"};
-
-        string[] values = null;
-
-        /* TODO: make this async */
-        try {
-            values = TrackerContainer.metadata.Get (this.tracker_category,
-                                                    path,
-                                                    keys);
-        } catch (GLib.Error error) {
-            critical ("failed to get metadata for %s: %s\n",
-                      path,
-                      error.message);
-
-            return false;
-        }
-
-        string title;
-        if (values[2] != "")
-            title = values[2];
-        else
-            /* If title wasn't provided, use filename instead */
-            title = values[0];
-
-        MediaItem item = new MediaItem (this.root_id + ":" + path,
-                                        this.id,
-                                        title,
-                                        this.child_class);
-
-        if (values[4] != "")
-            item.width = values[4].to_int ();
-
-        if (values[5] != "")
-            item.height = values[5].to_int ();
-
-        item.date = seconds_to_iso8601 (values[6]);
-        item.mime = values[1];
-        item.author = values[3];
-        item.uri = uri_from_path (path);
-
-        item.serialize (didl_writer);
-
-        return true;
-    }
-
-    private bool add_image_item_from_db (DIDLLiteWriter didl_writer,
-                                         string         path) {
-        string[] keys = new string[] {"File:Name",
-                                      "File:Mime",
-                                      "Image:Title",
-                                      "Image:Creator",
-                                      "Image:Width",
-                                      "Image:Height",
-                                      "Image:Album",
-                                      "Image:Date",
-                                      "DC:Date"};
-
-        string[] values = null;
-
-        /* TODO: make this async */
-        try {
-            values = TrackerContainer.metadata.Get (this.tracker_category,
-                                                    path,
-                                                    keys);
-        } catch (GLib.Error error) {
-            critical ("failed to get metadata for %s: %s\n",
-                      path,
-                      error.message);
-
-            return false;
-        }
-
-        string title;
-        if (values[2] != "")
-            title = values[2];
-        else
-            /* If title wasn't provided, use filename instead */
-            title = values[0];
-
-        MediaItem item = new MediaItem (this.root_id + ":" + path,
-                                        this.id,
-                                        title,
-                                        this.child_class);
-
-        if (values[4] != "")
-            item.width = values[4].to_int ();
-
-        if (values[5] != "")
-            item.height = values[5].to_int ();
-
-        if (values[8] != "") {
-            item.date = seconds_to_iso8601 (values[8]);
-        } else {
-            item.date = seconds_to_iso8601 (values[7]);
-        }
-
-        item.mime = values[1];
-        item.author = values[3];
-        item.album = values[6];
-        item.uri = uri_from_path (path);
 
         item.serialize (didl_writer);
 

Added: trunk/src/media-providers/tracker/rygel-tracker-image-item.vala
==============================================================================
--- (empty file)
+++ trunk/src/media-providers/tracker/rygel-tracker-image-item.vala	Tue Nov 11 17:41:54 2008
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+
+public class Rygel.TrackerImageItem : MediaItem {
+    private TrackerContainer parent;
+    private string path;
+    private GUPnP.Context context;
+
+    private dynamic DBus.Object metadata;
+
+    string[] keys;
+
+    public TrackerImageItem (string              id,
+                             string              path,
+                             TrackerContainer    parent,
+                             dynamic DBus.Object metadata,
+                             GUPnP.Context       context) {
+        this.id = id;
+        this.path = path;
+        this.parent = parent;
+        this.parent_id = parent.id;
+        this.upnp_class = parent.child_class;
+
+        this.metadata = metadata;
+        this.context = context;
+
+        keys = new string[] {"File:Name",
+                             "File:Mime",
+                             "Image:Title",
+                             "Image:Creator",
+                             "Image:Width",
+                             "Image:Height",
+                             "Image:Album",
+                             "Image:Date",
+                             "DC:Date"};
+    }
+
+    public override void serialize (DIDLLiteWriter didl_writer) {
+        string[] values = null;
+
+        /* TODO: make this async */
+        try {
+            values = this.metadata.Get (parent.tracker_category, path, keys);
+        } catch (GLib.Error error) {
+            critical ("failed to get metadata for %s: %s\n",
+                      path,
+                      error.message);
+
+            return;
+        }
+
+        if (values[2] != "")
+            this.title = values[2];
+        else
+            /* If title wasn't provided, use filename instead */
+            this.title = values[0];
+
+        if (values[4] != "")
+            this.width = values[4].to_int ();
+
+        if (values[5] != "")
+            this.height = values[5].to_int ();
+
+        if (values[8] != "") {
+            this.date = seconds_to_iso8601 (values[8]);
+        } else {
+            this.date = seconds_to_iso8601 (values[7]);
+        }
+
+        this.mime = values[1];
+        this.author = values[3];
+        this.album = values[6];
+        this.uri = this.uri_from_path (path);
+
+        base.serialize (didl_writer);
+    }
+
+    private string seconds_to_iso8601 (string seconds) {
+        string date;
+
+        if (seconds != "") {
+            TimeVal tv;
+
+            tv.tv_sec = seconds.to_int ();
+            tv.tv_usec = 0;
+
+            date = tv.to_iso8601 ();
+        } else {
+            date = "";
+        }
+
+        return date;
+    }
+
+    private string uri_from_path (string path) {
+        string escaped_path = Uri.escape_string (path, "/", true);
+
+        return "http://%s:%u%s".printf (this.context.host_ip,
+                                        this.context.port,
+                                        escaped_path);
+    }
+}
+

Added: trunk/src/media-providers/tracker/rygel-tracker-music-item.vala
==============================================================================
--- (empty file)
+++ trunk/src/media-providers/tracker/rygel-tracker-music-item.vala	Tue Nov 11 17:41:54 2008
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+
+public class Rygel.TrackerMusicItem : MediaItem {
+    private TrackerContainer parent;
+    private string path;
+    private GUPnP.Context context;
+
+    private dynamic DBus.Object metadata;
+
+    string[] keys;
+
+    public TrackerMusicItem (string              id,
+                             string              path,
+                             TrackerContainer    parent,
+                             dynamic DBus.Object metadata,
+                             GUPnP.Context       context) {
+        this.id = id;
+        this.path = path;
+        this.parent = parent;
+        this.parent_id = parent.id;
+        this.upnp_class = parent.child_class;
+
+        this.metadata = metadata;
+        this.context = context;
+
+        keys = new string[] {"File:Name",
+                             "File:Mime",
+                             "Audio:Title",
+                             "Audio:Artist",
+                             "Audio:TrackNo",
+                             "Audio:Album",
+                             "Audio:ReleaseDate",
+                             "Audio:DateAdded",
+                             "DC:Date"};
+    }
+
+    public override void serialize (DIDLLiteWriter didl_writer) {
+        string[] values = null;
+
+        /* TODO: make this async */
+        try {
+            values = this.metadata.Get (parent.tracker_category, path, keys);
+        } catch (GLib.Error error) {
+            critical ("failed to get metadata for %s: %s\n",
+                      path,
+                      error.message);
+
+            return;
+        }
+
+        if (values[2] != "")
+            this.title = values[2];
+        else
+            /* If title wasn't provided, use filename instead */
+            this.title = values[0];
+
+        if (values[4] != "")
+            this.track_number = values[4].to_int ();
+
+        if (values[8] != "") {
+            this.date = seconds_to_iso8601 (values[8]);
+        } else if (values[6] != "") {
+            this.date = seconds_to_iso8601 (values[6]);
+        } else {
+            this.date = seconds_to_iso8601 (values[7]);
+        }
+
+        this.mime = values[1];
+        this.author = values[3];
+        this.album = values[5];
+        this.uri = this.uri_from_path (path);
+
+        base.serialize (didl_writer);
+    }
+
+    private string seconds_to_iso8601 (string seconds) {
+        string date;
+
+        if (seconds != "") {
+            TimeVal tv;
+
+            tv.tv_sec = seconds.to_int ();
+            tv.tv_usec = 0;
+
+            date = tv.to_iso8601 ();
+        } else {
+            date = "";
+        }
+
+        return date;
+    }
+
+    private string uri_from_path (string path) {
+        string escaped_path = Uri.escape_string (path, "/", true);
+
+        return "http://%s:%u%s".printf (this.context.host_ip,
+                                        this.context.port,
+                                        escaped_path);
+    }
+}
+

Added: trunk/src/media-providers/tracker/rygel-tracker-video-item.vala
==============================================================================
--- (empty file)
+++ trunk/src/media-providers/tracker/rygel-tracker-video-item.vala	Tue Nov 11 17:41:54 2008
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+
+public class Rygel.TrackerVideoItem : MediaItem {
+    private TrackerContainer parent;
+    private string path;
+    private GUPnP.Context context;
+
+    private dynamic DBus.Object metadata;
+
+    string[] keys;
+
+    public TrackerVideoItem (string              id,
+                             string              path,
+                             TrackerContainer    parent,
+                             dynamic DBus.Object metadata,
+                             GUPnP.Context       context) {
+        this.id = id;
+        this.path = path;
+        this.parent = parent;
+        this.parent_id = parent.id;
+        this.upnp_class = parent.child_class;
+
+        this.metadata = metadata;
+        this.context = context;
+
+        keys = new string[] {"File:Name",
+                             "File:Mime",
+                             "Video:Title",
+                             "Video:Author",
+                             "Video:Width",
+                             "Video:Height",
+                             "DC:Date"};
+    }
+
+    public override void serialize (DIDLLiteWriter didl_writer) {
+        string[] values = null;
+
+        /* TODO: make this async */
+        try {
+            values = this.metadata.Get (parent.tracker_category, path, keys);
+        } catch (GLib.Error error) {
+            critical ("failed to get metadata for %s: %s\n",
+                      path,
+                      error.message);
+
+            return;
+        }
+
+        if (values[2] != "")
+            this.title = values[2];
+        else
+            /* If title wasn't provided, use filename instead */
+            this.title = values[0];
+
+        if (values[4] != "")
+            this.width = values[4].to_int ();
+
+        if (values[5] != "")
+            this.height = values[5].to_int ();
+
+        this.date = this.seconds_to_iso8601 (values[6]);
+        this.mime = values[1];
+        this.author = values[3];
+        this.uri = this.uri_from_path (path);
+
+        base.serialize (didl_writer);
+    }
+
+    private string seconds_to_iso8601 (string seconds) {
+        string date;
+
+        if (seconds != "") {
+            TimeVal tv;
+
+            tv.tv_sec = seconds.to_int ();
+            tv.tv_usec = 0;
+
+            date = tv.to_iso8601 ();
+        } else {
+            date = "";
+        }
+
+        return date;
+    }
+
+    private string uri_from_path (string path) {
+        string escaped_path = Uri.escape_string (path, "/", true);
+
+        return "http://%s:%u%s".printf (this.context.host_ip,
+                                        this.context.port,
+                                        escaped_path);
+    }
+}
+



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