comparison 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
comparison
equal deleted inserted replaced
1336:2ecc07a8f91b 1337:f29beedb33b0
70 self.show_status = False 70 self.show_status = False
71 # TODO: this may lead to two successive UI refresh and needs an optimization 71 # TODO: this may lead to two successive UI refresh and needs an optimization
72 self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups) 72 self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups)
73 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts) 73 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts)
74 74
75 # 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)
76 self.presenceListener = self.updatePresence
77 self.host.addListener('presence', self.presenceListener, [profile])
78
75 def __contains__(self, entity): 79 def __contains__(self, entity):
76 """Check if entity is in contact list 80 """Check if entity is in contact list
77 81
78 @param entity (jid.JID): jid of the entity (resource is not ignored, use bare jid if needed) 82 @param entity (jid.JID): jid of the entity (resource is not ignored, use bare jid if needed)
79 """ 83 """
91 @return: set(jid.JID) 95 @return: set(jid.JID)
92 """ 96 """
93 return self._roster 97 return self._roster
94 98
95 @property 99 @property
100 def roster_entities_connected(self):
101 """Return all the bare JIDs of the roster entities that are connected.
102
103 @return: set(jid.JID)
104 """
105 return set([entity for entity in self._roster if self.getCache(entity, C.PRESENCE_SHOW) is not None])
106
107 @property
96 def roster_entities_by_group(self): 108 def roster_entities_by_group(self):
97 """Return a dictionary binding the roster groups to their entities bare JIDs. 109 """Return a dictionary binding the roster groups to their entities bare
110 JIDs. This also includes the empty group (None key).
98 111
99 @return: dict{unicode: set(jid.JID)} 112 @return: dict{unicode: set(jid.JID)}
100 """ 113 """
101 return {group: self._groups[group]['jids'] for group in self._groups} 114 return {group: self._groups[group]['jids'] for group in self._groups}
102 115
103 @property 116 @property
104 def roster_groups_by_entity(self, contact_jid_s): 117 def roster_groups_by_entity(self):
105 """Return a dictionary binding the entities bare JIDs to their roster groups. 118 """Return a dictionary binding the entities bare JIDs to their roster
119 groups. The empty group is filtered out.
106 120
107 @return: dict{jid.JID: set(unicode)} 121 @return: dict{jid.JID: set(unicode)}
108 """ 122 """
109 result = {} 123 result = {}
110 for group, data in self._groups.iteritems(): 124 for group, data in self._groups.iteritems():
209 @param entity(jid.JID): jid of the special entity 223 @param entity(jid.JID): jid of the special entity
210 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to remove special flag 224 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to remove special flag
211 """ 225 """
212 assert special_type in C.CONTACT_SPECIAL_ALLOWED + (None,) 226 assert special_type in C.CONTACT_SPECIAL_ALLOWED + (None,)
213 self.setCache(entity, C.CONTACT_SPECIAL, special_type) 227 self.setCache(entity, C.CONTACT_SPECIAL, special_type)
228
229 def getSpecials(self, special_type=None):
230 """Return all the bare JIDs of the special roster entities of the type
231 specified by special_type. If special_type is None, return all specials.
232
233 @param special_type: one of special type (e.g. C.CONTACT_SPECIAL_GROUP) or None to return all specials.
234 @return: set(jid.JID)
235 """
236 if special_type is None:
237 return self._specials
238 return set([entity for entity in self._specials if self.getCache(entity, C.CONTACT_SPECIAL) == special_type])
214 239
215 def clearContacts(self): 240 def clearContacts(self):
216 """Clear all the contact list""" 241 """Clear all the contact list"""
217 self.unselectAll() 242 self.unselectAll()
218 self._cache.clear() 243 self._cache.clear()
423 show = C.bool(show) 448 show = C.bool(show)
424 if self.show_resources == show: 449 if self.show_resources == show:
425 return 450 return
426 self.show_resources = show 451 self.show_resources = show
427 self.update() 452 self.update()
453
454 def onDelete(self):
455 QuickWidget.onDelete(self)
456 self.host.removeListener('presence', self.presenceListener)