From 0c2d703f259c9b3cf1a4c07718640630145ee0ac Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 15 Dec 2010 22:08:42 +0100 Subject: [PATCH] finish supporting jabber:iq:gateway. Fixes #6054 --- src/common/connection.py | 11 +++++++++-- src/common/connection_handlers_events.py | 10 ++++++++-- src/dialogs.py | 23 +++++++++++++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 9848e029a..835aa506d 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1953,11 +1953,18 @@ class Connection(CommonConnection, ConnectionHandlers): self.entity_time_ids.append(id_) self.connection.send(iq) - def request_gateway_prompt(self, jid): + def request_gateway_prompt(self, jid, prompt=None): def _on_prompt_result(resp): gajim.nec.push_incoming_event(GatewayPromptReceivedEvent(None, conn=self, stanza=resp)) - iq = common.xmpp.Iq(typ='get', queryNS=common.xmpp.NS_GATEWAY, to=jid) + if prompt: + typ_ = 'set' + else: + typ_ = 'get' + iq = common.xmpp.Iq(typ=typ_, to=jid) + query = iq.addChild(name='query', namespace=common.xmpp.NS_GATEWAY) + if prompt: + query.setTagData('prompt', prompt) self.connection.SendAndCallForResponse(iq, _on_prompt_result) def get_settings(self): diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index d3195f5fb..2c4fda6a9 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1820,6 +1820,12 @@ class GatewayPromptReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): def generate(self): self.get_jid_resource() query = self.stanza.getTag('query') - self.desc = query.getTagData('desc') - self.prompt = query.getTagData('prompt') + if query: + self.desc = query.getTagData('desc') + self.prompt = query.getTagData('prompt') + self.prompt_jid = query.getTagData('jid') + else: + self.desc = None + self.prompt = None + self.prompt_jid = None return True diff --git a/src/dialogs.py b/src/dialogs.py index 90fc5dbf9..9b43b6668 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -844,6 +844,7 @@ class AddNewContactWindow: def __init__(self, account=None, jid=None, user_nick=None, group=None): self.account = account + self.adding_jid = False if account is None: # fill accounts with active accounts accounts = [] @@ -1054,8 +1055,17 @@ class AddNewContactWindow: if type_ != 'jabber': transport = self.protocol_jid_combobox.get_active_text().decode( 'utf-8') - jid = jid.replace('@', '%') + '@' + transport + if self.account: + self.adding_jid = (jid, transport) + gajim.connections[self.account].request_gateway_prompt( + transport, jid) + else: + jid = jid.replace('@', '%') + '@' + transport + self._add_jid(jid) + else: + self._add_jid(jid) + def _add_jid(self, jid): # check if jid is conform to RFC and stringprep it try: jid = helpers.parse_jid(jid) @@ -1119,6 +1129,8 @@ class AddNewContactWindow: def on_protocol_jid_combobox_changed(self, widget): model = widget.get_model() iter_ = widget.get_active_iter() + if not iter_: + return jid_ = model[iter_][0] model = self.protocol_combobox.get_model() iter_ = self.protocol_combobox.get_active_iter() @@ -1226,7 +1238,14 @@ class AddNewContactWindow: self.transport_signed_out(obj.jid) def _nec_gateway_prompt_received(self, obj): - if obj.jid in self.gateway_prompt: + if self.adding_jid: + if obj.prompt_jid: + self._add_jid(obj.prompt_jid) + else: + jid, transport = self.adding_jid + jid = jid.replace('@', '%') + '@' + transport + self._add_jid(jid) + elif obj.jid in self.gateway_prompt: if obj.desc: self.gateway_prompt[obj.jid]['desc'] = obj.desc if obj.prompt: