changeset 9396:84594a281500

[gaim-migrate @ 10208] This fixes a bug that shx pointed out, that I accidently introduced, whereby, if a buddy has an icon, that hasn't been updated since you started gaim, but was cached at some earlier point in time, and you are using the small list, when you opened a conversation with them, you would not see their buddy icon. The work-around for 0.79 is to use the big list, or have friends who change their buddy icons a lot. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Fri, 25 Jun 2004 05:30:10 +0000
parents bd81a3c6f8ab
children 3b0c6255033e
files src/buddyicon.c src/buddyicon.h src/gtkblist.c
diffstat 3 files changed, 58 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddyicon.c	Fri Jun 25 03:50:53 2004 +0000
+++ b/src/buddyicon.c	Fri Jun 25 05:30:10 2004 +0000
@@ -32,6 +32,31 @@
 static char       *cache_dir     = NULL;
 static gboolean    icon_caching  = TRUE;
 
+static GaimBuddyIcon *
+gaim_buddy_icon_create(GaimAccount *account, const char *username)
+{
+	GaimBuddyIcon *icon;
+	GHashTable *icon_cache;
+
+	icon = g_new0(GaimBuddyIcon, 1);
+
+	gaim_buddy_icon_set_account(icon,  account);
+	gaim_buddy_icon_set_username(icon, username);
+
+	icon_cache = g_hash_table_lookup(account_cache, account);
+
+	if (icon_cache == NULL)
+	{
+		icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
+
+		g_hash_table_insert(account_cache, account, icon_cache);
+	}
+
+	g_hash_table_insert(icon_cache,
+	                   (char *)gaim_buddy_icon_get_username(icon), icon);
+	return icon;
+}
+
 GaimBuddyIcon *
 gaim_buddy_icon_new(GaimAccount *account, const char *username,
 					void *icon_data, size_t icon_len)
@@ -46,26 +71,7 @@
 	icon = gaim_buddy_icons_find(account, username);
 
 	if (icon == NULL)
-	{
-		GHashTable *icon_cache;
-
-		icon = g_new0(GaimBuddyIcon, 1);
-
-		gaim_buddy_icon_set_account(icon,  account);
-		gaim_buddy_icon_set_username(icon, username);
-
-		icon_cache = g_hash_table_lookup(account_cache, account);
-
-		if (icon_cache == NULL)
-		{
-			icon_cache = g_hash_table_new(g_str_hash, g_str_equal);
-
-			g_hash_table_insert(account_cache, account, icon_cache);
-		}
-
-		g_hash_table_insert(icon_cache,
-							(char *)gaim_buddy_icon_get_username(icon), icon);
-	}
+		icon = gaim_buddy_icon_create(account, username);
 
 	gaim_buddy_icon_ref(icon);
 	gaim_buddy_icon_set_data(icon, icon_data, icon_len);
@@ -335,19 +341,44 @@
 }
 
 GaimBuddyIcon *
-gaim_buddy_icons_find(const GaimAccount *account, const char *username)
+gaim_buddy_icons_find(GaimAccount *account, const char *username)
 {
 	GHashTable *icon_cache;
+	GaimBuddyIcon *ret = NULL;
 
 	g_return_val_if_fail(account  != NULL, NULL);
 	g_return_val_if_fail(username != NULL, NULL);
 
 	icon_cache = g_hash_table_lookup(account_cache, account);
 
-	if (icon_cache == NULL)
-		return NULL;
+	if ((icon_cache == NULL) || ((ret = g_hash_table_lookup(icon_cache, username)) == NULL)) {
+		const char *file;
+		struct stat st;
+		GaimBuddy *b = gaim_find_buddy(account, username);
+
+		if (!b)
+			return NULL;
+
+		if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
+			return NULL;
 
-	return g_hash_table_lookup(icon_cache, username);
+		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);
+				ret = gaim_buddy_icon_create(account, username);
+				gaim_buddy_icon_ref(ret);
+				gaim_buddy_icon_set_data(ret, data, st.st_size);
+				gaim_buddy_icon_unref(ret);
+				g_free(data);
+				return ret;
+			}
+		}
+	}
+
+	return ret;
 }
 
 void
--- a/src/buddyicon.h	Fri Jun 25 03:50:53 2004 +0000
+++ b/src/buddyicon.h	Fri Jun 25 05:30:10 2004 +0000
@@ -182,7 +182,7 @@
  *
  * @return The icon data if found, or @c NULL if not found.
  */
-GaimBuddyIcon *gaim_buddy_icons_find(const GaimAccount *account,
+GaimBuddyIcon *gaim_buddy_icons_find(GaimAccount *account,
 									 const char *username);
 
 /**
--- a/src/gtkblist.c	Fri Jun 25 03:50:53 2004 +0000
+++ b/src/gtkblist.c	Fri Jun 25 05:30:10 2004 +0000
@@ -2623,36 +2623,19 @@
 
 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBuddy *b)
 {
-	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 (!(icon = gaim_buddy_get_icon(b))) {
-		if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
+	if (!(icon = gaim_buddy_get_icon(b)))
+		if (!(icon = gaim_buddy_icons_find(b->account, b->name))) /* Not sure I like this...*/
 			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);