[rygel] external: Turn ExternalItem class into a factory



commit 5624b2588e3bbabec3335b44294b4c2f9cec4591
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Oct 25 02:10:51 2009 +0300

    external: Turn ExternalItem class into a factory

 src/plugins/external/Makefile.am                   |    2 +-
 src/plugins/external/rygel-external-container.vala |    8 +-
 ...-item.vala => rygel-external-item-factory.vala} |  118 ++++++++-----------
 3 files changed, 56 insertions(+), 72 deletions(-)
---
diff --git a/src/plugins/external/Makefile.am b/src/plugins/external/Makefile.am
index bbb1ebb..3236b2b 100644
--- a/src/plugins/external/Makefile.am
+++ b/src/plugins/external/Makefile.am
@@ -17,7 +17,7 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
 
 librygel_external_la_SOURCES = rygel-external-content-dir.vala \
 			       rygel-external-container.vala \
-			       rygel-external-item.vala \
+			       rygel-external-item-factory.vala \
 			       rygel-external-thumbnail-factory.vala \
 			       rygel-external-plugin.vala \
 			       rygel-external-interfaces.vala \
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index b680221..83f6071 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -86,7 +86,8 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
         var obj_paths = this.actual_container.items;
         foreach (var obj_path in obj_paths) {
             try {
-                var item = yield ExternalItem.create_for_path (obj_path, this);
+                var factory = new ExternalItemFactory ();
+                var item = yield factory.create_for_path (obj_path, this);
 
                 media_objects.add (item);
             } catch (GLib.Error err) {
@@ -106,8 +107,9 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
                                                     Cancellable? cancellable)
                                                     throws GLib.Error {
         MediaObject media_object = find_container (id);
-        if (media_object == null && ExternalItem.id_valid (id)) {
-            media_object = yield ExternalItem.create_for_id (id, this);
+        if (media_object == null && ExternalItemFactory.id_valid (id)) {
+            var factory = new ExternalItemFactory ();
+            media_object = yield factory.create_for_id (id, this);
         }
 
         return media_object;
diff --git a/src/plugins/external/rygel-external-item.vala b/src/plugins/external/rygel-external-item-factory.vala
similarity index 55%
rename from src/plugins/external/rygel-external-item.vala
rename to src/plugins/external/rygel-external-item-factory.vala
index 9e9c3f5..1af410a 100644
--- a/src/plugins/external/rygel-external-item.vala
+++ b/src/plugins/external/rygel-external-item-factory.vala
@@ -27,32 +27,31 @@ using DBus;
 using FreeDesktop;
 
 /**
- * Represents External item.
+ * Creates item for external plugins.
  */
-public class Rygel.ExternalItem : Rygel.MediaItem {
+public class Rygel.ExternalItemFactory {
     private static string OBJECT_IFACE = "org.gnome.UPnP.MediaObject1";
     private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1";
 
-    public static async ExternalItem create_for_path (
-                                        string            object_path,
-                                        ExternalContainer parent)
-                                        throws GLib.Error {
-        return yield create ("item:" + object_path, object_path, parent);
+    public async MediaItem create_for_path (string            object_path,
+                                            ExternalContainer parent)
+                                            throws GLib.Error {
+        return yield this.create ("item:" + object_path, object_path, parent);
     }
 
-    public static async ExternalItem create_for_id (string            id,
-                                                    ExternalContainer parent)
-                                                    throws GLib.Error {
+    public async MediaItem create_for_id (string            id,
+                                          ExternalContainer parent)
+                                          throws GLib.Error {
         var object_path = id.str ("/");
         assert (object_path != null);
 
-        return yield create (id, object_path, parent);
+        return yield this.create (id, object_path, parent);
     }
 
-    private static async ExternalItem create (string            id,
-                                              string            object_path,
-                                              ExternalContainer parent)
-                                              throws GLib.Error {
+    private async MediaItem create (string            id,
+                                    string            object_path,
+                                    ExternalContainer parent)
+                                    throws GLib.Error {
         DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
 
         var props = connection.get_object (parent.service_name,
@@ -62,54 +61,28 @@ public class Rygel.ExternalItem : Rygel.MediaItem {
         var object_props = yield props.get_all (OBJECT_IFACE);
         var item_props = yield props.get_all (ITEM_IFACE);
 
-        Thumbnail thumbnail = null;
-        var value = item_props.lookup ("Thumbnail");
-        if (value != null) {
-            var thumbnail_path = value.get_string ();
-
-            var factory = new ExternalThumbnailFactory ();
-            thumbnail = yield factory.create (thumbnail_path,
-                                              parent.service_name,
-                                              parent.host_ip);
-        }
-
-        return new ExternalItem (id,
-                                 object_path,
-                                 parent,
-                                 object_props,
-                                 item_props,
-                                 thumbnail);
-    }
-
-    private ExternalItem (string                   id,
-                          string                   object_path,
-                          ExternalContainer        parent,
-                          HashTable<string,Value?> object_props,
-                          HashTable<string,Value?> item_props,
-                          Thumbnail?               thumbnail)
-                          throws GLib.Error {
-        base (id,
-              parent,
-              "Unknown",        /* Title Unknown at this point */
-              "Unknown");       /* UPnP Class Unknown at this point */
+        var item = new MediaItem (id,
+                                  parent,
+                                  "Unknown",  /* Title Unknown atm */
+                                  "Unknown"); /* UPnP Class Unknown atm */
 
         var value = object_props.lookup ("DisplayName");
-        this.title = parent.substitute_keywords (value.get_string ());
+        item.title = parent.substitute_keywords (value.get_string ());
 
         value = item_props.lookup ("Type");
         string type = value.get_string ();
         if (type == "audio") {
-            this.upnp_class = MediaItem.AUDIO_CLASS;
+            item.upnp_class = MediaItem.AUDIO_CLASS;
         } else if (type == "music") {
-            this.upnp_class = MediaItem.MUSIC_CLASS;
+            item.upnp_class = MediaItem.MUSIC_CLASS;
         } else if (type == "video") {
-            this.upnp_class = MediaItem.VIDEO_CLASS;
+            item.upnp_class = MediaItem.VIDEO_CLASS;
         } else {
-            this.upnp_class = MediaItem.IMAGE_CLASS;
+            item.upnp_class = MediaItem.IMAGE_CLASS;
         }
 
         value = item_props.lookup ("MIMEType");
-        this.mime_type = value.get_string ();
+        item.mime_type = value.get_string ();
 
         value = item_props.lookup ("URLs");
         weak string[] uris = (string[]) value.get_boxed ();
@@ -117,7 +90,7 @@ public class Rygel.ExternalItem : Rygel.MediaItem {
         for (var i = 0; uris[i] != null; i++) {
             var tmp = uris[i].replace ("@ADDRESS@", parent.host_ip);
 
-            this.add_uri (tmp, null);
+            item.add_uri (tmp, null);
         }
 
         // Optional properties
@@ -131,81 +104,90 @@ public class Rygel.ExternalItem : Rygel.MediaItem {
 
         value = item_props.lookup ("DLNAProfile");
         if (value != null) {
-            this.dlna_profile = value.get_string ();
+            item.dlna_profile = value.get_string ();
         }
 
         value = item_props.lookup ("Size");
         if (value != null) {
-            this.size = value.get_int ();
+            item.size = value.get_int ();
         }
 
         value = item_props.lookup ("Artist");
         if (value != null) {
-            this.author = value.get_string ();
+            item.author = value.get_string ();
         }
 
         value = item_props.lookup ("Album");
         if (value != null) {
-            this.album = value.get_string ();
+            item.album = value.get_string ();
         }
 
         value = item_props.lookup ("Date");
         if (value != null) {
-            this.date = value.get_string ();
+            item.date = value.get_string ();
         }
 
         // Properties specific to video and audio/music
 
         value = item_props.lookup ("Duration");
         if (value != null) {
-            this.duration = value.get_int ();
+            item.duration = value.get_int ();
         }
 
         value = item_props.lookup ("Bitrate");
         if (value != null) {
-            this.bitrate = value.get_int ();
+            item.bitrate = value.get_int ();
         }
 
         value = item_props.lookup ("SampleRate");
         if (value != null) {
-            this.sample_freq = value.get_int ();
+            item.sample_freq = value.get_int ();
         }
 
         value = item_props.lookup ("BitsPerSample");
         if (value != null) {
-            this.bits_per_sample = value.get_int ();
+            item.bits_per_sample = value.get_int ();
         }
 
         // Properties specific to video and image
 
         value = item_props.lookup ("Width");
         if (value != null) {
-            this.width = value.get_int ();
+            item.width = value.get_int ();
         }
 
         value = item_props.lookup ("Height");
         if (value != null) {
-            this.height = value.get_int ();
+            item.height = value.get_int ();
         }
 
         value = item_props.lookup ("ColorDepth");
         if (value != null) {
-            this.color_depth = value.get_int ();
+            item.color_depth = value.get_int ();
         }
 
         value = item_props.lookup ("PixelWidth");
         if (value != null) {
-            this.pixel_width = value.get_int ();
+            item.pixel_width = value.get_int ();
         }
 
         value = item_props.lookup ("PixelHeight");
         if (value != null) {
-            this.pixel_height = value.get_int ();
+            item.pixel_height = value.get_int ();
         }
 
-        if (thumbnail != null) {
-            this.thumbnails.add (thumbnail);
+        value = item_props.lookup ("Thumbnail");
+        if (value != null) {
+            var thumbnail_path = value.get_string ();
+
+            var factory = new ExternalThumbnailFactory ();
+            var thumbnail = yield factory.create (thumbnail_path,
+                                                  parent.service_name,
+                                                  parent.host_ip);
+            item.thumbnails.add (thumbnail);
         }
+
+        return item;
     }
 
     public static bool id_valid (string id) {



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