comparison libpurple/protocols/qq/buddy_info.c @ 16386:e0c9a46b459f

Move the prpl icon checksum code into the core, so we can delete the checksum if the cache file disappears. See ticket #223
author Richard Laager <rlaager@wiktel.com>
date Wed, 25 Apr 2007 00:56:13 +0000
parents c9b4ff420140
children 4fc51a87ce42
comparison
equal deleted inserted replaced
16385:a0df0eb75e1b 16386:e0c9a46b459f
529 qd->my_icon = 3 * (face_num - 1) + offset; 529 qd->my_icon = 3 * (face_num - 1) + offset;
530 qd->modifying_face = TRUE; 530 qd->modifying_face = TRUE;
531 qq_send_packet_get_info(gc, qd->uid, FALSE); 531 qq_send_packet_get_info(gc, qd->uid, FALSE);
532 } 532 }
533 533
534 void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *iconfile) 534 void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *icon_num, const gchar *iconfile)
535 { 535 {
536 FILE *file; 536 gchar *data;
537 struct stat st; 537 gsize len;
538 538
539 g_return_if_fail(g_stat(iconfile, &st) == 0); 539 if (!g_file_get_contents(iconfile, &data, &len, NULL))
540 file = g_fopen(iconfile, "rb"); 540 g_return_if_reached();
541 if (file) { 541 else
542 PurpleBuddyIcon *icon; 542 {
543 size_t data_len; 543 purple_buddy_icons_set_for_user(account, who, data, len, icon_num);
544 gchar *data = g_new(gchar, st.st_size + 1); 544 g_free(data);
545 data_len = fread(data, 1, st.st_size, file);
546 fclose(file);
547 purple_buddy_icons_set_for_user(account, who, data, data_len);
548 // TODO: Set a blist setting or something
549 } 545 }
550 } 546 }
551 547
552 /* TODO: custom faces for QQ members and users with level >= 16 */ 548 /* TODO: custom faces for QQ members and users with level >= 16 */
553 void qq_set_my_buddy_icon(PurpleConnection *gc, const gchar *iconfile) 549 void qq_set_my_buddy_icon(PurpleConnection *gc, const gchar *iconfile)
597 } 593 }
598 g_free(errmsg); 594 g_free(errmsg);
599 /* tell server my icon changed */ 595 /* tell server my icon changed */
600 _qq_send_packet_modify_face(gc, icon_num); 596 _qq_send_packet_modify_face(gc, icon_num);
601 /* display in blist */ 597 /* display in blist */
602 qq_set_buddy_icon_for_user(account, account->username, icon_path); 598 qq_set_buddy_icon_for_user(account, account->username, icon, icon_path);
603 } 599 }
604 600
605 601
606 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)
607 { 603 {
608 gchar *icon_path;
609 PurpleBuddyIcon *icon = purple_buddy_icons_find(account, name); 604 PurpleBuddyIcon *icon = purple_buddy_icons_find(account, name);
610 gchar *icon_num_str = face_to_icon_str(face); 605 gchar *icon_num_str = face_to_icon_str(face);
611 // TODO: This needs to use a blist setting or something. 606 const gchar *old_icon_num = purple_buddy_icon_get_checksum(icon);
612 const gchar *old_path = NULL; 607
613 const gchar *buddy_icon_dir = qq_buddy_icon_dir(); 608 if (icon == NULL || old_icon_num == NULL ||
614 609 strcmp(icon_num_str, old_icon_num))
615 icon_path = g_strconcat(buddy_icon_dir, G_DIR_SEPARATOR_S, QQ_ICON_PREFIX, 610 {
616 icon_num_str, QQ_ICON_SUFFIX, NULL); 611 gchar *icon_path;
617 if (icon == NULL || old_path == NULL 612
618 || g_ascii_strcasecmp(icon_path, old_path) != 0) 613 icon_path = g_strconcat(qq_buddy_icon_dir(), G_DIR_SEPARATOR_S,
619 qq_set_buddy_icon_for_user(account, name, icon_path); 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 }
620 g_free(icon_num_str); 620 g_free(icon_num_str);
621 g_free(icon_path);
622 } 621 }
623 622
624 /* after getting info or modify myself, refresh the buddy list accordingly */ 623 /* after getting info or modify myself, refresh the buddy list accordingly */
625 void qq_refresh_buddy_and_myself(contact_info *info, PurpleConnection *gc) 624 void qq_refresh_buddy_and_myself(contact_info *info, PurpleConnection *gc)
626 { 625 {