comparison libpurple/protocols/jabber/buddy.c @ 25938:45c33d60c547

Retrieve and display buddy's local time in Get Info dialog
author Paul Aurich <paul@darkrain42.org>
date Sun, 08 Feb 2009 08:00:31 +0000
parents c814641afcf2
children 150282919040
comparison
equal deleted inserted replaced
25937:a4cba207068f 25938:45c33d60c547
153 if(!jbr) { 153 if(!jbr) {
154 jbr = g_new0(JabberBuddyResource, 1); 154 jbr = g_new0(JabberBuddyResource, 1);
155 jbr->jb = jb; 155 jbr->jb = jb;
156 jbr->name = g_strdup(resource); 156 jbr->name = g_strdup(resource);
157 jbr->capabilities = JABBER_CAP_XHTML; 157 jbr->capabilities = JABBER_CAP_XHTML;
158 jbr->tz_off = PURPLE_NO_TZ_OFF;
158 jb->resources = g_list_append(jb->resources, jbr); 159 jb->resources = g_list_append(jb->resources, jbr);
159 } 160 }
160 jbr->priority = priority; 161 jbr->priority = priority;
161 jbr->state = state; 162 jbr->state = state;
162 g_free(jbr->status); 163 g_free(jbr->status);
798 g_free(tmp); 799 g_free(tmp);
799 800
800 if(jbr->client.os) { 801 if(jbr->client.os) {
801 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 802 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
802 } 803 }
803 } 804 }
805 if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) {
806 time_t now_t;
807 struct tm *now;
808 time(&now_t);
809 now_t += jbr->tz_off;
810 now = gmtime(&now_t);
811
812 purple_notify_user_info_add_pair(user_info, _("Local Time"), purple_time_format(now));
813 }
804 if(jbir) { 814 if(jbir) {
805 if(jbir->idle_seconds > 0) { 815 if(jbir->idle_seconds > 0) {
806 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 816 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
807 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle); 817 purple_notify_user_info_prepend_pair(user_info, _("Idle"), idle);
808 g_free(idle); 818 g_free(idle);
967 g_free(tmp); 977 g_free(tmp);
968 978
969 if(jbr->client.os) { 979 if(jbr->client.os) {
970 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os); 980 purple_notify_user_info_prepend_pair(user_info, _("Operating System"), jbr->client.os);
971 } 981 }
982 }
983
984 if (jbr->tz_off != PURPLE_NO_TZ_OFF) {
985 time_t now_t;
986 struct tm *now;
987 time(&now_t);
988 now_t += jbr->tz_off;
989 now = gmtime(&now_t);
990
991 purple_notify_user_info_add_pair(user_info, _("Local Time"), purple_time_format(now));
972 } 992 }
973 993
974 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) { 994 if(jbr->name && (jbir = g_hash_table_lookup(jbi->resources, jbr->name))) {
975 if(jbir->idle_seconds > 0) { 995 if(jbir->idle_seconds > 0) {
976 char *idle = purple_str_seconds_to_string(jbir->idle_seconds); 996 char *idle = purple_str_seconds_to_string(jbir->idle_seconds);
1638 } 1658 }
1639 1659
1640 jabber_buddy_info_show_if_ready(jbi); 1660 jabber_buddy_info_show_if_ready(jbi);
1641 } 1661 }
1642 1662
1663 static void jabber_time_parse(JabberStream *js, xmlnode *packet, gpointer data)
1664 {
1665 JabberBuddyInfo *jbi = data;
1666 JabberBuddyResource *jbr;
1667 char *resource_name;
1668 const char *type, *id, *from;
1669
1670 g_return_if_fail(jbi != NULL);
1671
1672 id = xmlnode_get_attrib(packet, "id");
1673 type = xmlnode_get_attrib(packet, "type");
1674 from = xmlnode_get_attrib(packet, "from");
1675
1676 jabber_buddy_info_remove_id(jbi, id);
1677
1678 if (!from)
1679 return;
1680
1681 resource_name = jabber_get_resource(from);
1682 jbr = resource_name ? jabber_buddy_find_resource(jbi->jb, resource_name) : NULL;
1683 if (resource_name && jbr) {
1684 if (type && !strcmp(type, "result")) {
1685 xmlnode *time = xmlnode_get_child(packet, "time");
1686 xmlnode *tzo = time ? xmlnode_get_child(packet, "tzo") : NULL;
1687 xmlnode *utc = time ? xmlnode_get_child(packet, "utc") : NULL;
1688 if (tzo && utc) {
1689 char *timestamp = g_strdup_printf("%s %s",
1690 xmlnode_get_data(utc), xmlnode_get_data(tzo));
1691 purple_str_to_time(timestamp, FALSE, NULL, &(jbr->tz_off), NULL);
1692 g_free(timestamp);
1693 }
1694 }
1695 g_free(resource_name);
1696 }
1697
1698 jabber_buddy_info_show_if_ready(jbi);
1699 }
1700
1643 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js) 1701 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js)
1644 { 1702 {
1645 if (js->pending_buddy_info_requests) 1703 if (js->pending_buddy_info_requests)
1646 { 1704 {
1647 JabberBuddyInfo *jbi; 1705 JabberBuddyInfo *jbi;
1765 * office. */ 1823 * office. */
1766 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { 1824 if(!_client_is_blacklisted(jbr, "jabber:iq:last")) {
1767 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); 1825 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
1768 xmlnode_set_attrib(iq->node, "to", full_jid); 1826 xmlnode_set_attrib(iq->node, "to", full_jid);
1769 jabber_iq_set_callback(iq, jabber_last_parse, jbi); 1827 jabber_iq_set_callback(iq, jabber_last_parse, jbi);
1828 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1829 jabber_iq_send(iq);
1830 }
1831
1832 if (jbr->tz_off == PURPLE_NO_TZ_OFF &&
1833 jabber_resource_has_capability(jbr, "urn:xmpp:time")) {
1834 xmlnode *child;
1835 iq = jabber_iq_new(js, JABBER_IQ_GET);
1836 xmlnode_set_attrib(iq->node, "to", full_jid);
1837 child = xmlnode_new_child(iq->node, "time");
1838 xmlnode_set_namespace(child, "urn:xmpp:time");
1839 jabber_iq_set_callback(iq, jabber_time_parse, jbi);
1770 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); 1840 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1771 jabber_iq_send(iq); 1841 jabber_iq_send(iq);
1772 } 1842 }
1773 1843
1774 g_free(full_jid); 1844 g_free(full_jid);