changeset 49bd9f5cf408 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=49bd9f5cf408
description: use GED for disco.py

diffstat:

 src/disco.py         |  45 ++++++++++++++++++++++++++++++++++++++++-----
 src/gui_interface.py |  30 ------------------------------
 2 files changed, 40 insertions(+), 35 deletions(-)

diffs (168 lines):

diff -r 5df538abe459 -r 49bd9f5cf408 src/disco.py
--- a/src/disco.py      Tue Jan 19 22:06:00 2010 +0100
+++ b/src/disco.py      Tue Jan 19 22:23:19 2010 +0100
@@ -62,6 +62,7 @@
 from common import xmpp
 from common.exceptions import GajimGeneralException
 from common import helpers
+from common import ged
 
 # Dictionary mapping category, type pairs to browser class, image pairs.
 # This is a function, so we can call it after the classes are declared.
@@ -254,6 +255,24 @@
                self._info = CacheDictionary(0, getrefresh = False)
                self._subscriptions = CacheDictionary(5, getrefresh=False)
                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):
                self._items.cleanup()
@@ -383,10 +402,15 @@
                        self._cbs[cbkey] = [cb]
                        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
+               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)
 
                # Store in cache
@@ -401,10 +425,15 @@
                        if cbkey in self._cbs:
                                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
+               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)
 
                # Store in cache
@@ -419,11 +448,14 @@
                        if cbkey in self._cbs:
                                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
                namespaces
                """
+               # We receive events from all accounts from GED
+               if account != self.account:
+                       return
                addr = get_agent_address(jid)
 
                # Call callbacks
@@ -435,11 +467,14 @@
                        if cbkey in self._cbs:
                                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
                namespaces
                """
+               # We receive events from all accounts from GED
+               if account != self.account:
+                       return
                addr = get_agent_address(jid)
 
                # Call callbacks
@@ -1003,7 +1038,7 @@
                self.window.progressbar.show()
                self._pulse_timeout = gobject.timeout_add(250, 
self._pulse_timeout_cb)
                self.cache.get_items(self.jid, self.node, self._agent_items,
-                       force = force, args = (force,))
+                       force=force, args=(force,))
 
        def _pulse_timeout_cb(self, *args):
                """
diff -r 5df538abe459 -r 49bd9f5cf408 src/gui_interface.py
--- a/src/gui_interface.py      Tue Jan 19 22:06:00 2010 +0100
+++ b/src/gui_interface.py      Tue Jan 19 22:23:19 2010 +0100
@@ -661,20 +661,6 @@
                        notify.popup(event_type, jid, account, 'unsubscribed', 
path,
                                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):
                # remove transport's contacts from treeview
                jid_list = gajim.contacts.get_jid_list(account)
@@ -708,19 +694,6 @@
                array[0] == our_jid:
                        
gajim.interface.instances[account]['pep_services'].items_received(
                                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):
                #('NEW_ACC_CONNECTED', account, (infos, is_form, ssl_msg, 
ssl_err,
@@ -2033,12 +2006,9 @@
                        'SUBSCRIBED': [self.handle_event_subscribed],
                        'UNSUBSCRIBED': [self.handle_event_unsubscribed],
                        '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],
                        'REGISTER_AGENT_INFO': 
[self.handle_event_register_agent_info],
                        'AGENT_INFO_ITEMS': 
[self.handle_event_agent_info_items],
-                       'AGENT_INFO_INFO': [self.handle_event_agent_info_info],
                        'QUIT': [self.handle_event_quit],
                        'NEW_ACC_CONNECTED': 
[self.handle_event_new_acc_connected],
                        'NEW_ACC_NOT_CONNECTED': 
[self.handle_event_new_acc_not_connected],
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to