mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +00:00
Pass events to plugins in a more resource aware way. Based on andar's
proposition.
This commit is contained in:
parent
a0ca8a031e
commit
27d5db228a
3 changed files with 17 additions and 9 deletions
17
src/core.py
17
src/core.py
|
@ -226,6 +226,9 @@ class Manager:
|
||||||
# Apply preferences. Note that this is before any torrents are added
|
# Apply preferences. Note that this is before any torrents are added
|
||||||
self.apply_prefs()
|
self.apply_prefs()
|
||||||
|
|
||||||
|
# Event callbacks for use with plugins
|
||||||
|
self.event_callbacks = {}
|
||||||
|
|
||||||
PREF_FUNCTIONS["enable_dht"] = self.set_DHT
|
PREF_FUNCTIONS["enable_dht"] = self.set_DHT
|
||||||
|
|
||||||
# Unpickle the state, or create a new one
|
# Unpickle the state, or create a new one
|
||||||
|
@ -248,8 +251,6 @@ class Manager:
|
||||||
else:
|
else:
|
||||||
self.state = persistent_state()
|
self.state = persistent_state()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
# Analyze data needed for pickling, etc.
|
# Analyze data needed for pickling, etc.
|
||||||
self.pre_quitting()
|
self.pre_quitting()
|
||||||
|
@ -500,6 +501,11 @@ class Manager:
|
||||||
|
|
||||||
# Event handling
|
# Event handling
|
||||||
|
|
||||||
|
def connect_event(self, event_type, plugin_instance):
|
||||||
|
if event_type not in self.event_callbacks:
|
||||||
|
self.event_callbacks[event_type] = []
|
||||||
|
self.event_callbacks[event_type].append(plugin_instance)
|
||||||
|
|
||||||
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
|
||||||
# wants to do something - show messages, for example
|
# wants to do something - show messages, for example
|
||||||
|
@ -528,7 +534,12 @@ class Manager:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
event = pop_event()
|
event = pop_event()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Call event callbacks
|
||||||
|
if event['event_type'] in self.event_callbacks:
|
||||||
|
for plugin_instance in self.event_callbacks[event['event_type']]:
|
||||||
|
plugin_instance.handle_event(event)
|
||||||
|
|
||||||
if event['event_type'] is self.constants['EVENT_FINISHED']:
|
if event['event_type'] is self.constants['EVENT_FINISHED']:
|
||||||
# Queue seeding torrent to bottom if needed
|
# Queue seeding torrent to bottom if needed
|
||||||
if(self.get_pref('enable_move_completed')):
|
if(self.get_pref('enable_move_completed')):
|
||||||
|
|
|
@ -848,7 +848,7 @@ class DelugeGTK:
|
||||||
|
|
||||||
# Handle the events
|
# Handle the events
|
||||||
try:
|
try:
|
||||||
events = self.manager.handle_events()
|
self.manager.handle_events()
|
||||||
except core.SystemError, e:
|
except core.SystemError, e:
|
||||||
print "SystemError", e
|
print "SystemError", e
|
||||||
dialogs.show_popup_warning(self.window, _("You cannot move torrent to a different partition. Please fix your preferences"))
|
dialogs.show_popup_warning(self.window, _("You cannot move torrent to a different partition. Please fix your preferences"))
|
||||||
|
@ -863,7 +863,7 @@ class DelugeGTK:
|
||||||
self.update_statusbar_and_tray()
|
self.update_statusbar_and_tray()
|
||||||
|
|
||||||
#Update any active plugins
|
#Update any active plugins
|
||||||
self.plugins.update_active_plugins(events)
|
self.plugins.update_active_plugins()
|
||||||
|
|
||||||
# Put the generated message into the statusbar
|
# Put the generated message into the statusbar
|
||||||
# This gives plugins a chance to write to the
|
# This gives plugins a chance to write to the
|
||||||
|
|
|
@ -93,14 +93,11 @@ class PluginManager:
|
||||||
def configure_plugin(self, name):
|
def configure_plugin(self, name):
|
||||||
self.enabled_plugins[name].configure()
|
self.enabled_plugins[name].configure()
|
||||||
|
|
||||||
def update_active_plugins(self, events):
|
def update_active_plugins(self):
|
||||||
for name in self.enabled_plugins.keys():
|
for name in self.enabled_plugins.keys():
|
||||||
plugin = self.enabled_plugins[name]
|
plugin = self.enabled_plugins[name]
|
||||||
if 'update' in dir(plugin):
|
if 'update' in dir(plugin):
|
||||||
plugin.update()
|
plugin.update()
|
||||||
|
|
||||||
if 'handle_events' in dir(plugin):
|
|
||||||
plugin.handle_events(events)
|
|
||||||
|
|
||||||
def shutdown_all_plugins(self):
|
def shutdown_all_plugins(self):
|
||||||
for name in self.enabled_plugins.keys():
|
for name in self.enabled_plugins.keys():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue