comparison frontends/src/quick_frontend/quick_app.py @ 1338:139263ee85c5 frontends_multi_profiles

quick frontends: fixed use of profile for listeners
author Goffi <goffi@goffi.org>
date Tue, 24 Feb 2015 14:40:19 +0100
parents f29beedb33b0
children 18cd46a264e9
comparison
equal deleted inserted replaced
1337:f29beedb33b0 1338:139263ee85c5
310 """Add a listener for an event 310 """Add a listener for an event
311 311
312 /!\ don't forget to remove listener when not used anymore (e.g. if you delete a widget) 312 /!\ don't forget to remove listener when not used anymore (e.g. if you delete a widget)
313 @param type_: type of event, can be: 313 @param type_: type of event, can be:
314 - avatar: called when avatar data is updated 314 - avatar: called when avatar data is updated
315 args: (entity, avatar file) 315 args: (entity, avatar file, profile)
316 - presence: called when a presence is received 316 - presence: called when a presence is received
317 args: (entity, show, priority, statuses) 317 args: (entity, show, priority, statuses, profile)
318 @param callback: method to call on event 318 @param callback: method to call on event
319 @param profiles_filter (set[unicode]): if set and not empty, the 319 @param profiles_filter (set[unicode]): if set and not empty, the
320 listener will be callable only by one of the given profiles. 320 listener will be callable only by one of the given profiles.
321 """ 321 """
322 assert type_ in C.LISTENERS 322 assert type_ in C.LISTENERS
329 @param callback: callback to remove 329 @param callback: callback to remove
330 """ 330 """
331 assert type_ in C.LISTENERS 331 assert type_ in C.LISTENERS
332 self._listeners[type_].pop(callback) 332 self._listeners[type_].pop(callback)
333 333
334 def callListeners(self, type_, profile, *args): 334 def callListeners(self, type_, *args, **kwargs):
335 """Call the methods which listen type_ event. If a profiles filter has 335 """Call the methods which listen type_ event. If a profiles filter has
336 been register with a listener and profile argument is not None, the 336 been register with a listener and profile argument is not None, the
337 listener will be called only if profile is in the profiles filter list. 337 listener will be called only if profile is in the profiles filter list.
338 338
339 @param type_: same as for [addListener] 339 @param type_: same as for [addListener]
340 @param profile (unicode): %(doc_profile)s
341 @param *args: arguments sent to callback 340 @param *args: arguments sent to callback
341 @param **kwargs: keywords argument, mainly used to pass "profile" when needed
342 """ 342 """
343 assert type_ in C.LISTENERS 343 assert type_ in C.LISTENERS
344 try: 344 try:
345 listeners = self._listeners[type_] 345 listeners = self._listeners[type_]
346 except KeyError: 346 except KeyError:
347 pass 347 pass
348 else: 348 else:
349 profile = kwargs.get("profile")
349 for listener, profiles_filter in listeners.iteritems(): 350 for listener, profiles_filter in listeners.iteritems():
350 if profile is None or not profiles_filter or profile in profiles_filter: 351 if profile is None or not profiles_filter or profile in profiles_filter:
351 listener(*args) 352 listener(*args)
352 353
353 def check_profile(self, profile): 354 def check_profile(self, profile):
493 494
494 # #FIXME: must be moved in a plugin 495 # #FIXME: must be moved in a plugin
495 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']: 496 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']:
496 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare) 497 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare)
497 498
498 self.callListeners('presence', profile, entity, show, priority, statuses) 499 self.callListeners('presence', entity, show, priority, statuses, profile=profile)
499 500
500 def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile): 501 def roomJoinedHandler(self, room_jid_s, room_nicks, user_nick, profile):
501 """Called when a MUC room is joined""" 502 """Called when a MUC room is joined"""
502 log.debug("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks}) 503 log.debug("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks})
503 room_jid = jid.JID(room_jid_s) 504 room_jid = jid.JID(room_jid_s)
686 self.contact_lists[profile].setCache(entity, 'nick', value) 687 self.contact_lists[profile].setCache(entity, 'nick', value)
687 elif key == "avatar": 688 elif key == "avatar":
688 if entity in self.contact_lists[profile]: 689 if entity in self.contact_lists[profile]:
689 def gotFilename(filename): 690 def gotFilename(filename):
690 self.contact_lists[profile].setCache(entity, 'avatar', filename) 691 self.contact_lists[profile].setCache(entity, 'avatar', filename)
691 self.callListeners('avatar', profile, entity, filename) 692 self.callListeners('avatar', entity, filename, profile=profile)
692 self.bridge.getAvatarFile(value, callback=gotFilename) 693 self.bridge.getAvatarFile(value, callback=gotFilename)
693 694
694 def askConfirmationHandler(self, confirm_id, confirm_type, data, profile): 695 def askConfirmationHandler(self, confirm_id, confirm_type, data, profile):
695 raise NotImplementedError 696 raise NotImplementedError
696 697