disco cleanup:

we don't use old jabber:iq:browse and jabber:iq:agents
we ask info only when we select the row
This commit is contained in:
Yann Leboulanger 2005-09-06 11:54:23 +00:00
parent 0db258bccf
commit ac5e1897b5
2 changed files with 31 additions and 48 deletions

View File

@ -37,6 +37,7 @@ from common import gajim
from common import GnuPG from common import GnuPG
import socks5 import socks5
USE_GPG = GnuPG.USE_GPG USE_GPG = GnuPG.USE_GPG
print USE_GPG
from common import i18n from common import i18n
_ = i18n._ _ = i18n._
@ -980,28 +981,6 @@ class Connection:
self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups)) self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups))
raise common.xmpp.NodeProcessed raise common.xmpp.NodeProcessed
def _BrowseResultCB(self, con, iq_obj):
gajim.log.debug('BrowseResultCB')
identities, features, items = [], [], []
for q in iq_obj.getChildren():
if q.getNamespace() != common.xmpp.NS_BROWSE:
continue
attr = {}
for key in q.getAttrs().keys():
attr[key] = q.getAttr(key)
identities = [attr]
for node in q.getChildren():
if node.getName() == 'ns':
features.append(node.getData())
else:
infos = {}
for key in node.getAttrs().keys():
infos[key] = node.getAttr(key)
infos['category'] = node.getName()
items.append(infos)
jid = unicode(iq_obj.getFrom())
self.dispatch('AGENT_INFO', (jid, identities, features, items))
def _DiscoverItemsCB(self, con, iq_obj): def _DiscoverItemsCB(self, con, iq_obj):
gajim.log.debug('DiscoverItemsCB') gajim.log.debug('DiscoverItemsCB')
q = iq_obj.getTag('query') q = iq_obj.getTag('query')
@ -1020,12 +999,6 @@ class Connection:
jid = unicode(iq_obj.getFrom()) jid = unicode(iq_obj.getFrom())
self.dispatch('AGENT_INFO_ITEMS', (jid, node, items)) self.dispatch('AGENT_INFO_ITEMS', (jid, node, items))
def _DiscoverInfoErrorCB(self, con, iq_obj):
gajim.log.debug('DiscoverInfoErrorCB')
iq = common.xmpp.Iq(to = iq_obj.getFrom(), typ = 'get', queryNS =\
common.xmpp.NS_AGENTS)
self.to_be_sent.append(iq)
def _DiscoverInfoCB(self, con, iq_obj): def _DiscoverInfoCB(self, con, iq_obj):
gajim.log.debug('DiscoverInfoCB') gajim.log.debug('DiscoverInfoCB')
# According to JEP-0030: # According to JEP-0030:
@ -1048,12 +1021,8 @@ class Connection:
elif i.getName() == 'feature': elif i.getName() == 'feature':
features.append(i.getAttr('var')) features.append(i.getAttr('var'))
jid = unicode(iq_obj.getFrom()) jid = unicode(iq_obj.getFrom())
if not identities: if identities: #if not: an error occured
self.to_be_sent.append(common.xmpp.Iq(typ = 'get', queryNS = \
common.xmpp.NS_AGENTS))
else:
self.dispatch('AGENT_INFO_INFO', (jid, node, identities, features)) self.dispatch('AGENT_INFO_INFO', (jid, node, identities, features))
self.discoverItems(jid, node)
def _VersionCB(self, con, iq_obj): def _VersionCB(self, con, iq_obj):
gajim.log.debug('VersionCB') gajim.log.debug('VersionCB')
@ -1231,7 +1200,7 @@ class Connection:
def _StanzaArrivedCB(self, con, obj): def _StanzaArrivedCB(self, con, obj):
self.last_io = time.time() self.last_io = time.time()
def _event_dispatcher(self, realm, event, data): def _event_dispatcher(self, realm, event, data):
if realm == common.xmpp.NS_REGISTER: if realm == common.xmpp.NS_REGISTER:
if event == common.xmpp.features.REGISTER_DATA_RECEIVED: if event == common.xmpp.features.REGISTER_DATA_RECEIVED:
# data is (agent, DataFrom) # data is (agent, DataFrom)
@ -1340,14 +1309,10 @@ class Connection:
common.xmpp.NS_BYTESTREAM) common.xmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamErrorCB, 'error', con.RegisterHandler('iq', self._bytestreamErrorCB, 'error',
common.xmpp.NS_BYTESTREAM) common.xmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._BrowseResultCB, 'result',
common.xmpp.NS_BROWSE)
con.RegisterHandler('iq', self._DiscoverItemsCB, 'result', con.RegisterHandler('iq', self._DiscoverItemsCB, 'result',
common.xmpp.NS_DISCO_ITEMS) common.xmpp.NS_DISCO_ITEMS)
con.RegisterHandler('iq', self._DiscoverInfoCB, 'result', con.RegisterHandler('iq', self._DiscoverInfoCB, 'result',
common.xmpp.NS_DISCO_INFO) common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._DiscoverInfoErrorCB, 'error',
common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._VersionCB, 'get', con.RegisterHandler('iq', self._VersionCB, 'get',
common.xmpp.NS_VERSION) common.xmpp.NS_VERSION)
con.RegisterHandler('iq', self._VersionResultCB, 'result', con.RegisterHandler('iq', self._VersionResultCB, 'result',
@ -1665,8 +1630,7 @@ class Connection:
def request_agents(self, jid, node): def request_agents(self, jid, node):
if self.connection: if self.connection:
self.to_be_sent.append(common.xmpp.Iq(to = jid, typ = 'get', self.to_be_sent.append(common.xmpp.Iq(to = jid, typ = 'get',
queryNS = common.xmpp.NS_BROWSE)) queryNS = common.xmpp.NS_DISCO_ITEMS))
self.discoverInfo(jid, node)
def request_register_agent_info(self, agent): def request_register_agent_info(self, agent):
if not self.connection: if not self.connection:

View File

@ -1403,7 +1403,7 @@ _('To change the account name, you must be disconnected.')).get_response()
gajim.connections[name].password = config['password'] gajim.connections[name].password = config['password']
#update variables #update variables
self.plugin.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, \ self.plugin.windows[name] = {'infos': {}, 'chats': {}, 'gc': {}, \
'gc_config': {}} 'gc_config': {}}
self.plugin.windows[name]['xml_console'] = \ self.plugin.windows[name]['xml_console'] = \
dialogs.XMLConsoleWindow(self.plugin, name) dialogs.XMLConsoleWindow(self.plugin, name)
gajim.awaiting_messages[name] = {} gajim.awaiting_messages[name] = {}
@ -2090,6 +2090,7 @@ class ServiceDiscoveryWindow:
self.plugin = plugin self.plugin = plugin
self.account = account self.account = account
self.agent_infos = {} self.agent_infos = {}
self.items_asked = [] #we already asked items to these jids
if gajim.connections[account].connected < 2: if gajim.connections[account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'), dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not browse available services')).get_response() _('Without a connection, you can not browse available services')).get_response()
@ -2157,6 +2158,7 @@ _('Without a connection, you can not browse available services')).get_response()
iter = model.append(None, (jid, jid, node)) iter = model.append(None, (jid, jid, node))
self.agent_infos[jid] = {'features' : []} self.agent_infos[jid] = {'features' : []}
gajim.connections[self.account].request_agents(jid, node) gajim.connections[self.account].request_agents(jid, node)
self.items_asked.append(jid+node)
def agents(self, agents): def agents(self, agents):
'''When list of available agent arrive: '''When list of available agent arrive:
@ -2182,13 +2184,14 @@ _('Without a connection, you can not browse available services')).get_response()
def on_services_treeview_row_expanded(self, widget, iter, path): def on_services_treeview_row_expanded(self, widget, iter, path):
model = self.services_treeview.get_model() model = self.services_treeview.get_model()
jid = model[iter][1].decode('utf-8') if model.iter_n_children(iter) > 15:
return
child = model.iter_children(iter) child = model.iter_children(iter)
while child: while child:
child_jid = model.get_value(child, 1).decode('utf-8') child_jid = model.get_value(child, 1).decode('utf-8')
child_node = model.get_value(child, 2).decode('utf-8') child_node = model.get_value(child, 2).decode('utf-8')
# We never requested its infos # We never requested its infos
if not self.agent_infos[child_jid + child_node].has_key('features'): if child_jid + child_node not in self.items_asked:
self.browse(child_jid, child_node) self.browse(child_jid, child_node)
child = model.iter_next(child) child = model.iter_next(child)
@ -2215,7 +2218,7 @@ _('Without a connection, you can not browse available services')).get_response()
self.agent_infos[agent + node]['identities'] = identities self.agent_infos[agent + node]['identities'] = identities
if identities[0].has_key('name'): if identities[0].has_key('name'):
model.set_value(iter, 0, identities[0]['name']) model.set_value(iter, 0, identities[0]['name'])
self.on_services_treeview_cursor_changed(self.services_treeview) self.update_buttons()
def agent_info_items(self, agent, node, items, do_browse = True): def agent_info_items(self, agent, node, items, do_browse = True):
'''When we recieve items about an agent''' '''When we recieve items about an agent'''
@ -2316,10 +2319,8 @@ _('Without a connection, you can not browse available services')).get_response()
gajim.connections[self.account].request_register_agent_info(service) gajim.connections[self.account].request_register_agent_info(service)
self.window.destroy() self.window.destroy()
def on_services_treeview_cursor_changed(self, widget): def update_buttons(self):
'''When we select a row :
activate buttons if needed'''
self.join_button.set_sensitive(False) self.join_button.set_sensitive(False)
self.register_button.set_sensitive(False) self.register_button.set_sensitive(False)
model, iter = self.services_treeview.get_selection().get_selected() model, iter = self.services_treeview.get_selection().get_selected()
@ -2348,6 +2349,24 @@ _('Without a connection, you can not browse available services')).get_response()
if self.agent_infos[jid + node]['identities'][0]['category'] == \ if self.agent_infos[jid + node]['identities'][0]['category'] == \
'conference': 'conference':
self.join_button.set_sensitive(True) self.join_button.set_sensitive(True)
def on_services_treeview_cursor_changed(self, widget):
'''When we select a row :
activate buttons if needed'''
print 'changed'
self.update_buttons()
model, iter = self.services_treeview.get_selection().get_selected()
if not iter:
return
path = model.get_path(iter)
if len(path) == 1: # we selected the jabber server
return
jid = model[iter][1].decode('utf-8')
node = model[iter][2].decode('utf-8')
if jid+node not in self.items_asked:
self.browse(jid, node)
if not self.agent_infos[jid + node].has_key('features'):
gajim.connections[self.account].discoverInfo(jid, node)
def on_go_button_clicked(self, widget): def on_go_button_clicked(self, widget):
server_address = self.address_comboboxentry.child.get_text().decode('utf-8') server_address = self.address_comboboxentry.child.get_text().decode('utf-8')