[rygel] external: Use icon if provided by the service



commit 6c0a1bd9f3836b5c78fa5fd9a710f77807d7f08f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Oct 20 18:29:50 2009 +0300

    external: Use icon if provided by the service

 src/plugins/external/rygel-external-plugin.vala |   78 +++++++++++++++++++++--
 1 files changed, 71 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-plugin.vala b/src/plugins/external/rygel-external-plugin.vala
index 7b4c356..7bc9530 100644
--- a/src/plugins/external/rygel-external-plugin.vala
+++ b/src/plugins/external/rygel-external-plugin.vala
@@ -22,7 +22,11 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+using FreeDesktop;
+
 public class Rygel.ExternalPlugin : Rygel.Plugin {
+    private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1";
+
     public string service_name;
     public string root_object;
 
@@ -32,22 +36,82 @@ public class Rygel.ExternalPlugin : Rygel.Plugin {
         var root_object = "/" + service_name.replace (".", "/");
 
         // Create proxy to MediaObject iface to get the display name through
-        var obj = (ExternalMediaObject) connection.get_object (service_name,
-                                                               root_object);
+        var root_container = connection.get_object (service_name,
+                                                    root_object)
+                                                    as ExternalMediaContainer;
+
+        var icon = yield fetch_icon (connection, service_name, root_container);
 
         return new ExternalPlugin (service_name,
-                                   obj.display_name,
-                                   root_object);
+                                   root_container.display_name,
+                                   root_object,
+                                   icon);
     }
 
-    public ExternalPlugin (string service_name,
-                           string title,
-                           string root_object) {
+    public ExternalPlugin (string    service_name,
+                           string    title,
+                           string    root_object,
+                           IconInfo? icon) {
         base.MediaServer (service_name,
                           title,
                           typeof (ExternalContentDir));
 
         this.service_name = service_name;
         this.root_object = root_object;
+        if (icon != null) {
+            this.add_icon (icon);
+        }
+    }
+
+    public static async IconInfo? fetch_icon (
+                                        DBus.Connection        connection,
+                                        string                 service_name,
+                                        ExternalMediaContainer root_container) {
+        if (root_container.icon == null)
+            return null;
+
+        var props = connection.get_object (service_name,
+                                           root_container.icon)
+                                           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;
+        }
+
+        var 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]