request_register_agent_info is now async

This commit is contained in:
Yann Leboulanger 2005-05-08 20:56:11 +00:00
parent 4985612036
commit f4b05e51fa
3 changed files with 49 additions and 16 deletions

View File

@ -103,13 +103,13 @@ class Connection:
"""Connection class"""
def __init__(self, name):
# dict of function to be calledfor each event
self.handlers = {'ROSTER': [], 'WARNING': [], 'ERROR': [], 'STATUS': [], \
'NOTIFY': [], 'MSG': [], 'MSGERROR': [], 'MSGSENT': [] , \
'SUBSCRIBED': [], 'UNSUBSCRIBED': [], 'SUBSCRIBE': [], \
'AGENT_INFO': [], 'AGENT_INFO_ITEMS': [], 'AGENT_INFO_INFO': [], \
'QUIT': [], 'ACC_OK': [], 'MYVCARD': [], 'OS_INFO': [], 'VCARD': [], \
'GC_MSG': [], 'GC_SUBJECT': [], 'GC_CONFIG': [], 'BAD_PASSPHRASE': [],\
'ROSTER_INFO': []}
self.handlers = {'ROSTER': [], 'WARNING': [], 'ERROR': [], 'STATUS': [],
'NOTIFY': [], 'MSG': [], 'MSGERROR': [], 'MSGSENT': [] ,
'SUBSCRIBED': [], 'UNSUBSCRIBED': [], 'SUBSCRIBE': [],
'AGENT_INFO': [], 'REGISTER_AGENT_INFO': [], 'AGENT_INFO_ITEMS': [],
'AGENT_INFO_INFO': [], 'QUIT': [], 'ACC_OK': [], 'MYVCARD': [],
'OS_INFO': [], 'VCARD': [], 'GC_MSG': [], 'GC_SUBJECT': [],
'GC_CONFIG': [], 'BAD_PASSPHRASE': [], 'ROSTER_INFO': []}
self.name = name
self.connected = 0 # offline
self.connection = None # xmpppy instance
@ -724,10 +724,38 @@ class Connection:
queryNS = common.xmpp.NS_BROWSE))
self.discoverInfo(jid, node)
def ask_register_agent_info(self, agent):
def _receive_register_agent_info(self, con, iq_obj, agent):
if not common.xmpp.isResultNode(iq_obj):
return
iq = common.xmpp.Iq('get', common.xmpp.NS_REGISTER, to = agent)
df = iq_obj.getTag('query', namespace = common.xmpp.NS_REGISTER).\
getTag('x', namespace = common.xmpp.NS_DATA)
if df:
df = common.xmpp.DataForm(node = df)
self.dispatch('REGISTER_AGENT_INFO', (agent, df.asDict()))
return
df = common.xmpp.DataForm(typ = 'form')
for i in iq_obj.getQueryPayload():
if type(i) != type(iq):
pass
elif i.getName() == 'instructions':
df.addInstructions(i.getData())
else:
df.setField(i.getName()).setValue(i.getData())
self.dispatch('REGISTER_AGENT_INFO', (agent, df.asDict()))
return
def request_register_agent_info(self, agent):
if not self.connection:
return None
return common.xmpp.features.getRegInfo(self.connection, agent).asDict() # FIXME: blocking
iq = common.xmpp.Iq('get', common.xmpp.NS_REGISTER, to = agent)
self.connection.SendAndCallForResponse(iq,
self._receive_register_agent_info, {'agent': agent})
return
rep = common.xmpp.features.getRegInfo(self.connection, agent).asDict() # FIXME: blocking
print '\n\nTOTO\n\n'
print rep
return rep
def register_agent(self, agent, info):
if not self.connection:

View File

@ -1862,11 +1862,7 @@ class Service_discovery_window:
if not iter :
return
service = model.get_value(iter, 1)
infos = gajim.connections[self.account].ask_register_agent_info(service)
if infos.has_key('instructions'):
Service_registration_window(service, infos, self.plugin, self.account)
else:
dialogs.Error_dialog(_('error contacting %s') % service)
gajim.connections[self.account].request_register_agent_info(service)
self.window.destroy()

View File

@ -350,6 +350,13 @@ class Interface:
self.windows[account]['disco'].agent_info(array[0], array[1], \
array[2], array[3])
def handle_event_register_agent_info(self, account, array):
#('AGENT_INFO', account, (agent, infos))
if array[1].has_key('instructions'):
config.Service_registration_window(array[0], array[1], self, account)
else:
dialogs.Error_dialog(_('error contacting %s') % array[0])
def handle_event_agent_info_items(self, account, array):
#('AGENT_INFO_ITEMS', account, (agent, node, items))
if self.windows[account].has_key('disco'):
@ -611,9 +618,11 @@ class Interface:
conn.register_handler('UNSUBSCRIBED', self.handle_event_unsubscribed)
conn.register_handler('SUBSCRIBE', self.handle_event_subscribe)
conn.register_handler('AGENT_INFO', self.handle_event_agent_info)
conn.register_handler('AGENT_INFO_ITEMS', \
conn.register_handler('REGISTER_AGENT_INFO',
self.handle_event_register_agent_info)
conn.register_handler('AGENT_INFO_ITEMS',
self.handle_event_agent_info_items)
conn.register_handler('AGENT_INFO_INFO', \
conn.register_handler('AGENT_INFO_INFO',
self.handle_event_agent_info_info)
conn.register_handler('QUIT', self.handle_event_quit)
conn.register_handler('ACC_OK', self.handle_event_acc_ok)