diff frontends/src/quick_frontend/quick_app.py @ 2067:7834743705f0

quich frontend, primivius (chat): better avatar handling: - new getAvatar method in QuickApp which request vCard if avatar if needed and return default avatar is no avatar is found - frontends based on quick frontend can now specify if they handle avatar or not using AVATARS_HANDLER - when avatar is updated, occupant widget(s) and all message widget(s) of the concerned entity are updated
author Goffi <goffi@goffi.org>
date Fri, 09 Sep 2016 23:54:33 +0200
parents 09c18fcd8225
children 4633cfcbcccb
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Fri Sep 09 23:54:33 2016 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Fri Sep 09 23:54:33 2016 +0200
@@ -186,7 +186,8 @@
 
 class QuickApp(object):
     """This class contain the main methods needed for the frontend"""
-    MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
+    MB_HANDLER = True  # Set to False if the frontend doesn't manage microblog
+    AVATARS_HANDLER = True  # set to False if avatars are not used
 
     def __init__(self, create_bridge, xmlui, check_options=None):
         """Create a frontend application
@@ -670,7 +671,7 @@
         """
         service_s = jid.JID(service_s)
 
-        if category == C.PS_MICROBLOG and self.MB_HANDLE:
+        if category == C.PS_MICROBLOG and self.MB_HANDLER:
             if event_type == C.PS_PUBLISH:
                 if not 'content' in data:
                     log.warning("No content found in microblog data")
@@ -831,6 +832,17 @@
 
         self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
 
+    def getAvatar(self, entity, profile):
+        """return avatar path for an entity"""
+        contact_list = self.contact_lists[profile]
+        avatar = contact_list.getCache(entity, "avatar")
+        if avatar is None:
+            self.bridge.getCard(unicode(entity), profile)
+            contact_list.setCache(entity, "avatar", "")
+        if not avatar:
+            avatar = self.getDefaultAvatar(entity)
+        return avatar
+
     def getDefaultAvatar(self, entity=None):
         """return default avatar to use with given entity