quick frontends: fixed use of profile for listeners

This commit is contained in:
Goffi 2015-02-24 14:40:19 +01:00
commit 3d568ab9c8

View file

@ -312,9 +312,9 @@ class QuickApp(object):
/!\ don't forget to remove listener when not used anymore (e.g. if you delete a widget)
@param type_: type of event, can be:
- avatar: called when avatar data is updated
args: (entity, avatar file)
args: (entity, avatar file, profile)
- presence: called when a presence is received
args: (entity, show, priority, statuses)
args: (entity, show, priority, statuses, profile)
@param callback: method to call on event
@param profiles_filter (set[unicode]): if set and not empty, the
listener will be callable only by one of the given profiles.
@ -331,14 +331,14 @@ class QuickApp(object):
assert type_ in C.LISTENERS
self._listeners[type_].pop(callback)
def callListeners(self, type_, profile, *args):
def callListeners(self, type_, *args, **kwargs):
"""Call the methods which listen type_ event. If a profiles filter has
been register with a listener and profile argument is not None, the
listener will be called only if profile is in the profiles filter list.
@param type_: same as for [addListener]
@param profile (unicode): %(doc_profile)s
@param *args: arguments sent to callback
@param **kwargs: keywords argument, mainly used to pass "profile" when needed
"""
assert type_ in C.LISTENERS
try:
@ -346,6 +346,7 @@ class QuickApp(object):
except KeyError:
pass
else:
profile = kwargs.get("profile")
for listener, profiles_filter in listeners.iteritems():
if profile is None or not profiles_filter or profile in profiles_filter:
listener(*args)
@ -495,7 +496,7 @@ class QuickApp(object):
# if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']:
# self.showAlert(_("Watched jid [%s] is connected !") % entity.bare)
self.callListeners('presence', profile, entity, show, priority, statuses)
self.callListeners('presence', entity, show, priority, statuses, profile=profile)
def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile):
"""Called when a MUC room is joined"""
@ -688,7 +689,7 @@ class QuickApp(object):
if entity in self.contact_lists[profile]:
def gotFilename(filename):
self.contact_lists[profile].setCache(entity, 'avatar', filename)
self.callListeners('avatar', profile, entity, filename)
self.callListeners('avatar', entity, filename, profile=profile)
self.bridge.getAvatarFile(value, callback=gotFilename)
def askConfirmationHandler(self, confirm_id, confirm_type, data, profile):