gnome-panel r11587 - trunk/gnome-panel



Author: vuntz
Date: Tue Apr 14 20:05:50 2009
New Revision: 11587
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11587&view=rev

Log:
2009-04-14  Vincent Untz  <vuntz gnome org>

	Correctly handle icons for all locations in the menu, via the right use
	of GIcon. Fix bug #578859.

	* menu.c: (do_icons_to_add), (load_icons_handler): just use
	gtk_image_set_from_gicon() instead of trying to get an icon name or a
	pixbuf out of a GIcon
	* panel-util.[ch]: (panel_util_get_pixbuf_from_g_loadable_icon): killed
	(panel_util_get_icon_name_from_g_icon): make static


Modified:
   trunk/gnome-panel/ChangeLog
   trunk/gnome-panel/menu.c
   trunk/gnome-panel/panel-util.c
   trunk/gnome-panel/panel-util.h

Modified: trunk/gnome-panel/menu.c
==============================================================================
--- trunk/gnome-panel/menu.c	(original)
+++ trunk/gnome-panel/menu.c	Tue Apr 14 20:05:50 2009
@@ -61,6 +61,7 @@
 typedef struct {
 	GtkWidget   *image;
 	const char  *stock_id;
+	GIcon       *gicon;
 	GdkPixbuf   *pixbuf;
 	GtkIconSize  icon_size;
 } IconToAdd;
@@ -519,12 +520,17 @@
 
 		icons_to_add = g_list_delete_link (icons_to_add, icons_to_add);
 
-		if (icon_to_add->stock_id)
+		if (icon_to_add->stock_id) {
 			gtk_image_set_from_stock (
 				GTK_IMAGE (icon_to_add->image),
 				icon_to_add->stock_id,
 				icon_to_add->icon_size);
-		else {
+		} else if (icon_to_add->gicon) {
+			gtk_image_set_from_gicon (
+				GTK_IMAGE (icon_to_add->image),
+				icon_to_add->gicon,
+				icon_to_add->icon_size);
+		} else {
 			g_assert (icon_to_add->pixbuf);
 
 			gtk_image_set_from_pixbuf (
@@ -538,6 +544,8 @@
 			g_object_unref (icon_to_add->pixbuf);
 		}
 
+		if (icon_to_add->gicon)
+			g_object_unref (icon_to_add->gicon);
 		g_object_unref (icon_to_add->image);
 		g_free (icon_to_add);
 	}
@@ -571,7 +579,7 @@
 		goto load_icons_handler_again;
 	}
 
-	if (icon->stock_id) {
+	if (icon->stock_id || icon->gicon) {
 		IconToAdd *icon_to_add;
 
 		icon_to_add            = g_new (IconToAdd, 1);
@@ -579,54 +587,10 @@
 		icon_to_add->stock_id  = icon->stock_id;
 		icon_to_add->pixbuf    = NULL;
 		icon_to_add->icon_size = icon->icon_size;
-
-		icons_to_add = g_list_prepend (icons_to_add, icon_to_add);
-	} else if (icon->gicon) {
-		IconToAdd *icon_to_add;
-		char      *icon_name;
-		GdkPixbuf *pb;
-		int        icon_height = PANEL_DEFAULT_MENU_ICON_SIZE;
-
-		gtk_icon_size_lookup (icon->icon_size, NULL, &icon_height);
-
-		icon_name = panel_util_get_icon_name_from_g_icon (icon->gicon);
-
-		if (icon_name) {
-			pb = panel_make_menu_icon (icon->icon_theme,
-						   icon_name,
-						   icon->fallback_image,
-						   icon_height,
-						   &long_operation);
-			g_free (icon_name);
-		} else {
-			pb = panel_util_get_pixbuf_from_g_loadable_icon (icon->gicon, icon_height);
-			if (!pb && icon->fallback_image) {
-				pb = panel_make_menu_icon (icon->icon_theme,
-							   NULL,
-							   icon->fallback_image,
-							   icon_height,
-							   &long_operation);
-			}
-		}
-
-		if (!pb) {
-			icon_to_load_free (icon);
-			if (long_operation)
-				/* this may have been a long operation so jump
-				 * back to the main loop for a while */
-				return TRUE;
-			else
-				/* we didn't do anything long/hard, so just do
-				 * this again, this is fun, don't go back to
-				 * main loop */
-				goto load_icons_handler_again;
-		}
-
-		icon_to_add            = g_new (IconToAdd, 1);
-		icon_to_add->image     = g_object_ref (icon->pixmap);
-		icon_to_add->stock_id  = NULL;
-		icon_to_add->pixbuf    = pb;
-		icon_to_add->icon_size = icon->icon_size;
+		if (icon->gicon)
+			icon_to_add->gicon = g_object_ref (icon->gicon);
+		else
+			icon_to_add->gicon = NULL;
 
 		icons_to_add = g_list_prepend (icons_to_add, icon_to_add);
 	} else {
@@ -656,6 +620,7 @@
 		icon_to_add            = g_new (IconToAdd, 1);
 		icon_to_add->image     = g_object_ref (icon->pixmap);
 		icon_to_add->stock_id  = NULL;
+		icon_to_add->gicon     = NULL;
 		icon_to_add->pixbuf    = pb;
 		icon_to_add->icon_size = icon->icon_size;
 

Modified: trunk/gnome-panel/panel-util.c
==============================================================================
--- trunk/gnome-panel/panel-util.c	(original)
+++ trunk/gnome-panel/panel-util.c	Tue Apr 14 20:05:50 2009
@@ -771,7 +771,7 @@
 	return parent_old;
 }
 
-char *
+static char *
 panel_util_get_icon_name_from_g_icon (GIcon *gicon)
 {
 	const char * const *names;
@@ -792,46 +792,6 @@
 	return NULL;
 }
 
-GdkPixbuf *
-panel_util_get_pixbuf_from_g_loadable_icon (GIcon *gicon,
-					    int    size)
-{
-	GdkPixbuf    *pixbuf;
-	GInputStream *stream;
-
-	if (!G_IS_LOADABLE_ICON (gicon))
-		return NULL;
-
-	pixbuf = NULL;
-
-	stream = g_loadable_icon_load (G_LOADABLE_ICON (gicon),
-				       size,
-				       NULL, NULL, NULL);
-	if (stream) {
-		pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
-		g_object_unref (stream);
-	}
-
-	if (pixbuf) {
-		gint width, height;
-
-		width = gdk_pixbuf_get_width (pixbuf);
-		height = gdk_pixbuf_get_height (pixbuf);
-
-		if (width > size || height > size) {
-			GdkPixbuf *tmp;
-
-			tmp = gdk_pixbuf_scale_simple (pixbuf, size, size,
-						       GDK_INTERP_BILINEAR);
-
-			g_object_unref (pixbuf);
-			pixbuf = tmp;
-		}
-	}
-
-	return pixbuf;
-}
-
 static char *
 panel_util_get_file_display_name_if_mount (GFile *file)
 {

Modified: trunk/gnome-panel/panel-util.h
==============================================================================
--- trunk/gnome-panel/panel-util.h	(original)
+++ trunk/gnome-panel/panel-util.h	Tue Apr 14 20:05:50 2009
@@ -62,9 +62,6 @@
 void panel_util_set_tooltip_text (GtkWidget  *widget,
 				  const char *text);
 
-char *panel_util_get_icon_name_from_g_icon (GIcon *gicon);
-GdkPixbuf *panel_util_get_pixbuf_from_g_loadable_icon (GIcon *gicon,
-						       int    size);
 GFile *panel_util_get_file_optional_homedir (const char *location);
 
 G_END_DECLS



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