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
import socks5
USE_GPG = GnuPG.USE_GPG
print USE_GPG
from common import i18n
_ = i18n._
@ -980,28 +981,6 @@ class Connection:
self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups))
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):
gajim.log.debug('DiscoverItemsCB')
q = iq_obj.getTag('query')
@ -1020,12 +999,6 @@ class Connection:
jid = unicode(iq_obj.getFrom())
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):
gajim.log.debug('DiscoverInfoCB')
# According to JEP-0030:
@ -1048,12 +1021,8 @@ class Connection:
elif i.getName() == 'feature':
features.append(i.getAttr('var'))
jid = unicode(iq_obj.getFrom())
if not identities:
self.to_be_sent.append(common.xmpp.Iq(typ = 'get', queryNS = \
common.xmpp.NS_AGENTS))
else:
if identities: #if not: an error occured
self.dispatch('AGENT_INFO_INFO', (jid, node, identities, features))
self.discoverItems(jid, node)
def _VersionCB(self, con, iq_obj):
gajim.log.debug('VersionCB')
@ -1340,14 +1309,10 @@ class Connection:
common.xmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._bytestreamErrorCB, 'error',
common.xmpp.NS_BYTESTREAM)
con.RegisterHandler('iq', self._BrowseResultCB, 'result',
common.xmpp.NS_BROWSE)
con.RegisterHandler('iq', self._DiscoverItemsCB, 'result',
common.xmpp.NS_DISCO_ITEMS)
con.RegisterHandler('iq', self._DiscoverInfoCB, 'result',
common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._DiscoverInfoErrorCB, 'error',
common.xmpp.NS_DISCO_INFO)
con.RegisterHandler('iq', self._VersionCB, 'get',
common.xmpp.NS_VERSION)
con.RegisterHandler('iq', self._VersionResultCB, 'result',
@ -1665,8 +1630,7 @@ class Connection:
def request_agents(self, jid, node):
if self.connection:
self.to_be_sent.append(common.xmpp.Iq(to = jid, typ = 'get',
queryNS = common.xmpp.NS_BROWSE))
self.discoverInfo(jid, node)
queryNS = common.xmpp.NS_DISCO_ITEMS))
def request_register_agent_info(self, agent):
if not self.connection:

View File

@ -2090,6 +2090,7 @@ class ServiceDiscoveryWindow:
self.plugin = plugin
self.account = account
self.agent_infos = {}
self.items_asked = [] #we already asked items to these jids
if gajim.connections[account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'),
_('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))
self.agent_infos[jid] = {'features' : []}
gajim.connections[self.account].request_agents(jid, node)
self.items_asked.append(jid+node)
def agents(self, agents):
'''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):
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)
while child:
child_jid = model.get_value(child, 1).decode('utf-8')
child_node = model.get_value(child, 2).decode('utf-8')
# 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)
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
if identities[0].has_key('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):
'''When we recieve items about an agent'''
@ -2317,9 +2320,7 @@ _('Without a connection, you can not browse available services')).get_response()
self.window.destroy()
def on_services_treeview_cursor_changed(self, widget):
'''When we select a row :
activate buttons if needed'''
def update_buttons(self):
self.join_button.set_sensitive(False)
self.register_button.set_sensitive(False)
model, iter = self.services_treeview.get_selection().get_selected()
@ -2349,6 +2350,24 @@ _('Without a connection, you can not browse available services')).get_response()
'conference':
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):
server_address = self.address_comboboxentry.child.get_text().decode('utf-8')
if server_address in self.latest_addresses: