diff --git a/deluge/core/core.py b/deluge/core/core.py index 449d6c3f4..be86f36d7 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -179,7 +179,7 @@ class Core( self.torrents = TorrentManager(self.session, self.alerts) # Load plugins - self.plugins = PluginManager() + self.plugins = PluginManager(self) # Register alert handlers self.alerts.register_handler("torrent_paused_alert", diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index c9ee11b5f..c4b3e97da 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -40,7 +40,8 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): """PluginManager handles the loading of plugins and provides plugins with functions to access parts of the core.""" - def __init__(self): + def __init__(self, core): + self.core = core # Set up the hooks dictionary self.hooks = { "post_torrent_add": [], @@ -53,6 +54,10 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): deluge.pluginmanagerbase.PluginManagerBase.__init__( self, "core.conf", "deluge.plugin.core") + def get_core(self): + """Returns a reference to the core""" + return self.core + def register_status_field(self, field, function): """Register a new status field. This can be used in the same way the client requests other status information from core.""" diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index b5da2ff7c..8746203da 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -107,7 +107,7 @@ class PluginManagerBase: for name in egg.get_entry_map(self.entry_name): entry_point = egg.get_entry_info(self.entry_name, name) cls = entry_point.load() - instance = cls(self) + instance = cls(self, plugin_name.replace("-", "_")) instance.enable() plugin_name = plugin_name.replace("-", " ") self.plugins[plugin_name] = instance diff --git a/deluge/plugins/queue/queue/__init__.py b/deluge/plugins/queue/queue/__init__.py index 0d69a2054..37219e170 100644 --- a/deluge/plugins/queue/queue/__init__.py +++ b/deluge/plugins/queue/queue/__init__.py @@ -36,19 +36,19 @@ from deluge.log import LOG as log from deluge.plugins.init import PluginBase class CorePlugin(PluginBase): - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): # Load the Core portion of the plugin try: from core import Core - self.plugin = Core(plugin_api) + self.plugin = Core(plugin_api, plugin_name) except Exception, e: log.debug("Did not load a Core plugin: %s", e) class GtkUIPlugin(PluginBase): - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): # Load the GtkUI portion of the plugin try: from gtkui import GtkUI - self.plugin = GtkUI(plugin_api) + self.plugin = GtkUI(plugin_api, plugin_name) except Exception, e: log.debug("Did not load a GtkUI plugin: %s", e) diff --git a/deluge/plugins/queue/queue/core.py b/deluge/plugins/queue/queue/core.py index ca4d67b65..12f354b02 100644 --- a/deluge/plugins/queue/queue/core.py +++ b/deluge/plugins/queue/queue/core.py @@ -33,13 +33,9 @@ from torrentqueue import TorrentQueue from deluge.log import LOG as log +from deluge.plugins.corepluginbase import CorePluginBase -class Core: - def __init__(self, plugin_api): - # Get the plugin_api - self.plugin = plugin_api - log.info("Queue Core plugin initialized..") - +class Core(CorePluginBase): def enable(self): # Instantiate the TorrentQueue object self.queue = TorrentQueue() @@ -90,7 +86,7 @@ class Core: try: # If the queue method returns True, then we should emit a signal if self.queue.top(torrent_id): - self.torrent_queue_changed() + self._torrent_queue_changed() except KeyError: log.warning("torrent_id: %s does not exist in the queue", torrent_id) @@ -100,7 +96,7 @@ class Core: try: # If the queue method returns True, then we should emit a signal if self.queue.up(torrent_id): - self.torrent_queue_changed() + self._torrent_queue_changed() except KeyError: log.warning("torrent_id: %s does not exist in the queue", torrent_id) @@ -110,7 +106,7 @@ class Core: try: # If the queue method returns True, then we should emit a signal if self.queue.down(torrent_id): - self.torrent_queue_changed() + self._torrent_queue_changed() except KeyError: log.warning("torrent_id: %s does not exist in the queue", torrent_id) @@ -120,7 +116,7 @@ class Core: try: # If the queue method returns True, then we should emit a signal if self.queue.bottom(torrent_id): - self.torrent_queue_changed() + self._torrent_queue_changed() except KeyError: log.warning("torrent_id: %s does not exist in the queue", torrent_id) diff --git a/deluge/plugins/queue/queue/gtkui.py b/deluge/plugins/queue/queue/gtkui.py index 8722b60c5..ee0ef626e 100644 --- a/deluge/plugins/queue/queue/gtkui.py +++ b/deluge/plugins/queue/queue/gtkui.py @@ -37,10 +37,10 @@ from deluge.log import LOG as log import ui class GtkUI(ui.UI): - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): log.debug("Calling UI init") # Call UI constructor - ui.UI.__init__(self, plugin_api) + ui.UI.__init__(self, plugin_api, plugin_name) log.debug("Queue GtkUI plugin initalized..") def load_interface(self): @@ -73,7 +73,7 @@ class GtkUI(ui.UI): position=0, status_field=["queue"]) # Update the new column right away - self.update_interface() + self.update() # Add a toolbar buttons self.toolbar_sep = self.plugin.add_toolbar_separator() @@ -105,5 +105,5 @@ class GtkUI(ui.UI): self.plugin.remove_toolbar_button(self.toolbutton_down) self.plugin.remove_torrentview_column("#") - def update_interface(self): + def update(self): self.plugin.update_torrent_view(["#"]) diff --git a/deluge/plugins/queue/queue/ui.py b/deluge/plugins/queue/queue/ui.py index 7a188c371..d50b8d7ca 100644 --- a/deluge/plugins/queue/queue/ui.py +++ b/deluge/plugins/queue/queue/ui.py @@ -34,10 +34,11 @@ import gettext import locale import pkg_resources +import deluge.ui.client as client from deluge.log import LOG as log class UI: - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): self.plugin = plugin_api # Initialize gettext locale.setlocale(locale.LC_MESSAGES, '') @@ -67,7 +68,7 @@ class UI: def unload_interface(self): pass - def update_interface(self): + def update(self): pass ## Menu callbacks ## @@ -76,7 +77,10 @@ class UI: # Get the selected torrents torrent_ids = self.plugin.get_selected_torrents() for torrent_id in torrent_ids: - self.core.queue_top(torrent_id) + try: + client.get_core().queue_queue_top(torrent_id) + except Exception, e: + log.debug("Unable to queue top torrent: %s", e) return def on_queueup_activate(self, data=None): @@ -84,7 +88,10 @@ class UI: # Get the selected torrents torrent_ids = self.plugin.get_selected_torrents() for torrent_id in torrent_ids: - self.core.queue_up(torrent_id) + try: + client.get_core().queue_queue_up(torrent_id) + except Exception, e: + log.debug("Unable to queue up torrent: %s", e) return def on_queuedown_activate(self, data=None): @@ -92,7 +99,10 @@ class UI: # Get the selected torrents torrent_ids = self.plugin.get_selected_torrents() for torrent_id in torrent_ids: - self.core.queue_down(torrent_id) + try: + client.get_core().queue_queue_down(torrent_id) + except Exception, e: + log.debug("Unable to queue down torrent: %s", e) return def on_queuebottom_activate(self, data=None): @@ -100,7 +110,10 @@ class UI: # Get the selected torrents torrent_ids = self.plugin.get_selected_torrents() for torrent_id in torrent_ids: - self.core.queue_bottom(torrent_id) + try: + client.get_core().queue_queue_bottom(torrent_id) + except Exception, e: + log.debug("Unable to queue bottom torrent: %s", e) return ## Signals ## @@ -110,7 +123,6 @@ class UI: """ log.debug("torrent_queue_changed signal received..") # We only need to update the queue column -# self.torrentview.update(["#"]) - self.update_interface() + self.update() return diff --git a/deluge/plugins/testp/testp/__init__.py b/deluge/plugins/testp/testp/__init__.py index 6a417f2b3..0aeca2568 100644 --- a/deluge/plugins/testp/testp/__init__.py +++ b/deluge/plugins/testp/testp/__init__.py @@ -36,16 +36,16 @@ from deluge.log import LOG as log from deluge.plugins.init import PluginBase class CorePlugin(PluginBase): - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): # Load the Core portion of the plugin try: from core import Core - self.plugin = Core(plugin_api) + self.plugin = Core(plugin_api, plugin_name) except: pass class GtkUIPlugin(PluginBase): - def __init__(self, plugin_api): + def __init__(self, plugin_api, plugin_name): # Load the GtkUI portion of the plugin try: from gtkui import GtkUI