Mercurial > pidgin
changeset 15071:902f3621aa13
[gaim-migrate @ 17855]
Use the QQ faces as buddy icons instead of status icons. Also, a few minor cleanups and a bug fix for faces > 33.
committer: Tailor Script <tailor@pidgin.im>
line wrap: on
line diff
--- a/configure.ac Thu Nov 30 10:19:09 2006 +0000 +++ b/configure.ac Thu Nov 30 10:30:13 2006 +0000 @@ -1875,6 +1875,8 @@ m4macros/Makefile gtk/Makefile gtk/pixmaps/Makefile + gtk/pixmaps/buddy_icons/Makefile + gtk/pixmaps/buddy_icons/qq/Makefile gtk/pixmaps/smileys/Makefile gtk/pixmaps/smileys/default/Makefile gtk/pixmaps/smileys/none/Makefile
--- a/gtk/pixmaps/Makefile.am Thu Nov 30 10:19:09 2006 +0000 +++ b/gtk/pixmaps/Makefile.am Thu Nov 30 10:30:13 2006 +0000 @@ -1,4 +1,4 @@ -SUBDIRS = smileys status +SUBDIRS = buddy_icons smileys status EXTRA_DIST = \ about_menu.png \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk/pixmaps/buddy_icons/Makefile.am Thu Nov 30 10:30:13 2006 +0000 @@ -0,0 +1,1 @@ +SUBDIRS = qq
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk/pixmaps/buddy_icons/Makefile.mingw Thu Nov 30 10:30:13 2006 +0000 @@ -0,0 +1,16 @@ +# +# Makefile.mingw +# +# Description: Makefile for win32 (mingw) version of Gaim pixmaps +# + +include ./Makefile.am + +.PHONY: install + +install: + if test '$(SUBDIRS)'; then \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + $(MAKE) -C $$subdir -f Makefile.mingw install; \ + done; \ + fi;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk/pixmaps/buddy_icons/qq/Makefile.am Thu Nov 30 10:30:13 2006 +0000 @@ -0,0 +1,105 @@ +EXTRA_DIST = \ + qq_1.png \ + qq_2.png \ + qq_3.png \ + qq_4.png \ + qq_5.png \ + qq_6.png \ + qq_7.png \ + qq_8.png \ + qq_9.png \ + qq_10.png \ + qq_11.png \ + qq_12.png \ + qq_13.png \ + qq_14.png \ + qq_15.png \ + qq_16.png \ + qq_17.png \ + qq_18.png \ + qq_19.png \ + qq_20.png \ + qq_21.png \ + qq_22.png \ + qq_23.png \ + qq_24.png \ + qq_25.png \ + qq_26.png \ + qq_27.png \ + qq_28.png \ + qq_29.png \ + qq_30.png \ + qq_31.png \ + qq_32.png \ + qq_33.png \ + qq_34.png \ + qq_35.png \ + qq_36.png \ + qq_37.png \ + qq_38.png \ + qq_39.png \ + qq_40.png \ + qq_41.png \ + qq_42.png \ + qq_43.png \ + qq_44.png \ + qq_45.png \ + qq_46.png \ + qq_47.png \ + qq_48.png \ + qq_49.png \ + qq_50.png \ + qq_51.png \ + qq_52.png \ + qq_53.png \ + qq_54.png \ + qq_55.png \ + qq_56.png \ + qq_57.png \ + qq_58.png \ + qq_59.png \ + qq_60.png \ + qq_61.png \ + qq_62.png \ + qq_63.png \ + qq_64.png \ + qq_65.png \ + qq_66.png \ + qq_67.png \ + qq_68.png \ + qq_69.png \ + qq_70.png \ + qq_71.png \ + qq_72.png \ + qq_73.png \ + qq_74.png \ + qq_75.png \ + qq_76.png \ + qq_77.png \ + qq_78.png \ + qq_79.png \ + qq_80.png \ + qq_81.png \ + qq_82.png \ + qq_83.png \ + qq_84.png \ + qq_85.png \ + qq_86.png \ + qq_87.png \ + qq_88.png \ + qq_89.png \ + qq_90.png \ + qq_91.png \ + qq_92.png \ + qq_93.png \ + qq_94.png \ + qq_95.png \ + qq_96.png \ + qq_97.png \ + qq_98.png \ + qq_99.png \ + qq_100.png + +qqbuddyiconspixdir = $(datadir)/pixmaps/gaim/buddy_icons/qq + +qqbuddyiconspix_DATA = $(EXTRA_DIST)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk/pixmaps/buddy_icons/qq/Makefile.mingw Thu Nov 30 10:30:13 2006 +0000 @@ -0,0 +1,18 @@ +# +## Makefile.mingw +# +## Description: Makefile for win32 (mingw) version of Gaim QQ buddy icons +# +# + +GAIM_TOP = ../../../.. +include $(GAIM_TOP)/libgaim/win32/global.mak + +datadir = $(GAIM_INSTALL_DIR) +include ./Makefile.am + +install: + if test '$(qqbuddyiconspix_DATA)'; then \ + mkdir -p $(qqbuddyiconspixdir); \ + cp $(qqbuddyiconspix_DATA) $(qqbuddyiconspixdir); \ + fi;
--- a/gtk/pixmaps/status/default/Makefile.am Thu Nov 30 10:19:09 2006 +0000 +++ b/gtk/pixmaps/status/default/Makefile.am Thu Nov 30 10:30:13 2006 +0000 @@ -33,106 +33,6 @@ op.png \ pending.png \ qq.png \ - qq_1.png \ - qq_2.png \ - qq_3.png \ - qq_4.png \ - qq_5.png \ - qq_6.png \ - qq_7.png \ - qq_8.png \ - qq_9.png \ - qq_10.png \ - qq_11.png \ - qq_12.png \ - qq_13.png \ - qq_14.png \ - qq_15.png \ - qq_16.png \ - qq_17.png \ - qq_18.png \ - qq_19.png \ - qq_20.png \ - qq_21.png \ - qq_22.png \ - qq_23.png \ - qq_24.png \ - qq_25.png \ - qq_26.png \ - qq_27.png \ - qq_28.png \ - qq_29.png \ - qq_30.png \ - qq_31.png \ - qq_32.png \ - qq_33.png \ - qq_34.png \ - qq_35.png \ - qq_36.png \ - qq_37.png \ - qq_38.png \ - qq_39.png \ - qq_40.png \ - qq_41.png \ - qq_42.png \ - qq_43.png \ - qq_44.png \ - qq_45.png \ - qq_46.png \ - qq_47.png \ - qq_48.png \ - qq_49.png \ - qq_50.png \ - qq_51.png \ - qq_52.png \ - qq_53.png \ - qq_54.png \ - qq_55.png \ - qq_56.png \ - qq_57.png \ - qq_58.png \ - qq_59.png \ - qq_60.png \ - qq_61.png \ - qq_62.png \ - qq_63.png \ - qq_64.png \ - qq_65.png \ - qq_66.png \ - qq_67.png \ - qq_68.png \ - qq_69.png \ - qq_70.png \ - qq_71.png \ - qq_72.png \ - qq_73.png \ - qq_74.png \ - qq_75.png \ - qq_76.png \ - qq_77.png \ - qq_78.png \ - qq_79.png \ - qq_80.png \ - qq_81.png \ - qq_82.png \ - qq_83.png \ - qq_84.png \ - qq_85.png \ - qq_86.png \ - qq_87.png \ - qq_88.png \ - qq_89.png \ - qq_90.png \ - qq_91.png \ - qq_92.png \ - qq_93.png \ - qq_94.png \ - qq_95.png \ - qq_96.png \ - qq_97.png \ - qq_98.png \ - qq_99.png \ - qq_100.png \ secure.png \ silc.png \ simple.png \
--- a/libgaim/protocols/qq/Makefile.am Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/Makefile.am Thu Nov 30 10:30:13 2006 +0000 @@ -4,10 +4,6 @@ pkgdir = $(libdir)/gaim QQSOURCES = \ - utils.c \ - utils.h \ - packet_parse.c \ - packet_parse.h \ buddy_info.c \ buddy_info.h \ buddy_list.c \ @@ -16,11 +12,12 @@ buddy_opt.h \ buddy_status.c \ buddy_status.h \ - qq.c \ char_conv.c \ char_conv.h \ crypt.c \ crypt.h \ + file_trans.c \ + file_trans.h \ group.c \ group.h \ group_conv.c \ @@ -45,7 +42,6 @@ group_opt.h \ group_search.c \ group_search.h \ - qq.h \ header_info.c \ header_info.h \ im.c \ @@ -54,22 +50,26 @@ keep_alive.h \ login_logout.c \ login_logout.h \ + packet_parse.c \ + packet_parse.h \ + qq.c \ + qq.h \ qq_proxy.c \ qq_proxy.h \ recv_core.c \ recv_core.h \ send_core.c \ send_core.h \ + send_file.c \ + send_file.h \ sendqueue.c \ sendqueue.h \ sys_msg.c \ sys_msg.h \ udp_proxy_s5.c \ udp_proxy_s5.h \ - send_file.c \ - send_file.h \ - file_trans.c \ - file_trans.h + utils.c \ + utils.h AM_CFLAGS = $(st) @@ -94,7 +94,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/libgaim \ -DVERSION=\"$(VERSION)\" \ - -DDATADIR=\"$(datadir)\" \ + -DQQBUDDYICONDIR=\"$(datadir)/pixmaps/gaim/buddy_icons/qq\" \ $(DEBUG_CFLAGS) \ $(GLIB_CFLAGS) \ $(GAIM_CFLAGS)
--- a/libgaim/protocols/qq/buddy_info.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/buddy_info.c Thu Nov 30 10:30:13 2006 +0000 @@ -508,33 +508,114 @@ } } +static void _qq_send_packet_modify_face(GaimConnection *gc, gint face_num) +{ + GaimAccount *account = gaim_connection_get_account(gc); + GaimPresence *presence = gaim_account_get_presence(account); + qq_data *qd = (qq_data *) gc->proto_data; + gint offset; + + if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) { + offset = 2; + } else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY) + || gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) { + offset = 1; + } else { + offset = 0; + } + + qd->my_icon = 3 * (face_num - 1) + offset; + qd->modifying_face = TRUE; + qq_send_packet_get_info(gc, qd->uid, FALSE); +} + +void qq_set_buddy_icon_for_user(GaimAccount *account, const gchar *who, const gchar *iconfile) +{ + FILE *file; + struct stat st; + + g_return_if_fail(g_stat(iconfile, &st) == 0); + file = g_fopen(iconfile, "rb"); + if (file) { + GaimBuddyIcon *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); + gaim_buddy_icons_set_for_user(account, who, data, data_len); + icon = gaim_buddy_icons_find(account, who); + gaim_buddy_icon_set_path(icon, iconfile); + } +} + +/* TODO: figure out how/when we can use a custom face + * for now, only allow the stock icons */ +void qq_set_my_buddy_icon(GaimConnection *gc, const gchar *iconfile) +{ + gchar *icon; + gint icon_num; + GaimAccount *account = gaim_connection_get_account(gc); + const gchar *icon_path = gaim_account_get_buddy_icon_path(account); + gint prefix_len = strlen(QQ_ICON_PREFIX); + gint suffix_len = strlen(QQ_ICON_SUFFIX); + gint dir_len = strlen(QQBUDDYICONDIR); + gint icon_len = strlen(icon_path) - dir_len - 1 - prefix_len - suffix_len; + gchar *errmsg = g_strconcat(_("You are attempting to set a custom face. Gaim currently only allows the standard faces. Please choose an image from "), QQBUDDYICONDIR, ".", NULL); + + /* make sure we're using an appropriate icon */ + if (!(g_ascii_strncasecmp(icon_path, QQBUDDYICONDIR, dir_len) == 0 + && icon_path[dir_len] == G_DIR_SEPARATOR + && g_ascii_strncasecmp(icon_path + dir_len + 1, QQ_ICON_PREFIX, prefix_len) == 0 + && g_ascii_strncasecmp(icon_path + dir_len + 1 + prefix_len + icon_len, QQ_ICON_SUFFIX, suffix_len) == 0 + && icon_len <= 3)) { + gaim_notify_error(gc, _("Invalid QQ Facea"), errmsg, NULL); + return; + } + /* strip everything but number */ + icon = g_strndup(icon_path + dir_len + 1 + prefix_len, icon_len); + icon_num = strtol(icon, NULL, 10); + g_free(icon); + /* ensure face number in proper range */ + if (icon_num > QQ_FACES) { + gaim_notify_error(gc, _("Invalid QQ Face"), errmsg, NULL); + return; + } + /* 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); +} + /* after getting info or modify myself, refresh the buddy list accordingly */ void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc) { GaimBuddy *b; qq_data *qd; qq_buddy *q_bud; - gchar *alias_utf8; + gchar *alias_utf8, *gaim_name; + GaimAccount *account = gaim_connection_get_account(gc); qd = (qq_data *) gc->proto_data; + gaim_name = uid_to_gaim_name(strtol(info->uid, NULL, 10)); alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT); if (qd->uid == strtol(info->uid, NULL, 10)) { /* it is me */ qd->my_icon = strtol(info->face, NULL, 10); if (alias_utf8 != NULL) - gaim_account_set_alias(gc->account, alias_utf8); + gaim_account_set_alias(account, alias_utf8); } /* update buddy list (including myself, if myself is the buddy) */ - b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10))); + b = gaim_find_buddy(gc->account, gaim_name); q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; if (q_bud != NULL) { /* I have this buddy */ q_bud->age = strtol(info->age, NULL, 10); q_bud->gender = strtol(info->gender, NULL, 10); - q_bud->icon = strtol(info->face, NULL, 10); + q_bud->face = strtol(info->face, NULL, 10); if (alias_utf8 != NULL) q_bud->nickname = g_strdup(alias_utf8); qq_update_buddy_contact(gc, q_bud); } + g_free(gaim_name); g_free(alias_utf8); } @@ -564,11 +645,11 @@ info = (contact_info *) segments; if (qd->modifying_face && strtol(info->face, NULL, 10) != qd->my_icon) { - gchar *icon = g_strdup_printf("%i", qd->my_icon); + gchar *icon = g_strdup_printf("%d", qd->my_icon); qd->modifying_face = FALSE; - memcpy(info->face, icon, 2); + g_free(info->face); + info->face = icon; qq_send_packet_modify_info(gc, segments); - g_free(icon); } qq_refresh_buddy_and_myself(info, gc);
--- a/libgaim/protocols/qq/buddy_info.h Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/buddy_info.h Thu Nov 30 10:30:13 2006 +0000 @@ -41,6 +41,9 @@ #define QQ_BUDDY_GENDER_MM 0x01 #define QQ_BUDDY_GENDER_UNKNOWN 0xff +#define QQ_ICON_PREFIX "qq_" +#define QQ_ICON_SUFFIX ".png" + typedef struct _contact_info { gchar *uid; gchar *nick; @@ -83,6 +86,8 @@ void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc); void qq_send_packet_get_info(GaimConnection *gc, guint32 uid, gboolean show_window); +void qq_set_my_buddy_icon(GaimConnection *gc, const gchar *iconfile); +void qq_set_buddy_icon_for_user(GaimAccount *account, const gchar *who, const gchar *iconfile); void qq_prepare_modify_info(GaimConnection *gc); void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc); void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc);
--- a/libgaim/protocols/qq/buddy_list.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/buddy_list.c Thu Nov 30 10:30:13 2006 +0000 @@ -271,7 +271,7 @@ /* 000-003: uid */ bytes += read_packet_dw(data, &cursor, len, &q_bud->uid); /* 004-005: icon index (1-255) */ - bytes += read_packet_w(data, &cursor, len, &q_bud->icon); + bytes += read_packet_w(data, &cursor, len, &q_bud->face); /* 006-006: age */ bytes += read_packet_b(data, &cursor, len, &q_bud->age); /* 007-007: gender */
--- a/libgaim/protocols/qq/group_info.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/group_info.c Thu Nov 30 10:30:13 2006 +0000 @@ -314,7 +314,7 @@ g_return_if_fail(member != NULL); i++; - read_packet_w(data, cursor, len, &(member->icon)); + read_packet_w(data, cursor, len, &(member->face)); read_packet_b(data, cursor, len, &(member->age)); read_packet_b(data, cursor, len, &(member->gender)); pascal_len = convert_as_pascal_string(*cursor, &(member->nickname), QQ_CHARSET_DEFAULT);
--- a/libgaim/protocols/qq/keep_alive.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/keep_alive.c Thu Nov 30 10:30:13 2006 +0000 @@ -31,6 +31,7 @@ #include "debug.h" #include "server.h" +#include "buddy_info.h" #include "buddy_list.h" #include "buddy_status.h" #include "crypt.h" @@ -118,6 +119,20 @@ } } +static void _qq_update_buddy_icon(GaimAccount *account, const gchar *name, gint face) +{ + GaimBuddyIcon *icon = gaim_buddy_icons_find(account, name); + gchar *icon_num_str = face_to_icon_str(face); + gchar *icon_path = g_strconcat(QQBUDDYICONDIR, G_DIR_SEPARATOR_S, + QQ_ICON_PREFIX, icon_num_str, QQ_ICON_SUFFIX, NULL); + const gchar *old_path = gaim_buddy_icon_get_path(icon); + if (icon == NULL || old_path == NULL + || g_ascii_strcasecmp(icon_path, old_path) != 0) + qq_set_buddy_icon_for_user(account, name, icon_path); + g_free(icon_num_str); + g_free(icon_path); +} + void qq_update_buddy_contact(GaimConnection *gc, qq_buddy *q_bud) { gchar *name; @@ -161,6 +176,7 @@ } gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id); gaim_prpl_got_user_status(gc->account, name, status_id, NULL); + _qq_update_buddy_icon(gc->account, name, q_bud->face); } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy: %d\n", q_bud->uid); }
--- a/libgaim/protocols/qq/qq.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/qq.c Thu Nov 30 10:30:13 2006 +0000 @@ -149,17 +149,7 @@ /* returns the icon name for a buddy or protocol */ static const gchar *_qq_list_icon(GaimAccount *a, GaimBuddy *b) { - gchar *filename; - qq_buddy *q_bud; - - /* do not use g_return_val_if_fail, as it is not assertion */ - if (b == NULL || b->proto_data == NULL) - return "qq"; - - q_bud = (qq_buddy *) b->proto_data; - filename = get_icon_name(q_bud->icon / 3 + 1); - - return filename; + return "qq"; } @@ -246,7 +236,7 @@ /* we can show tiny icons on the four corners of buddy icon, */ static void _qq_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) { - /* each char ** are refering to filename in pixmaps/gaim/status/default/ *png */ + /* each char** are refering to a filename in pixmaps/gaim/status/default/ */ qq_buddy *q_bud = b->proto_data; const char *emblems[4] = { NULL, NULL, NULL, NULL }; @@ -388,80 +378,6 @@ qq_prepare_modify_info(gc); } -static void _qq_change_face_cb(GaimConnection *gc, GaimRequestFields *fields) -{ - qq_data *qd; - GaimRequestField *field; - gint suffix; - - qd = (qq_data *) gc->proto_data; - - field = gaim_request_fields_get_field(fields, "face_num"); - suffix = get_icon_offset(gc); - qd->my_icon = gaim_request_field_choice_get_value(field) * 3 + suffix; - qd->modifying_face = TRUE; - qq_send_packet_get_info(gc, qd->uid, FALSE); -} - -static void _qq_add_face_choice(GaimRequestFieldGroup *group, gint face_num) -{ - GaimRequestField *field; - struct stat img_stat; - FILE *file; - gchar *filename, *img_data; - gchar face[15]; - gint size; - - g_snprintf(face, sizeof(face), "qq_%i.png", face_num); - filename = g_build_filename(DATADIR, "pixmaps", - "gaim","status","default", face, NULL); - g_snprintf(face, sizeof(face), "%i", face_num); - file = g_fopen(filename, "rb"); - if (file && fstat(fileno(file), &img_stat) == 0) { - img_data = g_malloc(img_stat.st_size); - size = fread(img_data, 1, img_stat.st_size, file); - - field = gaim_request_field_image_new(face, face, img_data, size); - gaim_request_field_group_add_field(group, field); - - g_free(img_data); - fclose(file); - } -} - -/* Change your status icon (face) */ -static void _qq_menu_change_face(GaimPluginAction *action) -{ - GaimConnection *gc = (GaimConnection *) action->context; - qq_data *qd = (qq_data *) gc->proto_data; - GaimRequestFields *fields; - GaimRequestFieldGroup *group; - GaimRequestField *field; - gchar label[15]; - gint i; - - fields = gaim_request_fields_new(); - group = gaim_request_field_group_new(_("Selection")); - gaim_request_fields_add_group(fields, group); - field = gaim_request_field_choice_new("face_num", - _("Select a number"), qd->my_icon / 3); - for(i = 1; i <= QQ_FACES; i++) { - g_snprintf(label, sizeof(label), "%i", i); - gaim_request_field_choice_add(field, label); - } - gaim_request_field_group_add_field(group, field); - group = gaim_request_field_group_new(_("Faces")); - gaim_request_fields_add_group(fields, group); - for(i = 1; i <= QQ_FACES; i++) - _qq_add_face_choice(group, i); - - gaim_request_fields(gc, _("Change Your QQ Face"), - _("Change Face"), NULL, fields, - _("Update"), G_CALLBACK(_qq_change_face_cb), - _("Cancel"), NULL, - gc); -} - static void _qq_menu_change_password(GaimPluginAction *action) { gaim_notify_uri(NULL, "https://password.qq.com"); @@ -521,7 +437,7 @@ g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip); g_string_append(info, "<hr>\n"); - g_string_append(info, _("<i>Information below may not be accurate</i><br>\n")); + g_string_append(info, "<i>Information below may not be accurate</i><br>\n"); g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time)); g_string_append_printf(info, _("<b>Last Login IP</b>: %s<br>\n"), qd->last_login_ip); @@ -597,203 +513,6 @@ } */ -/* attempt to output the value and byte length of a given field */ -/* -static gboolean _qq_parse_custom_packet_field(GaimRequestFields *fields, - const gchar *id, guint8 **value, gint *len, gboolean allow_null) -{ - GaimRequestField *field; - const gchar *str; - gint i; - gboolean success; - - success = FALSE; - field = gaim_request_fields_get_field(fields, id); - str = gaim_request_field_string_get_value(field); - if (!str && allow_null) { - return TRUE; - } else if (str) { - success = TRUE; - if (strcmp(id, "uid") != 0) { - *value = hex_str_to_bytes(str, len); - if (!*value) - success = FALSE; - } else { - for (i = 0; i < strlen(str); i++) { - if (!g_ascii_isdigit(str[i])) { - success = FALSE; - break; - } - } - if (success) { - *(guint32 *) value = strtoul(str, NULL, 10); - if (errno == ERANGE) - success = FALSE; - } - } - } - if (!success) - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid entry: %s\n", id); - return success; -} -*/ - -/* attempt to output the field values and body length */ -/* -static gboolean _qq_parse_custom_packet_fields(GaimRequestFields *fields, - guint8 **client, guint8 **cmd, guint8 **seq, guint32 *uid, - guint8 **body, guint8 **key, gint *body_len) -{ - gint len; - gboolean success; - - success = FALSE; - *client = *cmd = *seq = *body = *key = NULL; - *uid = *body_len = 0; - if ((_qq_parse_custom_packet_field(fields, "client", client, &len, FALSE) - && len == 2 - && _qq_parse_custom_packet_field(fields, "cmd", cmd, &len, FALSE) - && len == 2 - && _qq_parse_custom_packet_field(fields, "uid", (guint8 **) uid, &len, FALSE) - && _qq_parse_custom_packet_field(fields, "seq", seq, &len, FALSE) - && len == 2 - && _qq_parse_custom_packet_field(fields, "body", body, body_len, TRUE))) { - if (*body_len > MAX_PACKET_SIZE / 8) { - g_free(*client); - g_free(*cmd); - g_free(*seq); - g_free(*body); - return FALSE; - } - if (!gaim_request_fields_get_bool(fields, "encrypt")) - return TRUE; - else - success = _qq_parse_custom_packet_field(fields, - "key", key, &len, FALSE) - && len == 16 - && *body_len > 0; - } - if (!success) { - if (*client) - g_free(*client); - if (*cmd) - g_free(*cmd); - if (*seq) - g_free(*seq); - if (*key) - g_free(*key); - return FALSE; - } - return TRUE; -} -*/ - -/* parses the request fields and attempts to send the packet */ -/* -static void _qq_send_custom_packet_cb(GaimConnection *gc, GaimRequestFields *fields) -{ - guint32 uid; - guint8 *buf, *client, *cmd, *seq, *body, *encr_body, *key, *cursor; - gint bytes, len, encr_len; - qq_data *qd; - gboolean success; - - qd = (qq_data *) gc->proto_data; - - success = _qq_parse_custom_packet_fields(fields, &client, &cmd, - &seq, &uid, &body, &key, &len); - if (!success) { - gaim_notify_error(gc, _("Error"), _("Invalid entry"), NULL); - return; - } - - bytes = 0; - buf = g_newa(guint8, MAX_PACKET_SIZE); - cursor = buf; -*/ - /* QQ TCP packet has two bytes in the beginning to define packet length - * so I leave room here for size */ -/* - if (qd->use_tcp) - bytes += create_packet_w(buf, &cursor, 0x0000); - bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAG); - bytes += create_packet_w(buf, &cursor, *(guint16 *) client); - bytes += create_packet_w(buf, &cursor, *(guint16 *) cmd); - bytes += create_packet_w(buf, &cursor, *(guint16 *) seq); - bytes += create_packet_dw(buf, &cursor, uid); - if (body) { - if (gaim_request_fields_get_bool(fields, "encrypt")) { - if (gaim_request_fields_get_bool(fields, "prepend")) - bytes += create_packet_data(buf, &cursor, key, 16); - encr_body = g_newa(guint8, MAX_PACKET_SIZE); - qq_crypt(ENCRYPT, body, len, key, encr_body, &encr_len); - bytes += create_packet_data(buf, &cursor, encr_body, encr_len); - g_free(key); - } else { - bytes += create_packet_data(buf, &cursor, body, len); - } - - g_free(body); - } - bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL); - - gaim_debug(GAIM_DEBUG_INFO, "QQ", "Custom packet of length %i\n", bytes); - _qq_show_packet("Outgoing custom packet", buf, bytes); - - _qq_send_packet(gc, buf, bytes, *(guint16 *) cmd); - g_free(client); - g_free(cmd); - g_free(seq); -} -*/ - -/* send a custom packet to the server - for protocol testing */ -/* -static void _qq_menu_send_custom_packet(GaimPluginAction *action) -{ - GaimConnection *gc; - GaimRequestFields *fields; - GaimRequestFieldGroup *group; - GaimRequestField *field; - gchar tmp[15]; - qq_data *qd; - - gc = (GaimConnection *) action->context; - qd = (qq_data *) gc->proto_data; - - fields = gaim_request_fields_new(); - group = gaim_request_field_group_new(_("Basic Elements")); - gaim_request_fields_add_group(fields, group); - g_snprintf(tmp, sizeof(tmp), "%04X", QQ_CLIENT); - field = gaim_request_field_string_new("client", _("Client (hex)"), tmp, FALSE); - gaim_request_field_group_add_field(group, field); - field = gaim_request_field_string_new("cmd", _("Command (hex)"), "0000", FALSE); - gaim_request_field_group_add_field(group, field); - field = gaim_request_field_string_new("seq", _("Sequence (hex)"), "0000", FALSE); - gaim_request_field_group_add_field(group, field); - g_snprintf(tmp, sizeof(tmp), "%u", qd->uid); - field = gaim_request_field_string_new("uid", _("QQ Number (decimal)"), tmp, FALSE); - gaim_request_field_group_add_field(group, field); - field = gaim_request_field_string_new("body", _("Body (hex)"), NULL, TRUE); - gaim_request_field_group_add_field(group, field); - group = gaim_request_field_group_new(_("Encryption")); - gaim_request_fields_add_group(fields, group); - field = gaim_request_field_bool_new("encrypt", _("Encrypt Packet Body"), FALSE); - gaim_request_field_group_add_field(group, field); - field = gaim_request_field_bool_new("prepend", _("Prepend Key to Body"), FALSE); - gaim_request_field_group_add_field(group, field); - field = gaim_request_field_string_new("key", _("Encryption Key (hex)"), NULL, FALSE); - gaim_request_field_group_add_field(group, field); - - - gaim_request_fields(gc, _("Send a custom packet"), - _("Send a custom packet"), NULL, fields, - _("Send"), G_CALLBACK(_qq_send_custom_packet_cb), - _("Cancel"), NULL, - gc); -} -*/ - /* protocol related menus */ static GList *_qq_actions(GaimPlugin *plugin, gpointer context) { @@ -804,20 +523,12 @@ act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info); m = g_list_append(m, act); - act = gaim_plugin_action_new(_("Change My Face"), _qq_menu_change_face); - m = g_list_append(m, act); - act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password); m = g_list_append(m, act); act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info); m = g_list_append(m, act); -/* - act = gaim_plugin_action_new(_("Send Custom Packet"), _qq_menu_send_custom_packet); - m = g_list_append(m, act); -*/ - /* act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group); m = g_list_append(m, act); @@ -918,75 +629,69 @@ return chat_name_to_gaim_name(who); } -void qq_function_not_implemented(GaimConnection *gc) -{ - gaim_notify_warning(gc, NULL, - _("This function has not be implemented yet"), _("Please wait for new version")); -} - GaimPlugin *my_protocol = NULL; static GaimPluginProtocolInfo prpl_info = { OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE, - NULL, /* user_splits */ - NULL, /* protocol_options */ - NO_BUDDY_ICONS, /* icon_spec */ - _qq_list_icon, /* list_icon */ - _qq_list_emblems, /* list_emblems */ - _qq_status_text, /* status_text */ - _qq_tooltip_text, /* tooltip_text */ - _qq_away_states, /* away_states */ - _qq_buddy_menu, /* blist_node_menu */ - qq_chat_info, /* chat_info */ - qq_chat_info_defaults, /* chat_info_defaults */ - _qq_login, /* login */ - _qq_close, /* close */ - _qq_send_im, /* send_im */ - NULL, /* set_info */ - NULL, /* send_typing */ - _qq_get_info, /* get_info */ - _qq_set_away, /* set_away */ - NULL, /* set_idle */ - NULL, /* change_passwd */ - qq_add_buddy, /* add_buddy */ - NULL, /* add_buddies */ - qq_remove_buddy, /* remove_buddy */ - NULL, /* remove_buddies */ - NULL, /* add_permit */ - NULL, /* add_deny */ - NULL, /* rem_permit */ - NULL, /* rem_deny */ - NULL, /* set_permit_deny */ - qq_group_join, /* join_chat */ - NULL, /* reject chat invite */ - NULL, /* get_chat_name */ - NULL, /* chat_invite */ - NULL, /* chat_leave */ - NULL, /* chat_whisper */ - _qq_chat_send, /* chat_send */ - _qq_keep_alive, /* keepalive */ - NULL, /* register_user */ - _qq_get_chat_buddy_info, /* get_cb_info */ - NULL, /* get_cb_away */ - NULL, /* alias_buddy */ - NULL, /* group_buddy */ - NULL, /* rename_group */ - NULL, /* buddy_free */ - NULL, /* convo_closed */ - NULL, /* normalize */ - NULL, /* set_buddy_icon */ - NULL, /* remove_group */ - _qq_get_chat_buddy_real_name, /* get_cb_real_name */ - NULL, /* set_chat_topic */ - NULL, /* find_blist_chat */ - qq_roomlist_get_list, /* roomlist_get_list */ - qq_roomlist_cancel, /* roomlist_cancel */ - NULL, /* roomlist_expand_category */ - NULL, /* can_receive_file */ - qq_send_file, /* send_file */ - NULL, /* new xfer */ - NULL, /* offline_message */ - NULL, /* GaimWhiteboardPrplOps */ - NULL, /* send_raw */ + NULL, /* user_splits */ + NULL, /* protocol_options */ + {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */ + _qq_list_icon, /* list_icon */ + _qq_list_emblems, /* list_emblems */ + _qq_status_text, /* status_text */ + _qq_tooltip_text, /* tooltip_text */ + _qq_away_states, /* away_states */ + _qq_buddy_menu, /* blist_node_menu */ + qq_chat_info, /* chat_info */ + qq_chat_info_defaults, /* chat_info_defaults */ + _qq_login, /* login */ + _qq_close, /* close */ + _qq_send_im, /* send_im */ + NULL, /* set_info */ + NULL, /* send_typing */ + _qq_get_info, /* get_info */ + _qq_set_away, /* set_away */ + NULL, /* set_idle */ + NULL, /* change_passwd */ + qq_add_buddy, /* add_buddy */ + NULL, /* add_buddies */ + qq_remove_buddy, /* remove_buddy */ + NULL, /* remove_buddies */ + NULL, /* add_permit */ + NULL, /* add_deny */ + NULL, /* rem_permit */ + NULL, /* rem_deny */ + NULL, /* set_permit_deny */ + qq_group_join, /* join_chat */ + NULL, /* reject chat invite */ + NULL, /* get_chat_name */ + NULL, /* chat_invite */ + NULL, /* chat_leave */ + NULL, /* chat_whisper */ + _qq_chat_send, /* chat_send */ + _qq_keep_alive, /* keepalive */ + NULL, /* register_user */ + _qq_get_chat_buddy_info, /* get_cb_info */ + NULL, /* get_cb_away */ + NULL, /* alias_buddy */ + NULL, /* group_buddy */ + NULL, /* rename_group */ + NULL, /* buddy_free */ + NULL, /* convo_closed */ + NULL, /* normalize */ + qq_set_my_buddy_icon, /* set_buddy_icon */ + NULL, /* remove_group */ + _qq_get_chat_buddy_real_name, /* get_cb_real_name */ + NULL, /* set_chat_topic */ + NULL, /* find_blist_chat */ + qq_roomlist_get_list, /* roomlist_get_list */ + qq_roomlist_cancel, /* roomlist_cancel */ + NULL, /* roomlist_expand_category */ + NULL, /* can_receive_file */ + qq_send_file, /* send_file */ + NULL, /* new xfer */ + NULL, /* offline_message */ + NULL, /* GaimWhiteboardPrplOps */ + NULL, /* send_raw */ }; static GaimPluginInfo info = {
--- a/libgaim/protocols/qq/qq.h Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/qq.h Thu Nov 30 10:30:13 2006 +0000 @@ -40,7 +40,7 @@ struct _qq_buddy { guint32 uid; - guint16 icon; /* index: 01 - 85 */ + guint16 face; /* index: 0 - 299 */ guint8 age; guint8 gender; gchar *nickname; @@ -86,7 +86,7 @@ /* get from keep_alive packet */ gchar *my_ip; /* my ip address detected by server */ guint16 my_port; /* my port detected by server */ - guint16 my_icon; /* my icon index */ + guint16 my_icon; /* my icon index */ guint32 all_online; /* the number of online QQ users */ time_t last_get_online; /* last time send get_friends_online packet */ @@ -108,7 +108,7 @@ GList *add_buddy_request; GQueue *before_login_packets; - /* TODO is there a better way of handling these? */ + /* TODO pass qq_send_packet_get_info() a callback and use signals to get rid of these */ gboolean modifying_info; gboolean modifying_face; };
--- a/libgaim/protocols/qq/utils.c Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/utils.c Thu Nov 30 10:30:13 2006 +0000 @@ -159,13 +159,6 @@ return ip; } -/* return the QQ icon file name - * the return needs to be freed */ -gchar *get_icon_name(gint set) -{ - return g_strdup_printf("qq_%d", set); -} - /* convert Gaim name to original QQ UID */ guint32 gaim_name_to_uid(const gchar *const name) { @@ -337,3 +330,22 @@ return ret; } + +/* convert face num from packet (0-299) to local face (1-100) */ +gchar *face_to_icon_str(gint face) +{ + gchar *icon_num_str; + gint icon_num = face / 3 + 1; + icon_num_str = g_strdup_printf("%d", icon_num); + return icon_num_str; +} + +/* +gint face_to_icon_num(const gchar *face) +{ + gchar *icon_str = face_to_icon_str(face); + gint icon_num = strtol(icon_str, NULL, 10); + g_free(icon_str); + return icon_num; +} +*/
--- a/libgaim/protocols/qq/utils.h Thu Nov 30 10:19:09 2006 +0000 +++ b/libgaim/protocols/qq/utils.h Thu Nov 30 10:30:13 2006 +0000 @@ -42,7 +42,7 @@ gchar *uid_to_gaim_name(guint32 uid); gchar *chat_name_to_gaim_name(const gchar *const name); -gchar *get_icon_name(gint set); +gchar *face_to_icon_str(gint face); void try_dump_as_gbk(const guint8 *const data, gint len);