diff browser_side/contact.py @ 62:12e889a683ce SàT v0.2.0

server side: misc stuff: - fixed lot of misuse in callbacks - chat history fixed - a visual indicator now appear when we have message waiting from a contact - fixed About dialog size issue in webkit - fixed Drag'n'Drop for webkit - defaut room to join is now libervia@conference.libervia.org
author Goffi <goffi@goffi.org>
date Tue, 31 May 2011 17:06:59 +0200
parents d5266c41ca24
children 9d8e79ac4c9c
line wrap: on
line diff
--- a/browser_side/contact.py	Tue May 31 17:03:37 2011 +0200
+++ b/browser_side/contact.py	Tue May 31 17:06:59 2011 +0200
@@ -24,11 +24,13 @@
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.Label import Label
+from pyjamas.ui.HTML import HTML
 from pyjamas import Window
 from pyjamas import DOM
 
 from pyjamas.dnd import makeDraggable
 from pyjamas.ui.DragWidget import DragWidget, DragContainer
+from browser_side.tools import html_sanitize
 from jid import JID
 
 class DragLabel(DragWidget):
@@ -39,28 +41,9 @@
         self._type = type
     
     def onDragStart(self, event):
-        print "onDragStart"
         dt = event.dataTransfer
-        #self.addMessage('types is %s' % dt.getTypes())
-        dt.setData('Text', self._text)
-        dt.setData('type', self._type)
-        #self.addMessage('after setting, len is %s' % len(dt.dataStore.items))
-        #self.addMessage('types is %s' % dt.getTypes())
+        dt.setData('text/plain', "%s\n%s" % (self._text, self._type))
         dt.setDragImage(self.getElement(), 15, 15)
-        #dt.effectAllowed = 'copy'
-        #self.addMessage('mode is %s' % dt.dataStore.items.mode)
-
-    def onDragEnd(self, event):
-        print "onDragEnd"
-        #self.addMessage('Drag ended')
-        #self.addMessage('mode is %s' % dt._data.mode)
-
-    def addMessage(self, message):
-        print "addMessage"
-        #parent = self.getParent()
-        #while not hasattr(parent, 'addMessage'):
-        #    parent = parent.getParent()
-        #parent.addMessage(message)
 
 class GroupLabel(DragLabel, Label):
     def __init__(self, group):
@@ -70,15 +53,28 @@
         DragLabel.__init__(self, group, "GROUP")
     
 
-class ContactLabel(DragLabel, Label):
+class ContactLabel(DragLabel, HTML):
     def __init__(self, jid, name=None):
-        if not name:
-            name=jid
-        Label.__init__(self, name)
+        HTML.__init__(self)
+        self.name = name or jid
+        self.waiting = False
         self.jid=jid
+        self._fill()
         self.setStyleName('contact')
         DragLabel.__init__(self, jid, "CONTACT")
 
+    def _fill(self):
+        if self.waiting:
+            _wait_html = "<b>(*)</b>&nbsp;"
+        self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html,
+                                           'name': 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()
+
 class GroupList(VerticalPanel):
 
     def __init__(self, parent):
@@ -132,16 +128,24 @@
                 return wid
         return None
 
-    def setState(self, jid, state):
+    def setState(self, jid, type, state):
         """Change the appearance of the contact, according to the state
         @param jid: jid which need to change state
-        @param state: 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1"""
+        @param type: one of availability, messageWaiting
+        @param state:
+            - for messageWaiting type:
+                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:
-            if state == 'unavailable':
-                _item.removeStyleName('contactConnected')
-            else:
-                _item.addStyleName('contactConnected')
+            if type == 'availability':
+                if state == 'unavailable':
+                    _item.removeStyleName('contactConnected')
+                else:
+                    _item.addStyleName('contactConnected')
+            elif type == 'messageWaiting':
+                _item.setMessageWaiting(state)
 
 class ContactTitleLabel(DragLabel, Label):
     def __init__(self, text):
@@ -219,7 +223,15 @@
             if not self.connected.has_key(jid):
                 self.connected[jid] = {}
             self.connected[jid][resource] = (availability, priority, statuses)
-        self._contact_list.setState(jid, availability)
+        self._contact_list.setState(jid, "availability", availability)
+
+    def setContactMessageWaiting(self, jid, waiting):
+        """Show an visual indicator that contact has send a message
+        @param jid: jid of the contact
+        @param waiting: True if message are waiting"""
+        self._contact_list.setState(jid, "messageWaiting", waiting)
+
+
 
     def getConnected(self):
         """return a list of all jid (bare jid) connected"""