changeset 14144:92f5e6f3acfb

[gaim-migrate @ 16786] More/better assertion fixes. Especially when starting Gaim with an account that doesn't have the global buddy icon preference set, or when trying to set an icon using a file that is not an image. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 16 Aug 2006 07:19:41 +0000
parents 11394a70de37
children 6958202c8ee6
files src/gtkstatusbox.c src/gtkutils.c
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkstatusbox.c	Wed Aug 16 07:02:26 2006 +0000
+++ b/src/gtkstatusbox.c	Wed Aug 16 07:19:41 2006 +0000
@@ -1179,16 +1179,19 @@
 	icon_alc.x = allocation->width - icon_alc.width;
 	icon_alc.y += 3;
 
-	if ((status_box->buddy_icon_path != NULL) &&
-		(status_box->icon_size != icon_alc.height))
+	if (status_box->icon_size != icon_alc.height)
 	{
-		scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path,
-							   icon_alc.height, icon_alc.width, FALSE, NULL);
-		status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled);
-		do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30);
-		g_object_unref(status_box->buddy_icon);
-		status_box->buddy_icon = scaled;
-		gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon);
+		if ((status_box->buddy_icon_path != NULL) &&
+			(*status_box->buddy_icon_path != '\0'))
+		{
+			scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path,
+								   icon_alc.height, icon_alc.width, FALSE, NULL);
+			status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled);
+			do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30);
+			g_object_unref(status_box->buddy_icon);
+			status_box->buddy_icon = scaled;
+			gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon);
+		}
 		status_box->icon_size = icon_alc.height;
 	}
 	gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->icon_box, &icon_alc);
@@ -1337,15 +1340,19 @@
 	g_free(box->buddy_icon_path);
 	box->buddy_icon_path = g_strdup(filename);
 
-	if (filename != NULL)
+	if ((filename != NULL) && (*filename != '\0'))
 	{
+		if (box->buddy_icon != NULL)
+			g_object_unref(box->buddy_icon);
 		scaled = gdk_pixbuf_new_from_file_at_scale(filename,
 							   box->icon_size, box->icon_size, FALSE, NULL);
-		box->buddy_icon_hover = gdk_pixbuf_copy(scaled);
-		do_colorshift(box->buddy_icon_hover, box->buddy_icon_hover, 30);
-		g_object_unref(box->buddy_icon);
-		box->buddy_icon = scaled;
-		gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon);
+		if (scaled != NULL)
+		{
+			box->buddy_icon_hover = gdk_pixbuf_copy(scaled);
+			do_colorshift(box->buddy_icon_hover, box->buddy_icon_hover, 30);
+			box->buddy_icon = scaled;
+			gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon);
+		}
 	}
 
 	gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename);
--- a/src/gtkutils.c	Wed Aug 16 07:02:26 2006 +0000
+++ b/src/gtkutils.c	Wed Aug 16 07:19:41 2006 +0000
@@ -2453,7 +2453,7 @@
 }
 #endif
 
-char*
+char *
 gaim_gtk_convert_buddy_icon(GaimPlugin *plugin, const char *path)
 {
 #if GTK_CHECK_VERSION(2,2,0)
@@ -2518,6 +2518,8 @@
 	format = gdk_pixbuf_loader_get_format(loader);
 	g_object_unref(G_OBJECT(loader));
 #endif
+	if (format == NULL)
+		return NULL;
 	pixbuf_formats =  gdk_pixbuf_format_get_extensions(format);
 
 	if (str_array_match(pixbuf_formats, prpl_formats) &&                  /* This is an acceptable format AND */