[rygel] external: Separate factory for icon info fetching



commit f5395231e1ed48fe222f00ce19a9f48fd06b5289
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Oct 21 00:11:08 2009 +0300

    external: Separate factory for icon info fetching

 src/plugins/external/Makefile.am                   |    3 +-
 .../external/rygel-external-icon-factory.vala      |   89 ++++++++++++++++++++
 .../external/rygel-external-plugin-factory.vala    |   68 ++-------------
 3 files changed, 98 insertions(+), 62 deletions(-)
---
diff --git a/src/plugins/external/Makefile.am b/src/plugins/external/Makefile.am
index 9974cef..81efc51 100644
--- a/src/plugins/external/Makefile.am
+++ b/src/plugins/external/Makefile.am
@@ -21,7 +21,8 @@ librygel_external_la_SOURCES = rygel-external-content-dir.vala \
 			       rygel-external-thumbnail.vala \
 			       rygel-external-plugin.vala \
 			       rygel-external-interfaces.vala \
-			       rygel-external-plugin-factory.vala
+			       rygel-external-plugin-factory.vala \
+			       rygel-external-icon-factory.vala
 
 rygel-external.stamp: $(librygel_external_la_VALASOURCES)
 librygel_external_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \
diff --git a/src/plugins/external/rygel-external-icon-factory.vala b/src/plugins/external/rygel-external-icon-factory.vala
new file mode 100644
index 0000000..a7e05af
--- /dev/null
+++ b/src/plugins/external/rygel-external-icon-factory.vala
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2009 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+using FreeDesktop;
+
+public class Rygel.ExternalIconFactory {
+    private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1";
+
+    DBus.Connection connection;
+
+    public ExternalIconFactory (DBus.Connection connection) {
+        this.connection = connection;
+    }
+
+    public async IconInfo? create (string                   service_name,
+                                   HashTable<string,Value?> container_props) {
+        var value = container_props.lookup ("Icon");
+        if (value == null) {
+            // Seems no icon is provided, nevermind
+            return null;
+        }
+
+        var icon_path = value.get_string ();
+        var props = this.connection.get_object (service_name,
+                                                icon_path)
+                                                as Properties;
+
+        HashTable<string,Value?> item_props;
+        try {
+            item_props = yield props.get_all (ITEM_IFACE);
+        } catch (DBus.Error err) {
+            warning ("Error fetching icon properties from %s", service_name);
+
+            return null;
+        }
+
+        value = item_props.lookup ("MIMEType");
+        var icon = new IconInfo (value.get_string ());
+
+        value = item_props.lookup ("URLs");
+        weak string[] uris = (string[]) value.get_boxed ();
+        if (uris != null && uris[0] != null) {
+            icon.uri = uris[0];
+        }
+
+        value = item_props.lookup ("Size");
+        if (value != null) {
+            icon.size = value.get_int ();
+        }
+
+        value = item_props.lookup ("Width");
+        if (value != null) {
+            icon.width = value.get_int ();
+        }
+
+        value = item_props.lookup ("Height");
+        if (value != null) {
+            icon.height = value.get_int ();
+        }
+
+        value = item_props.lookup ("ColorDepth");
+        if (value != null) {
+            icon.depth = value.get_int ();
+        }
+
+        return icon;
+    }
+}
diff --git a/src/plugins/external/rygel-external-plugin-factory.vala b/src/plugins/external/rygel-external-plugin-factory.vala
index 28cc4b3..73b10d6 100644
--- a/src/plugins/external/rygel-external-plugin-factory.vala
+++ b/src/plugins/external/rygel-external-plugin-factory.vala
@@ -45,16 +45,17 @@ public class ExternalPluginFactory {
 
     private static string OBJECT_IFACE = "org.gnome.UPnP.MediaObject1";
     private static string CONTAINER_IFACE = "org.gnome.UPnP.MediaContainer1";
-    private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1";
 
     private const string SERVICE_PREFIX = "org.gnome.UPnP.MediaServer1.";
 
-    DBusObject      dbus_obj;
-    DBus.Connection connection;
-    PluginLoader    loader;
+    DBusObject          dbus_obj;
+    DBus.Connection     connection;
+    PluginLoader        loader;
+    ExternalIconFactory icon_factory;
 
     public ExternalPluginFactory (PluginLoader loader) throws DBus.Error {
         this.connection = DBus.Bus.get (DBus.BusType.SESSION);
+        this.icon_factory = new ExternalIconFactory (this.connection);
 
         this.dbus_obj = connection.get_object (DBUS_SERVICE,
                                                DBUS_OBJECT)
@@ -136,7 +137,8 @@ public class ExternalPluginFactory {
             return;
         }
 
-        var icon = yield fetch_icon (connection, service_name, container_props);
+        var icon = yield this.icon_factory.create (service_name,
+                                                   container_props);
 
         string title;
         var value = object_props.lookup ("DisplayName");
@@ -153,60 +155,4 @@ public class ExternalPluginFactory {
 
         this.loader.add_plugin (plugin);
     }
-
-    public async IconInfo? fetch_icon (DBus.Connection connection,
-                                       string          service_name,
-                                       HashTable<string,Value?>
-                                                       container_props) {
-        var value = container_props.lookup ("Icon");
-        if (value == null) {
-            // Seems no icon is provided, nevermind
-            return null;
-        }
-
-        var icon_path = value.get_string ();
-        var props = connection.get_object (service_name,
-                                           icon_path)
-                                           as Properties;
-
-        HashTable<string,Value?> item_props;
-        try {
-            item_props = yield props.get_all (ITEM_IFACE);
-        } catch (DBus.Error err) {
-            warning ("Error fetching icon properties from %s", service_name);
-
-            return null;
-        }
-
-        value = item_props.lookup ("MIMEType");
-        var icon = new IconInfo (value.get_string ());
-
-        value = item_props.lookup ("URLs");
-        weak string[] uris = (string[]) value.get_boxed ();
-        if (uris != null && uris[0] != null) {
-            icon.uri = uris[0];
-        }
-
-        value = item_props.lookup ("Size");
-        if (value != null) {
-            icon.size = value.get_int ();
-        }
-
-        value = item_props.lookup ("Width");
-        if (value != null) {
-            icon.width = value.get_int ();
-        }
-
-        value = item_props.lookup ("Height");
-        if (value != null) {
-            icon.height = value.get_int ();
-        }
-
-        value = item_props.lookup ("ColorDepth");
-        if (value != null) {
-            icon.depth = value.get_int ();
-        }
-
-        return icon;
-    }
 }



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