diff 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
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_contact_list.py	Sat Jan 24 00:15:01 2015 +0100
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Sat Jan 24 01:00:29 2015 +0100
@@ -22,7 +22,18 @@
 log = getLogger(__name__)
 from sat_frontends.quick_frontend.quick_widgets import QuickWidget
 from sat_frontends.quick_frontend.constants import Const as C
-from sat_frontends.tools import jid
+
+
+try:
+    # FIXME: to be removed when an acceptable solution is here
+    unicode('') # XXX: unicode doesn't exist in pyjamas
+except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
+    # XXX: pyjamas' max doesn't support key argument, so we implement it ourself
+    pyjamas_max = max
+    def max(iterable, key):
+        iter_cpy = list(iterable)
+        iter_cpy.sort(key=key)
+        return pyjamas_max(iter_cpy)
 
 
 class QuickContactList(QuickWidget):
@@ -78,18 +89,6 @@
             for contact in contacts:
                 self.host.newContactHandler(*contact, profile=self.profile)
 
-            presences = self.host.bridge.getPresenceStatuses(self.profile)
-            for contact in presences:
-                for res in presences[contact]:
-                    jabber_id = ('%s/%s' % (jid.JID(contact).bare, res)) if res else contact
-                    show = presences[contact][res][0]
-                    priority = presences[contact][res][1]
-                    statuses = presences[contact][res][2]
-                    self.host.presenceUpdateHandler(jabber_id, show, priority, statuses, self.profile)
-                data = self.host.bridge.getEntityData(contact, ['avatar', 'nick'], self.profile)
-                for key in ('avatar', 'nick'):
-                    if key in data:
-                        self.host.entityDataUpdatedHandler(contact, key, data[key], self.profile)
         self.host.bridge.getContacts(self.profile, callback=gotContacts)
 
     def update(self):
@@ -105,7 +104,12 @@
                 - if resource is given, it is used
         @param name(unicode): name the data to get, or None to get everything
         """
-        cache = self._cache[entity.bare]
+        try:
+            cache = self._cache[entity.bare]
+        except KeyError:
+            self.setContact(entity)
+            cache = self._cache[entity.bare]
+
         if name is None:
             return cache
         try:
@@ -280,10 +284,6 @@
             set_.difference_update(to_remove)
         self.update()
 
-    def add(self, jid, param_groups=None):
-        """add a contact to the list"""
-        raise NotImplementedError
-
     def updatePresence(self, entity, show, priority, statuses):
         """Update entity's presence status
 
@@ -311,7 +311,6 @@
 
             priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
             cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
-            self.update()
 
     def unselectAll(self):
         """Unselect all contacts"""