comparison 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
comparison
equal deleted inserted replaced
61:80c490e6a1a7 62:12e889a683ce
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.VerticalPanel import VerticalPanel 24 from pyjamas.ui.VerticalPanel import VerticalPanel
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel 25 from pyjamas.ui.HorizontalPanel import HorizontalPanel
26 from pyjamas.ui.Label import Label 26 from pyjamas.ui.Label import Label
27 from pyjamas.ui.HTML import HTML
27 from pyjamas import Window 28 from pyjamas import Window
28 from pyjamas import DOM 29 from pyjamas import DOM
29 30
30 from pyjamas.dnd import makeDraggable 31 from pyjamas.dnd import makeDraggable
31 from pyjamas.ui.DragWidget import DragWidget, DragContainer 32 from pyjamas.ui.DragWidget import DragWidget, DragContainer
33 from browser_side.tools import html_sanitize
32 from jid import JID 34 from jid import JID
33 35
34 class DragLabel(DragWidget): 36 class DragLabel(DragWidget):
35 37
36 def __init__(self, text, type): 38 def __init__(self, text, type):
37 DragWidget.__init__(self) 39 DragWidget.__init__(self)
38 self._text = text 40 self._text = text
39 self._type = type 41 self._type = type
40 42
41 def onDragStart(self, event): 43 def onDragStart(self, event):
42 print "onDragStart"
43 dt = event.dataTransfer 44 dt = event.dataTransfer
44 #self.addMessage('types is %s' % dt.getTypes()) 45 dt.setData('text/plain', "%s\n%s" % (self._text, self._type))
45 dt.setData('Text', self._text)
46 dt.setData('type', self._type)
47 #self.addMessage('after setting, len is %s' % len(dt.dataStore.items))
48 #self.addMessage('types is %s' % dt.getTypes())
49 dt.setDragImage(self.getElement(), 15, 15) 46 dt.setDragImage(self.getElement(), 15, 15)
50 #dt.effectAllowed = 'copy'
51 #self.addMessage('mode is %s' % dt.dataStore.items.mode)
52
53 def onDragEnd(self, event):
54 print "onDragEnd"
55 #self.addMessage('Drag ended')
56 #self.addMessage('mode is %s' % dt._data.mode)
57
58 def addMessage(self, message):
59 print "addMessage"
60 #parent = self.getParent()
61 #while not hasattr(parent, 'addMessage'):
62 # parent = parent.getParent()
63 #parent.addMessage(message)
64 47
65 class GroupLabel(DragLabel, Label): 48 class GroupLabel(DragLabel, Label):
66 def __init__(self, group): 49 def __init__(self, group):
67 self.group = group 50 self.group = group
68 Label.__init__(self, group) #, Element=DOM.createElement('div') 51 Label.__init__(self, group) #, Element=DOM.createElement('div')
69 self.setStyleName('group') 52 self.setStyleName('group')
70 DragLabel.__init__(self, group, "GROUP") 53 DragLabel.__init__(self, group, "GROUP")
71 54
72 55
73 class ContactLabel(DragLabel, Label): 56 class ContactLabel(DragLabel, HTML):
74 def __init__(self, jid, name=None): 57 def __init__(self, jid, name=None):
75 if not name: 58 HTML.__init__(self)
76 name=jid 59 self.name = name or jid
77 Label.__init__(self, name) 60 self.waiting = False
78 self.jid=jid 61 self.jid=jid
62 self._fill()
79 self.setStyleName('contact') 63 self.setStyleName('contact')
80 DragLabel.__init__(self, jid, "CONTACT") 64 DragLabel.__init__(self, jid, "CONTACT")
65
66 def _fill(self):
67 if self.waiting:
68 _wait_html = "<b>(*)</b>&nbsp;"
69 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html,
70 'name': html_sanitize(self.name)})
71
72 def setMessageWaiting(self, waiting):
73 """Show a visual indicator if message are waiting
74 @param waiting: True if message are waiting"""
75 self.waiting = waiting
76 self._fill()
81 77
82 class GroupList(VerticalPanel): 78 class GroupList(VerticalPanel):
83 79
84 def __init__(self, parent): 80 def __init__(self, parent):
85 VerticalPanel.__init__(self) 81 VerticalPanel.__init__(self)
130 for wid in self: 126 for wid in self:
131 if isinstance(wid, ContactLabel) and wid.jid == contact_jid: 127 if isinstance(wid, ContactLabel) and wid.jid == contact_jid:
132 return wid 128 return wid
133 return None 129 return None
134 130
135 def setState(self, jid, state): 131 def setState(self, jid, type, state):
136 """Change the appearance of the contact, according to the state 132 """Change the appearance of the contact, according to the state
137 @param jid: jid which need to change state 133 @param jid: jid which need to change state
138 @param state: 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" 134 @param type: one of availability, messageWaiting
135 @param state:
136 - for messageWaiting type:
137 True if message are waiting
138 - for availability type:
139 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1"""
139 _item = self.getContactLabel(jid) 140 _item = self.getContactLabel(jid)
140 if _item: 141 if _item:
141 if state == 'unavailable': 142 if type == 'availability':
142 _item.removeStyleName('contactConnected') 143 if state == 'unavailable':
143 else: 144 _item.removeStyleName('contactConnected')
144 _item.addStyleName('contactConnected') 145 else:
146 _item.addStyleName('contactConnected')
147 elif type == 'messageWaiting':
148 _item.setMessageWaiting(state)
145 149
146 class ContactTitleLabel(DragLabel, Label): 150 class ContactTitleLabel(DragLabel, Label):
147 def __init__(self, text): 151 def __init__(self, text):
148 Label.__init__(self, text) #, Element=DOM.createElement('div') 152 Label.__init__(self, text) #, Element=DOM.createElement('div')
149 self.setStyleName('contactTitle') 153 self.setStyleName('contactTitle')
217 del self.connected[jid] 221 del self.connected[jid]
218 else: 222 else:
219 if not self.connected.has_key(jid): 223 if not self.connected.has_key(jid):
220 self.connected[jid] = {} 224 self.connected[jid] = {}
221 self.connected[jid][resource] = (availability, priority, statuses) 225 self.connected[jid][resource] = (availability, priority, statuses)
222 self._contact_list.setState(jid, availability) 226 self._contact_list.setState(jid, "availability", availability)
227
228 def setContactMessageWaiting(self, jid, waiting):
229 """Show an visual indicator that contact has send a message
230 @param jid: jid of the contact
231 @param waiting: True if message are waiting"""
232 self._contact_list.setState(jid, "messageWaiting", waiting)
233
234
223 235
224 def getConnected(self): 236 def getConnected(self):
225 """return a list of all jid (bare jid) connected""" 237 """return a list of all jid (bare jid) connected"""
226 return self.connected.keys() 238 return self.connected.keys()
227 239