add XEP-202 in vcard window. Fixes #4007

This commit is contained in:
Yann Leboulanger 2009-02-10 21:45:44 +00:00
parent bec8b7ff15
commit 7c96178126
7 changed files with 1671 additions and 1757 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1481,7 +1481,7 @@ class Connection(ConnectionHandlers):
to_whom_jid = jid
if resource:
to_whom_jid += '/' + resource
iq = common.xmpp.Iq(to = to_whom_jid, typ = 'get', queryNS =\
iq = common.xmpp.Iq(to=to_whom_jid, typ='get', queryNS=\
common.xmpp.NS_VERSION)
id_ = self.connection.getAnID()
iq.setID(id_)
@ -1490,6 +1490,27 @@ class Connection(ConnectionHandlers):
self.version_ids.append(id_)
self.connection.send(iq)
def request_entity_time(self, jid, resource, groupchat_jid=None):
'''groupchat_jid is used when we want to send a request to a real jid
and act as if the answer comes from the groupchat_jid'''
if not self.connection:
return
# If we are invisible, do not request
if self.connected == gajim.SHOW_LIST.index('invisible'):
self.dispatch('ENTITY_TIME', (jid, resource, _('Not fetched because of invisible status')))
return
to_whom_jid = jid
if resource:
to_whom_jid += '/' + resource
iq = common.xmpp.Iq(to=to_whom_jid, typ='get', queryNS=\
common.xmpp.NS_TIME_REVISED)
id_ = self.connection.getAnID()
iq.setID(id_)
if groupchat_jid:
self.groupchat_jids[id_] = groupchat_jid
self.entity_time_ids.append(id_)
self.connection.send(iq)
def get_settings(self):
''' Get Gajim settings as described in XEP 0049 '''
if not self.connection:

View File

@ -38,6 +38,7 @@ import hashlib
from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
time as time_time, timezone, tzname)
from calendar import timegm
import datetime
import socks5
import common.xmpp
@ -1426,6 +1427,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
self.last_ids = []
# IDs of jabber:iq:version requests
self.version_ids = []
# IDs of urn:xmpp:time requests
self.entity_time_ids = []
# ID of urn:xmpp:ping requests
self.awaiting_xmpp_ping_id = None
self.continue_connect_info = None
@ -1475,6 +1478,10 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, -1, ''))
self.last_ids.remove(id_)
return
if id_ in self.entity_time_ids:
self.dispatch('ENTITY_TIME', (jid_stripped, resource, ''))
self.entity_time_ids.remove(id_)
return
if id_ == self.awaiting_xmpp_ping_id:
self.awaiting_xmpp_ping_id = None
errmsg = iq_obj.getErrorMsg()
@ -1639,6 +1646,47 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
self.connection.send(iq_obj)
raise common.xmpp.NodeProcessed
def _TimeRevisedResultCB(self, con, iq_obj):
log.debug('TimeRevisedResultCB')
time_info = ''
qp = iq_obj.getTag('time')
tzo = qp.getTag('tzo').getData()
if tzo == 'Z':
tzo = '0:0'
tzoh, tzom = tzo.split(':')
utc_time = qp.getTag('utc').getData()
ZERO = datetime.timedelta(0)
class UTC(datetime.tzinfo):
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO
class contact_tz(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=int(tzoh), minutes=int(tzom))
def tzname(self, dt):
return "remote timezone"
def dst(self, dt):
return ZERO
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
t = t.replace(tzinfo=UTC())
time_info = t.astimezone(contact_tz()).strftime('%c')
id_ = iq_obj.getID()
if id_ in self.groupchat_jids:
who = self.groupchat_jids[id_]
del self.groupchat_jids[id_]
else:
who = helpers.get_full_jid_from_iq(iq_obj)
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
if id_ in self.entity_time_ids:
self.entity_time_ids.remove(id_)
self.dispatch('ENTITY_TIME', (jid_stripped, resource, time_info))
def _gMailNewMailCB(self, con, gm):
'''Called when we get notified of new mail messages in gmail account'''
if not self.connection or self.connected < 2:
@ -2543,6 +2591,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
common.xmpp.NS_LAST)
con.RegisterHandler('iq', self._VersionResultCB, 'result',
common.xmpp.NS_VERSION)
con.RegisterHandler('iq', self._TimeRevisedResultCB, 'result',
common.xmpp.NS_TIME_REVISED)
con.RegisterHandler('iq', self._MucOwnerCB, 'result',
common.xmpp.NS_MUC_OWNER)
con.RegisterHandler('iq', self._MucAdminCB, 'result',

View File

@ -1178,6 +1178,18 @@ class Interface:
if self.remote_ctrl:
self.remote_ctrl.raise_signal('OsInfo', (account, array))
def handle_event_entity_time(self, account, array):
#'ENTITY_TIME' (account, (jid, resource, time_info))
win = None
if array[0] in self.instances[account]['infos']:
win = self.instances[account]['infos'][array[0]]
elif array[0] + '/' + array[1] in self.instances[account]['infos']:
win = self.instances[account]['infos'][array[0] + '/' + array[1]]
if win:
win.set_entity_time(array[1], array[2])
if self.remote_ctrl:
self.remote_ctrl.raise_signal('EntityTime', (account, array))
def handle_event_gc_notify(self, account, array):
#'GC_NOTIFY' (account, (room_jid, show, status, nick,
# role, affiliation, jid, reason, actor, statusCode, newNick, avatar_sha))
@ -2163,6 +2175,7 @@ class Interface:
'VCARD': self.handle_event_vcard,
'LAST_STATUS_TIME': self.handle_event_last_status_time,
'OS_INFO': self.handle_event_os_info,
'ENTITY_TIME': self.handle_event_entity_time,
'GC_NOTIFY': self.handle_event_gc_notify,
'GC_MSG': self.handle_event_gc_msg,
'GC_SUBJECT': self.handle_event_gc_subject,

View File

@ -171,6 +171,10 @@ class SignalObject(dbus.service.Object):
def OsInfo(self, account_and_array):
pass
@dbus.service.signal(INTERFACE, signature='av')
def EntityTime(self, account_and_array):
pass
@dbus.service.signal(INTERFACE, signature='av')
def GCPresence(self, account_and_array):
pass

View File

@ -112,6 +112,7 @@ class VcardWindow:
self.avatar_encoded = None
self.vcard_arrived = False
self.os_info_arrived = False
self.entity_time_arrived = False
self.update_progressbar_timeout_id = gobject.timeout_add(100,
self.update_progressbar)
@ -215,7 +216,7 @@ class VcardWindow:
def test_remove_progressbar(self):
if self.update_progressbar_timeout_id is not None and \
self.vcard_arrived and self.os_info_arrived:
self.vcard_arrived and self.os_info_arrived and self.entity_time_arrived:
gobject.source_remove(self.update_progressbar_timeout_id)
self.progressbar.hide()
self.update_progressbar_timeout_id = None
@ -250,6 +251,26 @@ class VcardWindow:
self.os_info_arrived = True
self.test_remove_progressbar()
def set_entity_time(self, resource, time_info):
if self.xml.get_widget('information_notebook').get_n_pages() < 5:
return
i = 0
time_s = ''
while i in self.time_info:
if not self.time_info[i]['resource'] or \
self.time_info[i]['resource'] == resource:
self.time_info[i]['time'] = time_info
if i > 0:
time_s += '\n'
time_s += self.time_info[i]['time']
i += 1
if time_s == '':
time_s = Q_('?Time:Unknown')
self.xml.get_widget('time_label').set_text(time_s)
self.entity_time_arrived = True
self.test_remove_progressbar()
def fill_status_label(self):
if self.xml.get_widget('information_notebook').get_n_pages() < 5:
return
@ -364,8 +385,25 @@ class VcardWindow:
else:
gobject.idle_add(gajim.connections[self.account].request_os_info,
self.contact.jid, self.contact.resource)
# do not wait for entity_time if contact is not connected or has error
# additional check for observer is needed, as show is offline for him
if self.contact.show in ('offline', 'error')\
and not self.contact.is_observer():
self.entity_time_arrived = True
else: # Request entity time if contact is connected
if self.gc_contact:
j, r = gajim.get_room_and_nick_from_fjid(self.real_jid)
gobject.idle_add(gajim.connections[self.account].\
request_entity_time, j, r, self.contact.jid)
else:
gobject.idle_add(gajim.connections[self.account].\
request_entity_time, self.contact.jid, self.contact.resource)
self.os_info = {0: {'resource': self.contact.resource, 'client': '',
'os': ''}}
self.time_info = {0: {'resource': self.contact.resource, 'time': ''}}
i = 1
contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid)
if contact_list:
@ -379,11 +417,15 @@ class VcardWindow:
gobject.idle_add(
gajim.connections[self.account].request_os_info, c.jid,
c.resource)
gobject.idle_add(gajim.connections[self.account].\
request_entity_time, c.jid, c.resource)
gajim.connections[self.account].request_last_status_time(c.jid,
c.resource)
self.os_info[i] = {'resource': c.resource, 'client': '',
'os': ''}
self.time_info[i] = {'resource': c.resource, 'time': ''}
i += 1
self.xml.get_widget('resource_prio_label').set_text(resources)
resource_prio_label_eventbox = self.xml.get_widget(
'resource_prio_label_eventbox')