From 6d3fe8e4592e1bbe96bb95f132a16c404557f8f0 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 6 Nov 2005 10:12:22 +0000 Subject: [PATCH] hack in order to register our Event handler as soon as Dispatcher is pluged in --- src/common/connection.py | 5 +---- src/common/xmpp/client.py | 5 ++++- src/common/xmpp/dispatcher.py | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 5f516ca6e..ea081923e 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1487,7 +1487,7 @@ class Connection: else: proxy = None if gajim.verbose: - con = common.xmpp.Client(hostname) + con = common.xmpp.Client(hostname, caller = self) else: con = common.xmpp.Client(hostname, debug = []) common.xmpp.dispatcher.DefaultTimeout = try_connecting_for_foo_secs @@ -1617,7 +1617,6 @@ class Connection: con.RegisterHandler('iq', self._StanzaArrivedCB) con.RegisterHandler('presence', self._StanzaArrivedCB) con.RegisterHandler('message', self._StanzaArrivedCB) - con.RegisterEventHandler(self._event_dispatcher) name = gajim.config.get_per('accounts', self.name, 'name') hostname = gajim.config.get_per('accounts', self.name, 'hostname') @@ -1636,7 +1635,6 @@ class Connection: return None if hasattr(con, 'Resource'): self.server_resource = con.Resource - con.RegisterEventHandler(self._event_dispatcher) if auth: con.initRoster() self.last_io = time.time() @@ -1937,7 +1935,6 @@ class Connection: (_('Could not connect to "%s"') % config['hostname'])) return - con.RegisterEventHandler(self._event_dispatcher) self.new_account_info = config self.connection = con self.name = name diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py index 7fe3c9fec..fe1e7173d 100644 --- a/src/common/xmpp/client.py +++ b/src/common/xmpp/client.py @@ -87,7 +87,7 @@ class PlugIn: import transports,dispatcher,auth,roster class CommonClient: """ Base for Client and Component classes.""" - def __init__(self,server,port=5222,debug=['always', 'nodebuilder']): + def __init__(self,server,port=5222,debug=['always', 'nodebuilder'],caller=None): """ Caches server name and (optionally) port to connect to. "debug" parameter specifies the debug IDs that will go into debug output. You can either specifiy an "include" or "exclude" list. The latter is done via adding "always" pseudo-ID to the list. @@ -99,6 +99,9 @@ class CommonClient: self.disconnect_handlers=[] self.Server=server self.Port=port + # Who initiated this client + # Used to register the EventDispatcher + self._caller=caller if debug and type(debug)<>list: debug=['always', 'nodebuilder'] self._DEBUG=Debug.Debug(debug) self.DEBUG=self._DEBUG.Show diff --git a/src/common/xmpp/dispatcher.py b/src/common/xmpp/dispatcher.py index 693dab9d3..8f98ef4e6 100644 --- a/src/common/xmpp/dispatcher.py +++ b/src/common/xmpp/dispatcher.py @@ -69,6 +69,8 @@ class Dispatcher(PlugIn): self.RegisterProtocol('presence',Presence) self.RegisterProtocol('message',Message) self.RegisterDefaultHandler(self.returnStanzaHandler) + # Register Gajim's event handler as soon as dispatcher begins + self.RegisterEventHandler(self._owner._caller._event_dispatcher) # self.RegisterHandler('error',self.streamErrorHandler,xmlns=NS_STREAMS) def plugin(self, owner):