changeset 15222:26357b7f117e

[gaim-migrate @ 18012] * Get rid of an assertion failure that I think was happening when you added a new account without setting a custom icon for it, and you still had the Accounts window open * A little code-reuse in some buddy icon scaling code * An minor memleak that could happen when unable open a new file in $HOME/.gaim/icons/ committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 17 Dec 2006 05:04:23 +0000
parents 3043806ad900
children e261feef1ce7
files ChangeLog.API gtk/gtkaccount.c gtk/gtkblist.c gtk/gtkconv.c gtk/gtkutils.c libgaim/buddyicon.c
diffstat 6 files changed, 61 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sun Dec 17 04:55:12 2006 +0000
+++ b/ChangeLog.API	Sun Dec 17 05:04:23 2006 +0000
@@ -145,8 +145,13 @@
 	* gaim_gtk_set_custom_buddy_icon() sets custom icon for a user.
 	* Hid the definition of _GaimStringref, which already had a warning to
 	  avoid accessing it directly.
-    * notify_userinfo() UI op is passed a GaimNotifyUserInfo instead of a char*
-      for the user information
+	* notify_userinfo() UI op is passed a GaimNotifyUserInfo instead of a char*
+	  for the user information
+	* gaim_buddy_icon_get_scale_size() and
+	  gaim_gtk_buddy_icon_get_scale_size() were changed to ALWAYS scale
+	  the icon instead of only when icon_spec->scale_rules contains
+	  GAIM_ICON_SCALE_DISPLAY.  Callers should be changed to check the
+	  scale_rules before calling this function.
 
 	Removed:
 	* gaim_gtk_sound_{get,set}_mute() (replaced by the /gaim/gtk/sound/mute
--- a/gtk/gtkaccount.c	Sun Dec 17 04:55:12 2006 +0000
+++ b/gtk/gtkaccount.c	Sun Dec 17 05:04:23 2006 +0000
@@ -218,8 +218,9 @@
 		int width, height;
 		GdkPixbuf *scale;
 
-		gaim_gtk_buddy_icon_get_scale_size(pixbuf,
-							&dialog->prpl_info->icon_spec, &width, &height);
+		if (dialog->prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_DISPLAY)
+			gaim_gtk_buddy_icon_get_scale_size(pixbuf,
+					&dialog->prpl_info->icon_spec, &width, &height);
 		scale = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
 
 		g_object_unref(G_OBJECT(pixbuf));
@@ -614,7 +615,7 @@
 		if (!(dialog->prpl_info->options & OPT_PROTO_MAIL_CHECK))
 			gtk_widget_hide(dialog->new_mail_check);
 
-		if (!(dialog->prpl_info->icon_spec.format != NULL))
+		if (dialog->prpl_info->icon_spec.format == NULL)
 			gtk_widget_hide(dialog->icon_hbox);
 	}
 
@@ -1974,6 +1975,7 @@
 static void
 set_account(GtkListStore *store, GtkTreeIter *iter, GaimAccount *account)
 {
+	const char *path;
 	GdkPixbuf *pixbuf;
 	GdkPixbuf *statusicon_pixbuf;
 	GdkPixbuf *statusicon_pixbuf_scaled;
@@ -1982,7 +1984,12 @@
 	if ((pixbuf != NULL) && gaim_account_is_disconnected(account))
 		gdk_pixbuf_saturate_and_pixelate(pixbuf, pixbuf, 0.0, FALSE);
 
-	statusicon_pixbuf = gdk_pixbuf_new_from_file(gaim_account_get_ui_string(account, GAIM_GTK_UI, "non-global-buddyicon-path", NULL), NULL); 
+	path = gaim_account_get_ui_string(account, GAIM_GTK_UI, "non-global-buddyicon-path", NULL);
+	if (path != NULL)
+		statusicon_pixbuf = gdk_pixbuf_new_from_file(path, NULL);
+	else
+		statusicon_pixbuf = NULL;
+
 	if (statusicon_pixbuf) {
 		statusicon_pixbuf_scaled = gdk_pixbuf_scale_simple(statusicon_pixbuf, 16, 16, GDK_INTERP_HYPER);
 	} else {
--- a/gtk/gtkblist.c	Sun Dec 17 04:55:12 2006 +0000
+++ b/gtk/gtkblist.c	Sun Dec 17 05:04:23 2006 +0000
@@ -2068,7 +2068,8 @@
 		scale_width = orig_width = gdk_pixbuf_get_width(buf);
 		scale_height = orig_height = gdk_pixbuf_get_height(buf);
 
-		gaim_buddy_icon_get_scale_size(prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height);
+		if (prpl_info && prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_DISPLAY)
+			gaim_buddy_icon_get_scale_size(&prpl_info->icon_spec, &scale_width, &scale_height);
 
 		if (scaled) {
 			if(scale_height > scale_width) {
--- a/gtk/gtkconv.c	Sun Dec 17 04:55:12 2006 +0000
+++ b/gtk/gtkconv.c	Sun Dec 17 05:04:23 2006 +0000
@@ -2308,8 +2308,9 @@
 	gdk_pixbuf_animation_iter_advance(gtkconv->u.im->iter, NULL);
 	buf = gdk_pixbuf_animation_iter_get_pixbuf(gtkconv->u.im->iter);
 
-	gaim_gtk_buddy_icon_get_scale_size(buf, prpl_info ? &prpl_info->icon_spec :
-			NULL, &scale_width, &scale_height);
+	if (prpl_info && prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_DISPLAY)
+		gaim_gtk_buddy_icon_get_scale_size(buf, &prpl_info->icon_spec,
+				&scale_width, &scale_height);
 
 	/* this code is ugly, and scares me */
 	scale = gdk_pixbuf_scale_simple(buf,
@@ -6024,8 +6025,9 @@
 			start_anim(NULL, gtkconv);
 	}
 
-	gaim_gtk_buddy_icon_get_scale_size(buf, prpl_info ? &prpl_info->icon_spec :
-			NULL, &scale_width, &scale_height);
+	if (prpl_info && prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_DISPLAY)
+		gaim_gtk_buddy_icon_get_scale_size(buf, &prpl_info->icon_spec,
+			&scale_width, &scale_height);
 	scale = gdk_pixbuf_scale_simple(buf,
 				MAX(gdk_pixbuf_get_width(buf) * scale_width /
 				    gdk_pixbuf_animation_get_width(gtkconv->u.im->anim), 1),
--- a/gtk/gtkutils.c	Sun Dec 17 04:55:12 2006 +0000
+++ b/gtk/gtkutils.c	Sun Dec 17 05:04:23 2006 +0000
@@ -2455,6 +2455,7 @@
 }
 #endif
 
+/* TODO: Use icon_spec.filesize */
 char *
 gaim_gtk_convert_buddy_icon(GaimPlugin *plugin, const char *path)
 {
@@ -2467,11 +2468,10 @@
 	GdkPixbuf *pixbuf;
 #if !GTK_CHECK_VERSION(2,4,0)
 	GdkPixbufLoader *loader;
-	FILE *file;
-	struct stat st;
-	void *data = NULL;
 #endif
 #endif
+	gchar *contents;
+	gsize length;
 	const char *dirname;
 	char *random;
 	char *filename;
@@ -2504,12 +2504,9 @@
 	format = gdk_pixbuf_get_file_info (path, &width, &height);
 #else
 	loader = gdk_pixbuf_loader_new();
-	if (!g_stat(path, &st) && (file = g_fopen(path, "rb")) != NULL) {
-		data = g_malloc(st.st_size);
-		fread(data, 1, st.st_size, file);
-		fclose(file);
-		gdk_pixbuf_loader_write(loader, data, st.st_size, NULL);
-		g_free(data);
+	if (g_file_get_contents(path, &contents, &length, NULL)) {
+		gdk_pixbuf_loader_write(loader, contents, length, NULL);
+		g_free(contents);
 	}
 	gdk_pixbuf_loader_close(loader, NULL);
 	pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
@@ -2530,8 +2527,6 @@
 		   prpl_info->icon_spec.max_height >= height)))                   /* The icon is the correct size */
 #endif
 	{
-		gchar *contents;
-		gsize length;
 		FILE *image;
 
 #if GTK_CHECK_VERSION(2,2,0)
@@ -2539,13 +2534,15 @@
 		g_strfreev(pixbuf_formats);
 #endif
 
-		/* Copy the image to the cache folder as "filename". */
-
+		/* We don't need to scale the image, so copy it to the cache folder verbatim */
+
+		contents = NULL;
 		if (!g_file_get_contents(path, &contents, &length, NULL) ||
 		    (image = g_fopen(filename, "wb")) == NULL)
 		{
 			g_free(random);
 			g_free(filename);
+			g_free(contents);
 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
 			g_object_unref(G_OBJECT(pixbuf));
 #endif
@@ -2592,22 +2589,7 @@
 			int new_width = width;
 			int new_height = height;
 
-			if(new_width > prpl_info->icon_spec.max_width)
-				new_width = prpl_info->icon_spec.max_width;
-			else if(new_width < prpl_info->icon_spec.min_width)
-				new_width = prpl_info->icon_spec.min_width;
-			if(new_height > prpl_info->icon_spec.max_height)
-				new_height = prpl_info->icon_spec.max_height;
-			else if(new_height < prpl_info->icon_spec.min_height)
-				new_height = prpl_info->icon_spec.min_height;
-
-			/* preserve aspect ratio */
-			if ((double)height * (double)new_width >
-				(double)width * (double)new_height) {
-					new_width = 0.5 + (double)width * (double)new_height / (double)height;
-			} else {
-					new_height = 0.5 + (double)height * (double)new_width / (double)width;
-			}
+			gaim_buddy_icon_get_scale_size(&prpl_info->icon_spec, &new_width, &new_height);
 
 			scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
 					GDK_INTERP_HYPER);
@@ -2625,10 +2607,9 @@
 
 		for (i = 0; prpl_formats[i]; i++) {
 			gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename);
-			/* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful,
-			 * FALSE if an error was set. */
-			if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE)
-					break;
+			if (gdk_pixbuf_save(pixbuf, filename, prpl_formats[i], &error, NULL))
+				/* Success! */
+				break;
 			gaim_debug_warning("buddyicon", "Could not convert to %s: %s\n", prpl_formats[i], error->message);
 			g_error_free(error);
 			error = NULL;
--- a/libgaim/buddyicon.c	Sun Dec 17 04:55:12 2006 +0000
+++ b/libgaim/buddyicon.c	Sun Dec 17 05:04:23 2006 +0000
@@ -546,32 +546,30 @@
 
 void gaim_buddy_icon_get_scale_size(GaimBuddyIconSpec *spec, int *width, int *height)
 {
-	if(spec && spec->scale_rules & GAIM_ICON_SCALE_DISPLAY) {
-		int new_width, new_height;
+	int new_width, new_height;
+
+	new_width = *width;
+	new_height = *height;
 
-		new_width = *width;
-		new_height = *height;
-
-		if(*width < spec->min_width)
-			new_width = spec->min_width;
-		else if(*width > spec->max_width)
-			new_width = spec->max_width;
+	if (*width < spec->min_width)
+		new_width = spec->min_width;
+	else if (*width > spec->max_width)
+		new_width = spec->max_width;
 
-		if(*height < spec->min_height)
-			new_height = spec->min_height;
-		else if(*height  > spec->max_height)
-			new_height = spec->max_height;
+	if (*height < spec->min_height)
+		new_height = spec->min_height;
+	else if (*height > spec->max_height)
+		new_height = spec->max_height;
 
-		/* preserve aspect ratio */
-		if ((double)*height * (double)new_width >
-			(double)*width * (double)new_height) {
-				new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
-		} else {
-				new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
-		}
+	/* preserve aspect ratio */
+	if ((double)*height * (double)new_width >
+		(double)*width * (double)new_height) {
+			new_width = 0.5 + (double)*width * (double)new_height / (double)*height;
+	} else {
+			new_height = 0.5 + (double)*height * (double)new_width / (double)*width;
+	}
 
-		*width = new_width;
-		*height = new_height;
-	}
+	*width = new_width;
+	*height = new_height;
 }