[alacarte/vala+garcon] really fix icon loading



commit e41a598a85c1a31188dbda68493b76d9aacd1410
Author: Travis Watkins <amaranth ubuntu com>
Date:   Sun May 17 16:19:01 2009 -0500

    really fix icon loading
    
    Add in code to strip extensions from icon names if they are
    common icon extensions like png. Also fix fallback handling
    to also load a default icon when the icon specified cannot be
    found instead of only when there is no icon specified.
---
 src/mainwindow.vala |   39 +++++++++++++++++++++++++++++----------
 1 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/mainwindow.vala b/src/mainwindow.vala
index 8eb659c..df0880a 100644
--- a/src/mainwindow.vala
+++ b/src/mainwindow.vala
@@ -33,21 +33,28 @@ public class MainWindow
 
 	private Gdk.Pixbuf? get_icon (Garcon.MenuElement item)
 	{
+		var icon_theme = Gtk.IconTheme.get_default ();
 		Gdk.Pixbuf pixbuf = null;
 
 		var icon_name = item.get_icon_name ();
-
-		if (icon_name == null)
-		{
-			if (item is Garcon.Menu)
-				icon_name = "gnome-fs-directory";
-			else if (item is Garcon.MenuItem)
-				icon_name = "application-default-icon";
-		}
-
 		if (icon_name != null)
 		{
-			var icon_theme = Gtk.IconTheme.get_default ();
+			// Strip extension if it is a common icon extension
+			if (!GLib.Path.is_absolute (icon_name))
+			{
+				if (icon_name.has_suffix (".xpm") ||
+					icon_name.has_suffix (".png") ||
+					icon_name.has_suffix (".jpg") ||
+					icon_name.has_suffix (".gif"))
+				{
+					var basename = GLib.Path.get_basename (icon_name);
+					var extension = basename.rchr (-1, '.');
+
+					if (extension != null)
+						icon_name = basename.substring (0, basename.size () - extension.size ());
+				}
+			}
+
 			try
 			{
 				pixbuf = icon_theme.load_icon (icon_name, 24, Gtk.IconLookupFlags.USE_BUILTIN);
@@ -59,6 +66,18 @@ public class MainWindow
 			}
 		}
 
+		if (pixbuf == null)
+		{
+			if (item is Garcon.Menu)
+				icon_name = "gnome-fs-directory";
+			else if (item is Garcon.MenuItem)
+				icon_name = "application-default-icon";
+			else
+				return null;
+
+			pixbuf = icon_theme.load_icon (icon_name, 24, Gtk.IconLookupFlags.USE_BUILTIN);
+		}
+
 		if (pixbuf != null)
 			pixbuf = pixbuf.scale_simple (24, 24, Gdk.InterpType.BILINEAR);
 



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