use nec / ged to handle time, version and last received event
This commit is contained in:
parent
01d486ec60
commit
8595638cb4
|
@ -815,33 +815,16 @@ class ConnectionHandlersBase:
|
|||
|
||||
def _ErrorCB(self, con, iq_obj):
|
||||
log.debug('ErrorCB')
|
||||
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from)
|
||||
id_ = unicode(iq_obj.getID())
|
||||
if id_ in self.last_ids:
|
||||
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, -1, ''))
|
||||
self.last_ids.remove(id_)
|
||||
return
|
||||
gajim.nec.push_incoming_event(LastResultReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
return True
|
||||
|
||||
def _LastResultCB(self, con, iq_obj):
|
||||
log.debug('LastResultCB')
|
||||
qp = iq_obj.getTag('query')
|
||||
seconds = qp.getAttr('seconds')
|
||||
status = qp.getData()
|
||||
try:
|
||||
seconds = int(seconds)
|
||||
except Exception:
|
||||
return
|
||||
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)
|
||||
if id_ in self.last_ids:
|
||||
self.last_ids.remove(id_)
|
||||
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
|
||||
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, seconds, status))
|
||||
gajim.nec.push_incoming_event(LastResultReceivedEvent(None, conn=self,
|
||||
iq_obj=iq_obj))
|
||||
|
||||
def get_sessions(self, jid):
|
||||
"""
|
||||
|
@ -1043,18 +1026,18 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
|||
|
||||
def _ErrorCB(self, con, iq_obj):
|
||||
log.debug('ErrorCB')
|
||||
ConnectionHandlersBase._ErrorCB(self, con, iq_obj)
|
||||
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from)
|
||||
if ConnectionHandlersBase._ErrorCB(self, con, iq_obj):
|
||||
return
|
||||
id_ = unicode(iq_obj.getID())
|
||||
if id_ in self.version_ids:
|
||||
self.dispatch('OS_INFO', (jid_stripped, resource, '', ''))
|
||||
self.version_ids.remove(id_)
|
||||
gajim.nec.push_incoming_event(VersionResultReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
return
|
||||
if id_ in self.entity_time_ids:
|
||||
self.dispatch('ENTITY_TIME', (jid_stripped, resource, ''))
|
||||
self.entity_time_ids.remove(id_)
|
||||
gajim.nec.push_incoming_event(LastResultReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
return
|
||||
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||
errmsg = iq_obj.getErrorMsg()
|
||||
errcode = iq_obj.getErrorCode()
|
||||
self.dispatch('ERROR_ANSWER', (id_, jid_from, errmsg, errcode))
|
||||
|
@ -1220,25 +1203,8 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
|||
|
||||
def _VersionResultCB(self, con, iq_obj):
|
||||
log.debug('VersionResultCB')
|
||||
client_info = ''
|
||||
os_info = ''
|
||||
qp = iq_obj.getTag('query')
|
||||
if qp.getTag('name'):
|
||||
client_info += qp.getTag('name').getData()
|
||||
if qp.getTag('version'):
|
||||
client_info += ' ' + qp.getTag('version').getData()
|
||||
if qp.getTag('os'):
|
||||
os_info += qp.getTag('os').getData()
|
||||
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.version_ids:
|
||||
self.version_ids.remove(id_)
|
||||
self.dispatch('OS_INFO', (jid_stripped, resource, client_info, os_info))
|
||||
gajim.nec.push_incoming_event(VersionResultReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
|
||||
def _TimeCB(self, con, iq_obj):
|
||||
log.debug('TimeCB')
|
||||
|
@ -1270,50 +1236,8 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
|||
|
||||
def _TimeRevisedResultCB(self, con, iq_obj):
|
||||
log.debug('TimeRevisedResultCB')
|
||||
time_info = ''
|
||||
qp = iq_obj.getTag('time')
|
||||
if not qp:
|
||||
# wrong answer
|
||||
return
|
||||
tzo = qp.getTag('tzo').getData()
|
||||
if tzo.lower() == '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
|
||||
|
||||
try:
|
||||
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')
|
||||
except ValueError, e:
|
||||
log.info('Wrong time format: %s' % str(e))
|
||||
|
||||
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))
|
||||
gajim.nec.push_incoming_event(TimeResultReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
|
||||
def _gMailNewMailCB(self, con, gm):
|
||||
"""
|
||||
|
@ -2466,6 +2390,18 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
|||
con.RegisterHandler('message', self._StanzaArrivedCB)
|
||||
con.RegisterHandler('unknown', self._StreamCB, 'urn:ietf:params:xml:ns:xmpp-streams', xmlns='http://etherx.jabber.org/streams')
|
||||
|
||||
class HelperEvent:
|
||||
def get_jid_resource(self):
|
||||
if self.id_ in self.conn.groupchat_jids:
|
||||
who = self.conn.groupchat_jids[self.id_]
|
||||
del self.conn.groupchat_jids[self.id_]
|
||||
else:
|
||||
who = helpers.get_full_jid_from_iq(self.iq_obj)
|
||||
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(who)
|
||||
|
||||
def get_id(self):
|
||||
self.id_ = self.iq_obj.getID()
|
||||
|
||||
class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'http-auth-received'
|
||||
base_network_events = []
|
||||
|
@ -2483,3 +2419,121 @@ class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
|
|||
# In case it's a message with a body
|
||||
self.msg = self.iq_obj.getTagData('body')
|
||||
return True
|
||||
|
||||
class LastResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'last-result-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if not self.conn:
|
||||
self.conn = self.base_event.conn
|
||||
if not self.iq_obj:
|
||||
self.iq_obj = self.base_event.xmpp_iq
|
||||
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
if self.id_ in self.conn.last_ids:
|
||||
self.conn.last_ids.remove(self.id_)
|
||||
|
||||
self.status = ''
|
||||
self.seconds = -1
|
||||
|
||||
if self.iq_obj.getType() == 'error':
|
||||
return True
|
||||
|
||||
qp = self.iq_obj.getTag('query')
|
||||
sec = qp.getAttr('seconds')
|
||||
self.status = qp.getData()
|
||||
try:
|
||||
self.seconds = int(sec)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
return True
|
||||
|
||||
class VersionResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'version-result-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if not self.conn:
|
||||
self.conn = self.base_event.conn
|
||||
if not self.iq_obj:
|
||||
self.iq_obj = self.base_event.xmpp_iq
|
||||
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
if self.id_ in self.conn.version_ids:
|
||||
self.conn.version_ids.remove(self.id_)
|
||||
|
||||
self.client_info = ''
|
||||
self.os_info = ''
|
||||
|
||||
if self.iq_obj.getType() == 'error':
|
||||
return True
|
||||
|
||||
qp = self.iq_obj.getTag('query')
|
||||
if qp.getTag('name'):
|
||||
self.client_info += qp.getTag('name').getData()
|
||||
if qp.getTag('version'):
|
||||
self.client_info += ' ' + qp.getTag('version').getData()
|
||||
if qp.getTag('os'):
|
||||
self.os_info += qp.getTag('os').getData()
|
||||
|
||||
return True
|
||||
|
||||
class TimeResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'version-result-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if not self.conn:
|
||||
self.conn = self.base_event.conn
|
||||
if not self.iq_obj:
|
||||
self.iq_obj = self.base_event.xmpp_iq
|
||||
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
if self.id_ in self.conn.entity_time_ids:
|
||||
self.conn.entity_time_ids.remove(self.id_)
|
||||
|
||||
self.time_info = ''
|
||||
|
||||
if self.iq_obj.getType() == 'error':
|
||||
return True
|
||||
|
||||
qp = self.iq_obj.getTag('time')
|
||||
if not qp:
|
||||
# wrong answer
|
||||
return
|
||||
tzo = qp.getTag('tzo').getData()
|
||||
if tzo.lower() == '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
|
||||
|
||||
try:
|
||||
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
|
||||
t = t.replace(tzinfo=UTC())
|
||||
self.time_info = t.astimezone(contact_tz()).strftime('%c')
|
||||
except ValueError, e:
|
||||
log.info('Wrong time format: %s' % str(e))
|
||||
return
|
||||
|
||||
return True
|
||||
|
|
|
@ -825,57 +825,24 @@ class Interface:
|
|||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('VcardInfo', (account, vcard))
|
||||
|
||||
def handle_event_last_status_time(self, account, array):
|
||||
def handle_event_last_status_time(self, obj):
|
||||
# ('LAST_STATUS_TIME', account, (jid, resource, seconds, status))
|
||||
tim = array[2]
|
||||
if tim < 0:
|
||||
if obj.seconds < 0:
|
||||
# Ann error occured
|
||||
return
|
||||
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]]
|
||||
c = gajim.contacts.get_contact(account, array[0], array[1])
|
||||
account = obj.conn.name
|
||||
c = gajim.contacts.get_contact(account, obj.jid, obj.resource)
|
||||
if c: # c can be none if it's a gc contact
|
||||
if array[3]:
|
||||
c.status = array[3]
|
||||
if obj.status:
|
||||
c.status = obj.status
|
||||
self.roster.draw_contact(c.jid, account) # draw offline status
|
||||
last_time = time.localtime(time.time() - tim)
|
||||
last_time = time.localtime(time.time() - obj.seconds)
|
||||
if c.show == 'offline':
|
||||
c.last_status_time = last_time
|
||||
else:
|
||||
c.last_activity_time = last_time
|
||||
if win:
|
||||
win.set_last_status_time()
|
||||
if self.roster.tooltip.id and self.roster.tooltip.win:
|
||||
self.roster.tooltip.update_last_time(last_time)
|
||||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('LastStatusTime', (account, array))
|
||||
|
||||
def handle_event_os_info(self, account, array):
|
||||
#'OS_INFO' (account, (jid, resource, client_info, os_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_os_info(array[1], array[2], array[3])
|
||||
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,
|
||||
|
@ -2118,9 +2085,6 @@ class Interface:
|
|||
'ACC_OK': [self.handle_event_acc_ok],
|
||||
'MYVCARD': [self.handle_event_myvcard],
|
||||
'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],
|
||||
|
@ -2183,6 +2147,7 @@ class Interface:
|
|||
'PEP_RECEIVED': [self.handle_event_pep_received],
|
||||
'CAPS_RECEIVED': [self.handle_event_caps_received],
|
||||
'http-auth-received': [self.handle_event_http_auth],
|
||||
'last-result-received': [self.handle_event_last_status_time],
|
||||
}
|
||||
|
||||
def register_core_handlers(self):
|
||||
|
|
|
@ -36,6 +36,7 @@ from common import gajim
|
|||
from common import helpers
|
||||
from time import time
|
||||
from dialogs import AddNewContactWindow, NewChatDialog, JoinGroupchatWindow
|
||||
from common import ged
|
||||
|
||||
from common import dbus_support
|
||||
if dbus_support.supported:
|
||||
|
@ -104,6 +105,25 @@ class Remote:
|
|||
bus_name = dbus.service.BusName(SERVICE, bus=session_bus)
|
||||
self.signal_object = SignalObject(bus_name)
|
||||
|
||||
gajim.ged.register_event_handler('last-result-received', ged.POSTGUI,
|
||||
self.on_last_status_time)
|
||||
gajim.ged.register_event_handler('version-result-received', ged.POSTGUI,
|
||||
self.on_os_info)
|
||||
gajim.ged.register_event_handler('time-result-received', ged.POSTGUI,
|
||||
self.on_time)
|
||||
|
||||
def on_last_status_time(self, obj):
|
||||
self.raise_signal('LastStatusTime', (obj.conn.name, [
|
||||
obj.jid, obj.resource, obj.seconds, obj.status]))
|
||||
|
||||
def on_os_info(self, obj):
|
||||
self.raise_signal('OsInfo', (obj.conn.name, [obj.jid, obj.resource,
|
||||
obj.client_info, obj.os_info]))
|
||||
|
||||
def on_time(self, obj):
|
||||
self.raise_signal('EntityTime', (obj.conn.name, [obj.jid, obj.resource,
|
||||
obj.time_info]))
|
||||
|
||||
def raise_signal(self, signal, arg):
|
||||
if self.signal_object:
|
||||
try:
|
||||
|
|
30
src/vcard.py
30
src/vcard.py
|
@ -42,6 +42,7 @@ import gtkgui_helpers
|
|||
|
||||
from common import helpers
|
||||
from common import gajim
|
||||
from common import ged
|
||||
from common.i18n import Q_
|
||||
|
||||
def get_avatar_pixbuf_encoded_mime(photo):
|
||||
|
@ -125,6 +126,13 @@ class VcardWindow:
|
|||
self.update_progressbar_timeout_id = gobject.timeout_add(100,
|
||||
self.update_progressbar)
|
||||
|
||||
gajim.ged.register_event_handler('version-result-received', ged.GUI1,
|
||||
self.set_os_info)
|
||||
gajim.ged.register_event_handler('last-result-received', ged.GUI2,
|
||||
self.set_last_status_time)
|
||||
gajim.ged.register_event_handler('time-result-received', ged.GUI1,
|
||||
self.set_entity_time)
|
||||
|
||||
self.fill_jabber_page()
|
||||
annotations = gajim.connections[self.account].annotations
|
||||
if self.contact.jid in annotations:
|
||||
|
@ -150,6 +158,12 @@ class VcardWindow:
|
|||
if annotation != connection.annotations.get(self.contact.jid, ''):
|
||||
connection.annotations[self.contact.jid] = annotation
|
||||
connection.store_annotations()
|
||||
gajim.ged.remove_event_handler('version-result-received', ged.GUI1,
|
||||
self.set_os_info)
|
||||
gajim.ged.remove_event_handler('last-result-received', ged.GUI2,
|
||||
self.set_last_status_time)
|
||||
gajim.ged.remove_event_handler('time-result-received', ged.GUI1,
|
||||
self.set_entity_time)
|
||||
|
||||
def on_vcard_information_window_key_press_event(self, widget, event):
|
||||
if event.keyval == gtk.keysyms.Escape:
|
||||
|
@ -226,10 +240,10 @@ class VcardWindow:
|
|||
self.progressbar.hide()
|
||||
self.update_progressbar_timeout_id = None
|
||||
|
||||
def set_last_status_time(self):
|
||||
def set_last_status_time(self, obj):
|
||||
self.fill_status_label()
|
||||
|
||||
def set_os_info(self, resource, client_info, os_info):
|
||||
def set_os_info(self, obj):
|
||||
if self.xml.get_object('information_notebook').get_n_pages() < 5:
|
||||
return
|
||||
i = 0
|
||||
|
@ -237,9 +251,9 @@ class VcardWindow:
|
|||
os = ''
|
||||
while i in self.os_info:
|
||||
if not self.os_info[i]['resource'] or \
|
||||
self.os_info[i]['resource'] == resource:
|
||||
self.os_info[i]['client'] = client_info
|
||||
self.os_info[i]['os'] = os_info
|
||||
self.os_info[i]['resource'] == obj.resource:
|
||||
self.os_info[i]['client'] = obj.client_info
|
||||
self.os_info[i]['os'] = obj.os_info
|
||||
if i > 0:
|
||||
client += '\n'
|
||||
os += '\n'
|
||||
|
@ -256,15 +270,15 @@ class VcardWindow:
|
|||
self.os_info_arrived = True
|
||||
self.test_remove_progressbar()
|
||||
|
||||
def set_entity_time(self, resource, time_info):
|
||||
def set_entity_time(self, obj):
|
||||
if self.xml.get_object('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
|
||||
self.time_info[i]['resource'] == obj.resource:
|
||||
self.time_info[i]['time'] = obj.time_info
|
||||
if i > 0:
|
||||
time_s += '\n'
|
||||
time_s += self.time_info[i]['time']
|
||||
|
|
Loading…
Reference in New Issue