comparison frontends/wix/main_window.py @ 42:874de3020e1c

Initial VCard (XEP-0054) support + misc fixes - new xep-0054 plugin, avatar are cached, new getProfile bridge method - gateways plugin (XEP-0100): new __private__ key in resulting data, used to keep target jid
author Goffi <goffi@goffi.org>
date Mon, 21 Dec 2009 13:22:11 +1100
parents 3e24753b9e0b
children 8c67ea98ab91
comparison
equal deleted inserted replaced
41:d24629c631fc 42:874de3020e1c
23 import wx 23 import wx
24 from chat import Chat 24 from chat import Chat
25 from param import Param 25 from param import Param
26 from form import Form 26 from form import Form
27 from gateways import GatewaysManager 27 from gateways import GatewaysManager
28 from profile import Profile
28 import gobject 29 import gobject
29 import os.path 30 import os.path
30 import pdb 31 import pdb
31 from tools.jid import JID 32 from tools.jid import JID
32 from logging import debug, info, error 33 from logging import debug, info, error
41 idDISCONNECT = 2 42 idDISCONNECT = 2
42 idEXIT = 3 43 idEXIT = 3
43 idPARAM = 4 44 idPARAM = 4
44 idADD_CONTACT = 5 45 idADD_CONTACT = 5
45 idREMOVE_CONTACT = 6 46 idREMOVE_CONTACT = 6
46 idFIND_GATEWAYS = 7 47 idSHOW_PROFILE = 7
48 idFIND_GATEWAYS = 8
47 const_DEFAULT_GROUP = "Unclassed" 49 const_DEFAULT_GROUP = "Unclassed"
48 const_STATUS = {"Online":"", 50 const_STATUS = {"Online":"",
49 "Want to discuss":"chat", 51 "Want to discuss":"chat",
50 "AFK":"away", 52 "AFK":"away",
51 "Do Not Disturb":"dnd", 53 "Do Not Disturb":"dnd",
206 connectMenu.AppendSeparator() 208 connectMenu.AppendSeparator()
207 connectMenu.Append(idEXIT,"E&xit"," Terminate the program") 209 connectMenu.Append(idEXIT,"E&xit"," Terminate the program")
208 contactMenu = wx.Menu() 210 contactMenu = wx.Menu()
209 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list") 211 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list")
210 contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list") 212 contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list")
213 contactMenu.AppendSeparator()
214 contactMenu.Append(idSHOW_PROFILE, "&Show profile", " Show contact's profile")
211 communicationMenu = wx.Menu() 215 communicationMenu = wx.Menu()
212 communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM") 216 communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM")
213 menuBar = wx.MenuBar() 217 menuBar = wx.MenuBar()
214 menuBar.Append(connectMenu,"&General") 218 menuBar.Append(connectMenu,"&General")
215 menuBar.Append(contactMenu,"&Contacts") 219 menuBar.Append(contactMenu,"&Contacts")
221 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) 225 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest)
222 wx.EVT_MENU(self, idPARAM, self.onParam) 226 wx.EVT_MENU(self, idPARAM, self.onParam)
223 wx.EVT_MENU(self, idEXIT, self.onExit) 227 wx.EVT_MENU(self, idEXIT, self.onExit)
224 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) 228 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact)
225 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact) 229 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact)
230 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile)
226 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) 231 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways)
227 232
228 233
229 def newMessage(self, from_jid, msg, type, to_jid): 234 def newMessage(self, from_jid, msg, type, to_jid):
230 QuickApp.newMessage(self, from_jid, msg, type, to_jid) 235 QuickApp.newMessage(self, from_jid, msg, type, to_jid)
330 dlg.Destroy() 335 dlg.Destroy()
331 elif type == "FORM": 336 elif type == "FORM":
332 self.current_action_ids.remove(id) 337 self.current_action_ids.remove(id)
333 debug ("Form received") 338 debug ("Form received")
334 form=Form(self, title='Registration', target = data['target'], type = data['type'], xml_data = data['xml']) 339 form=Form(self, title='Registration', target = data['target'], type = data['type'], xml_data = data['xml'])
335 elif type == "DICT_DICT": 340 elif type == "RESULT":
336 self.current_action_ids.remove(id) 341 self.current_action_ids.remove(id)
337 if self.current_action_ids_cb.has_key(id): 342 if self.current_action_ids_cb.has_key(id):
338 callback = self.current_action_ids_cb[id] 343 callback = self.current_action_ids_cb[id]
339 del self.current_action_ids_cb[id] 344 del self.current_action_ids_cb[id]
340 callback(id,data) 345 callback(data)
346 elif type == "DICT_DICT":
347 self.current_action_ids.remove(id)
348 if self.current_action_ids_cb.has_key(id):
349 callback = self.current_action_ids_cb[id]
350 del self.current_action_ids_cb[id]
351 callback(data)
341 print ("Dict of dict found as result") 352 print ("Dict of dict found as result")
342 else: 353 else:
343 error ("FIXME FIXME FIXME: type [%s] not implemented" % type) 354 error ("FIXME FIXME FIXME: type [%s] not implemented" % type)
344 raise NotImplementedError 355 raise NotImplementedError
345 356
426 ) 437 )
427 dlg.ShowModal() 438 dlg.ShowModal()
428 dlg.Destroy() 439 dlg.Destroy()
429 return 440 return
430 441
431 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short, 442 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short,
432 'Contact suppression', 443 'Contact suppression',
433 wx.YES_NO | wx.ICON_QUESTION 444 wx.YES_NO | wx.ICON_QUESTION
434 ) 445 )
435 446
436 if dlg.ShowModal() == wx.ID_YES: 447 if dlg.ShowModal() == wx.ID_YES:
437 info("Unsubsribing %s presence", target.short) 448 info("Unsubsribing %s presence", target.short)
438 self.bridge.delContact(target.short) 449 self.bridge.delContact(target.short)
439 450
440 dlg.Destroy() 451 dlg.Destroy()
452
453 def onShowProfile(self, e):
454 debug("Show contact's profile request")
455 target = self.contactList.getSelection()
456 if not target:
457 dlg = wx.MessageDialog(self, "You haven't selected any contact !",
458 'Error',
459 wx.OK | wx.ICON_ERROR
460 )
461 dlg.ShowModal()
462 dlg.Destroy()
463 return
464 id = self.bridge.getProfile(target.short)
465 self.current_action_ids.add(id)
466 self.current_action_ids_cb[id] = self.onProfileReceived
467
468 def onProfileReceived(self, data):
469 """Called when a profile is received"""
470 debug ('Profile received: [%s]' % data)
471 profile=Profile(self, data)
472
441 473
442 def onFindGateways(self, e): 474 def onFindGateways(self, e):
443 debug("Find Gateways request") 475 debug("Find Gateways request")
444 id = self.bridge.findGateways(self.whoami.domain) 476 id = self.bridge.findGateways(self.whoami.domain)
445 self.current_action_ids.add(id) 477 self.current_action_ids.add(id)
446 self.current_action_ids_cb[id] = self.onGatewaysFound 478 self.current_action_ids_cb[id] = self.onGatewaysFound
447 print "Find Gateways id=", id 479 print "Find Gateways id=", id
448 480
449 def onGatewaysFound(self, id, data): 481 def onGatewaysFound(self, data):
450 """Called when SàT has found the server gateways""" 482 """Called when SàT has found the server gateways"""
451 gatewayManager = GatewaysManager(self, data) 483 target = data['__private__']['target']
484 del data['__private__']
485 gatewayManager = GatewaysManager(self, data, server=target)
452 486
453 def onClose(self, e): 487 def onClose(self, e):
454 info("Exiting...") 488 info("Exiting...")
455 e.Skip() 489 e.Skip()
456 490