Add 'on_apply_prefs' plugin hook.
This commit is contained in:
parent
06ffa8c628
commit
8ee529d229
|
@ -45,6 +45,24 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
|||
deluge.pluginmanagerbase.PluginManagerBase.__init__(
|
||||
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):
|
||||
"""Start the plugin manager"""
|
||||
# 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
|
||||
self.enable_plugins()
|
||||
|
||||
def apply_prefs(self):
|
||||
"""Attempts to call 'apply_prefs()' in each enabled plugin. This is
|
||||
called when a user clicks OK or Apply in the preferences window and is
|
||||
designed to give plugins the opportunity to save their prefs."""
|
||||
for key in self.plugins.keys():
|
||||
try:
|
||||
self.plugins[key].apply_prefs()
|
||||
except AttributeError:
|
||||
pass
|
||||
## Hook functions
|
||||
def run_on_apply_prefs(self):
|
||||
"""This hook is run after the user clicks Apply or OK in the preferences
|
||||
dialog.
|
||||
"""
|
||||
log.debug("run_on_apply_prefs")
|
||||
for function in self.hooks["on_apply_prefs"]:
|
||||
function()
|
||||
|
||||
## Plugin functions.. will likely move to own class..
|
||||
|
||||
|
|
|
@ -529,14 +529,14 @@ class Preferences(component.Component):
|
|||
def on_button_ok_clicked(self, data):
|
||||
log.debug("on_button_ok_clicked")
|
||||
self.set_config()
|
||||
component.get("PluginManager").apply_prefs()
|
||||
component.get("PluginManager").run_on_apply_prefs()
|
||||
self.hide()
|
||||
return True
|
||||
|
||||
def on_button_apply_clicked(self, data):
|
||||
log.debug("on_button_apply_clicked")
|
||||
self.set_config()
|
||||
component.get("PluginManager").apply_prefs()
|
||||
component.get("PluginManager").run_on_apply_prefs()
|
||||
|
||||
def on_button_cancel_clicked(self, data):
|
||||
log.debug("on_button_cancel_clicked")
|
||||
|
|
Loading…
Reference in New Issue