comparison libpurple/protocols/qq/buddy_info.c @ 16483:5e47b3427b28

propagate from branch 'im.pidgin.rlaager.gaim_migration' (head dcc40d46afbe3f87cc674e4fb1526ac722bc35cb) to branch 'im.pidgin.pidgin' (head 0ef5b6c44115778e329fd628324124f872f5253b)
author Sean Egan <seanegan@gmail.com>
date Fri, 27 Apr 2007 02:14:44 +0000
parents 08db93bbd798 24bbd7e46bfe
children 56823a55581a
comparison
equal deleted inserted replaced
16467:b2044e10915a 16483:5e47b3427b28
530 qd->my_icon = 3 * (face_num - 1) + offset; 530 qd->my_icon = 3 * (face_num - 1) + offset;
531 qd->modifying_face = TRUE; 531 qd->modifying_face = TRUE;
532 qq_send_packet_get_info(gc, qd->uid, FALSE); 532 qq_send_packet_get_info(gc, qd->uid, FALSE);
533 } 533 }
534 534
535 void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *iconfile) 535 void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *icon_num, const gchar *iconfile)
536 { 536 {
537 FILE *file; 537 gchar *data;
538 struct stat st; 538 gsize len;
539 539
540 g_return_if_fail(g_stat(iconfile, &st) == 0); 540 if (!g_file_get_contents(iconfile, &data, &len, NULL))
541 file = g_fopen(iconfile, "rb"); 541 g_return_if_reached();
542 if (file) { 542 else
543 PurpleBuddyIcon *icon; 543 {
544 size_t data_len; 544 purple_buddy_icons_set_for_user(account, who, data, len, icon_num);
545 gchar *data = g_new(gchar, st.st_size + 1);
546 data_len = fread(data, 1, st.st_size, file);
547 fclose(file);
548 purple_buddy_icons_set_for_user(account, who, data, data_len);
549 icon = purple_buddy_icons_find(account, who);
550 purple_buddy_icon_set_path(icon, iconfile);
551 } 545 }
552 } 546 }
553 547
554 /* TODO: custom faces for QQ members and users with level >= 16 */ 548 /* TODO: custom faces for QQ members and users with level >= 16 */
555 void qq_set_my_buddy_icon(PurpleConnection *gc, const gchar *iconfile) 549 void qq_set_my_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
556 { 550 {
557 gchar *icon; 551 gchar *icon;
558 gint icon_num; 552 gint icon_num;
559 gint icon_len; 553 gint icon_len;
560 PurpleAccount *account = purple_connection_get_account(gc); 554 PurpleAccount *account = purple_connection_get_account(gc);
599 } 593 }
600 g_free(errmsg); 594 g_free(errmsg);
601 /* tell server my icon changed */ 595 /* tell server my icon changed */
602 _qq_send_packet_modify_face(gc, icon_num); 596 _qq_send_packet_modify_face(gc, icon_num);
603 /* display in blist */ 597 /* display in blist */
604 qq_set_buddy_icon_for_user(account, account->username, icon_path); 598 qq_set_buddy_icon_for_user(account, account->username, icon, icon_path);
605 } 599 }
606 600
607 601
608 static void _qq_update_buddy_icon(PurpleAccount *account, const gchar *name, gint face) 602 static void _qq_update_buddy_icon(PurpleAccount *account, const gchar *name, gint face)
609 { 603 {
610 gchar *icon_path;
611 PurpleBuddyIcon *icon = purple_buddy_icons_find(account, name); 604 PurpleBuddyIcon *icon = purple_buddy_icons_find(account, name);
612 gchar *icon_num_str = face_to_icon_str(face); 605 gchar *icon_num_str = face_to_icon_str(face);
613 const gchar *old_path = purple_buddy_icon_get_path(icon); 606 const gchar *old_icon_num = purple_buddy_icon_get_checksum(icon);
614 const gchar *buddy_icon_dir = qq_buddy_icon_dir(); 607
615 608 if (icon == NULL || old_icon_num == NULL ||
616 icon_path = g_strconcat(buddy_icon_dir, G_DIR_SEPARATOR_S, QQ_ICON_PREFIX, 609 strcmp(icon_num_str, old_icon_num))
617 icon_num_str, QQ_ICON_SUFFIX, NULL); 610 {
618 if (icon == NULL || old_path == NULL 611 gchar *icon_path;
619 || g_ascii_strcasecmp(icon_path, old_path) != 0) 612
620 qq_set_buddy_icon_for_user(account, name, icon_path); 613 icon_path = g_strconcat(qq_buddy_icon_dir(), G_DIR_SEPARATOR_S,
614 QQ_ICON_PREFIX, icon_num_str,
615 QQ_ICON_SUFFIX, NULL);
616
617 qq_set_buddy_icon_for_user(account, name, icon_num_str, icon_path);
618 g_free(icon_path);
619 }
621 g_free(icon_num_str); 620 g_free(icon_num_str);
622 g_free(icon_path);
623 } 621 }
624 622
625 /* after getting info or modify myself, refresh the buddy list accordingly */ 623 /* after getting info or modify myself, refresh the buddy list accordingly */
626 void qq_refresh_buddy_and_myself(contact_info *info, PurpleConnection *gc) 624 void qq_refresh_buddy_and_myself(contact_info *info, PurpleConnection *gc)
627 { 625 {