comparison frontends/src/quick_frontend/quick_app.py @ 501:e9634d2e7b38

core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1: - QuickContactManagement is not used anymore and will be removed, ContactList + Core are used instead - disconnected contacts are now displayed in Primitivus (M-d to show/hide them) - avatars are temporary unavailable in wix - new bridge method: getContactsFromGroup
author Goffi <goffi@goffi.org>
date Tue, 25 Sep 2012 00:58:34 +0200
parents 2a072735e459
children debcf5dd404a
comparison
equal deleted inserted replaced
500:00d3679976ab 501:e9634d2e7b38
17 17
18 You should have received a copy of the GNU Affero General Public License 18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, error 22 from logging import debug, info, warning, error
23 from sat.tools.jid import JID 23 from sat.tools.jid import JID
24 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 24 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
25 from optparse import OptionParser 25 from optparse import OptionParser
26 import pdb 26 import pdb
27 27
30 30
31 class QuickApp(): 31 class QuickApp():
32 """This class contain the main methods needed for the frontend""" 32 """This class contain the main methods needed for the frontend"""
33 33
34 def __init__(self, single_profile=True): 34 def __init__(self, single_profile=True):
35 self.rosterList = {}
36 self.profiles = {} 35 self.profiles = {}
37 self.single_profile = single_profile 36 self.single_profile = single_profile
38 self.check_options() 37 self.check_options()
39 38
40 ## bridge ## 39 ## bridge ##
155 else: 154 else:
156 self.setStatusOnline(True) 155 self.setStatusOnline(True)
157 156
158 ### now we fill the contact list ### 157 ### now we fill the contact list ###
159 for contact in self.bridge.getContacts(profile): 158 for contact in self.bridge.getContacts(profile):
160 self.newContact(contact[0], contact[1], contact[2], profile) 159 self.newContact(*contact, profile=profile)
161 160
162 presences = self.bridge.getPresenceStatus(profile) 161 presences = self.bridge.getPresenceStatus(profile)
163 for contact in presences: 162 for contact in presences:
164 for res in presences[contact]: 163 for res in presences[contact]:
165 jabber_id = contact+('/'+res if res else '') 164 jabber_id = contact+('/'+res if res else '')
205 def disconnected(self, profile): 204 def disconnected(self, profile):
206 """called when the connection is closed""" 205 """called when the connection is closed"""
207 if not self.check_profile(profile): 206 if not self.check_profile(profile):
208 return 207 return
209 debug(_("Disconnected")) 208 debug(_("Disconnected"))
210 self.CM.clear() 209 self.contactList.clearContacts()
211 self.contactList.clear_contacts()
212 self.setStatusOnline(False) 210 self.setStatusOnline(False)
213 211
214 def connectionError(self, error_type, profile): 212 def connectionError(self, error_type, profile):
215 """called when something goest wrong with the connection""" 213 """called when something goest wrong with the connection"""
216 if not self.check_profile(profile): 214 if not self.check_profile(profile):
225 def newContact(self, JabberId, attributes, groups, profile): 223 def newContact(self, JabberId, attributes, groups, profile):
226 if not self.check_profile(profile): 224 if not self.check_profile(profile):
227 return 225 return
228 entity=JID(JabberId) 226 entity=JID(JabberId)
229 _groups = list(groups) 227 _groups = list(groups)
230 self.rosterList[entity.short]=(dict(attributes), _groups) 228 self.contact_list._replace(entity, _groups, attributes)
231 if entity in self.CM:
232 self.CM.update(entity, 'groups', _groups)
233 self.contactList.replace(entity, self.CM.getAttr(entity, 'groups'))
234 229
235 def newMessage(self, from_jid, msg, type, to_jid, profile): 230 def newMessage(self, from_jid, msg, type, to_jid, profile):
236 if not self.check_profile(profile): 231 if not self.check_profile(profile):
237 return 232 return
238 sender=JID(from_jid) 233 sender=JID(from_jid)
264 self.setStatusOnline(True) 259 self.setStatusOnline(True)
265 elif type=="unavailable": 260 elif type=="unavailable":
266 self.setStatusOnline(False) 261 self.setStatusOnline(False)
267 return 262 return
268 263
264 self.contact_list.updatePresence(from_jid, show, priority, statuses)
265
269 if show != 'unavailable': 266 if show != 'unavailable':
270 name="" 267
271 groups = []
272 if self.rosterList.has_key(from_jid.short):
273 if self.rosterList[from_jid.short][0].has_key("name"):
274 name=self.rosterList[from_jid.short][0]["name"]
275 groups=self.rosterList[from_jid.short][1]
276
277 #FIXME: must be moved in a plugin 268 #FIXME: must be moved in a plugin
278 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: 269 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
279 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) 270 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
280 271
281 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed 272 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
282 self.CM.add(from_jid) 273
283 self.CM.update(from_jid, 'name', unicode(name)) 274 #TODO: vcard data (avatar)
284 self.CM.update(from_jid, 'show', show)
285 self.CM.update(from_jid, 'statuses', statuses)
286 self.CM.update(from_jid, 'groups', groups)
287 cache = self.bridge.getCardCache(from_jid, profile)
288 if cache.has_key('nick'):
289 self.CM.update(from_jid, 'nick', unicode(cache['nick']))
290 if cache.has_key('avatar'):
291 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar']))
292 self.contactList.replace(from_jid, self.CM.getAttr(from_jid, 'groups'))
293 275
294 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']: 276 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']:
295 self.profiles[profile]['onlineContact'].remove(from_jid) 277 self.profiles[profile]['onlineContact'].remove(from_jid)
296 self.CM.remove(from_jid)
297 if not self.CM.isConnected(from_jid):
298 self.contactList.disconnect(from_jid)
299 278
300 def roomJoined(self, room_jid, room_nicks, user_nick, profile): 279 def roomJoined(self, room_jid, room_nicks, user_nick, profile):
301 """Called when a MUC room is joined""" 280 """Called when a MUC room is joined"""
302 if not self.check_profile(profile): 281 if not self.check_profile(profile):
303 return 282 return
489 468
490 def contactDeleted(self, jid, profile): 469 def contactDeleted(self, jid, profile):
491 if not self.check_profile(profile): 470 if not self.check_profile(profile):
492 return 471 return
493 target = JID(jid) 472 target = JID(jid)
494 self.contactList.remove(self.CM.get_full(target)) 473 self.contactList.remove(target)
495 self.CM.remove(target)
496 try: 474 try:
497 self.profiles[profile]['onlineContact'].remove(target.short) 475 self.profiles[profile]['onlineContact'].remove(target.short)
498 except KeyError: 476 except KeyError:
499 pass 477 pass
500 478
501 def updatedValue(self, name, data, profile): 479 def updatedValue(self, name, data, profile):
480 #FIXME: to be removed
502 if not self.check_profile(profile): 481 if not self.check_profile(profile):
503 return 482 return
504 if name == "card_nick": 483 if name == "card_nick":
505 target = JID(data['jid']) 484 target = JID(data['jid'])
506 if target in self.contactList: 485 if target in self.contactList:
507 self.CM.update(target, 'nick', unicode(data['nick'])) 486 #self.CM.update(target, 'nick', unicode(data['nick']))
508 self.contactList.replace(target) 487 self.contact_list._replace(target)
509 elif name == "card_avatar": 488 elif name == "card_avatar":
510 target = JID(data['jid']) 489 target = JID(data['jid'])
511 if target in self.contactList: 490 if target in self.contactList:
512 filename = self.bridge.getAvatarFile(data['avatar']) 491 filename = self.bridge.getAvatarFile(data['avatar'])
513 self.CM.update(target, 'avatar', filename) 492 #self.CM.update(target, 'avatar', filename)
514 self.contactList.replace(target) 493 self.contact_list._replace(target)
515 494
516 def askConfirmation(self, type, id, data): 495 def askConfirmation(self, type, id, data):
517 raise NotImplementedError 496 raise NotImplementedError
518 497
519 def actionResult(self, type, id, data): 498 def actionResult(self, type, id, data):