Tweaks to plugins events.

This commit is contained in:
Alex Dedul 2007-07-16 11:51:12 +00:00
commit 3115498790
3 changed files with 12 additions and 6 deletions

View file

@ -42,7 +42,7 @@ class TorrentNotification:
self.interface = interface self.interface = interface
self.window = self.interface.window self.window = self.interface.window
self.window.connect("focus_in_event", self.set_tray_flashing_off) self.window.connect("focus_in_event", self.set_tray_flashing_off)
self.core.connect_event(self.core.constants['EVENT_FINISHED'], self) self.core.connect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
# Create an options file and try to load existing Values # Create an options file and try to load existing Values
self.config_file = deluge.common.CONFIG_DIR + "/notification.conf" self.config_file = deluge.common.CONFIG_DIR + "/notification.conf"
@ -63,6 +63,7 @@ class TorrentNotification:
self.show_notification(event) self.show_notification(event)
def unload(self): def unload(self):
self.core.disconnect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
self.config.save(self.config_file) self.config.save(self.config_file)
def set_tray_flashing_off(self, focusdata1, focusdata2): def set_tray_flashing_off(self, focusdata1, focusdata2):

View file

@ -505,10 +505,15 @@ class Manager:
# Event handling # Event handling
def connect_event(self, event_type, plugin_instance): def connect_event(self, event_type, callback):
if event_type not in self.event_callbacks: if event_type not in self.event_callbacks:
self.event_callbacks[event_type] = [] self.event_callbacks[event_type] = []
self.event_callbacks[event_type].append(plugin_instance) self.event_callbacks[event_type].append(callback)
def disconnect_event(self, event_type, callback):
if event_type in self.event_callbacks and \
callback in self.event_callbacks[event_type]:
self.event_callbacks[event_type].remove(callback)
def handle_events(self): def handle_events(self):
# Handle them for the backend's purposes, but still send them up in case the client # Handle them for the backend's purposes, but still send them up in case the client
@ -544,8 +549,8 @@ class Manager:
# Call plugins events callbacks # Call plugins events callbacks
if event['event_type'] in self.event_callbacks: if event['event_type'] in self.event_callbacks:
for plugin_instance in self.event_callbacks[event['event_type']]: for callback in self.event_callbacks[event['event_type']]:
plugin_instance.handle_event(event) callback(event)
if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']: if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']:
if event['message'] == "move_failed": if event['message'] == "move_failed":

View file

@ -82,7 +82,7 @@ class PluginManager:
plugin = self.enabled_plugins[name] plugin = self.enabled_plugins[name]
if 'unload' in dir(plugin): if 'unload' in dir(plugin):
plugin.unload() plugin.unload()
self.enabled_plugins.pop(name) del self.enabled_plugins[name]
def configurable_plugin(self, name): def configurable_plugin(self, name):
if name in self.enabled_plugins: if name in self.enabled_plugins: