=================================================================== RCS file: /cvsroot/gaim/gaim/src/buddyicon.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- gaim/gaim/src/buddyicon.c 2004/06/20 08:02:39 1.12 +++ gaim/gaim/src/buddyicon.c 2004/06/25 05:30:10 1.13 @@ -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; + + 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 g_hash_table_lookup(icon_cache, username); + return ret; } void =================================================================== RCS file: /cvsroot/gaim/gaim/src/buddyicon.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- gaim/gaim/src/buddyicon.h 2004/01/10 04:04:55 1.5 +++ gaim/gaim/src/buddyicon.h 2004/06/25 05:30:10 1.6 @@ -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); /** =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkblist.c,v retrieving revision 1.127 retrieving revision 1.128 diff -u -r1.127 -r1.128 --- gaim/gaim/src/gtkblist.c 2004/06/22 01:05:42 1.127 +++ gaim/gaim/src/gtkblist.c 2004/06/25 05:30:10 1.128 @@ -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);