Mercurial > pidgin
comparison libgaim/protocols/qq/buddy_info.c @ 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>
author | Mark Huetsch <markhuetsch> |
---|---|
date | Thu, 30 Nov 2006 10:30:13 +0000 |
parents | c039c920e11c |
children | 2c93b0620065 |
comparison
equal
deleted
inserted
replaced
15070:97ae8709d6dc | 15071:902f3621aa13 |
---|---|
506 } else { | 506 } else { |
507 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n"); | 507 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n"); |
508 } | 508 } |
509 } | 509 } |
510 | 510 |
511 static void _qq_send_packet_modify_face(GaimConnection *gc, gint face_num) | |
512 { | |
513 GaimAccount *account = gaim_connection_get_account(gc); | |
514 GaimPresence *presence = gaim_account_get_presence(account); | |
515 qq_data *qd = (qq_data *) gc->proto_data; | |
516 gint offset; | |
517 | |
518 if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) { | |
519 offset = 2; | |
520 } else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY) | |
521 || gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) { | |
522 offset = 1; | |
523 } else { | |
524 offset = 0; | |
525 } | |
526 | |
527 qd->my_icon = 3 * (face_num - 1) + offset; | |
528 qd->modifying_face = TRUE; | |
529 qq_send_packet_get_info(gc, qd->uid, FALSE); | |
530 } | |
531 | |
532 void qq_set_buddy_icon_for_user(GaimAccount *account, const gchar *who, const gchar *iconfile) | |
533 { | |
534 FILE *file; | |
535 struct stat st; | |
536 | |
537 g_return_if_fail(g_stat(iconfile, &st) == 0); | |
538 file = g_fopen(iconfile, "rb"); | |
539 if (file) { | |
540 GaimBuddyIcon *icon; | |
541 size_t data_len; | |
542 gchar *data = g_new(gchar, st.st_size + 1); | |
543 data_len = fread(data, 1, st.st_size, file); | |
544 fclose(file); | |
545 gaim_buddy_icons_set_for_user(account, who, data, data_len); | |
546 icon = gaim_buddy_icons_find(account, who); | |
547 gaim_buddy_icon_set_path(icon, iconfile); | |
548 } | |
549 } | |
550 | |
551 /* TODO: figure out how/when we can use a custom face | |
552 * for now, only allow the stock icons */ | |
553 void qq_set_my_buddy_icon(GaimConnection *gc, const gchar *iconfile) | |
554 { | |
555 gchar *icon; | |
556 gint icon_num; | |
557 GaimAccount *account = gaim_connection_get_account(gc); | |
558 const gchar *icon_path = gaim_account_get_buddy_icon_path(account); | |
559 gint prefix_len = strlen(QQ_ICON_PREFIX); | |
560 gint suffix_len = strlen(QQ_ICON_SUFFIX); | |
561 gint dir_len = strlen(QQBUDDYICONDIR); | |
562 gint icon_len = strlen(icon_path) - dir_len - 1 - prefix_len - suffix_len; | |
563 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); | |
564 | |
565 /* make sure we're using an appropriate icon */ | |
566 if (!(g_ascii_strncasecmp(icon_path, QQBUDDYICONDIR, dir_len) == 0 | |
567 && icon_path[dir_len] == G_DIR_SEPARATOR | |
568 && g_ascii_strncasecmp(icon_path + dir_len + 1, QQ_ICON_PREFIX, prefix_len) == 0 | |
569 && g_ascii_strncasecmp(icon_path + dir_len + 1 + prefix_len + icon_len, QQ_ICON_SUFFIX, suffix_len) == 0 | |
570 && icon_len <= 3)) { | |
571 gaim_notify_error(gc, _("Invalid QQ Facea"), errmsg, NULL); | |
572 return; | |
573 } | |
574 /* strip everything but number */ | |
575 icon = g_strndup(icon_path + dir_len + 1 + prefix_len, icon_len); | |
576 icon_num = strtol(icon, NULL, 10); | |
577 g_free(icon); | |
578 /* ensure face number in proper range */ | |
579 if (icon_num > QQ_FACES) { | |
580 gaim_notify_error(gc, _("Invalid QQ Face"), errmsg, NULL); | |
581 return; | |
582 } | |
583 /* tell server my icon changed */ | |
584 _qq_send_packet_modify_face(gc, icon_num); | |
585 /* display in blist */ | |
586 qq_set_buddy_icon_for_user(account, account->username, icon_path); | |
587 } | |
588 | |
511 /* after getting info or modify myself, refresh the buddy list accordingly */ | 589 /* after getting info or modify myself, refresh the buddy list accordingly */ |
512 void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc) | 590 void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc) |
513 { | 591 { |
514 GaimBuddy *b; | 592 GaimBuddy *b; |
515 qq_data *qd; | 593 qq_data *qd; |
516 qq_buddy *q_bud; | 594 qq_buddy *q_bud; |
517 gchar *alias_utf8; | 595 gchar *alias_utf8, *gaim_name; |
596 GaimAccount *account = gaim_connection_get_account(gc); | |
518 | 597 |
519 qd = (qq_data *) gc->proto_data; | 598 qd = (qq_data *) gc->proto_data; |
599 gaim_name = uid_to_gaim_name(strtol(info->uid, NULL, 10)); | |
520 | 600 |
521 alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT); | 601 alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT); |
522 if (qd->uid == strtol(info->uid, NULL, 10)) { /* it is me */ | 602 if (qd->uid == strtol(info->uid, NULL, 10)) { /* it is me */ |
523 qd->my_icon = strtol(info->face, NULL, 10); | 603 qd->my_icon = strtol(info->face, NULL, 10); |
524 if (alias_utf8 != NULL) | 604 if (alias_utf8 != NULL) |
525 gaim_account_set_alias(gc->account, alias_utf8); | 605 gaim_account_set_alias(account, alias_utf8); |
526 } | 606 } |
527 /* update buddy list (including myself, if myself is the buddy) */ | 607 /* update buddy list (including myself, if myself is the buddy) */ |
528 b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10))); | 608 b = gaim_find_buddy(gc->account, gaim_name); |
529 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; | 609 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; |
530 if (q_bud != NULL) { /* I have this buddy */ | 610 if (q_bud != NULL) { /* I have this buddy */ |
531 q_bud->age = strtol(info->age, NULL, 10); | 611 q_bud->age = strtol(info->age, NULL, 10); |
532 q_bud->gender = strtol(info->gender, NULL, 10); | 612 q_bud->gender = strtol(info->gender, NULL, 10); |
533 q_bud->icon = strtol(info->face, NULL, 10); | 613 q_bud->face = strtol(info->face, NULL, 10); |
534 if (alias_utf8 != NULL) | 614 if (alias_utf8 != NULL) |
535 q_bud->nickname = g_strdup(alias_utf8); | 615 q_bud->nickname = g_strdup(alias_utf8); |
536 qq_update_buddy_contact(gc, q_bud); | 616 qq_update_buddy_contact(gc, q_bud); |
537 } | 617 } |
618 g_free(gaim_name); | |
538 g_free(alias_utf8); | 619 g_free(alias_utf8); |
539 } | 620 } |
540 | 621 |
541 /* process reply to get_info packet */ | 622 /* process reply to get_info packet */ |
542 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) | 623 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) |
562 if (NULL == (segments = split_data(data, len, "\x1e", QQ_CONTACT_FIELDS))) | 643 if (NULL == (segments = split_data(data, len, "\x1e", QQ_CONTACT_FIELDS))) |
563 return; | 644 return; |
564 | 645 |
565 info = (contact_info *) segments; | 646 info = (contact_info *) segments; |
566 if (qd->modifying_face && strtol(info->face, NULL, 10) != qd->my_icon) { | 647 if (qd->modifying_face && strtol(info->face, NULL, 10) != qd->my_icon) { |
567 gchar *icon = g_strdup_printf("%i", qd->my_icon); | 648 gchar *icon = g_strdup_printf("%d", qd->my_icon); |
568 qd->modifying_face = FALSE; | 649 qd->modifying_face = FALSE; |
569 memcpy(info->face, icon, 2); | 650 g_free(info->face); |
651 info->face = icon; | |
570 qq_send_packet_modify_info(gc, segments); | 652 qq_send_packet_modify_info(gc, segments); |
571 g_free(icon); | |
572 } | 653 } |
573 | 654 |
574 qq_refresh_buddy_and_myself(info, gc); | 655 qq_refresh_buddy_and_myself(info, gc); |
575 | 656 |
576 query_list = qd->info_query; | 657 query_list = qd->info_query; |