comparison sat.tac @ 37:a61beb21d16d

Gateway registration, unregistration & edition - default values added in form - DBus bridge: fixed array of struct management when adding dynamically a method - fixed doc for some methods - ugly fix for presence status - added dependency for XEP-0077 in XEP-0100 plugin - Wix: added unregister button in gateways manager - Wix: added privacy warning in gateways manager
author Goffi <goffi@goffi.org>
date Tue, 15 Dec 2009 01:27:32 +1100
parents 6491b7956c80
children 2e3411a6baad
comparison
equal deleted inserted replaced
36:6491b7956c80 37:a61beb21d16d
40 40
41 import signal, sys 41 import signal, sys
42 import os.path 42 import os.path
43 43
44 from tools.memory import Memory 44 from tools.memory import Memory
45 from tools.xml_tools import XMLTools
45 from glob import glob 46 from glob import glob
46 47
47 try: 48 try:
48 from twisted.words.protocols.xmlstream import XMPPHandler 49 from twisted.words.protocols.xmlstream import XMPPHandler
49 except ImportError: 50 except ImportError:
276 self.bridge.register("addContact", self.addContact) 277 self.bridge.register("addContact", self.addContact)
277 self.bridge.register("delContact", self.delContact) 278 self.bridge.register("delContact", self.delContact)
278 self.bridge.register("isConnected", self.isConnected) 279 self.bridge.register("isConnected", self.isConnected)
279 self.bridge.register("launchAction", self.launchAction) 280 self.bridge.register("launchAction", self.launchAction)
280 self.bridge.register("confirmationAnswer", self.confirmationAnswer) 281 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
281 self.bridge.register("submitForm", self.submitForm)
282 self.bridge.register("getProgress", self.getProgress) 282 self.bridge.register("getProgress", self.getProgress)
283 283
284 self._import_plugins() 284 self._import_plugins()
285 285
286 286
371 self.roster.requestRoster() 371 self.roster.requestRoster()
372 372
373 self.presence.available() 373 self.presence.available()
374 374
375 self.disco.requestInfo(jid.JID(self.memory.getParamA("Server", "Connection"))).addCallback(self.serverDisco) 375 self.disco.requestInfo(jid.JID(self.memory.getParamA("Server", "Connection"))).addCallback(self.serverDisco)
376 376
377 ## Misc methods ## 377 ## Misc methods ##
378 378
379 def registerNewAccount(self, login, password, server, port = 5222, id = None): 379 def registerNewAccount(self, login, password, server, port = 5222, id = None):
380 """Connect to a server and create a new account using in-band registration""" 380 """Connect to a server and create a new account using in-band registration"""
381 381
382 next_id = id or sat_next_id() #the id is used to send server's answer 382 next_id = id or sat_next_id() #the id is used to send server's answer
417 if accepted: 417 if accepted:
418 self.registerNewAccount(user, password, server, id=action_id) 418 self.registerNewAccount(user, password, server, id=action_id)
419 else: 419 else:
420 self.actionResult(action_id, "SUPPRESS", {}) 420 self.actionResult(action_id, "SUPPRESS", {})
421 421
422 def submitForm(self, target, fields): 422 def submitForm(self, action, target, fields):
423 """Called when a form is submited""" 423 """submit a form
424 @param target: target jid where we are submitting
425 @param fields: list of tuples (name, value)
426 @return: tuple: (id, deferred)
427 """
424 to_jid = jid.JID(target) 428 to_jid = jid.JID(target)
425 print "Form submitted !", fields 429
426 return self.get_next_id() 430 iq = compat.IQ(self.xmlstream, 'set')
431 iq["to"] = target
432 iq["from"] = self.me.full()
433 query = iq.addElement(('jabber:iq:register', 'query'))
434 if action=='SUBMIT':
435 form = XMLTools.tupleList2dataForm(fields)
436 query.addChild(form.toElement())
437 elif action=='CANCEL':
438 query.addElement('remove')
439 else:
440 error ("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm" % action)
441 raise NotImplementedError
442
443 deferred = iq.send(target)
444 return (iq['id'], deferred)
427 445
428 ## Client management ## 446 ## Client management ##
429 447
430 def setParam(self, name, value, category): 448 def setParam(self, name, value, category):
431 """set wanted paramater and notice observers""" 449 """set wanted paramater and notice observers"""
446 return False 464 return False
447 465
448 def launchAction(self, type, data): 466 def launchAction(self, type, data):
449 """Launch a specific action asked by client 467 """Launch a specific action asked by client
450 @param type: action type (button) 468 @param type: action type (button)
451 @data: needed data to launch the action 469 @param data: needed data to launch the action
452 470
453 @return: action id for result, or empty string in case or error 471 @return: action id for result, or empty string in case or error
454 """ 472 """
455 if type=="button": 473 if type=="button":
456 try: 474 try:
487 "unsubscribe", "unsubscribed", "prob", "error"]: 505 "unsubscribe", "unsubscribed", "prob", "error"]:
488 error("Type error !") 506 error("Type error !")
489 #TODO: throw an error 507 #TODO: throw an error
490 return 508 return
491 to_jid=jid.JID(to) 509 to_jid=jid.JID(to)
510 status = None if not status else {None:status} #FIXME: use the proper way here (change signature to use dict)
492 #TODO: refactor subscription bridge API 511 #TODO: refactor subscription bridge API
493 if type=="": 512 if type=="":
494 self.presence.available(to_jid, show, status, priority) 513 self.presence.available(to_jid, show, status, priority)
495 elif type=="subscribe": 514 elif type=="subscribe":
496 self.presence.subscribe(to_jid) 515 self.presence.subscribe(to_jid)
529 ## Generic HMI ## 548 ## Generic HMI ##
530 549
531 def actionResult(self, id, type, data): 550 def actionResult(self, id, type, data):
532 """Send the result of an action 551 """Send the result of an action
533 @param id: same id used with action 552 @param id: same id used with action
534 @type: result type ("PARAM", "SUCCESS", "ERROR", "FORM") 553 @param type: result type ("PARAM", "SUCCESS", "ERROR", "FORM")
535 @data: dictionary 554 @param data: dictionary
536 """ 555 """
537 self.bridge.actionResult(type, id, data) 556 self.bridge.actionResult(type, id, data)
538 557
539 def actionResultExt(self, id, type, data): 558 def actionResultExt(self, id, type, data):
540 """Send the result of an action, extended version 559 """Send the result of an action, extended version
541 @param id: same id used with action 560 @param id: same id used with action
542 @type: result type /!\ only "DICT_DICT" for this method 561 @param type: result type /!\ only "DICT_DICT" for this method
543 @data: dictionary of dictionaries 562 @param data: dictionary of dictionaries
544 """ 563 """
545 if type != "DICT_DICT": 564 if type != "DICT_DICT":
546 error("type for actionResultExt must be DICT_DICT, fixing it") 565 error("type for actionResultExt must be DICT_DICT, fixing it")
547 type = "DICT_DICT" 566 type = "DICT_DICT"
548 self.bridge.actionResultExt(type, id, data) 567 self.bridge.actionResultExt(type, id, data)
550 569
551 570
552 def askConfirmation(self, id, type, data, cb): 571 def askConfirmation(self, id, type, data, cb):
553 """Add a confirmation callback 572 """Add a confirmation callback
554 @param id: id used to get answer 573 @param id: id used to get answer
555 @type: confirmation type ("YES/NO", "FILE_TRANSFERT") 574 @param type: confirmation type ("YES/NO", "FILE_TRANSFERT")
556 @data: data (depend of confirmation type) 575 @param data: data (depend of confirmation type)
557 @cb: callback called with the answer 576 @param cb: callback called with the answer
558 """ 577 """
559 if self.__waiting_conf.has_key(id): 578 if self.__waiting_conf.has_key(id):
560 error ("Attempt to register two callbacks for the same confirmation") 579 error ("Attempt to register two callbacks for the same confirmation")
561 else: 580 else:
562 self.__waiting_conf[id] = cb 581 self.__waiting_conf[id] = cb