Mercurial > pidgin
diff 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 |
line wrap: on
line diff
--- a/libpurple/protocols/qq/buddy_info.c Tue Apr 24 20:23:50 2007 +0000 +++ b/libpurple/protocols/qq/buddy_info.c Wed Apr 25 00:56:13 2007 +0000 @@ -531,21 +531,17 @@ qq_send_packet_get_info(gc, qd->uid, FALSE); } -void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *iconfile) +void qq_set_buddy_icon_for_user(PurpleAccount *account, const gchar *who, const gchar *icon_num, const gchar *iconfile) { - FILE *file; - struct stat st; + gchar *data; + gsize len; - g_return_if_fail(g_stat(iconfile, &st) == 0); - file = g_fopen(iconfile, "rb"); - if (file) { - PurpleBuddyIcon *icon; - size_t data_len; - gchar *data = g_new(gchar, st.st_size + 1); - data_len = fread(data, 1, st.st_size, file); - fclose(file); - purple_buddy_icons_set_for_user(account, who, data, data_len); - // TODO: Set a blist setting or something + if (!g_file_get_contents(iconfile, &data, &len, NULL)) + g_return_if_reached(); + else + { + purple_buddy_icons_set_for_user(account, who, data, len, icon_num); + g_free(data); } } @@ -599,26 +595,29 @@ /* tell server my icon changed */ _qq_send_packet_modify_face(gc, icon_num); /* display in blist */ - qq_set_buddy_icon_for_user(account, account->username, icon_path); + qq_set_buddy_icon_for_user(account, account->username, icon, icon_path); } static void _qq_update_buddy_icon(PurpleAccount *account, const gchar *name, gint face) { - gchar *icon_path; PurpleBuddyIcon *icon = purple_buddy_icons_find(account, name); gchar *icon_num_str = face_to_icon_str(face); - // TODO: This needs to use a blist setting or something. - const gchar *old_path = NULL; - const gchar *buddy_icon_dir = qq_buddy_icon_dir(); + const gchar *old_icon_num = purple_buddy_icon_get_checksum(icon); + + if (icon == NULL || old_icon_num == NULL || + strcmp(icon_num_str, old_icon_num)) + { + gchar *icon_path; - icon_path = g_strconcat(buddy_icon_dir, G_DIR_SEPARATOR_S, QQ_ICON_PREFIX, - icon_num_str, QQ_ICON_SUFFIX, NULL); - if (icon == NULL || old_path == NULL - || g_ascii_strcasecmp(icon_path, old_path) != 0) - qq_set_buddy_icon_for_user(account, name, icon_path); + icon_path = g_strconcat(qq_buddy_icon_dir(), G_DIR_SEPARATOR_S, + QQ_ICON_PREFIX, icon_num_str, + QQ_ICON_SUFFIX, NULL); + + qq_set_buddy_icon_for_user(account, name, icon_num_str, icon_path); + g_free(icon_path); + } g_free(icon_num_str); - g_free(icon_path); } /* after getting info or modify myself, refresh the buddy list accordingly */