changeset 479:c21ea1fe3593

browser side: small refactoring to prepare displaying avatars in the contact panel
author souliane <souliane@mailoo.org>
date Sat, 14 Jun 2014 19:10:51 +0200
parents 992b900ab876
children 50b286866739
files src/browser/libervia_main.py src/browser/public/libervia.css src/browser/sat_browser/constants.py src/browser/sat_browser/contact.py
diffstat 4 files changed, 45 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Thu Jun 12 22:37:22 2014 +0200
+++ b/src/browser/libervia_main.py	Sat Jun 14 19:10:51 2014 +0200
@@ -249,7 +249,11 @@
         return True
 
     def getAvatar(self, jid_str):
-        """Return avatar of a jid if in cache, else ask for it"""
+        """Return avatar of a jid if in cache, else ask for it.
+
+        @param jid_str (str): JID of the contact
+        @return: the URL to the avatar (str)
+        """
         def dataReceived(result):
             if 'avatar' in result:
                 self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar'])
--- a/src/browser/public/libervia.css	Thu Jun 12 22:37:22 2014 +0200
+++ b/src/browser/public/libervia.css	Sat Jun 14 19:10:51 2014 +0200
@@ -359,7 +359,7 @@
 }
 /* Contact List */
 
-div.contactBox {
+div.contactPanel {
     width: 100%;
    /* We want the contact panel to not use all the available height when displayed
       in the unibox panel (grey part), because the dialogs panels (white part) should
@@ -425,7 +425,7 @@
     -webkit-transition: color 0.1s linear; 
     transition: color 0.1s linear;  
 }
-.contact {
+.contactLabel {
     font-size: 1em;
     margin-top: 3px;
     padding: 3px 10px 3px 10px;
@@ -440,25 +440,25 @@
 }
 
 /* START - contact presence status */
-.contact-connected {
+.contactLabel-connected {
     color: #3c7e0c;
     font-weight: bold;
 }
-.contact-unavailable {
+.contactLabel-unavailable {
 }
-.contact-chat {
+.contactLabel-chat {
     color: #3c7e0c;
     font-weight: bold;
 }
-.contact-away {
+.contactLabel-away {
     color: brown;
     font-weight: bold;
 }
-.contact-dnd {
+.contactLabel-dnd {
     color: red;
     font-weight: bold;
 }
-.contact-xa {
+.contactLabel-xa {
     color: red;
     font-weight: bold;
 }
--- a/src/browser/sat_browser/constants.py	Thu Jun 12 22:37:22 2014 +0200
+++ b/src/browser/sat_browser/constants.py	Sat Jun 14 19:10:51 2014 +0200
@@ -32,5 +32,6 @@
     #     - list them as a couple (category, name)
     CACHED_PARAMS = [(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM)]
 
-    # Default avatar
+    # Empty and default avatars
+    EMPTY_AVATAR = "/media/misc/empty_avatar"
     DEFAULT_AVATAR = "/media/misc/default_avatar.png"
--- a/src/browser/sat_browser/contact.py	Thu Jun 12 22:37:22 2014 +0200
+++ b/src/browser/sat_browser/contact.py	Sat Jun 14 19:10:51 2014 +0200
@@ -38,22 +38,23 @@
 import html_tools
 
 
-def setPresenceStyle(element, presence, base_style="contact"):
+def setPresenceStyle(widget, presence, base_style="contactLabel"):
     """
     Set the CSS style of a contact's element according to its presence.
-    @param item: the UI element of the contact
-    @param presence: a value in ("", "chat", "away", "dnd", "xa").
-    @param base_style: the base name of the style to apply
+
+    @param widget (Widget): the UI element of the contact
+    @param presence (str): a value in ("", "chat", "away", "dnd", "xa").
+    @param base_style (str): the base name of the style to apply
     """
-    if not hasattr(element, 'presence_style'):
-        element.presence_style = None
+    if not hasattr(widget, 'presence_style'):
+        widget.presence_style = None
     style = '%s-%s' % (base_style, presence or 'connected')
-    if style == element.presence_style:
+    if style == widget.presence_style:
         return
-    if element.presence_style is not None:
-        element.removeStyleName(element.presence_style)
-    element.addStyleName(style)
-    element.presence_style = style
+    if widget.presence_style is not None:
+        widget.removeStyleName(widget.presence_style)
+    widget.addStyleName(style)
+    widget.presence_style = style
 
 
 class GroupLabel(base_widget.DragLabel, Label, ClickHandler):
@@ -77,24 +78,25 @@
         self.name = name or jid
         self.waiting = False
         self.jid = jid
-        self._fill()
-        self.setStyleName('contact')
+        self.refresh()
+        self.setStyleName('contactLabel')
         base_widget.DragLabel.__init__(self, jid, "CONTACT")
         if handleClick:
             ClickHandler.__init__(self)
             self.addClickListener(self)
 
-    def _fill(self):
+    def refresh(self):
         if self.waiting:
-            _wait_html = "<b>(*)</b>&nbsp;"
-        self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html,
+            wait_html = "<b>(*)</b>&nbsp;"
+        self.setHTML("%(wait)s%(name)s" % {'wait': wait_html,
                                            'name': html_tools.html_sanitize(self.name)})
 
     def setMessageWaiting(self, waiting):
         """Show a visual indicator if message are waiting
+
         @param waiting: True if message are waiting"""
         self.waiting = waiting
-        self._fill()
+        self.refresh()
 
     def onClick(self, sender):
         self.host.getOrCreateLiberviaWidget(panels.ChatPanel, self.jid)
@@ -135,7 +137,13 @@
         self.contacts = []
         self.handleClick = handleClick
 
-    def add(self, jid, name=None, item_cb=None):
+    def add(self, jid, name=None, add_item_cb=None):
+        """Add a contact to the list.
+
+        @param jid (str): JID of the contact
+        @param name (str): optional name of the contact
+        @param add_item_cb (method): to be called on the contact's widget after it's been added to the list
+        """
         if jid in self.contacts:
             return
         index = 0
@@ -147,8 +155,8 @@
         _item = ContactLabel(self.host, jid, name, handleClick=self.handleClick)
         DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
         VerticalPanel.insert(self, _item, index)
-        if item_cb is not None:
-            item_cb(_item)
+        if add_item_cb:
+            add_item_cb(box)
 
     def remove(self, jid):
         wid = self.getContactLabel(jid)
@@ -204,9 +212,7 @@
         @param jid_s (str): JID as unicode
         @param name (str): nickname
         """
-        def item_cb(item):
-            self.context_menu.registerRightClickSender(item)
-        GenericContactList.add(self, jid_s, name, item_cb)
+        GenericContactList.add(self, jid_s, name, add_item_cb=lambda item: self.context_menu.registerRightClickSender(item))
 
     def setState(self, jid, type_, state):
         """Change the appearance of the contact, according to the state
@@ -264,7 +270,7 @@
         self.vPanel.add(self._contact_list)
         self.scroll_panel.add(self.vPanel)
         self.add(self.scroll_panel)
-        self.setStyleName('contactBox')
+        self.setStyleName('contactPanel')
         Window.addWindowResizeListener(self)
 
     def onWindowResized(self, width, height):