changeset 9324:af707cc1e229

[gaim-migrate @ 10132] Now when your buddies unset their icon, you'll no longer see it. Well on Yahoo! anyway, I doubt OSCAR actually ever tells the core when a buddy unsets his icon, since Chip just added the ability to do that a couple days ago. The caching needs to be fixed up, the file itself is never removed. I made gtkblist use GtkPixbufLoader, which i'm worried about because gtkconv has a comment about that leaking. The GaimBuddyIcon's end up being loaded from gtkblist.c, which is wrong, I think. However, they were previously not being created at all I think, except for new icons. So basicly, gtkconv and gtkblist use GaimBuddyIcon instead of loading the icon straight into a GdkPixap or whatever from the file. gtkblist will still read the file if it can't find a GaimBuddyIcon, but it creates one from the file, instead of just using the file. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Sun, 20 Jun 2004 06:57:54 +0000
parents 59bca4e8678c
children f40233043b5a
files src/blist.c src/conversation.c src/gtkblist.c src/gtkconv.c
diffstat 4 files changed, 67 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Sun Jun 20 05:39:21 2004 +0000
+++ b/src/blist.c	Sun Jun 20 06:57:54 2004 +0000
@@ -650,7 +650,10 @@
 		buddy->icon = (icon == NULL ? NULL : gaim_buddy_icon_ref(icon));
 	}
 
-	gaim_buddy_icon_cache(icon, buddy);
+	if (buddy->icon)
+		gaim_buddy_icon_cache(icon, buddy);
+	else
+		gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon");
 
 	schedule_blist_save();
 	
--- a/src/conversation.c	Sun Jun 20 05:39:21 2004 +0000
+++ b/src/conversation.c	Sun Jun 20 06:57:54 2004 +0000
@@ -808,10 +808,13 @@
 
 	if (type == GAIM_CONV_IM)
 	{
+		GaimBuddyIcon *icon;
 		conv->u.im = g_new0(GaimConvIm, 1);
 		conv->u.im->conv = conv;
 
 		ims = g_list_append(ims, conv);
+		if ((icon = gaim_buddy_icons_find(account, name)))
+			gaim_conv_im_set_icon(conv->u.im, icon);
 
 		gaim_conversation_set_logging(conv,
 				gaim_prefs_get_bool("/core/logging/log_ims"));
--- a/src/gtkblist.c	Sun Jun 20 05:39:21 2004 +0000
+++ b/src/gtkblist.c	Sun Jun 20 06:57:54 2004 +0000
@@ -2623,14 +2623,42 @@
 {
 	const char *file;
 	GdkPixbuf *buf, *ret;
+	GdkPixbufLoader *loader;
+	GaimBuddyIcon *icon;
+	const char *data;
+	size_t len;
+	struct stat st;
 
 	if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))
 		return NULL;
 
-	if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
-		return NULL;
-
-	buf = gdk_pixbuf_new_from_file(file, NULL);
+	if (!(icon = gaim_buddy_get_icon(b))) {
+		if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
+			return NULL;
+
+		/* This is a hack, we should be loading up the GaimBuddyIcon's somewhere
+		 * else, like the core, like when we parse the blist.xml file. */
+		if (!stat(file, &st)) {
+			FILE *f = fopen(file, "rb");
+			if (f) {
+				char *data = g_malloc(st.st_size);
+				fread(data, 1, st.st_size, f);
+				fclose(f);
+				gaim_buddy_icons_set_for_user(b->account, b->name, data, st.st_size);
+				g_free(data);
+			}
+		}
+
+		return NULL; /* Either no icon, or we just set one and so this will get called again */
+	}
+
+	loader = gdk_pixbuf_loader_new();
+	data = gaim_buddy_icon_get_data(icon, &len);
+	gdk_pixbuf_loader_write(loader, data, len, NULL);
+	buf = gdk_pixbuf_loader_get_pixbuf(loader);
+	if (buf)
+		g_object_ref(G_OBJECT(buf));
+	gdk_pixbuf_loader_close(loader, NULL);
 
 
 	if (buf) {
--- a/src/gtkconv.c	Sun Jun 20 05:39:21 2004 +0000
+++ b/src/gtkconv.c	Sun Jun 20 06:57:54 2004 +0000
@@ -5425,8 +5425,6 @@
 	FILE *file;
 	GError *err = NULL;
 
-	GaimBuddy *buddy;
-
 	const void *data;
 	size_t len;
 
@@ -5445,6 +5443,8 @@
 
 	GaimButtonStyle button_type;
 
+	GaimBuddyIcon *icon;
+
 	g_return_if_fail(conv != NULL);
 	g_return_if_fail(GAIM_IS_GTK_CONVERSATION(conv));
 	g_return_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_IM);
@@ -5465,54 +5465,32 @@
 	if (gtkconv->u.im->anim)
 		g_object_unref(G_OBJECT(gtkconv->u.im->anim));
 
-	if((buddy = gaim_find_buddy(gaim_conversation_get_account(conv),
-					gaim_conversation_get_name(conv))) != NULL) {
-		const char *iconfile;
-		if((iconfile = gaim_blist_node_get_string((GaimBlistNode*)buddy,
-												  "buddy_icon"))) {
-			GaimBuddyIcon *icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv));
-			struct stat st;
-			if ((icon == NULL) && (!stat(iconfile, &st))) {
-				FILE *file = fopen(iconfile, "rb");
-				if (file) {
-					char *data = g_malloc(st.st_size);
-					fread(data, 1, st.st_size, file);
-					fclose(file);
-					gaim_buddy_icons_set_for_user(gaim_conversation_get_account(conv), gaim_conversation_get_name(conv), data, st.st_size);
-					g_free(data);
-				}
-				return;
-			}
-			else
-				gtkconv->u.im->anim =
-					gdk_pixbuf_animation_new_from_file(iconfile, &err); /* LEAK */
-		}
-	}
-	else
-	{
-		GaimBuddyIcon *icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv));
-
-		if (icon == NULL)
-			return;
-
-		data = gaim_buddy_icon_get_data(icon, &len);
-
-		/* this is such an evil hack, i don't know why i'm even considering it.
-		 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */
-		g_snprintf(filename, sizeof(filename),
-				"%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d",
-				g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid());
-
-		if (!(file = fopen(filename, "wb")))
-			return;
-
-		fwrite(data, 1, len, file);
-		fclose(file);
-
-		gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err);
-		/* make sure we remove the file as soon as possible */
-		unlink(filename);
-	}
+
+
+	icon = gaim_conv_im_get_icon(GAIM_CONV_IM(conv));
+
+	if (icon == NULL)
+		return;
+
+	data = gaim_buddy_icon_get_data(icon, &len);
+
+	/* this is such an evil hack, i don't know why i'm even considering it.
+	 * we'll do it differently when gdk-pixbuf-loader isn't leaky anymore. */
+	/* gdk-pixbuf-loader was leaky? is it still? */
+	g_snprintf(filename, sizeof(filename),
+			"%s" G_DIR_SEPARATOR_S "gaimicon-%s.%d",
+			g_get_tmp_dir(), gaim_conversation_get_name(conv), getpid());
+
+	if (!(file = fopen(filename, "wb")))
+		return;
+
+	fwrite(data, 1, len, file);
+	fclose(file);
+
+	gtkconv->u.im->anim = gdk_pixbuf_animation_new_from_file(filename, &err);
+	/* make sure we remove the file as soon as possible */
+	unlink(filename);
+
 
 	if (err) {
 		gaim_debug(GAIM_DEBUG_ERROR, "gtkconv",