import ged from plugin-system branch

This commit is contained in:
Yann Leboulanger 2010-01-19 21:32:45 +01:00
parent daf73408d7
commit 32050296a8
3 changed files with 33 additions and 36 deletions

View File

@ -169,7 +169,7 @@ class CommonConnection:
""" """
Always passes account name as first param Always passes account name as first param
""" """
gajim.interface.dispatch(event, self.name, data) gajim.ged.raise_event(event, self.name, data)
def _reconnect(self): def _reconnect(self):
""" """

View File

@ -67,6 +67,8 @@ version = config.get('version')
connections = {} # 'account name': 'account (connection.Connection) instance' connections = {} # 'account name': 'account (connection.Connection) instance'
ipython_window = None ipython_window = None
ged = None # Global Events Dispatcher
log = logging.getLogger('gajim') log = logging.getLogger('gajim')
import logger import logger

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']
@ -2016,17 +2017,7 @@ class Interface:
if pm_ctrl and hasattr(pm_ctrl, "update_contact"): if pm_ctrl and hasattr(pm_ctrl, "update_contact"):
pm_ctrl.update_contact() pm_ctrl.update_contact()
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],
@ -2119,20 +2110,16 @@ class Interface:
'CAPS_RECEIVED': [self.handle_event_caps_received] 'CAPS_RECEIVED': [self.handle_event_caps_received]
} }
def dispatch(self, event, account, data): def register_core_handlers(self):
""" """
Dispatch an network event to the event handlers of this class. Return Register core handlers in Global Events Dispatcher (GED).
true if it could be dispatched to alteast one handler
"""
if event not in self.handlers:
log.warning('Unknown event %s dispatched to GUI: %s' % (event, data))
return False
else:
log.debug('Event %s distpached to GUI: %s' % (event, data))
for handler in self.handlers[event]:
handler(account, data)
return len(self.handlers[event])
This is part of rewriting whole events handling system to use GED.
"""
for event_name, event_handlers in self.handlers.iteritems():
for event_handler in event_handlers:
gajim.ged.register_event_handler(event_name, ged.CORE,
event_handler)
################################################################################ ################################################################################
### Methods dealing with gajim.events ### Methods dealing with gajim.events
@ -2800,13 +2787,15 @@ class Interface:
listener.disconnect(self.music_track_changed_signal) listener.disconnect(self.music_track_changed_signal)
self.music_track_changed_signal = None self.music_track_changed_signal = None
def music_track_changed(self, unused_listener, music_track_info, account=None): def music_track_changed(self, unused_listener, music_track_info,
account=None):
if not account: if not account:
accounts = gajim.connections.keys() accounts = gajim.connections.keys()
else: else:
accounts = [account] accounts = [account]
is_paused = hasattr(music_track_info, 'paused') and music_track_info.paused == 0 is_paused = hasattr(music_track_info, 'paused') and \
music_track_info.paused == 0
if not music_track_info or is_paused: if not music_track_info or is_paused:
artist = title = source = '' artist = title = source = ''
else: else:
@ -3276,7 +3265,13 @@ 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()
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] = \