Add 'on_apply_prefs' plugin hook.

This commit is contained in:
Andrew Resch 2008-02-26 17:10:44 +00:00
parent 06ffa8c628
commit 8ee529d229
2 changed files with 29 additions and 12 deletions

View File

@ -45,6 +45,24 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
deluge.pluginmanagerbase.PluginManagerBase.__init__( deluge.pluginmanagerbase.PluginManagerBase.__init__(
self, "gtkui.conf", "deluge.plugin.gtkui") self, "gtkui.conf", "deluge.plugin.gtkui")
self.hooks = {
"on_apply_prefs": []
}
def register_hook(self, hook, function):
"""Register a hook function with the plugin manager"""
try:
self.hooks[hook].append(function)
except KeyError:
log.warning("Plugin attempting to register invalid hook.")
def deregister_hook(self, hook, function):
"""Deregisters a hook function"""
try:
self.hooks[hook].remove(function)
except:
log.warning("Unable to deregister hook %s", hook)
def start(self): def start(self):
"""Start the plugin manager""" """Start the plugin manager"""
# Update the enabled_plugins from the core # Update the enabled_plugins from the core
@ -61,15 +79,14 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
# Enable the plugins that are enabled in the config and core # Enable the plugins that are enabled in the config and core
self.enable_plugins() self.enable_plugins()
def apply_prefs(self): ## Hook functions
"""Attempts to call 'apply_prefs()' in each enabled plugin. This is def run_on_apply_prefs(self):
called when a user clicks OK or Apply in the preferences window and is """This hook is run after the user clicks Apply or OK in the preferences
designed to give plugins the opportunity to save their prefs.""" dialog.
for key in self.plugins.keys(): """
try: log.debug("run_on_apply_prefs")
self.plugins[key].apply_prefs() for function in self.hooks["on_apply_prefs"]:
except AttributeError: function()
pass
## Plugin functions.. will likely move to own class.. ## Plugin functions.. will likely move to own class..

View File

@ -529,14 +529,14 @@ class Preferences(component.Component):
def on_button_ok_clicked(self, data): def on_button_ok_clicked(self, data):
log.debug("on_button_ok_clicked") log.debug("on_button_ok_clicked")
self.set_config() self.set_config()
component.get("PluginManager").apply_prefs() component.get("PluginManager").run_on_apply_prefs()
self.hide() self.hide()
return True return True
def on_button_apply_clicked(self, data): def on_button_apply_clicked(self, data):
log.debug("on_button_apply_clicked") log.debug("on_button_apply_clicked")
self.set_config() self.set_config()
component.get("PluginManager").apply_prefs() component.get("PluginManager").run_on_apply_prefs()
def on_button_cancel_clicked(self, data): def on_button_cancel_clicked(self, data):
log.debug("on_button_cancel_clicked") log.debug("on_button_cancel_clicked")