From 3665c99800ed42daacdad02a1d632cdd5f50291d Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Sun, 18 Oct 2009 20:53:15 +0200 Subject: [PATCH] Wrap global gajim.handlers with a dispatch method. --- src/common/connection.py | 7 +------ src/common/zeroconf/connection_zeroconf.py | 4 +--- src/gajim.py | 12 +++++++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 39a0cc5ca..36595d8d8 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -194,14 +194,9 @@ class Connection(ConnectionHandlers): self.secret_hmac = str(random.random())[2:] # END __init__ - def put_event(self, ev): - if ev[0] in gajim.handlers: - log.debug('Sending %s event to GUI: %s' % (ev[0], ev[1:])) - gajim.handlers[ev[0]](self.name, ev[1]) - def dispatch(self, event, data): '''always passes account name as first param''' - self.put_event((event, data)) + gajim.interface.dispatch(event, self.name, data) def _reconnect(self): diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index c23f4a125..c5a93b4b8 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -137,9 +137,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): # END __init__ def dispatch(self, event, data): - if event in gajim.handlers: - gajim.handlers[event](self.name, data) - + gajim.interface.dispatch(event, self.name, data) def _reconnect(self): # Do not try to reco while we are already trying diff --git a/src/gajim.py b/src/gajim.py index c461ea23f..87784d83d 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -2359,7 +2359,17 @@ class Interface: 'PUBSUB_NODE_REMOVED': self.handle_event_pubsub_node_removed, 'PUBSUB_NODE_NOT_REMOVED': self.handle_event_pubsub_node_not_removed, } - gajim.handlers = self.handlers + + def dispatch(self, event, account, data): + ''' + Dispatches an network event to the event handlers of this class + ''' + if event not in self.handlers: + log.warning('Unknown event %s dispatched to GUI: %s' % (event, data)) + else: + log.debug('Event %s distpached to GUI: %s' % (event, data)) + self.handlers[event](account, data) + ################################################################################ ### Methods dealing with gajim.events