diff src/browser/sat_browser/contact_list.py @ 684:e876f493dccc

browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation: - some MUC handlers are no more needed, the presence handler is enough - move the chat states logic to quick_frontend - display MUC games symbols - remove classes contact_list.ContactsPanel, contact_panel.Occupant and contact_panel.OccupantsList - move buildPresenceStyle and setPresenceStyle to html_tools - fixes games menu callback
author souliane <souliane@mailoo.org>
date Wed, 18 Mar 2015 10:17:04 +0100
parents a90cc8fc9605
children 9877607c719a
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_list.py	Thu Mar 19 20:41:46 2015 +0100
+++ b/src/browser/sat_browser/contact_list.py	Wed Mar 18 10:17:04 2015 +0100
@@ -38,37 +38,6 @@
 unicode = str # XXX: pyjama doesn't manage unicode
 
 
-def buildPresenceStyle(presence, base_style=None):
-    """Return the CSS classname to be used for displaying the given presence information.
-
-    @param presence (unicode): presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
-    @param base_style (unicode): base classname
-    @return: unicode
-    """
-    if not base_style:
-        base_style = "contactLabel"
-    return '%s-%s' % (base_style, presence or 'connected')
-
-
-def setPresenceStyle(widget, presence, base_style=None):
-    """
-    Set the CSS style of a contact's element according to its presence.
-
-    @param widget (Widget): the UI element of the contact
-    @param presence (unicode): a value in ("", "chat", "away", "dnd", "xa").
-    @param base_style (unicode): the base name of the style to apply
-    """
-    if not hasattr(widget, 'presence_style'):
-        widget.presence_style = None
-    style = buildPresenceStyle(presence, base_style)
-    if style == widget.presence_style:
-        return
-    if widget.presence_style is not None:
-        widget.removeStyleName(widget.presence_style)
-    widget.addStyleName(style)
-    widget.presence_style = style
-
-
 class GroupLabel(libervia_widget.DragLabel, Label, ClickHandler):
     def __init__(self, host, group):
         """
@@ -132,37 +101,6 @@
         return self._groups
 
 
-class ContactsPanel(contact_panel.ContactsPanel):
-    """The contact list that is displayed on the left side."""
-
-    def __init__(self, host):
-
-        def on_click(contact_jid):
-            self.host.displayWidget(chat.Chat, contact_jid, type_=C.CHAT_ONE2ONE)
-
-        contact_panel.ContactsPanel.__init__(self, host, contacts_click=on_click,
-                                             contacts_menus=(C.MENU_JID_CONTEXT, C.MENU_ROSTER_JID_CONTEXT))
-
-    def setState(self, jid_, type_, state):
-        """Change the appearance of the contact, according to the state
-
-        @param jid_ (jid.JID): jid.JID which need to change state
-        @param type_ (unicode): one of "availability", "messageWaiting"
-        @param state:
-            - for messageWaiting type:
-                True if message are waiting
-            - for availability type:
-                C.PRESENCE_UNAVAILABLE or None if not connected, else presence like RFC6121 #4.7.2.1"""
-        assert type_ in ('availability', 'messageWaiting')
-        contact_box = self.getContactBox(jid_)
-        if type_ == 'availability':
-            if state is None:
-                state = C.PRESENCE_UNAVAILABLE
-            setPresenceStyle(contact_box.label, state)
-        elif type_ == 'messageWaiting':
-            contact_box.setAlert(state)
-
-
 class ContactTitleLabel(libervia_widget.DragLabel, Label, ClickHandler):
 
     def __init__(self, host, text):
@@ -187,7 +125,11 @@
         self.vPanel = VerticalPanel()
         _title = ContactTitleLabel(host, 'Contacts')
         DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
-        self._contacts_panel = ContactsPanel(host)
+
+        def on_click(contact_jid):
+            self.host.displayWidget(chat.Chat, contact_jid, type_=C.CHAT_ONE2ONE)
+
+        self._contacts_panel = contact_panel.ContactsPanel(host, contacts_click=on_click, contacts_menus=(C.MENU_JID_CONTEXT, C.MENU_ROSTER_JID_CONTEXT))
         self._contacts_panel.setStyleName('contactPanel') # FIXME: style doesn't exists !
         self._group_panel = GroupPanel(self)
 
@@ -235,7 +177,7 @@
         self._contacts_panel.setList(to_show)
 
         for jid_ in self._alerts:
-            self._contacts_panel.setState(jid_, "messageWaiting", True)
+            self._contacts_panel.getContactBox(jid_).setAlert(True)
 
     def remove(self, entity):
         # FIXME: SimplePanel and QuickContactList both have a 'remove' method
@@ -430,10 +372,7 @@
 
     def onPresenceUpdate(self, entity, show, priority, statuses, profile):
         QuickContactList.onPresenceUpdate(self, entity, show, priority, statuses, profile)
-        entity_bare = entity.bare
-        show = self.getCache(entity_bare, C.PRESENCE_SHOW) # we use cache to have the show nformation of main resource only
-        self._contacts_panel.setState(entity_bare, "availability", show)
-        self.update()  # FIXME: should update the list without rebuilding it all
+        self._contacts_panel.setPresence(entity, show)
 
     # def updateVisibility(self, jids, groups):
     #     """Set the widgets visibility for the given contacts and groups