Mercurial > pidgin
comparison libpurple/protocols/jabber/buddy.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 2ec94166be43 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
463 JabberIq *iq; | 463 JabberIq *iq; |
464 JabberStream *js = purple_connection_get_protocol_data(gc); | 464 JabberStream *js = purple_connection_get_protocol_data(gc); |
465 xmlnode *vc_node; | 465 xmlnode *vc_node; |
466 const struct tag_attr *tag_attr; | 466 const struct tag_attr *tag_attr; |
467 | 467 |
468 /* if we have't grabbed the remote vcard yet, we can't | 468 /* if we haven't grabbed the remote vcard yet, we can't |
469 * assume that what we have here is correct */ | 469 * assume that what we have here is correct */ |
470 if(!js->vcard_fetched) | 470 if(!js->vcard_fetched) { |
471 PurpleStoredImage *image; | |
472 g_free(js->initial_avatar_hash); | |
473 image = purple_buddy_icons_find_account_icon(purple_connection_get_account(gc)); | |
474 if (image != NULL) { | |
475 js->initial_avatar_hash = | |
476 jabber_calculate_data_hash(purple_imgstore_get_data(image), | |
477 purple_imgstore_get_size(image), "sha1"); | |
478 purple_imgstore_unref(image); | |
479 } else { | |
480 js->initial_avatar_hash = NULL; | |
481 } | |
471 return; | 482 return; |
483 } | |
472 | 484 |
473 if (js->vcard_timer) { | 485 if (js->vcard_timer) { |
474 purple_timeout_remove(js->vcard_timer); | 486 purple_timeout_remove(js->vcard_timer); |
475 js->vcard_timer = 0; | 487 js->vcard_timer = 0; |
476 } | 488 } |
487 g_ascii_strncasecmp(vc_node->name, "vCard", 5))) { | 499 g_ascii_strncasecmp(vc_node->name, "vCard", 5))) { |
488 xmlnode_free(vc_node); | 500 xmlnode_free(vc_node); |
489 vc_node = NULL; | 501 vc_node = NULL; |
490 } | 502 } |
491 | 503 |
492 if ((img = purple_buddy_icons_find_account_icon(gc->account))) { | 504 if ((img = purple_buddy_icons_find_account_icon(purple_connection_get_account(gc)))) { |
493 gconstpointer avatar_data; | 505 gconstpointer avatar_data; |
494 gsize avatar_len; | 506 gsize avatar_len; |
495 xmlnode *photo, *binval, *type; | 507 xmlnode *photo, *binval, *type; |
496 gchar *enc; | 508 gchar *enc; |
497 | 509 |
543 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) | 555 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
544 { | 556 { |
545 PurpleAccount *account = purple_connection_get_account(gc); | 557 PurpleAccount *account = purple_connection_get_account(gc); |
546 | 558 |
547 /* Publish the avatar as specified in XEP-0084 */ | 559 /* Publish the avatar as specified in XEP-0084 */ |
548 jabber_avatar_set(gc->proto_data, img); | 560 jabber_avatar_set(purple_connection_get_protocol_data(gc), img); |
549 /* Set the image in our vCard */ | 561 /* Set the image in our vCard */ |
550 jabber_set_info(gc, purple_account_get_user_info(account)); | 562 jabber_set_info(gc, purple_account_get_user_info(account)); |
551 | 563 |
552 /* TODO: Fake image to ourselves, since a number of servers do not echo | 564 /* TODO: Fake image to ourselves, since a number of servers do not echo |
553 * back our presence to us. To do this without uselessly copying the data | 565 * back our presence to us. To do this without uselessly copying the data |
628 purple_request_fields_add_group(fields, group); | 640 purple_request_fields_add_group(fields, group); |
629 | 641 |
630 /* | 642 /* |
631 * Get existing, XML-formatted, user info | 643 * Get existing, XML-formatted, user info |
632 */ | 644 */ |
633 if((user_info = purple_account_get_user_info(gc->account)) != NULL) | 645 if((user_info = purple_account_get_user_info(purple_connection_get_account(gc))) != NULL) |
634 x_vc_data = xmlnode_from_str(user_info, -1); | 646 x_vc_data = xmlnode_from_str(user_info, -1); |
635 | 647 |
636 /* | 648 /* |
637 * Set up GSLists for edit with labels from "template," data from user info | 649 * Set up GSLists for edit with labels from "template," data from user info |
638 */ | 650 */ |
717 if (jbr && jbr->client.name) { | 729 if (jbr && jbr->client.name) { |
718 char *tmp = | 730 char *tmp = |
719 g_strdup_printf("%s%s%s", jbr->client.name, | 731 g_strdup_printf("%s%s%s", jbr->client.name, |
720 (jbr->client.version ? " " : ""), | 732 (jbr->client.version ? " " : ""), |
721 (jbr->client.version ? jbr->client.version : "")); | 733 (jbr->client.version ? jbr->client.version : "")); |
722 purple_notify_user_info_prepend_pair(user_info, _("Client"), tmp); | 734 /* TODO: Check whether it's correct to call prepend_pair_html, |
735 or if we should be using prepend_pair_plaintext */ | |
736 purple_notify_user_info_prepend_pair_html(user_info, _("Client"), tmp); | |
723 g_free(tmp); | 737 g_free(tmp); |
724 | 738 |
725 if (jbr->client.os) | 739 if (jbr->client.os) { |
726 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); | 740 /* TODO: Check whether it's correct to call prepend_pair_html, |
741 or if we should be using prepend_pair_plaintext */ | |
742 purple_notify_user_info_prepend_pair_html(user_info, _("Operating System"), jbr->client.os); | |
743 } | |
727 } | 744 } |
728 | 745 |
729 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) { | 746 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) { |
730 time_t now_t; | 747 time_t now_t; |
731 struct tm *now; | 748 struct tm *now; |
737 timestamp = | 754 timestamp = |
738 g_strdup_printf("%s %c%02d%02d", purple_time_format(now), | 755 g_strdup_printf("%s %c%02d%02d", purple_time_format(now), |
739 jbr->tz_off < 0 ? '-' : '+', | 756 jbr->tz_off < 0 ? '-' : '+', |
740 abs(jbr->tz_off / (60*60)), | 757 abs(jbr->tz_off / (60*60)), |
741 abs((jbr->tz_off % (60*60)) / 60)); | 758 abs((jbr->tz_off % (60*60)) / 60)); |
742 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp); | 759 purple_notify_user_info_prepend_pair_plaintext(user_info, _("Local Time"), timestamp); |
743 g_free(timestamp); | 760 g_free(timestamp); |
744 } | 761 } |
745 | 762 |
746 if (jbir && jbir->idle_seconds > 0) { | 763 if (jbir && jbir->idle_seconds > 0) { |
747 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); | 764 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); |
748 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); | 765 purple_notify_user_info_prepend_pair_plaintext(user_info, _("Idle"), idle); |
749 g_free(idle); | 766 g_free(idle); |
750 } | 767 } |
751 | 768 |
752 if (jbr) { | 769 if (jbr) { |
753 char *purdy = NULL; | 770 char *purdy = NULL; |
765 } | 782 } |
766 | 783 |
767 tmp = g_strdup_printf("%s%s%s", (status_name ? status_name : ""), | 784 tmp = g_strdup_printf("%s%s%s", (status_name ? status_name : ""), |
768 ((status_name && purdy) ? ": " : ""), | 785 ((status_name && purdy) ? ": " : ""), |
769 (purdy ? purdy : "")); | 786 (purdy ? purdy : "")); |
770 purple_notify_user_info_prepend_pair(user_info, _("Status"), tmp); | 787 purple_notify_user_info_prepend_pair_html(user_info, _("Status"), tmp); |
771 | 788 |
772 g_snprintf(priority, sizeof(priority), "%d", jbr->priority); | 789 g_snprintf(priority, sizeof(priority), "%d", jbr->priority); |
773 purple_notify_user_info_prepend_pair(user_info, _("Priority"), priority); | 790 purple_notify_user_info_prepend_pair_plaintext(user_info, _("Priority"), priority); |
774 | 791 |
775 g_free(tmp); | 792 g_free(tmp); |
776 g_free(purdy); | 793 g_free(purdy); |
777 } else { | 794 } else { |
778 purple_notify_user_info_prepend_pair(user_info, _("Status"), _("Unknown")); | 795 purple_notify_user_info_prepend_pair_plaintext(user_info, _("Status"), _("Unknown")); |
779 } | 796 } |
780 } | 797 } |
781 | 798 |
782 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) | 799 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) |
783 { | 800 { |
792 | 809 |
793 user_info = jbi->user_info; | 810 user_info = jbi->user_info; |
794 resource_name = jabber_get_resource(jbi->jid); | 811 resource_name = jabber_get_resource(jbi->jid); |
795 | 812 |
796 /* If we have one or more pairs from the vcard, put a section break above it */ | 813 /* If we have one or more pairs from the vcard, put a section break above it */ |
797 if (purple_notify_user_info_get_entries(user_info)) | 814 if (g_queue_get_length(purple_notify_user_info_get_entries(user_info))) |
798 purple_notify_user_info_prepend_section_break(user_info); | 815 purple_notify_user_info_prepend_section_break(user_info); |
799 | 816 |
800 /* Add the information about the user's resource(s) */ | 817 /* Add the information about the user's resource(s) */ |
801 if (resource_name) { | 818 if (resource_name) { |
802 jbr = jabber_buddy_find_resource(jbi->jb, resource_name); | 819 jbr = jabber_buddy_find_resource(jbi->jb, resource_name); |
813 if (resources != jbi->jb->resources) | 830 if (resources != jbi->jb->resources) |
814 purple_notify_user_info_prepend_section_break(user_info); | 831 purple_notify_user_info_prepend_section_break(user_info); |
815 | 832 |
816 add_jbr_info(jbi, jbr->name, jbr); | 833 add_jbr_info(jbi, jbr->name, jbr); |
817 | 834 |
818 if (jbr->name) | 835 if (jbr->name) { |
819 purple_notify_user_info_prepend_pair(user_info, _("Resource"), jbr->name); | 836 /* TODO: Check whether it's correct to call prepend_pair_html, |
837 or if we should be using prepend_pair_plaintext */ | |
838 purple_notify_user_info_prepend_pair_html(user_info, _("Resource"), jbr->name); | |
839 } | |
820 } | 840 } |
821 } | 841 } |
822 | 842 |
823 if (!jbi->jb->resources) { | 843 if (!jbi->jb->resources) { |
824 /* the buddy is offline */ | 844 /* the buddy is offline */ |
834 last = NULL; | 854 last = NULL; |
835 } else { | 855 } else { |
836 title = _("Logged Off"); | 856 title = _("Logged Off"); |
837 message = g_strdup_printf(_("%s ago"), last); | 857 message = g_strdup_printf(_("%s ago"), last); |
838 } | 858 } |
839 purple_notify_user_info_prepend_pair(user_info, title, message); | 859 purple_notify_user_info_prepend_pair_plaintext(user_info, title, message); |
840 g_free(last); | 860 g_free(last); |
841 g_free(message); | 861 g_free(message); |
842 } | 862 } |
843 | 863 |
844 if (!is_domain) { | 864 if (!is_domain) { |
845 gchar *status = | 865 gchar *status = |
846 g_strdup_printf("%s%s%s", _("Offline"), | 866 g_strdup_printf("%s%s%s", _("Offline"), |
847 jbi->last_message ? ": " : "", | 867 jbi->last_message ? ": " : "", |
848 jbi->last_message ? jbi->last_message : ""); | 868 jbi->last_message ? jbi->last_message : ""); |
849 purple_notify_user_info_prepend_pair(user_info, _("Status"), status); | 869 /* TODO: Check whether it's correct to call prepend_pair_html, |
870 or if we should be using prepend_pair_plaintext */ | |
871 purple_notify_user_info_prepend_pair_html(user_info, _("Status"), status); | |
850 g_free(status); | 872 g_free(status); |
851 } | 873 } |
852 } | 874 } |
853 | 875 |
854 g_free(resource_name); | 876 g_free(resource_name); |
1122 userid = xmlnode_get_data(child2); | 1144 userid = xmlnode_get_data(child2); |
1123 if(userid) { | 1145 if(userid) { |
1124 char *mailto; | 1146 char *mailto; |
1125 escaped = g_markup_escape_text(userid, -1); | 1147 escaped = g_markup_escape_text(userid, -1); |
1126 mailto = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", escaped, escaped); | 1148 mailto = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", escaped, escaped); |
1127 purple_notify_user_info_add_pair(user_info, _("Email"), mailto); | 1149 purple_notify_user_info_add_pair_html(user_info, _("Email"), mailto); |
1128 | 1150 |
1129 g_free(mailto); | 1151 g_free(mailto); |
1130 g_free(escaped); | 1152 g_free(escaped); |
1131 g_free(userid); | 1153 g_free(userid); |
1132 } | 1154 } |
1135 * out of spec */ | 1157 * out of spec */ |
1136 char *mailto; | 1158 char *mailto; |
1137 | 1159 |
1138 escaped = g_markup_escape_text(userid, -1); | 1160 escaped = g_markup_escape_text(userid, -1); |
1139 mailto = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", escaped, escaped); | 1161 mailto = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", escaped, escaped); |
1140 purple_notify_user_info_add_pair(user_info, _("Email"), mailto); | 1162 purple_notify_user_info_add_pair_html(user_info, _("Email"), mailto); |
1141 | 1163 |
1142 g_free(mailto); | 1164 g_free(mailto); |
1143 g_free(escaped); | 1165 g_free(escaped); |
1144 g_free(userid); | 1166 g_free(userid); |
1145 } | 1167 } |
1182 char *hash; | 1204 char *hash; |
1183 | 1205 |
1184 jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add_with_id(g_memdup(data, size), size, "logo.png"))); | 1206 jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add_with_id(g_memdup(data, size), size, "logo.png"))); |
1185 img_text = g_strdup_printf("<img id='%d'>", GPOINTER_TO_INT(jbi->vcard_imgids->data)); | 1207 img_text = g_strdup_printf("<img id='%d'>", GPOINTER_TO_INT(jbi->vcard_imgids->data)); |
1186 | 1208 |
1187 purple_notify_user_info_add_pair(user_info, (photo ? _("Photo") : _("Logo")), img_text); | 1209 purple_notify_user_info_add_pair_html(user_info, (photo ? _("Photo") : _("Logo")), img_text); |
1188 | 1210 |
1189 hash = jabber_calculate_data_hash(data, size, "sha1"); | 1211 hash = jabber_calculate_data_hash(data, size, "sha1"); |
1190 purple_buddy_icons_set_for_user(account, bare_jid, data, size, hash); | 1212 purple_buddy_icons_set_for_user(account, bare_jid, data, size, hash); |
1191 g_free(hash); | 1213 g_free(hash); |
1192 g_free(img_text); | 1214 g_free(img_text); |
1336 jbr->idle = 0; | 1358 jbr->idle = 0; |
1337 } | 1359 } |
1338 | 1360 |
1339 if (jbr == | 1361 if (jbr == |
1340 jabber_buddy_find_resource(jb, NULL)) { | 1362 jabber_buddy_find_resource(jb, NULL)) { |
1341 purple_prpl_got_user_idle(js->gc->account, | 1363 purple_prpl_got_user_idle(purple_connection_get_account(js->gc), |
1342 buddy_name, jbr->idle, jbr->idle); | 1364 buddy_name, jbr->idle, jbr->idle); |
1343 } | 1365 } |
1344 } | 1366 } |
1345 } | 1367 } |
1346 } | 1368 } |
2231 | 2253 |
2232 /* If the value provided isn't the disco#info default, persist it. Otherwise, | 2254 /* If the value provided isn't the disco#info default, persist it. Otherwise, |
2233 make sure we aren't persisting an old value */ | 2255 make sure we aren't persisting an old value */ |
2234 if(js->user_directories && js->user_directories->data && | 2256 if(js->user_directories && js->user_directories->data && |
2235 !strcmp(directory, js->user_directories->data)) { | 2257 !strcmp(directory, js->user_directories->data)) { |
2236 purple_account_set_string(js->gc->account, "user_directory", ""); | 2258 purple_account_set_string(purple_connection_get_account(js->gc), "user_directory", ""); |
2237 } | 2259 } |
2238 else { | 2260 else { |
2239 purple_account_set_string(js->gc->account, "user_directory", directory); | 2261 purple_account_set_string(purple_connection_get_account(js->gc), "user_directory", directory); |
2240 } | 2262 } |
2241 | 2263 |
2242 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search"); | 2264 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search"); |
2243 xmlnode_set_attrib(iq->node, "to", directory); | 2265 xmlnode_set_attrib(iq->node, "to", directory); |
2244 | 2266 |
2249 | 2271 |
2250 void jabber_user_search_begin(PurplePluginAction *action) | 2272 void jabber_user_search_begin(PurplePluginAction *action) |
2251 { | 2273 { |
2252 PurpleConnection *gc = (PurpleConnection *) action->context; | 2274 PurpleConnection *gc = (PurpleConnection *) action->context; |
2253 JabberStream *js = purple_connection_get_protocol_data(gc); | 2275 JabberStream *js = purple_connection_get_protocol_data(gc); |
2254 const char *def_val = purple_account_get_string(js->gc->account, "user_directory", ""); | 2276 const char *def_val = purple_account_get_string(purple_connection_get_account(js->gc), "user_directory", ""); |
2255 if(!*def_val && js->user_directories) | 2277 if(!*def_val && js->user_directories) |
2256 def_val = js->user_directories->data; | 2278 def_val = js->user_directories->data; |
2257 | 2279 |
2258 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), | 2280 purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), |
2259 _("Select a user directory to search"), | 2281 _("Select a user directory to search"), |