comparison 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
comparison
equal deleted inserted replaced
4756:85637881b342 4757:c4ebe1a8484b
557 { 557 {
558 struct gaim_conversation *conv; 558 struct gaim_conversation *conv;
559 struct icon_data tmp; 559 struct icon_data tmp;
560 GList *l; 560 GList *l;
561 struct icon_data *id; 561 struct icon_data *id;
562 struct buddy *b;
562 tmp.gc = gc; 563 tmp.gc = gc;
563 tmp.who = normalize(who); 564 tmp.who = normalize(who);
564 tmp.data=NULL; 565 tmp.data=NULL;
565 tmp.len = 0; 566 tmp.len = 0;
566 l = g_list_find_custom(icons, &tmp, find_icon_data); 567 l = g_list_find_custom(icons, &tmp, find_icon_data);
592 conv = gaim_find_conversation(who); 593 conv = gaim_find_conversation(who);
593 594
594 /* XXX Buddy Icon should probalby be part of struct buddy instead of this weird global 595 /* XXX Buddy Icon should probalby be part of struct buddy instead of this weird global
595 * linked list stuff. */ 596 * linked list stuff. */
596 597
597 if (gaim_find_buddy(gc->account, who)) { 598 if ((b = gaim_find_buddy(gc->account, who)) != NULL) {
598 /* This is one of our buddies, so we'll cache this icon for our buddy list */ 599 char *random = g_strdup_printf("%x", g_random_int());
599 600 char *filename = g_build_filename(gaim_user_dir(), "icons", random,
600 /* Because only OSCAR does buddy icons right now, I don't feel so bad doing nothing to 601 NULL);
601 save what protocol this is from. */ 602 char *dirname = g_build_filename(gaim_user_dir(), "icons", NULL);
602 char *filename = g_build_filename(gaim_user_dir(), "icons", normalize(who), NULL); 603 char *old_icon = gaim_buddy_get_setting(b, "buddy_icon");
603 FILE *file = NULL; 604 FILE *file = NULL;
604 605
606 g_free(random);
607
608 if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
609 mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR);
610
611 g_free(dirname);
612
605 file = fopen(filename, "wb"); 613 file = fopen(filename, "wb");
606 if (!file) 614 if (file) {
607 return; 615 fwrite(data, 1, len, file);
608 fwrite(data, 1, len, file); 616 fclose(file);
609 fclose(file); 617 }
610 } 618
611 619 if(old_icon) {
620 unlink(old_icon);
621 g_free(old_icon);
622 }
623
624 gaim_buddy_set_setting(b, "buddy_icon", filename);
625 gaim_blist_save();
626
627 g_free(filename);
628
629 gaim_blist_update_buddy_icon(b);
630 }
631
612 if (conv != NULL && gaim_conversation_get_gc(conv) == gc) 632 if (conv != NULL && gaim_conversation_get_gc(conv) == gc)
613 gaim_gtkconv_update_buddy_icon(conv); 633 gaim_gtkconv_update_buddy_icon(conv);
614 } 634 }
615 635
616 void remove_icon_data(struct gaim_connection *gc) 636 void remove_icon_data(struct gaim_connection *gc)