comparison frontends/src/quick_frontend/quick_contact_list.py @ 1290:faa1129559b8 frontends_multi_profiles

core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit): /!\ not finished, everything is still instable ! - bridge: DBus bridge has been modified to allow blocking call to be called in the same way as asynchronous calls - bridge: calls with a callback and no errback are now possible, default errback log the error - constants: removed hack to manage presence without OrderedDict, as an OrderedDict like class has been implemented in Libervia - core: getLastResource has been removed and replaced by getMainResource (there is a global better management of resources) - various style improvments: use of constants when possible, fixed variable overlaps, import of module instead of direct class import - frontends: printInfo and printMessage methods in (Quick)Chat are more generic (use of extra instead of timestamp) - frontends: bridge creation and option parsing (command line arguments) are now specified by the frontend in QuickApp __init__ - frontends: ProfileManager manage a more complete plug sequence (some stuff formerly manage in contact_list have moved to ProfileManager) - quick_frontend (quick_widgets): QuickWidgetsManager is now iterable (all widgets are then returned), or can return an iterator on a specific class (return all widgets of this class) with getWidgets - frontends: tools.jid can now be used in Pyjamas, with some care - frontends (XMLUI): profile is now managed - core (memory): big improvment on entities cache management (and specially resource management) - core (params/exceptions): added PermissionError - various fixes and improvments, check diff for more details
author Goffi <goffi@goffi.org>
date Sat, 24 Jan 2015 01:00:29 +0100
parents e3a9ea76de35
children ef7e8e23b353 447d28b1b4ec
comparison
equal deleted inserted replaced
1289:653f2e2eea31 1290:faa1129559b8
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22 log = getLogger(__name__) 22 log = getLogger(__name__)
23 from sat_frontends.quick_frontend.quick_widgets import QuickWidget 23 from sat_frontends.quick_frontend.quick_widgets import QuickWidget
24 from sat_frontends.quick_frontend.constants import Const as C 24 from sat_frontends.quick_frontend.constants import Const as C
25 from sat_frontends.tools import jid 25
26
27 try:
28 # FIXME: to be removed when an acceptable solution is here
29 unicode('') # XXX: unicode doesn't exist in pyjamas
30 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
31 # XXX: pyjamas' max doesn't support key argument, so we implement it ourself
32 pyjamas_max = max
33 def max(iterable, key):
34 iter_cpy = list(iterable)
35 iter_cpy.sort(key=key)
36 return pyjamas_max(iter_cpy)
26 37
27 38
28 class QuickContactList(QuickWidget): 39 class QuickContactList(QuickWidget):
29 """This class manage the visual representation of contacts""" 40 """This class manage the visual representation of contacts"""
30 41
76 """Get all contacts from backend, and fill the widget""" 87 """Get all contacts from backend, and fill the widget"""
77 def gotContacts(contacts): 88 def gotContacts(contacts):
78 for contact in contacts: 89 for contact in contacts:
79 self.host.newContactHandler(*contact, profile=self.profile) 90 self.host.newContactHandler(*contact, profile=self.profile)
80 91
81 presences = self.host.bridge.getPresenceStatuses(self.profile)
82 for contact in presences:
83 for res in presences[contact]:
84 jabber_id = ('%s/%s' % (jid.JID(contact).bare, res)) if res else contact
85 show = presences[contact][res][0]
86 priority = presences[contact][res][1]
87 statuses = presences[contact][res][2]
88 self.host.presenceUpdateHandler(jabber_id, show, priority, statuses, self.profile)
89 data = self.host.bridge.getEntityData(contact, ['avatar', 'nick'], self.profile)
90 for key in ('avatar', 'nick'):
91 if key in data:
92 self.host.entityDataUpdatedHandler(contact, key, data[key], self.profile)
93 self.host.bridge.getContacts(self.profile, callback=gotContacts) 92 self.host.bridge.getContacts(self.profile, callback=gotContacts)
94 93
95 def update(self): 94 def update(self):
96 """Update the display when something changed""" 95 """Update the display when something changed"""
97 raise NotImplementedError 96 raise NotImplementedError
103 if a resource specific information is requested: 102 if a resource specific information is requested:
104 - if no resource is given (bare jid), the main resource is used, according to priority 103 - if no resource is given (bare jid), the main resource is used, according to priority
105 - if resource is given, it is used 104 - if resource is given, it is used
106 @param name(unicode): name the data to get, or None to get everything 105 @param name(unicode): name the data to get, or None to get everything
107 """ 106 """
108 cache = self._cache[entity.bare] 107 try:
108 cache = self._cache[entity.bare]
109 except KeyError:
110 self.setContact(entity)
111 cache = self._cache[entity.bare]
112
109 if name is None: 113 if name is None:
110 return cache 114 return cache
111 try: 115 try:
112 if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): 116 if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW):
113 # these data are related to the resource 117 # these data are related to the resource
277 for set_entity in set_: 281 for set_entity in set_:
278 if set_entity.bare == entity.bare: 282 if set_entity.bare == entity.bare:
279 to_remove.add(set_entity) 283 to_remove.add(set_entity)
280 set_.difference_update(to_remove) 284 set_.difference_update(to_remove)
281 self.update() 285 self.update()
282
283 def add(self, jid, param_groups=None):
284 """add a contact to the list"""
285 raise NotImplementedError
286 286
287 def updatePresence(self, entity, show, priority, statuses): 287 def updatePresence(self, entity, show, priority, statuses):
288 """Update entity's presence status 288 """Update entity's presence status
289 289
290 @param entity(jid.JID): entity to update's entity 290 @param entity(jid.JID): entity to update's entity
309 resource_data[C.PRESENCE_PRIORITY] = int(priority) 309 resource_data[C.PRESENCE_PRIORITY] = int(priority)
310 resource_data[C.PRESENCE_STATUSES] = statuses 310 resource_data[C.PRESENCE_STATUSES] = statuses
311 311
312 priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY]) 312 priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
313 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource 313 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
314 self.update()
315 314
316 def unselectAll(self): 315 def unselectAll(self):
317 """Unselect all contacts""" 316 """Unselect all contacts"""
318 self._selected.clear() 317 self._selected.clear()
319 self.update() 318 self.update()