[rygel] core,plugins: Don't hardcode icon file extension



commit ddedbdb0b5363f32798436df38090a482c86816e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Aug 5 16:26:55 2010 +0300

    core,plugins: Don't hardcode icon file extension

 .../external/rygel-external-icon-factory.vala      |   13 ++++++++++++-
 src/plugins/tracker/rygel-tracker-plugin.vala      |    2 +-
 src/rygel/rygel-icon-info.vala                     |    4 +++-
 src/rygel/rygel-plugin.vala                        |   12 ++++++++----
 src/rygel/rygel-root-device-factory.vala           |    2 +-
 src/rygel/rygel-thumbnail.vala                     |    5 +++--
 6 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-icon-factory.vala b/src/plugins/external/rygel-external-icon-factory.vala
index c425bdf..6beb563 100644
--- a/src/plugins/external/rygel-external-icon-factory.vala
+++ b/src/plugins/external/rygel-external-icon-factory.vala
@@ -56,7 +56,8 @@ public class Rygel.External.IconFactory {
         }
 
         value = item_props.lookup ("MIMEType");
-        var icon = new IconInfo (value.get_string ());
+        var mime_type = value.get_string ();
+        var icon = new IconInfo (mime_type, this.get_ext_for_mime (mime_type));
 
         value = item_props.lookup ("URLs");
         weak string[] uris = (string[]) value.get_boxed ();
@@ -86,4 +87,14 @@ public class Rygel.External.IconFactory {
 
         return icon;
     }
+
+    private string get_ext_for_mime (string mime_type) {
+      if (mime_type == "image/jpeg") {
+            return "jpg";
+      } else if (mime_type == "image/gif") {
+            return "gif";
+      } else {
+            return "png"; // Assume PNG
+      }
+    }
 }
diff --git a/src/plugins/tracker/rygel-tracker-plugin.vala b/src/plugins/tracker/rygel-tracker-plugin.vala
index 2a6739a..dacd4c0 100644
--- a/src/plugins/tracker/rygel-tracker-plugin.vala
+++ b/src/plugins/tracker/rygel-tracker-plugin.vala
@@ -33,7 +33,7 @@ public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
               // and it doesn't need translation.
               _("@REALNAME@'s media"));
 
-        var icon_info = new IconInfo ("image/png");
+        var icon_info = new IconInfo ("image/png", "png");
 
         try {
             icon_info.uri = Filename.to_uri (ICON, null);
diff --git a/src/rygel/rygel-icon-info.vala b/src/rygel/rygel-icon-info.vala
index 0105404..556823b 100644
--- a/src/rygel/rygel-icon-info.vala
+++ b/src/rygel/rygel-icon-info.vala
@@ -27,14 +27,16 @@
 public class Rygel.IconInfo {
     public string mime_type;
     public string uri;
+    public string file_extension;
 
     public long size = -1;   // Size in bytes
     public int width = -1;   // Width in pixels
     public int height = -1;  // Height in pixels
     public int depth = -1;   // depth of pixels in bytes
 
-    public IconInfo (string mime_type) {
+    public IconInfo (string mime_type, string file_extension) {
         this.mime_type = mime_type;
+        this.file_extension = file_extension;
     }
 }
 
diff --git a/src/rygel/rygel-plugin.vala b/src/rygel/rygel-plugin.vala
index 98e10a8..4f0686b 100644
--- a/src/rygel/rygel-plugin.vala
+++ b/src/rygel/rygel-plugin.vala
@@ -29,12 +29,16 @@ using GUPnP;
  * class or a subclass.
  */
 public class Rygel.Plugin : GUPnP.ResourceFactory {
+    private static const string PNG_EXT = "png";
+
     private static const string ICON_BIG = "file://" +
                                            BuildConfig.BIG_ICON_DIR +
-                                           "/rygel.png";
+                                           "/rygel." +
+                                           PNG_EXT;
     private static const string ICON_SMALL = "file://" +
                                              BuildConfig.SMALL_ICON_DIR +
-                                             "/rygel.png";
+                                             "/rygel." +
+                                             PNG_EXT;
     private static const string ICON_MIME = "image/png";
     private static const int ICON_DEPTH = 32;
     private static const int ICON_BIG_WIDTH = 256;
@@ -75,14 +79,14 @@ public class Rygel.Plugin : GUPnP.ResourceFactory {
         this.icon_infos = new ArrayList<IconInfo> ();
         this.default_icons = new ArrayList<IconInfo> ();
 
-        var icon = new IconInfo (ICON_MIME);
+        var icon = new IconInfo (ICON_MIME, PNG_EXT);
         icon.uri = ICON_BIG;
         icon.width = ICON_BIG_WIDTH;
         icon.height = ICON_BIG_HEIGHT;
         icon.depth = ICON_DEPTH;
         this.default_icons.add (icon);
 
-        icon = new IconInfo (ICON_MIME);
+        icon = new IconInfo (ICON_MIME, PNG_EXT);
         icon.uri = ICON_SMALL;
         icon.width = ICON_SMALL_WIDTH;
         icon.height = ICON_SMALL_HEIGHT;
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index cb5f772..9cc0dc9 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -284,7 +284,7 @@ internal class Rygel.RootDeviceFactory {
             var remote_path = "/" + plugin.name + "-" +
                               width + "x" +
                               height + "x" +
-                              depth + ".png";
+                              depth + "." + icon_info.file_extension;
             var local_path = uri.offset (7);
 
             this.context.host_path (local_path, remote_path);
diff --git a/src/rygel/rygel-thumbnail.vala b/src/rygel/rygel-thumbnail.vala
index c83af73..15841e9 100644
--- a/src/rygel/rygel-thumbnail.vala
+++ b/src/rygel/rygel-thumbnail.vala
@@ -29,8 +29,9 @@ public class Rygel.Thumbnail : Rygel.IconInfo {
     public string dlna_profile;
 
     public Thumbnail (string mime_type = "image/jpeg",
-                      string dlna_profile = "JPEG_TN") {
-        base (mime_type);
+                      string dlna_profile = "JPEG_TN",
+                      string file_extension = "jpg") {
+        base (mime_type, file_extension);
 
         this.dlna_profile = dlna_profile;
     }



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