Added core events handlers to GED in src/gui_interface.py (previously kept in src/gajim.py).

This commit is contained in:
Mateusz Biliński 2009-11-14 23:41:28 +01:00
parent 70731dbab7
commit b38249c406
2 changed files with 28 additions and 27 deletions

View File

@ -137,7 +137,8 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
# END __init__ # END __init__
def dispatch(self, event, data): def dispatch(self, event, data):
gajim.interface.dispatch(event, self.name, data) #gajim.interface.dispatch(event, self.name, data)
gajim.ged.raise_event(event, self.name, data)
def _reconnect(self): def _reconnect(self):
# Do not try to reco while we are already trying # Do not try to reco while we are already trying

View File

@ -85,6 +85,7 @@ import roster_window
import profile_window import profile_window
import config import config
from threading import Thread from threading import Thread
from common import ged
gajimpaths = common.configpaths.gajimpaths gajimpaths = common.configpaths.gajimpaths
config_filename = gajimpaths['CONFIG_FILE'] config_filename = gajimpaths['CONFIG_FILE']
@ -1989,17 +1990,7 @@ class Interface:
_('PEP node %(node)s was not removed: %(message)s') % { _('PEP node %(node)s was not removed: %(message)s') % {
'node': data[1], 'message': data[2]}) 'node': data[1], 'message': data[2]})
def register_handler(self, event, handler): def create_core_handlers_list(self):
if event not in self.handlers:
self.handlers[event] = []
if handler not in self.handlers[event]:
self.handlers[event].append(handler)
def unregister_handler(self, event, handler):
self.handlers[event].remove(handler)
def register_handlers(self):
self.handlers = { self.handlers = {
'ROSTER': [self.handle_event_roster], 'ROSTER': [self.handle_event_roster],
'WARNING': [self.handle_event_warning], 'WARNING': [self.handle_event_warning],
@ -2090,21 +2081,17 @@ class Interface:
'JINGLE_ERROR': [self.handle_event_jingle_error], 'JINGLE_ERROR': [self.handle_event_jingle_error],
} }
def dispatch(self, event, account, data): def register_core_handlers(self):
''' '''
Dispatches an network event to the event handlers of this class. Register core handlers in Global Events Dispatcher (GED).
Return true if it could be dispatched to alteast one handler. This is part of rewriting whole events handling system to use GED.
''' '''
if event not in self.handlers: for event_name, event_handlers in self.handlers.iteritems():
log.warning('Unknown event %s dispatched to GUI: %s' % (event, data)) for event_handler in event_handlers:
return False gajim.ged.register_event_handler(event_name,
else: ged.CORE,
log.debug('Event %s distpached to GUI: %s' % (event, data)) event_handler)
for handler in self.handlers[event]:
handler(account, data)
return len(self.handlers[event])
################################################################################ ################################################################################
### Methods dealing with gajim.events ### Methods dealing with gajim.events
@ -3142,6 +3129,10 @@ class Interface:
pass pass
gobject.timeout_add_seconds(5, remote_init) gobject.timeout_add_seconds(5, remote_init)
# Creating plugin manager
import plugins
gajim.plugin_manager = plugins.PluginManager()
def __init__(self): def __init__(self):
gajim.interface = self gajim.interface = self
@ -3235,7 +3226,16 @@ class Interface:
self.handle_event_file_error) self.handle_event_file_error)
gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue) gajim.proxy65_manager = proxy65_manager.Proxy65Manager(gajim.idlequeue)
gajim.default_session_type = ChatControlSession gajim.default_session_type = ChatControlSession
self.register_handlers()
# Creating Global Events Dispatcher
from common import ged
gajim.ged = ged.GlobalEventsDispatcher()
# Creating Network Events Controller
from common import nec
gajim.nec = nec.NetworkEventsController()
self.create_core_handlers_list()
self.register_core_handlers()
if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'active') \ if gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'active') \
and gajim.HAVE_ZEROCONF: and gajim.HAVE_ZEROCONF:
gajim.connections[gajim.ZEROCONF_ACC_NAME] = \ gajim.connections[gajim.ZEROCONF_ACC_NAME] = \