comparison frontends/src/primitivus/contact_list.py @ 688:f7878ad3c846

tools: renamed tools.jid.JID attribute "short" to "bare"
author souliane <souliane@mailoo.org>
date Tue, 29 Oct 2013 16:26:55 +0100
parents 0b9bd47dffcd
children 6246eb6d64a0
comparison
equal deleted inserted replaced
687:af0d08a84cc6 688:f7878ad3c846
68 self.update() 68 self.update()
69 return super(ContactList, self).keypress(size, key) 69 return super(ContactList, self).keypress(size, key)
70 70
71 def __contains__(self, jid): 71 def __contains__(self, jid):
72 for group in self.groups: 72 for group in self.groups:
73 if jid.short in self.groups[group][1]: 73 if jid.bare in self.groups[group][1]:
74 return True 74 return True
75 return False 75 return False
76 76
77 def setFocus(self, text, select=False): 77 def setFocus(self, text, select=False):
78 """give focus to the first element that matches the given text. You can also 78 """give focus to the first element that matches the given text. You can also
106 pass 106 pass
107 idx += 1 107 idx += 1
108 108
109 def putAlert(self, jid): 109 def putAlert(self, jid):
110 """Put an alert on the jid to get attention from user (e.g. for new message)""" 110 """Put an alert on the jid to get attention from user (e.g. for new message)"""
111 self.alert_jid.add(jid.short) 111 self.alert_jid.add(jid.bare)
112 self.update() 112 self.update()
113 113
114 def __groupClicked(self, group_wid): 114 def __groupClicked(self, group_wid):
115 group = self.groups[group_wid.getValue()] 115 group = self.groups[group_wid.getValue()]
116 group[0] = not group[0] 116 group[0] = not group[0]
151 show = "unavailable" 151 show = "unavailable"
152 if (not self.show_disconnected and show == "unavailable" 152 if (not self.show_disconnected and show == "unavailable"
153 and not contact in self.alert_jid and contact != self.selected): 153 and not contact in self.alert_jid and contact != self.selected):
154 continue 154 continue
155 show_icon, show_attr = const_SHOW_ICON.get(show,('','default')) 155 show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
156 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short) 156 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare)
157 display = [ show_icon + " " , contact_disp] 157 display = [ show_icon + " " , contact_disp]
158 if self.show_status: 158 if self.show_status:
159 status_disp = ('status',"\n " + status) if status else "" 159 status_disp = ('status',"\n " + status) if status else ""
160 display.append(status_disp) 160 display.append(status_disp)
161 header = '(*) ' if contact in self.alert_jid else '' 161 header = '(*) ' if contact in self.alert_jid else ''
178 specials.sort() 178 specials.sort()
179 for special in specials: 179 for special in specials:
180 jid=JID(special) 180 jid=JID(special)
181 name = self.getCache(jid, 'name') 181 name = self.getCache(jid, 'name')
182 nick = self.getCache(jid, 'nick') 182 nick = self.getCache(jid, 'nick')
183 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) 183 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.bare)
184 display = [ " " , special_disp] 184 display = [ " " , special_disp]
185 header = '(*) ' if special in self.alert_jid else '' 185 header = '(*) ' if special in self.alert_jid else ''
186 widget = sat_widgets.SelectableText(display, 186 widget = sat_widgets.SelectableText(display,
187 selected = special==self.selected, 187 selected = special==self.selected,
188 header=header) 188 header=header)
231 self.update() 231 self.update()
232 232
233 def replace(self, jid, groups=None, attributes=None): 233 def replace(self, jid, groups=None, attributes=None):
234 """add a contact to the list if doesn't exist, else update it""" 234 """add a contact to the list if doesn't exist, else update it"""
235 QuickContactList.replace(self, jid, groups, attributes) 235 QuickContactList.replace(self, jid, groups, attributes)
236 if jid.short in self.specials: 236 if jid.bare in self.specials:
237 return 237 return
238 if not groups: 238 if not groups:
239 groups = [None] 239 groups = [None]
240 if not attributes: 240 if not attributes:
241 attributes={} 241 attributes={}
242 assert isinstance(groups, list) 242 assert isinstance(groups, list)
243 assert isinstance(jid, JID) 243 assert isinstance(jid, JID)
244 for group in groups: 244 for group in groups:
245 if not self.groups.has_key(group): 245 if not self.groups.has_key(group):
246 self.groups[group] = [True,set()] #[unfold,list_of_contacts] 246 self.groups[group] = [True,set()] #[unfold,list_of_contacts]
247 self.groups[group][1].add(jid.short) 247 self.groups[group][1].add(jid.bare)
248 self.update() 248 self.update()
249 249
250 def remove(self, jid): 250 def remove(self, jid):
251 """remove a contact from the list""" 251 """remove a contact from the list"""
252 QuickContactList.remove(self, jid) 252 QuickContactList.remove(self, jid)
253 groups_to_remove = [] 253 groups_to_remove = []
254 for group in self.groups: 254 for group in self.groups:
255 contacts = self.groups[group][1] 255 contacts = self.groups[group][1]
256 if jid.short in contacts: 256 if jid.bare in contacts:
257 contacts.remove(jid.short) 257 contacts.remove(jid.bare)
258 if not len(contacts): 258 if not len(contacts):
259 groups_to_remove.append(group) 259 groups_to_remove.append(group)
260 for group in groups_to_remove: 260 for group in groups_to_remove:
261 del self.groups[group] 261 del self.groups[group]
262 self.update() 262 self.update()
273 """ 273 """
274 QuickContactList.setSpecial(self, special_jid, special_type, show) 274 QuickContactList.setSpecial(self, special_jid, special_type, show)
275 if None in self.groups: 275 if None in self.groups:
276 folded, group_jids = self.groups[None] 276 folded, group_jids = self.groups[None]
277 for group_jid in group_jids: 277 for group_jid in group_jids:
278 if JID(group_jid).short == special_jid.short: 278 if JID(group_jid).bare == special_jid.bare:
279 group_jids.remove(group_jid) 279 group_jids.remove(group_jid)
280 break 280 break
281 self.update() 281 self.update()
282 if show: 282 if show:
283 # also display the dialog for this room 283 # also display the dialog for this room
284 self.setFocus(special_jid, True) 284 self.setFocus(special_jid, True)
285 self.host.redraw() 285 self.host.redraw()
286 286
287 def updatePresence(self, jid, show, priority, statuses): 287 def updatePresence(self, jid, show, priority, statuses):
288 #XXX: for the moment, we ignore presence updates for special entities 288 #XXX: for the moment, we ignore presence updates for special entities
289 if jid.short not in self.specials: 289 if jid.bare not in self.specials:
290 QuickContactList.updatePresence(self, jid, show, priority, statuses) 290 QuickContactList.updatePresence(self, jid, show, priority, statuses)