Mercurial > pidgin
comparison libpurple/protocols/qq/buddy_info.c @ 24653:fecedf6d9ee1
propagate from branch 'im.pidgin.pidgin' (head 97d295a04f3a9852a3b29cf0df43d56d1ddcc672)
to branch 'im.pidgin.pidgin.openq' (head a0d99396d1603b53838d74cad4391ece34f3ebbf)
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 14:51:36 +0000 |
parents | 40141d227b27 699e8f0571ac |
children | 8ee728876ded |
comparison
equal
deleted
inserted
replaced
24590:c457c635eb8f | 24653:fecedf6d9ee1 |
---|---|
226 gchar raw_data[16] = {0}; | 226 gchar raw_data[16] = {0}; |
227 | 227 |
228 g_return_if_fail(uid != 0); | 228 g_return_if_fail(uid != 0); |
229 | 229 |
230 qd = (qq_data *) gc->proto_data; | 230 qd = (qq_data *) gc->proto_data; |
231 g_snprintf(raw_data, sizeof(raw_data), "%d", uid); | 231 g_snprintf(raw_data, sizeof(raw_data), "%u", uid); |
232 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDY_INFO, (guint8 *) raw_data, strlen(raw_data), | 232 qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDY_INFO, (guint8 *) raw_data, strlen(raw_data), |
233 update_class, action); | 233 update_class, action); |
234 } | 234 } |
235 | 235 |
236 /* send packet to modify personal information */ | 236 /* send packet to modify personal information */ |
502 | 502 |
503 void qq_set_custom_icon(PurpleConnection *gc, PurpleStoredImage *img) | 503 void qq_set_custom_icon(PurpleConnection *gc, PurpleStoredImage *img) |
504 { | 504 { |
505 PurpleAccount *account = purple_connection_get_account(gc); | 505 PurpleAccount *account = purple_connection_get_account(gc); |
506 const gchar *icon_path = purple_account_get_buddy_icon_path(account); | 506 const gchar *icon_path = purple_account_get_buddy_icon_path(account); |
507 gchar **segments; | |
508 gint index; | |
507 | 509 |
508 g_return_if_fail(icon_path != NULL); | 510 g_return_if_fail(icon_path != NULL); |
509 | 511 |
510 /* Fixme: | 512 /* Fixme: |
511 * icon_path is always null | 513 * icon_path is always null |
512 * purple_imgstore_get_filename is always new file | 514 * purple_imgstore_get_filename is always new file |
513 * QQ buddy may set custom icon if level is over 16 */ | 515 * QQ buddy may set custom icon if level is over 16 */ |
514 purple_debug_info("QQ", "Change my icon to %s\n", icon_path); | 516 purple_debug_info("QQ", "Change my icon to %s\n", icon_path); |
517 segments = g_strsplit_set(icon_path, G_DIR_SEPARATOR_S, 0); | |
518 for (index = 0; segments[index] != NULL; index++) { | |
519 purple_debug_info("QQ", "Split to %s\n", segments[index]); | |
520 } | |
521 | |
522 g_strfreev(segments); | |
515 } | 523 } |
516 | 524 |
517 gchar *qq_get_icon_name(gint face) | 525 gchar *qq_get_icon_name(gint face) |
518 { | 526 { |
519 gint icon; | 527 gint icon; |
551 icon_path = g_strdup_printf("%s%c%s", icon_dir, G_DIR_SEPARATOR, icon_name); | 559 icon_path = g_strdup_printf("%s%c%s", icon_dir, G_DIR_SEPARATOR, icon_name); |
552 | 560 |
553 return icon_path; | 561 return icon_path; |
554 } | 562 } |
555 | 563 |
556 static void update_buddy_icon(PurpleAccount *account, const gchar *who, gint face) | 564 void qq_update_buddy_icon(PurpleAccount *account, const gchar *who, gint face) |
557 { | 565 { |
558 PurpleBuddy *buddy; | 566 PurpleBuddy *buddy; |
559 const gchar *icon_name_prev = NULL; | 567 const gchar *icon_name_prev = NULL; |
560 gchar *icon_name; | 568 gchar *icon_name; |
561 gchar *icon_path; | 569 gchar *icon_path; |
562 gchar *icon_file_content; | 570 gchar *icon_file_content; |
563 gsize icon_file_size; | 571 gsize icon_file_size; |
564 | 572 |
565 g_return_if_fail(account != NULL && who != NULL); | 573 g_return_if_fail(account != NULL && who != NULL); |
566 | 574 |
567 purple_debug_info("QQ", "Update %s icon to %d\n", who, face); | 575 /* purple_debug_info("QQ", "Update %s icon to %d\n", who, face); */ |
568 | 576 |
569 icon_name = qq_get_icon_name(face); | 577 icon_name = qq_get_icon_name(face); |
570 purple_debug_info("QQ", "icon file name is %s\n", icon_name); | 578 g_return_if_fail(icon_name != NULL); |
579 /* purple_debug_info("QQ", "icon file name is %s\n", icon_name); */ | |
571 | 580 |
572 if ((buddy = purple_find_buddy(account, who))) { | 581 if ((buddy = purple_find_buddy(account, who))) { |
573 icon_name_prev = purple_buddy_icons_get_checksum_for_user(buddy); | 582 icon_name_prev = purple_buddy_icons_get_checksum_for_user(buddy); |
574 if (icon_name_prev != NULL) { | 583 /* |
575 purple_debug_info("QQ", "Previous icon is %s\n", icon_name_prev); | 584 purple_debug_info("QQ", "Previous icon is %s\n", |
576 } | 585 icon_name_prev != NULL ? icon_name_prev : "(NULL)"); |
586 */ | |
577 } | 587 } |
578 if (icon_name_prev != NULL && !strcmp(icon_name, icon_name_prev)) { | 588 if (icon_name_prev != NULL && !strcmp(icon_name, icon_name_prev)) { |
579 purple_debug_info("QQ", "Icon is not changed\n"); | 589 /* purple_debug_info("QQ", "Icon is not changed\n"); */ |
580 g_free(icon_name); | 590 g_free(icon_name); |
581 return; | 591 return; |
582 } | 592 } |
583 | 593 |
584 icon_path = qq_get_icon_path(icon_name); | 594 icon_path = qq_get_icon_path(icon_name); |
588 } | 598 } |
589 | 599 |
590 if (!g_file_get_contents(icon_path, &icon_file_content, &icon_file_size, NULL)) { | 600 if (!g_file_get_contents(icon_path, &icon_file_content, &icon_file_size, NULL)) { |
591 purple_debug_error("QQ", "Failed reading icon file %s\n", icon_path); | 601 purple_debug_error("QQ", "Failed reading icon file %s\n", icon_path); |
592 } else { | 602 } else { |
603 purple_debug_info("QQ", "Update %s icon to %d (%s)\n", | |
604 who, face, icon_path); | |
593 purple_buddy_icons_set_for_user(account, who, | 605 purple_buddy_icons_set_for_user(account, who, |
594 icon_file_content, icon_file_size, icon_name); | 606 icon_file_content, icon_file_size, icon_name); |
595 } | 607 } |
596 g_free(icon_name); | 608 g_free(icon_name); |
597 g_free(icon_path); | 609 g_free(icon_path); |
608 gchar *alias_utf8; | 620 gchar *alias_utf8; |
609 PurpleAccount *account = purple_connection_get_account(gc); | 621 PurpleAccount *account = purple_connection_get_account(gc); |
610 | 622 |
611 qd = (qq_data *) gc->proto_data; | 623 qd = (qq_data *) gc->proto_data; |
612 | 624 |
613 uid = strtol(segments[QQ_INFO_UID], NULL, 10); | 625 uid = strtoul(segments[QQ_INFO_UID], NULL, 10); |
614 who = uid_to_purple_name(uid); | 626 who = uid_to_purple_name(uid); |
615 | 627 |
616 qq_filter_str(segments[QQ_INFO_NICK]); | 628 qq_filter_str(segments[QQ_INFO_NICK]); |
617 alias_utf8 = qq_to_utf8(segments[QQ_INFO_NICK], QQ_CHARSET_DEFAULT); | 629 alias_utf8 = qq_to_utf8(segments[QQ_INFO_NICK], QQ_CHARSET_DEFAULT); |
618 if (uid == qd->uid) { /* it is me */ | 630 if (uid == qd->uid) { /* it is me */ |
646 bd->last_update = time(NULL); | 658 bd->last_update = time(NULL); |
647 | 659 |
648 purple_blist_server_alias_buddy(buddy, bd->nickname); | 660 purple_blist_server_alias_buddy(buddy, bd->nickname); |
649 | 661 |
650 /* convert face num from packet (0-299) to local face (1-100) */ | 662 /* convert face num from packet (0-299) to local face (1-100) */ |
651 update_buddy_icon(gc->account, who, bd->face); | 663 qq_update_buddy_icon(gc->account, who, bd->face); |
652 | 664 |
653 g_free(who); | 665 g_free(who); |
654 g_free(alias_utf8); | 666 g_free(alias_utf8); |
655 } | 667 } |
656 | 668 |
784 while (data_len - bytes >= 12) { | 796 while (data_len - bytes >= 12) { |
785 bytes += qq_get32(&uid, data + bytes); | 797 bytes += qq_get32(&uid, data + bytes); |
786 bytes += qq_get32(&onlineTime, data + bytes); | 798 bytes += qq_get32(&onlineTime, data + bytes); |
787 bytes += qq_get16(&level, data + bytes); | 799 bytes += qq_get16(&level, data + bytes); |
788 bytes += qq_get16(&timeRemainder, data + bytes); | 800 bytes += qq_get16(&timeRemainder, data + bytes); |
789 purple_debug_info("QQ_LEVEL", "%d, tmOnline: %d, level: %d, tmRemainder: %d\n", | 801 purple_debug_info("QQ", "level: %d, uid %d, tmOnline: %d, tmRemainder: %d\n", |
790 uid, onlineTime, level, timeRemainder); | 802 level, uid, onlineTime, timeRemainder); |
791 | 803 |
792 bd = qq_buddy_data_find(gc, uid); | 804 bd = qq_buddy_data_find(gc, uid); |
793 if (bd == NULL) { | 805 if (bd == NULL) { |
794 purple_debug_error("QQ", "Got levels of %d not in my buddy list\n", uid); | 806 purple_debug_error("QQ", "Got levels of %u not in my buddy list\n", uid); |
795 continue; | 807 continue; |
796 } | 808 } |
797 | 809 |
798 bd->onlineTime = onlineTime; | 810 bd->onlineTime = onlineTime; |
799 bd->level = level; | 811 bd->level = level; |
819 bytes = 0; | 831 bytes = 0; |
820 bytes += qq_get32(&uid, data + bytes); | 832 bytes += qq_get32(&uid, data + bytes); |
821 bytes += qq_get32(&onlineTime, data + bytes); | 833 bytes += qq_get32(&onlineTime, data + bytes); |
822 bytes += qq_get16(&level, data + bytes); | 834 bytes += qq_get16(&level, data + bytes); |
823 bytes += qq_get16(&timeRemainder, data + bytes); | 835 bytes += qq_get16(&timeRemainder, data + bytes); |
824 purple_debug_info("QQ_LEVEL", "%d, tmOnline: %d, level: %d, tmRemainder: %d\n", | 836 purple_debug_info("QQ", "level: %d, uid %d, tmOnline: %d, tmRemainder: %d\n", |
825 uid, onlineTime, level, timeRemainder); | 837 level, uid, onlineTime, timeRemainder); |
826 | 838 |
827 bd = qq_buddy_data_find(gc, uid); | 839 bd = qq_buddy_data_find(gc, uid); |
828 if (bd == NULL) { | 840 if (bd == NULL) { |
829 purple_debug_error("QQ", "Got levels of %d not in my buddy list\n", uid); | 841 purple_debug_error("QQ", "Got levels of %d not in my buddy list\n", uid); |
830 return; | 842 return; |