Use central event_handler in Interface() instead of updating the GUI directly from XMPP callbacks.
This commit is contained in:
parent
5f4db2eed9
commit
6c0fb26e58
|
@ -231,8 +231,6 @@ class AbstractPEP(object):
|
|||
if jid == common.gajim.get_jid_from_account(account):
|
||||
self._update_account(account)
|
||||
|
||||
self.do(jid, account)
|
||||
|
||||
def _extract_info(self, items):
|
||||
'''To be implemented by subclasses'''
|
||||
raise NotImplementedError
|
||||
|
@ -292,16 +290,6 @@ class UserMoodPEP(AbstractPEP):
|
|||
retracted = items.getTag('retract') or not 'mood' in mood_dict
|
||||
return (mood_dict, retracted)
|
||||
|
||||
def do(self, jid, name):
|
||||
|
||||
if jid == common.gajim.get_jid_from_account(name):
|
||||
common.gajim.interface.roster.draw_account(name)
|
||||
common.gajim.interface.roster.draw_mood(jid, name)
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||
if ctrl:
|
||||
ctrl.update_mood()
|
||||
|
||||
|
||||
def asPixbufIcon(self):
|
||||
assert not self._retracted
|
||||
received_mood = self._pep_specific_data['mood']
|
||||
|
@ -342,15 +330,6 @@ class UserTunePEP(AbstractPEP):
|
|||
'title' in tune_dict)
|
||||
return (tune_dict, retracted)
|
||||
|
||||
|
||||
def do(self, jid, name):
|
||||
if jid == common.gajim.get_jid_from_account(name):
|
||||
common.gajim.interface.roster.draw_account(name)
|
||||
common.gajim.interface.roster.draw_tune(jid, name)
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||
if ctrl:
|
||||
ctrl.update_tune()
|
||||
|
||||
def asMarkupText(self):
|
||||
assert not self._retracted
|
||||
tune = self._pep_specific_data
|
||||
|
@ -397,20 +376,11 @@ class UserActivityPEP(AbstractPEP):
|
|||
retracted = items.getTag('retract') or not activity_dict
|
||||
return (activity_dict, retracted)
|
||||
|
||||
def do(self, jid, name):
|
||||
|
||||
if jid == common.gajim.get_jid_from_account(name):
|
||||
common.gajim.interface.roster.draw_account(name)
|
||||
common.gajim.interface.roster.draw_activity(jid, name)
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, name)
|
||||
if ctrl:
|
||||
ctrl.update_activity()
|
||||
|
||||
|
||||
class UserNicknamePEP(AbstractPEP):
|
||||
'''XEP-0172: User Nickname'''
|
||||
|
||||
type = 'activity'
|
||||
type = 'nickname'
|
||||
namespace = common.xmpp.NS_NICK
|
||||
|
||||
def _extract_info(self, items):
|
||||
|
@ -424,27 +394,19 @@ class UserNicknamePEP(AbstractPEP):
|
|||
retracted = items.getTag('retract') or not nick
|
||||
return (nick, retracted)
|
||||
|
||||
def do(self, jid, name):
|
||||
if jid == common.gajim.get_jid_from_account(name):
|
||||
if self._retracted:
|
||||
common.gajim.nicks[name] = common.gajim.config.get_per('accounts',
|
||||
name, 'name')
|
||||
else:
|
||||
common.gajim.nicks[name] = self._pep_specific_data
|
||||
|
||||
def _update_contacts(self, jid, account):
|
||||
# TODO: use dict instead
|
||||
nick = '' if self._retracted else self._pep_specific_data
|
||||
|
||||
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
||||
for contact in common.gajim.contacts.get_contacts(name, user):
|
||||
for contact in common.gajim.contacts.get_contacts(account, jid):
|
||||
contact.contact_name = nick
|
||||
common.gajim.interface.roster.draw_contact(user, name)
|
||||
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
|
||||
if ctrl:
|
||||
ctrl.update_ui()
|
||||
win = ctrl.parent_win
|
||||
win.redraw_tab(ctrl)
|
||||
win.show_title()
|
||||
def _update_account(self, account):
|
||||
# TODO: use dict instead
|
||||
if self._retracted:
|
||||
common.gajim.nicks[account] = common.gajim.config.get_per('accounts',
|
||||
account, 'name')
|
||||
else:
|
||||
common.gajim.nicks[account] = self._pep_specific_data
|
||||
|
||||
|
||||
SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, UserNicknamePEP]
|
||||
|
|
|
@ -1989,6 +1989,35 @@ class Interface:
|
|||
_('PEP node %(node)s was not removed: %(message)s') % {
|
||||
'node': data[1], 'message': data[2]})
|
||||
|
||||
def handle_event_pep_received(self, account, data):
|
||||
# ('PEP_RECEIVED', account, (jid, pep_type))
|
||||
jid = data[0]
|
||||
pep_type = data[1]
|
||||
ctrl = common.gajim.interface.msg_win_mgr.get_control(jid, account)
|
||||
|
||||
if jid == common.gajim.get_jid_from_account(account):
|
||||
self.roster.draw_account(account)
|
||||
|
||||
if pep_type == 'mood':
|
||||
self.roster.draw_mood(jid, account)
|
||||
if ctrl:
|
||||
ctrl.update_mood()
|
||||
elif pep_type == 'tune':
|
||||
self.roster.draw_tune(jid, account)
|
||||
if ctrl:
|
||||
ctrl.update_tune()
|
||||
elif pep_type == 'activity':
|
||||
self.roster.draw_activity(jid, account)
|
||||
if ctrl:
|
||||
ctrl.update_activity()
|
||||
elif pep_type == 'nickname':
|
||||
self.roster.draw_contact(jid, account)
|
||||
if ctrl:
|
||||
ctrl.update_ui()
|
||||
win = ctrl.parent_win
|
||||
win.redraw_tab(ctrl)
|
||||
win.show_title()
|
||||
|
||||
def register_handler(self, event, handler):
|
||||
if event not in self.handlers:
|
||||
self.handlers[event] = []
|
||||
|
@ -2088,6 +2117,7 @@ class Interface:
|
|||
'JINGLE_CONNECTED': [self.handle_event_jingle_connected],
|
||||
'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],
|
||||
'JINGLE_ERROR': [self.handle_event_jingle_error],
|
||||
'PEP_RECEIVED': [self.handle_event_pep_received]
|
||||
}
|
||||
|
||||
def dispatch(self, event, account, data):
|
||||
|
|
Loading…
Reference in New Issue