diff --git a/src/core.py b/src/core.py index 67bc55ff1..fcec0c130 100644 --- a/src/core.py +++ b/src/core.py @@ -226,6 +226,9 @@ class Manager: # Apply preferences. Note that this is before any torrents are added self.apply_prefs() + # Event callbacks for use with plugins + self.event_callbacks = {} + PREF_FUNCTIONS["enable_dht"] = self.set_DHT # Unpickle the state, or create a new one @@ -248,8 +251,6 @@ class Manager: else: self.state = persistent_state() - - def quit(self): # Analyze data needed for pickling, etc. self.pre_quitting() @@ -500,6 +501,11 @@ class Manager: # 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): # Handle them for the backend's purposes, but still send them up in case the client # wants to do something - show messages, for example @@ -528,7 +534,12 @@ class Manager: except KeyError: event = pop_event() 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']: # Queue seeding torrent to bottom if needed if(self.get_pref('enable_move_completed')): diff --git a/src/interface.py b/src/interface.py index f9b6ce2aa..336f3e3ab 100644 --- a/src/interface.py +++ b/src/interface.py @@ -848,7 +848,7 @@ class DelugeGTK: # Handle the events try: - events = self.manager.handle_events() + self.manager.handle_events() except core.SystemError, e: print "SystemError", e 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() #Update any active plugins - self.plugins.update_active_plugins(events) + self.plugins.update_active_plugins() # Put the generated message into the statusbar # This gives plugins a chance to write to the diff --git a/src/plugins.py b/src/plugins.py index 258786f79..1082ccd83 100644 --- a/src/plugins.py +++ b/src/plugins.py @@ -93,14 +93,11 @@ class PluginManager: def configure_plugin(self, name): self.enabled_plugins[name].configure() - def update_active_plugins(self, events): + def update_active_plugins(self): for name in self.enabled_plugins.keys(): plugin = self.enabled_plugins[name] if 'update' in dir(plugin): plugin.update() - - if 'handle_events' in dir(plugin): - plugin.handle_events(events) def shutdown_all_plugins(self): for name in self.enabled_plugins.keys():