diff 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
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Mon Feb 23 18:08:22 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Feb 24 14:40:19 2015 +0100
@@ -312,9 +312,9 @@
         /!\ 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 @@
         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 @@
         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 @@
         # 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 @@
             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):