hack in order to register our Event handler as soon as Dispatcher is pluged in

This commit is contained in:
Yann Leboulanger 2005-11-06 10:12:22 +00:00
parent 004cb9c5d3
commit 6d3fe8e459
3 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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):