changeset 480:50b286866739

browser side: display avatars in the contact panel
author souliane <souliane@mailoo.org>
date Sat, 14 Jun 2014 19:20:27 +0200
parents c21ea1fe3593
children bbdc5357dc00
files src/browser/libervia_main.py src/browser/public/libervia.css src/browser/sat_browser/contact.py src/browser/sat_browser/contact_group.py
diffstat 4 files changed, 83 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Sat Jun 14 19:10:51 2014 +0200
+++ b/src/browser/libervia_main.py	Sat Jun 14 19:20:27 2014 +0200
@@ -809,6 +809,7 @@
             avatar = '/avatars/%s' % value
 
             self.avatars_cache[entity_jid_s] = avatar
+            self.contact_panel.updateAvatar(entity_jid_s, avatar)
 
             for lib_wid in self.libervia_widgets:
                 if isinstance(lib_wid, panels.MicroblogPanel):
--- a/src/browser/public/libervia.css	Sat Jun 14 19:10:51 2014 +0200
+++ b/src/browser/public/libervia.css	Sat Jun 14 19:20:27 2014 +0200
@@ -425,6 +425,17 @@
     -webkit-transition: color 0.1s linear; 
     transition: color 0.1s linear;  
 }
+
+.contactBox {
+    cursor: pointer;
+    width: 100%;
+}
+
+.contactBox img {
+    width: 32px;
+    border-radius: 5px;
+}
+
 .contactLabel {
     font-size: 1em;
     margin-top: 3px;
@@ -759,6 +770,7 @@
     width: 48px;
     height: 48px;
     padding: 8px;
+    border-radius: 13px;  /* padding value + 5px */
 }
 
 .mb_entry_dialog {
--- a/src/browser/sat_browser/contact.py	Sat Jun 14 19:10:51 2014 +0200
+++ b/src/browser/sat_browser/contact.py	Sat Jun 14 19:20:27 2014 +0200
@@ -23,15 +23,17 @@
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.ScrollPanel import ScrollPanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.ClickListener import ClickHandler
 from pyjamas.ui.Label import Label
 from pyjamas.ui.HTML import HTML
+from pyjamas.ui.Image import Image
 from pyjamas import Window
 from pyjamas import DOM
 from __pyjamas__ import doc
 
+from constants import Const as C
 from jid import JID
-
 import base_panels
 import base_widget
 import panels
@@ -102,6 +104,35 @@
         self.host.getOrCreateLiberviaWidget(panels.ChatPanel, self.jid)
 
 
+class ContactBox(HorizontalPanel):
+    def __init__(self, host, jid, name=None, handleClick=True):
+        HorizontalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle')
+        self.jid = jid
+        self.label = ContactLabel(host, jid, name, handleClick)
+        self.avatar = Image()
+        self.updateAvatar(host.getAvatar(jid))
+        self.add(self.label)
+        spacer = Label(' ')
+        self.add(spacer)
+        self.setCellWidth(spacer, '100%')
+        self.add(self.avatar)
+        self.setCellHorizontalAlignment(self.avatar, 'right')
+
+    def setMessageWaiting(self, waiting):
+        """Show a visual indicator if message are waiting
+
+        @param waiting: True if message are waiting"""
+        self.label.setMessageWaiting(waiting)
+
+    def updateAvatar(self, url):
+        """Update the avatar
+
+        @param url (str): image url
+        """
+        self.avatar.setVisible(url != C.DEFAULT_AVATAR)
+        self.avatar.setUrl(url)
+
+
 class GroupList(VerticalPanel):
 
     def __init__(self, parent):
@@ -152,17 +183,16 @@
                 break
             index += 1
         self.contacts.insert(index, jid)
-        _item = ContactLabel(self.host, jid, name, handleClick=self.handleClick)
-        DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
-        VerticalPanel.insert(self, _item, index)
+        box = ContactBox(self.host, jid, name, handleClick=self.handleClick)
+        VerticalPanel.insert(self, box, index)
         if add_item_cb:
             add_item_cb(box)
 
     def remove(self, jid):
-        wid = self.getContactLabel(jid)
-        if not wid:
+        box = self.getContactBox(jid)
+        if not box:
             return
-        VerticalPanel.remove(self, wid)
+        VerticalPanel.remove(self, box)
         self.contacts.remove(jid)
 
     def isContactPresent(self, contact_jid):
@@ -172,14 +202,25 @@
     def getContacts(self):
         return self.contacts
 
-    def getContactLabel(self, contact_jid):
+    def getContactBox(self, contact_jid):
         """get contactList widget of a contact
-        @return: ContactLabel item if present, else None"""
+        @return: ContactBox instance if present, else None"""
         for wid in self:
-            if isinstance(wid, ContactLabel) and wid.jid == contact_jid:
+            if isinstance(wid, ContactBox) and wid.jid == contact_jid:
                 return wid
         return None
 
+    def updateAvatar(self, jid_s, url):
+        """Update the avatar of the given contact
+
+        @param jid_s (str): contact jid
+        @param url (str): image url
+        """
+        try:
+            self.getContactBox(jid_s).updateAvatar(url)
+        except TypeError:
+            pass
+
 
 class ContactList(GenericContactList):
     """The contact list that is displayed on the left side."""
@@ -223,12 +264,12 @@
                 True if message are waiting
             - for availability type:
                 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1"""
-        _item = self.getContactLabel(jid)
-        if _item:
+        contact_box = self.getContactBox(jid)
+        if contact_box:
             if type_ == 'availability':
-                setPresenceStyle(_item, state)
+                setPresenceStyle(contact_box.label, state)
             elif type_ == 'messageWaiting':
-                _item.setMessageWaiting(state)
+                contact_box.setMessageWaiting(state)
 
 
 class ContactTitleLabel(base_widget.DragLabel, Label, ClickHandler):
@@ -392,8 +433,8 @@
 
     def isContactInRoster(self, contact_jid):
         """Test if the contact is in our roster list"""
-        for _contact_label in self._contact_list:
-            if contact_jid == _contact_label.jid:
+        for contact_box in self._contact_list:
+            if contact_jid == contact_box.jid:
                 return True
         return False
 
@@ -416,10 +457,18 @@
         if isinstance(sender, GroupLabel):
             for contact in self._contact_list:
                 if contact.jid in self.groups[sender.group]:
-                    contact.addStyleName("selected")
+                    contact.label.addStyleName("selected")
 
     def onMouseLeave(self, sender):
         if isinstance(sender, GroupLabel):
             for contact in self._contact_list:
                 if contact.jid in self.groups[sender.group]:
-                    contact.removeStyleName("selected")
+                    contact.label.removeStyleName("selected")
+
+    def updateAvatar(self, jid_s, url):
+        """Update the avatar of the given contact
+
+        @param jid_s (str): contact jid
+        @param url (str): image url
+        """
+        self._contact_list.updateAvatar(jid_s, url)
--- a/src/browser/sat_browser/contact_group.py	Sat Jun 14 19:10:51 2014 +0200
+++ b/src/browser/sat_browser/contact_group.py	Sat Jun 14 19:20:27 2014 +0200
@@ -187,12 +187,12 @@
             contacts = self.all_contacts
         for contact_ in contacts:
             if sender.showAll:
-                self.contacts.getContactLabel(contact_).setVisible(True)
+                self.contacts.getContactBox(contact_).setVisible(True)
             else:
                 if contact_ in self.groups.remaining_list:
-                    self.contacts.getContactLabel(contact_).setVisible(True)
+                    self.contacts.getContactBox(contact_).setVisible(True)
                 else:
-                    self.contacts.getContactLabel(contact_).setVisible(False)
+                    self.contacts.getContactBox(contact_).setVisible(False)
 
     def __close(self):
         """Remove the widget from parent or close the popup."""