diff frontends/src/quick_frontend/quick_contact_list.py @ 1337:f29beedb33b0 frontends_multi_profiles

merged souliane changes
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:08:22 +0100
parents 15e177584d82 0f92b6a150ff
children 18cd46a264e9
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_contact_list.py	Mon Feb 23 18:04:25 2015 +0100
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Mon Feb 23 18:08:22 2015 +0100
@@ -72,6 +72,10 @@
         self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups)
         self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts)
 
+        # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
+        self.presenceListener = self.updatePresence
+        self.host.addListener('presence', self.presenceListener, [profile])
+
     def __contains__(self, entity):
         """Check if entity is in contact list
 
@@ -93,16 +97,26 @@
         return self._roster
 
     @property
+    def roster_entities_connected(self):
+        """Return all the bare JIDs of the roster entities that are connected.
+
+        @return: set(jid.JID)
+        """
+        return set([entity for entity in self._roster if self.getCache(entity, C.PRESENCE_SHOW) is not None])
+
+    @property
     def roster_entities_by_group(self):
-        """Return a dictionary binding the roster groups to their entities bare JIDs.
+        """Return a dictionary binding the roster groups to their entities bare
+        JIDs. This also includes the empty group (None key).
 
         @return: dict{unicode: set(jid.JID)}
         """
         return {group: self._groups[group]['jids'] for group in self._groups}
 
     @property
-    def roster_groups_by_entity(self, contact_jid_s):
-        """Return a dictionary binding the entities bare JIDs to their roster groups.
+    def roster_groups_by_entity(self):
+        """Return a dictionary binding the entities bare JIDs to their roster
+        groups. The empty group is filtered out.
 
         @return: dict{jid.JID: set(unicode)}
         """
@@ -212,6 +226,17 @@
         assert special_type in C.CONTACT_SPECIAL_ALLOWED + (None,)
         self.setCache(entity, C.CONTACT_SPECIAL, special_type)
 
+    def getSpecials(self, special_type=None):
+        """Return all the bare JIDs of the special roster entities of the type
+        specified by special_type. If special_type is None, return all specials.
+
+        @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to return all specials.
+        @return: set(jid.JID)
+        """
+        if special_type is None:
+            return self._specials
+        return set([entity for entity in self._specials if self.getCache(entity, C.CONTACT_SPECIAL) == special_type])
+
     def clearContacts(self):
         """Clear all the contact list"""
         self.unselectAll()
@@ -425,3 +450,7 @@
             return
         self.show_resources = show
         self.update()
+
+    def onDelete(self):
+        QuickWidget.onDelete(self)
+        self.host.removeListener('presence', self.presenceListener)