use GED for disco.py

This commit is contained in:
Yann Leboulanger 2010-01-19 22:23:19 +01:00
parent b99c10f696
commit d1d4a4e7c8
2 changed files with 40 additions and 35 deletions

View File

@ -62,6 +62,7 @@ from common import gajim
from common import xmpp from common import xmpp
from common.exceptions import GajimGeneralException from common.exceptions import GajimGeneralException
from common import helpers from common import helpers
from common import ged
# Dictionary mapping category, type pairs to browser class, image pairs. # Dictionary mapping category, type pairs to browser class, image pairs.
# This is a function, so we can call it after the classes are declared. # This is a function, so we can call it after the classes are declared.
@ -254,6 +255,24 @@ class ServicesCache:
self._info = CacheDictionary(0, getrefresh = False) self._info = CacheDictionary(0, getrefresh = False)
self._subscriptions = CacheDictionary(5, getrefresh=False) self._subscriptions = CacheDictionary(5, getrefresh=False)
self._cbs = {} self._cbs = {}
gajim.ged.register_event_handler('AGENT_ERROR_INFO', ged.CORE,
self.agent_info_error)
gajim.ged.register_event_handler('AGENT_ERROR_ITEMS', ged.CORE,
self.agent_items_error)
gajim.ged.register_event_handler('AGENT_INFO_ITEMS', ged.CORE,
self.agent_items)
gajim.ged.register_event_handler('AGENT_INFO_INFO', ged.CORE,
self.agent_info)
def __del__(self):
gajim.ged.remove_event_handler('AGENT_ERROR_INFO', ged.CORE,
self.agent_info_error)
gajim.ged.remove_event_handler('AGENT_ERROR_ITEMS', ged.CORE,
self.agent_items_error)
gajim.ged.remove_event_handler('AGENT_INFO_ITEMS', ged.CORE,
self.agent_items)
gajim.ged.remove_event_handler('AGENT_INFO_INFO', ged.CORE,
self.agent_info)
def cleanup(self): def cleanup(self):
self._items.cleanup() self._items.cleanup()
@ -383,10 +402,15 @@ class ServicesCache:
self._cbs[cbkey] = [cb] self._cbs[cbkey] = [cb]
gajim.connections[self.account].discoverItems(jid, node) gajim.connections[self.account].discoverItems(jid, node)
def agent_info(self, jid, node, identities, features, data): def agent_info(self, account, array):
""" """
Callback for when we receive an agent's info Callback for when we receive an agent's info
array is (agent, node, identities, features, data)
""" """
# We receive events from all accounts from GED
if account != self.account:
return
jid, node, identities, features, data = array
addr = get_agent_address(jid, node) addr = get_agent_address(jid, node)
# Store in cache # Store in cache
@ -401,10 +425,15 @@ class ServicesCache:
if cbkey in self._cbs: if cbkey in self._cbs:
del self._cbs[cbkey] del self._cbs[cbkey]
def agent_items(self, jid, node, items): def agent_items(self, account, array):
""" """
Callback for when we receive an agent's items Callback for when we receive an agent's items
array is (agent, node, items)
""" """
# We receive events from all accounts from GED
if account != self.account:
return
jid, node, items = array
addr = get_agent_address(jid, node) addr = get_agent_address(jid, node)
# Store in cache # Store in cache
@ -419,11 +448,14 @@ class ServicesCache:
if cbkey in self._cbs: if cbkey in self._cbs:
del self._cbs[cbkey] del self._cbs[cbkey]
def agent_info_error(self, jid): def agent_info_error(self, account, jid):
""" """
Callback for when a query fails. Even after the browse and agents Callback for when a query fails. Even after the browse and agents
namespaces namespaces
""" """
# We receive events from all accounts from GED
if account != self.account:
return
addr = get_agent_address(jid) addr = get_agent_address(jid)
# Call callbacks # Call callbacks
@ -435,11 +467,14 @@ class ServicesCache:
if cbkey in self._cbs: if cbkey in self._cbs:
del self._cbs[cbkey] del self._cbs[cbkey]
def agent_items_error(self, jid): def agent_items_error(self, account, jid):
""" """
Callback for when a query fails. Even after the browse and agents Callback for when a query fails. Even after the browse and agents
namespaces namespaces
""" """
# We receive events from all accounts from GED
if account != self.account:
return
addr = get_agent_address(jid) addr = get_agent_address(jid)
# Call callbacks # Call callbacks

View File

@ -661,20 +661,6 @@ class Interface:
notify.popup(event_type, jid, account, 'unsubscribed', path, notify.popup(event_type, jid, account, 'unsubscribed', path,
event_type, jid) event_type, jid)
def handle_event_agent_info_error(self, account, agent):
#('AGENT_ERROR_INFO', account, (agent))
try:
gajim.connections[account].services_cache.agent_info_error(agent)
except AttributeError:
return
def handle_event_agent_items_error(self, account, agent):
#('AGENT_ERROR_INFO', account, (agent))
try:
gajim.connections[account].services_cache.agent_items_error(agent)
except AttributeError:
return
def handle_event_agent_removed(self, account, agent): def handle_event_agent_removed(self, account, agent):
# remove transport's contacts from treeview # remove transport's contacts from treeview
jid_list = gajim.contacts.get_jid_list(account) jid_list = gajim.contacts.get_jid_list(account)
@ -708,19 +694,6 @@ class Interface:
array[0] == our_jid: array[0] == our_jid:
gajim.interface.instances[account]['pep_services'].items_received( gajim.interface.instances[account]['pep_services'].items_received(
array[2]) array[2])
try:
gajim.connections[account].services_cache.agent_items(array[0],
array[1], array[2])
except AttributeError:
return
def handle_event_agent_info_info(self, account, array):
#('AGENT_INFO_INFO', account, (agent, node, identities, features, data))
try:
gajim.connections[account].services_cache.agent_info(array[0],
array[1], array[2], array[3], array[4])
except AttributeError:
return
def handle_event_new_acc_connected(self, account, array): def handle_event_new_acc_connected(self, account, array):
#('NEW_ACC_CONNECTED', account, (infos, is_form, ssl_msg, ssl_err, #('NEW_ACC_CONNECTED', account, (infos, is_form, ssl_msg, ssl_err,
@ -2033,12 +2006,9 @@ class Interface:
'SUBSCRIBED': [self.handle_event_subscribed], 'SUBSCRIBED': [self.handle_event_subscribed],
'UNSUBSCRIBED': [self.handle_event_unsubscribed], 'UNSUBSCRIBED': [self.handle_event_unsubscribed],
'SUBSCRIBE': [self.handle_event_subscribe], 'SUBSCRIBE': [self.handle_event_subscribe],
'AGENT_ERROR_INFO': [self.handle_event_agent_info_error],
'AGENT_ERROR_ITEMS': [self.handle_event_agent_items_error],
'AGENT_REMOVED': [self.handle_event_agent_removed], 'AGENT_REMOVED': [self.handle_event_agent_removed],
'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info], 'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items], 'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
'AGENT_INFO_INFO': [self.handle_event_agent_info_info],
'QUIT': [self.handle_event_quit], 'QUIT': [self.handle_event_quit],
'NEW_ACC_CONNECTED': [self.handle_event_new_acc_connected], 'NEW_ACC_CONNECTED': [self.handle_event_new_acc_connected],
'NEW_ACC_NOT_CONNECTED': [self.handle_event_new_acc_not_connected], 'NEW_ACC_NOT_CONNECTED': [self.handle_event_new_acc_not_connected],