Mercurial > pidgin.yaz
diff src/prpl.c @ 4757:c4ebe1a8484b
[gaim-migrate @ 5074]
this fixes a bunch of little things, as well as a few big things, plugs a
few leaks, and makes the new buddy icon cache stuff much cooler. enjoy!
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 14 Mar 2003 01:14:24 +0000 |
parents | 283fb289c510 |
children | 6fe8008d6560 |
line wrap: on
line diff
--- a/src/prpl.c Thu Mar 13 23:28:25 2003 +0000 +++ b/src/prpl.c Fri Mar 14 01:14:24 2003 +0000 @@ -559,6 +559,7 @@ struct icon_data tmp; GList *l; struct icon_data *id; + struct buddy *b; tmp.gc = gc; tmp.who = normalize(who); tmp.data=NULL; @@ -594,21 +595,40 @@ /* XXX Buddy Icon should probalby be part of struct buddy instead of this weird global * linked list stuff. */ - if (gaim_find_buddy(gc->account, who)) { - /* This is one of our buddies, so we'll cache this icon for our buddy list */ - - /* Because only OSCAR does buddy icons right now, I don't feel so bad doing nothing to - save what protocol this is from. */ - char *filename = g_build_filename(gaim_user_dir(), "icons", normalize(who), NULL); + if ((b = gaim_find_buddy(gc->account, who)) != NULL) { + char *random = g_strdup_printf("%x", g_random_int()); + char *filename = g_build_filename(gaim_user_dir(), "icons", random, + NULL); + char *dirname = g_build_filename(gaim_user_dir(), "icons", NULL); + char *old_icon = gaim_buddy_get_setting(b, "buddy_icon"); FILE *file = NULL; + g_free(random); + + if(!g_file_test(dirname, G_FILE_TEST_IS_DIR)) + mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR); + + g_free(dirname); + file = fopen(filename, "wb"); - if (!file) - return; - fwrite(data, 1, len, file); - fclose(file); + if (file) { + fwrite(data, 1, len, file); + fclose(file); + } + + if(old_icon) { + unlink(old_icon); + g_free(old_icon); + } + + gaim_buddy_set_setting(b, "buddy_icon", filename); + gaim_blist_save(); + + g_free(filename); + + gaim_blist_update_buddy_icon(b); } - + if (conv != NULL && gaim_conversation_get_gc(conv) == gc) gaim_gtkconv_update_buddy_icon(conv); }