comparison browser_side/contact.py @ 54:f25c4077f6b9

addind contact + subscription management + misc - removed bad html_sanitize (not needed in Label !) - added isContactInRoster method in ContactPanel
author Goffi <goffi@goffi.org>
date Sat, 28 May 2011 20:18:14 +0200
parents 9f19e16187ff
children d5266c41ca24
comparison
equal deleted inserted replaced
53:dc7861390f10 54:f25c4077f6b9
28 from pyjamas import DOM 28 from pyjamas import DOM
29 29
30 from pyjamas.dnd import makeDraggable 30 from pyjamas.dnd import makeDraggable
31 from pyjamas.ui.DragWidget import DragWidget, DragContainer 31 from pyjamas.ui.DragWidget import DragWidget, DragContainer
32 from jid import JID 32 from jid import JID
33 from tools import html_sanitize
34 33
35 class DragLabel(DragWidget): 34 class DragLabel(DragWidget):
36 35
37 def __init__(self, text, type): 36 def __init__(self, text, type):
38 DragWidget.__init__(self) 37 DragWidget.__init__(self)
64 #parent.addMessage(message) 63 #parent.addMessage(message)
65 64
66 class GroupLabel(DragLabel, Label): 65 class GroupLabel(DragLabel, Label):
67 def __init__(self, group): 66 def __init__(self, group):
68 self.group = group 67 self.group = group
69 Label.__init__(self, html_sanitize(group)) #, Element=DOM.createElement('div') 68 Label.__init__(self, group) #, Element=DOM.createElement('div')
70 self.setStyleName('group') 69 self.setStyleName('group')
71 DragLabel.__init__(self, group, "GROUP") 70 DragLabel.__init__(self, group, "GROUP")
72 71
73 72
74 class ContactLabel(DragLabel, Label): 73 class ContactLabel(DragLabel, Label):
75 def __init__(self, jid, name=None): 74 def __init__(self, jid, name=None):
76 if not name: 75 if not name:
77 name=jid 76 name=jid
78 Label.__init__(self, html_sanitize(name)) 77 Label.__init__(self, name)
79 self.jid=jid 78 self.jid=jid
80 self.setStyleName('contact') 79 self.setStyleName('contact')
81 DragLabel.__init__(self, jid, "CONTACT") 80 DragLabel.__init__(self, jid, "CONTACT")
82 81
83 class GroupList(VerticalPanel): 82 class GroupList(VerticalPanel):
139 138
140 self.vPanel = VerticalPanel() 139 self.vPanel = VerticalPanel()
141 _title = ContactTitleLabel('Contacts') 140 _title = ContactTitleLabel('Contacts')
142 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") 141 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
143 142
144 self._contactList = ContactList() 143 self._contact_list = ContactList()
145 self._contactList.setStyleName('contactList') 144 self._contact_list.setStyleName('contactList')
146 self._groupList = GroupList(self) 145 self._groupList = GroupList(self)
147 self._groupList.setStyleName('groupList') 146 self._groupList.setStyleName('groupList')
148 147
149 self.vPanel.add(_title) 148 self.vPanel.add(_title)
150 self.vPanel.add(self._groupList) 149 self.vPanel.add(self._groupList)
151 self.vPanel.add(self._contactList) 150 self.vPanel.add(self._contact_list)
152 self.add(self.vPanel) 151 self.add(self.vPanel)
153 self.setStyleName('contactBox') 152 self.setStyleName('contactBox')
154 153
155 def addContact(self, jid, attributes, groups): 154 def addContact(self, jid, attributes, groups):
156 """Add a contact to the panel 155 """Add a contact to the panel
161 if not self.groups.has_key(group): 160 if not self.groups.has_key(group):
162 self.groups[group] = set() 161 self.groups[group] = set()
163 self._groupList.add(group) 162 self._groupList.add(group)
164 self.host.uni_box.addKey("@%s: " % group) 163 self.host.uni_box.addKey("@%s: " % group)
165 self.groups[group].add(jid) 164 self.groups[group].add(jid)
166 self._contactList.add(jid) 165 self._contact_list.add(jid)
167 166
168 def setConnected(self, jid, resource, availability, priority, statuses): 167 def setConnected(self, jid, resource, availability, priority, statuses):
169 """Set connection status""" 168 """Set connection status"""
170 if availability=='unavailable': 169 if availability=='unavailable':
171 if self.connected.has_key(jid): 170 if self.connected.has_key(jid):
175 del self.connected[jid] 174 del self.connected[jid]
176 else: 175 else:
177 if not self.connected.has_key(jid): 176 if not self.connected.has_key(jid):
178 self.connected[jid] = {} 177 self.connected[jid] = {}
179 self.connected[jid][resource] = (availability, priority, statuses) 178 self.connected[jid][resource] = (availability, priority, statuses)
180 self._contactList.setState(jid, availability) 179 self._contact_list.setState(jid, availability)
181 180
182 def getConnected(self): 181 def getConnected(self):
183 """return a list of all jid (bare jid) connected""" 182 """return a list of all jid (bare jid) connected"""
184 return self.connected.keys() 183 return self.connected.keys()
185 184
190 @return: True if contact_jid is in on of the groups""" 189 @return: True if contact_jid is in on of the groups"""
191 if self.groups.has_key(group) and contact_jid in self.groups[group]: 190 if self.groups.has_key(group) and contact_jid in self.groups[group]:
192 return True 191 return True
193 return False 192 return False
194 193
194 def isContactInRoster(self, contact_jid):
195 """Test if the contact is in our roster list"""
196 for _contact_label in self._contact_list:
197 if contact_jid == _contact_label.jid:
198 return True
199 return False
200
195 def getGroups(self): 201 def getGroups(self):
196 return self.groups.keys() 202 return self.groups.keys()
197 203
198 def onMouseMove(self, sender, x, y): 204 def onMouseMove(self, sender, x, y):
199 pass 205 pass
204 def onMouseUp(self, sender, x, y): 210 def onMouseUp(self, sender, x, y):
205 pass 211 pass
206 212
207 def onMouseEnter(self, sender): 213 def onMouseEnter(self, sender):
208 if isinstance(sender, GroupLabel): 214 if isinstance(sender, GroupLabel):
209 for contact in self._contactList: 215 for contact in self._contact_list:
210 if contact.jid in self.groups[sender.group]: 216 if contact.jid in self.groups[sender.group]:
211 contact.addStyleName("selected") 217 contact.addStyleName("selected")
212 218
213 def onMouseLeave(self, sender): 219 def onMouseLeave(self, sender):
214 if isinstance(sender, GroupLabel): 220 if isinstance(sender, GroupLabel):
215 for contact in self._contactList: 221 for contact in self._contact_list:
216 if contact.jid in self.groups[sender.group]: 222 if contact.jid in self.groups[sender.group]:
217 contact.removeStyleName("selected") 223 contact.removeStyleName("selected")