From 5d3275de016a78a2bd974fa8b37bf79416cb1c2e Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 31 Oct 2007 08:16:35 +0000 Subject: [PATCH] Some plugin updates. --- deluge/core/pluginmanager.py | 3 +- deluge/plugins/queue/queue/__init__.py | 3 ++ deluge/plugins/queue/queue/core.py | 62 +++++++++----------------- deluge/plugins/queue/queue/gtkui.py | 13 +----- deluge/ui/client.py | 14 ++++++ deluge/ui/gtkui/pluginmanager.py | 3 ++ deluge/ui/gtkui/preferences.py | 4 +- deluge/ui/gtkui/torrentview.py | 6 +-- 8 files changed, 49 insertions(+), 59 deletions(-) diff --git a/deluge/core/pluginmanager.py b/deluge/core/pluginmanager.py index cf0827375..c5313c0ce 100644 --- a/deluge/core/pluginmanager.py +++ b/deluge/core/pluginmanager.py @@ -56,6 +56,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): 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.""" + log.debug("Registering status field %s with PluginManager", field) self.status_fields[field] = function def get_status(self, torrent_id, fields): @@ -66,7 +67,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): status[field] = self.status_fields[field](torrent_id) except KeyError: log.warning("Status field %s is not registered with the\ - PluginManager.") + PluginManager.", field) return status def register_hook(self, hook, function): diff --git a/deluge/plugins/queue/queue/__init__.py b/deluge/plugins/queue/queue/__init__.py index 8f6655e0e..852a80fda 100644 --- a/deluge/plugins/queue/queue/__init__.py +++ b/deluge/plugins/queue/queue/__init__.py @@ -40,6 +40,9 @@ class CorePlugin: def __init__(self, plugin_manager): # Load the Core portion of the plugin self.core = Core(plugin_manager) + + def disable(self): + pass class GtkUIPlugin: def __init__(self, plugin_manager): diff --git a/deluge/plugins/queue/queue/core.py b/deluge/plugins/queue/queue/core.py index a82660b17..b69ab34f0 100644 --- a/deluge/plugins/queue/queue/core.py +++ b/deluge/plugins/queue/queue/core.py @@ -31,62 +31,52 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. -import dbus -import dbus.service -from dbus.mainloop.glib import DBusGMainLoop -DBusGMainLoop(set_as_default=True) - from torrentqueue import TorrentQueue from deluge.log import LOG as log -class Core(dbus.service.Object): - def __init__(self, plugin, path="/org/deluge_torrent/Plugin/Queue"): +class Core: + def __init__(self, plugin): # Get the pluginmanager reference self.plugin = plugin - # Setup DBUS - bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", - bus=dbus.SessionBus()) - - dbus.service.Object.__init__(self, bus_name, path) - # Instantiate the TorrentQueue object self.queue = TorrentQueue() # Register core hooks - self.plugin.register_hook("post_torrent_add", self.post_torrent_add) + self.plugin.register_hook("post_torrent_add", self._post_torrent_add) self.plugin.register_hook("post_torrent_remove", - self.post_torrent_remove) + self._post_torrent_remove) # Register the 'queue' status field - self.plugin.register_status_field("queue", self.status_field_queue) + self.plugin.register_status_field("queue", self._status_field_queue) log.info("Queue Core plugin initialized..") + def disable(self): + pass + def shutdown(self): # Save the queue state self.queue.save_state() - + ## Hooks for core ## - def post_torrent_add(self, torrent_id): + def _post_torrent_add(self, torrent_id): if torrent_id is not None: self.queue.append(torrent_id) - def post_torrent_remove(self, torrent_id): + def _post_torrent_remove(self, torrent_id): if torrent_id is not None: self.queue.remove(torrent_id) ## Status field function ## - def status_field_queue(self, torrent_id): + def _status_field_queue(self, torrent_id): try: return self.queue[torrent_id]+1 except TypeError: return None ## Queueing functions ## - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_top(self, torrent_id): + def export_queue_top(self, torrent_id): log.debug("Attempting to queue %s to top", torrent_id) try: # If the queue method returns True, then we should emit a signal @@ -96,9 +86,7 @@ class Core(dbus.service.Object): log.warning("torrent_id: %s does not exist in the queue", torrent_id) - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_up(self, torrent_id): + def export_queue_up(self, torrent_id): log.debug("Attempting to queue %s to up", torrent_id) try: # If the queue method returns True, then we should emit a signal @@ -107,10 +95,8 @@ class Core(dbus.service.Object): except KeyError: log.warning("torrent_id: %s does not exist in the queue", torrent_id) - - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_down(self, torrent_id): + + def export_queue_down(self, torrent_id): log.debug("Attempting to queue %s to down", torrent_id) try: # If the queue method returns True, then we should emit a signal @@ -120,9 +106,7 @@ class Core(dbus.service.Object): log.warning("torrent_id: %s does not exist in the queue", torrent_id) - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="") - def queue_bottom(self, torrent_id): + def export_queue_bottom(self, torrent_id): log.debug("Attempting to queue %s to bottom", torrent_id) try: # If the queue method returns True, then we should emit a signal @@ -132,24 +116,18 @@ class Core(dbus.service.Object): log.warning("torrent_id: %s does not exist in the queue", torrent_id) - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="", out_signature="as") - def get_queue_list(self): + def export_get_queue_list(self): """Returns the queue list. """ log.debug("Getting queue list") return self.queue.queue - @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", - in_signature="s", out_signature="i") - def get_position(self, torrent_id): + def export_get_position(self, torrent_id): """Returns the queue position of torrent_id""" log.debug("Getting queue position for %s", torrent_id) return self.queue[torrent_id] ## Signals ## - @dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge.Queue", - signature="") - def torrent_queue_changed(self): + def _torrent_queue_changed(self): """Emitted when a torrent queue position is changed""" log.debug("torrent_queue_changed signal emitted") diff --git a/deluge/plugins/queue/queue/gtkui.py b/deluge/plugins/queue/queue/gtkui.py index 30e301d60..e9600df8a 100644 --- a/deluge/plugins/queue/queue/gtkui.py +++ b/deluge/plugins/queue/queue/gtkui.py @@ -31,10 +31,6 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. -import dbus -from dbus.mainloop.glib import DBusGMainLoop -DBusGMainLoop(set_as_default=True) - import pkg_resources import gtk.glade import gettext @@ -58,11 +54,6 @@ class GtkUI: "deluge", "i18n")) log.debug("Queue GtkUI plugin initalized..") self.plugin = plugin_manager - # Get a reference to the core portion of the plugin - bus = dbus.SessionBus() - proxy = bus.get_object("org.deluge_torrent.Deluge", - "/org/deluge_torrent/Plugin/Queue") - self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge.Queue") # Get the queue menu from the glade file menu_glade = gtk.glade.XML(pkg_resources.resource_filename("queue", @@ -81,8 +72,8 @@ class GtkUI: menu = menu_glade.get_widget("menu_queue") # Connect to the 'torrent_queue_changed' signal - self.core.connect_to_signal("torrent_queue_changed", - self.torrent_queue_changed_signal) + #self.core.connect_to_signal("torrent_queue_changed", + # self.torrent_queue_changed_signal) # Get the torrentview component from the plugin manager self.torrentview = self.plugin.get_torrentview() diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 08bf18277..703a3f0e1 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -298,6 +298,20 @@ def get_num_connections(): set_core_uri(None) num_connections = 0 return num_connections + +def enable_plugin(plugin): + try: + return get_core().enable_plugin(plugin) + except (AttributeError, socket.error): + set_core_uri(None) + return + +def disable_plugin(plugin): + try: + return get_core().disable_plugin(plugin) + except (AttributeError, socket.error): + set_core_uri(None) + return def open_url_in_browser(url): """Opens link in the desktop's default browser""" diff --git a/deluge/ui/gtkui/pluginmanager.py b/deluge/ui/gtkui/pluginmanager.py index 990beb598..3d9bbfd12 100644 --- a/deluge/ui/gtkui/pluginmanager.py +++ b/deluge/ui/gtkui/pluginmanager.py @@ -46,6 +46,9 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase): # Register a callback with the client client.connect_on_new_core(self.start) + deluge.pluginmanagerbase.PluginManagerBase.__init__( + self, "gtkui.conf", "deluge.plugin.gtkui") + def start(self): """Start the plugin manager""" # Update the enabled_plugins from the core diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index baeb3d151..4acb1a0d1 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -437,9 +437,9 @@ class Preferences(component.Component): value = self.plugin_liststore.get_value(row, 1) self.plugin_liststore.set_value(row, 1, not value) if not value: - functions.enable_plugin(name) + client.enable_plugin(name) else: - functions.disable_plugin(name) + client.disable_plugin(name) def on_plugin_selection_changed(self, treeselection): log.debug("on_plugin_selection_changed") diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 05f92de36..162cd824a 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -233,9 +233,9 @@ class TorrentView(listview.ListView, component.Component): model.set_value(row, column_index, status[self.columns[column].status_field[0]]) - except TypeError: - log.warning("Unable to update column %s with value: %s", - column, status[self.columns[column].status_field[0]]) + except (TypeError, KeyError): + log.warning("Unable to update column %s", + column) else: # We have more than 1 liststore column to update for index in column_index: