Mercurial > pidgin
comparison libpurple/protocols/jabber/buddy.c @ 27324:77fc855ed8b7
Factor out the duplicated code for displaying XMPP Get Info
The only substantive difference is that, when Getting Info on someone in
in a (semi-)anonymous room, the contact's Priority is shown and the Client
Info is in the proper place (instead of below the vCard).
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 05 Jul 2009 05:53:54 +0000 |
parents | f92e2fdfeda4 |
children | 91e0cd125f3d |
comparison
equal
deleted
inserted
replaced
27323:f92e2fdfeda4 | 27324:77fc855ed8b7 |
---|---|
648 g_free(jbi->last_message); | 648 g_free(jbi->last_message); |
649 purple_notify_user_info_destroy(jbi->user_info); | 649 purple_notify_user_info_destroy(jbi->user_info); |
650 g_free(jbi); | 650 g_free(jbi); |
651 } | 651 } |
652 | 652 |
653 static void | |
654 add_jbr_info(JabberBuddyInfo *jbi, const char *resource, | |
655 JabberBuddyResource *jbr) | |
656 { | |
657 JabberBuddyInfoResource *jbir; | |
658 PurpleNotifyUserInfo *user_info; | |
659 | |
660 jbir = g_hash_table_lookup(jbi->resources, resource); | |
661 user_info = jbi->user_info; | |
662 | |
663 if (jbr && jbr->client.name) { | |
664 char *tmp = g_strdup_printf("%s%s%s", jbr->client.name, | |
665 (jbr->client.version ? " " : ""), | |
666 (jbr->client.version ? jbr->client.version : "")); | |
667 purple_notify_user_info_prepend_pair(user_info, _("Client"), tmp); | |
668 g_free(tmp); | |
669 | |
670 if (jbr->client.os) { | |
671 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); | |
672 } | |
673 } | |
674 | |
675 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) { | |
676 time_t now_t; | |
677 struct tm *now; | |
678 char *timestamp; | |
679 time(&now_t); | |
680 now_t += jbr->tz_off; | |
681 now = gmtime(&now_t); | |
682 | |
683 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now), | |
684 jbr->tz_off < 0 ? '-' : '+', | |
685 abs(jbr->tz_off / (60*60)), | |
686 abs((jbr->tz_off % (60*60)) / 60)); | |
687 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp); | |
688 g_free(timestamp); | |
689 } | |
690 | |
691 if (jbir && jbir->idle_seconds > 0) { | |
692 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); | |
693 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); | |
694 g_free(idle); | |
695 } | |
696 | |
697 if (jbr) { | |
698 char *purdy = NULL; | |
699 char *tmp; | |
700 char priority[12]; | |
701 const char *status_name = jabber_buddy_state_get_name(jbr->state); | |
702 | |
703 if (jbr->status) | |
704 purdy = purple_strdup_withhtml(jbr->status); | |
705 if (status_name && purdy && !strcmp(status_name, purdy)) | |
706 status_name = NULL; | |
707 | |
708 tmp = g_strdup_printf("%s%s%s", (status_name ? status_name : ""), | |
709 ((status_name && purdy) ? ": " : ""), | |
710 (purdy ? purdy : "")); | |
711 purple_notify_user_info_prepend_pair(user_info, _("Status"), tmp); | |
712 | |
713 g_snprintf(priority, sizeof(priority), "%d", jbr->priority); | |
714 purple_notify_user_info_prepend_pair(user_info, _("Priority"), priority); | |
715 | |
716 g_free(tmp); | |
717 g_free(purdy); | |
718 } else { | |
719 purple_notify_user_info_prepend_pair(user_info, _("Status"), _("Unknown")); | |
720 } | |
721 } | |
722 | |
653 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) | 723 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) |
654 { | 724 { |
655 char *resource_name, *tmp; | 725 char *resource_name; |
656 JabberBuddyResource *jbr; | 726 JabberBuddyResource *jbr; |
657 JabberBuddyInfoResource *jbir = NULL; | |
658 GList *resources; | 727 GList *resources; |
659 PurpleNotifyUserInfo *user_info; | 728 PurpleNotifyUserInfo *user_info; |
660 | 729 |
661 /* not yet */ | 730 /* not yet */ |
662 if(jbi->ids) | 731 if(jbi->ids) |
670 purple_notify_user_info_prepend_section_break(user_info); | 739 purple_notify_user_info_prepend_section_break(user_info); |
671 | 740 |
672 /* Prepend the primary buddy info to user_info so that it goes before the vcard. */ | 741 /* Prepend the primary buddy info to user_info so that it goes before the vcard. */ |
673 if(resource_name) { | 742 if(resource_name) { |
674 jbr = jabber_buddy_find_resource(jbi->jb, resource_name); | 743 jbr = jabber_buddy_find_resource(jbi->jb, resource_name); |
675 jbir = g_hash_table_lookup(jbi->resources, resource_name); | 744 add_jbr_info(jbi, resource_name, jbr); |
676 if(jbr && jbr->client.name) { | |
677 tmp = g_strdup_printf("%s%s%s", jbr->client.name, | |
678 (jbr->client.version ? " " : ""), | |
679 (jbr->client.version ? jbr->client.version : "")); | |
680 purple_notify_user_info_add_pair(user_info, _("Client"), tmp); | |
681 g_free(tmp); | |
682 | |
683 if(jbr->client.os) { | |
684 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); | |
685 } | |
686 } | |
687 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) { | |
688 time_t now_t; | |
689 struct tm *now; | |
690 char *timestamp; | |
691 time(&now_t); | |
692 now_t += jbr->tz_off; | |
693 now = gmtime(&now_t); | |
694 | |
695 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now), | |
696 jbr->tz_off < 0 ? '-' : '+', | |
697 abs(jbr->tz_off / (60*60)), | |
698 abs((jbr->tz_off % (60*60)) / 60)); | |
699 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp); | |
700 g_free(timestamp); | |
701 } | |
702 if(jbir) { | |
703 if(jbir->idle_seconds > 0) { | |
704 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); | |
705 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); | |
706 g_free(idle); | |
707 } | |
708 } | |
709 if(jbr) { | |
710 char *purdy = NULL; | |
711 const char *status_name = jabber_buddy_state_get_name(jbr->state); | |
712 if(jbr->status) | |
713 purdy = purple_strdup_withhtml(jbr->status); | |
714 if(status_name && purdy && !strcmp(status_name, purdy)) | |
715 status_name = NULL; | |
716 | |
717 tmp = g_strdup_printf("%s%s%s", (status_name ? status_name : ""), | |
718 ((status_name && purdy) ? ": " : ""), | |
719 (purdy ? purdy : "")); | |
720 purple_notify_user_info_prepend_pair(user_info, _("Status"), tmp); | |
721 g_free(tmp); | |
722 g_free(purdy); | |
723 } else { | |
724 purple_notify_user_info_prepend_pair(user_info, _("Status"), _("Unknown")); | |
725 } | |
726 } else { | 745 } else { |
727 gboolean multiple_resources = jbi->jb->resources && jbi->jb->resources->next; | 746 for (resources = jbi->jb->resources; resources; resources = resources->next) { |
728 | |
729 for(resources = jbi->jb->resources; resources; resources = resources->next) { | |
730 char *purdy = NULL; | |
731 const char *status_name = NULL; | |
732 | |
733 jbr = resources->data; | 747 jbr = resources->data; |
734 | 748 |
735 /* put a section break between resources, this is not needed if | 749 /* put a section break between resources, this is not needed if |
736 we are at the first, because one was already added for the vcard | 750 we are at the first, because one was already added for the vcard |
737 section */ | 751 section */ |
738 if (resources != jbi->jb->resources) { | 752 if (resources != jbi->jb->resources) { |
739 purple_notify_user_info_prepend_section_break(user_info); | 753 purple_notify_user_info_prepend_section_break(user_info); |
740 } | 754 } |
741 | 755 |
742 if(jbr->client.name) { | 756 add_jbr_info(jbi, jbr->name, jbr); |
743 tmp = g_strdup_printf("%s%s%s", jbr->client.name, | |
744 (jbr->client.version ? " " : ""), | |
745 (jbr->client.version ? jbr->client.version : "")); | |
746 purple_notify_user_info_prepend_pair(user_info, | |
747 _("Client"), tmp); | |
748 g_free(tmp); | |
749 | |
750 if(jbr->client.os) { | |
751 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); | |
752 } | |
753 } | |
754 | |
755 if (jbr->tz_off != PURPLE_NO_TZ_OFF) { | |
756 time_t now_t; | |
757 struct tm *now; | |
758 char *timestamp; | |
759 time(&now_t); | |
760 now_t += jbr->tz_off; | |
761 now = gmtime(&now_t); | |
762 | |
763 timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now), | |
764 jbr->tz_off < 0 ? '-' : '+', | |
765 abs(jbr->tz_off / (60*60)), | |
766 abs((jbr->tz_off % (60*60)) / 60)); | |
767 purple_notify_user_info_prepend_pair(user_info, _("Local Time"), timestamp); | |
768 g_free(timestamp); | |
769 } | |
770 | |
771 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) { | |
772 if(jbir->idle_seconds > 0) { | |
773 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); | |
774 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); | |
775 g_free(idle); | |
776 } | |
777 } | |
778 | |
779 status_name = jabber_buddy_state_get_name(jbr->state); | |
780 if(jbr->status) | |
781 purdy = purple_strdup_withhtml(jbr->status); | |
782 if(status_name && purdy && !strcmp(status_name, purdy)) | |
783 status_name = NULL; | |
784 | |
785 tmp = g_strdup_printf("%s%s%s", (status_name ? status_name : ""), | |
786 ((status_name && purdy) ? ": " : ""), | |
787 (purdy ? purdy : "")); | |
788 purple_notify_user_info_prepend_pair(user_info, _("Status"), tmp); | |
789 g_free(tmp); | |
790 g_free(purdy); | |
791 | |
792 if(multiple_resources) { | |
793 tmp = g_strdup_printf("%d", jbr->priority); | |
794 purple_notify_user_info_prepend_pair(user_info, _("Priority"), tmp); | |
795 g_free(tmp); | |
796 } | |
797 | 757 |
798 if(jbr->name) | 758 if(jbr->name) |
799 purple_notify_user_info_prepend_pair(user_info, _("Resource"), jbr->name); | 759 purple_notify_user_info_prepend_pair(user_info, _("Resource"), jbr->name); |
800 } | 760 } |
801 } | 761 } |