Some plugin updates.

This commit is contained in:
Andrew Resch 2007-10-31 08:16:35 +00:00
parent ff1391b8bf
commit 5d3275de01
8 changed files with 49 additions and 59 deletions

View File

@ -56,6 +56,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
def register_status_field(self, field, function): def register_status_field(self, field, function):
"""Register a new status field. This can be used in the same way the """Register a new status field. This can be used in the same way the
client requests other status information from core.""" client requests other status information from core."""
log.debug("Registering status field %s with PluginManager", field)
self.status_fields[field] = function self.status_fields[field] = function
def get_status(self, torrent_id, fields): def get_status(self, torrent_id, fields):
@ -66,7 +67,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
status[field] = self.status_fields[field](torrent_id) status[field] = self.status_fields[field](torrent_id)
except KeyError: except KeyError:
log.warning("Status field %s is not registered with the\ log.warning("Status field %s is not registered with the\
PluginManager.") PluginManager.", field)
return status return status
def register_hook(self, hook, function): def register_hook(self, hook, function):

View File

@ -40,6 +40,9 @@ class CorePlugin:
def __init__(self, plugin_manager): def __init__(self, plugin_manager):
# Load the Core portion of the plugin # Load the Core portion of the plugin
self.core = Core(plugin_manager) self.core = Core(plugin_manager)
def disable(self):
pass
class GtkUIPlugin: class GtkUIPlugin:
def __init__(self, plugin_manager): def __init__(self, plugin_manager):

View File

@ -31,62 +31,52 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # 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 torrentqueue import TorrentQueue
from deluge.log import LOG as log from deluge.log import LOG as log
class Core(dbus.service.Object): class Core:
def __init__(self, plugin, path="/org/deluge_torrent/Plugin/Queue"): def __init__(self, plugin):
# Get the pluginmanager reference # Get the pluginmanager reference
self.plugin = plugin 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 # Instantiate the TorrentQueue object
self.queue = TorrentQueue() self.queue = TorrentQueue()
# Register core hooks # 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.plugin.register_hook("post_torrent_remove",
self.post_torrent_remove) self._post_torrent_remove)
# Register the 'queue' status field # 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..") log.info("Queue Core plugin initialized..")
def disable(self):
pass
def shutdown(self): def shutdown(self):
# Save the queue state # Save the queue state
self.queue.save_state() self.queue.save_state()
## Hooks for core ## ## Hooks for core ##
def post_torrent_add(self, torrent_id): def _post_torrent_add(self, torrent_id):
if torrent_id is not None: if torrent_id is not None:
self.queue.append(torrent_id) 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: if torrent_id is not None:
self.queue.remove(torrent_id) self.queue.remove(torrent_id)
## Status field function ## ## Status field function ##
def status_field_queue(self, torrent_id): def _status_field_queue(self, torrent_id):
try: try:
return self.queue[torrent_id]+1 return self.queue[torrent_id]+1
except TypeError: except TypeError:
return None return None
## Queueing functions ## ## Queueing functions ##
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_queue_top(self, torrent_id):
in_signature="s", out_signature="")
def queue_top(self, torrent_id):
log.debug("Attempting to queue %s to top", torrent_id) log.debug("Attempting to queue %s to top", torrent_id)
try: try:
# If the queue method returns True, then we should emit a signal # 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", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_queue_up(self, torrent_id):
in_signature="s", out_signature="")
def queue_up(self, torrent_id):
log.debug("Attempting to queue %s to up", torrent_id) log.debug("Attempting to queue %s to up", torrent_id)
try: try:
# If the queue method returns True, then we should emit a signal # If the queue method returns True, then we should emit a signal
@ -107,10 +95,8 @@ class Core(dbus.service.Object):
except KeyError: except KeyError:
log.warning("torrent_id: %s does not exist in the queue", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_queue_down(self, torrent_id):
in_signature="s", out_signature="")
def queue_down(self, torrent_id):
log.debug("Attempting to queue %s to down", torrent_id) log.debug("Attempting to queue %s to down", torrent_id)
try: try:
# If the queue method returns True, then we should emit a signal # 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", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_queue_bottom(self, torrent_id):
in_signature="s", out_signature="")
def queue_bottom(self, torrent_id):
log.debug("Attempting to queue %s to bottom", torrent_id) log.debug("Attempting to queue %s to bottom", torrent_id)
try: try:
# If the queue method returns True, then we should emit a signal # 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", log.warning("torrent_id: %s does not exist in the queue",
torrent_id) torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_get_queue_list(self):
in_signature="", out_signature="as")
def get_queue_list(self):
"""Returns the queue list. """Returns the queue list.
""" """
log.debug("Getting queue list") log.debug("Getting queue list")
return self.queue.queue return self.queue.queue
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue", def export_get_position(self, torrent_id):
in_signature="s", out_signature="i")
def get_position(self, torrent_id):
"""Returns the queue position of torrent_id""" """Returns the queue position of torrent_id"""
log.debug("Getting queue position for %s", torrent_id) log.debug("Getting queue position for %s", torrent_id)
return self.queue[torrent_id] return self.queue[torrent_id]
## Signals ## ## Signals ##
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge.Queue", def _torrent_queue_changed(self):
signature="")
def torrent_queue_changed(self):
"""Emitted when a torrent queue position is changed""" """Emitted when a torrent queue position is changed"""
log.debug("torrent_queue_changed signal emitted") log.debug("torrent_queue_changed signal emitted")

View File

@ -31,10 +31,6 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # 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 pkg_resources
import gtk.glade import gtk.glade
import gettext import gettext
@ -58,11 +54,6 @@ class GtkUI:
"deluge", "i18n")) "deluge", "i18n"))
log.debug("Queue GtkUI plugin initalized..") log.debug("Queue GtkUI plugin initalized..")
self.plugin = plugin_manager 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 # Get the queue menu from the glade file
menu_glade = gtk.glade.XML(pkg_resources.resource_filename("queue", menu_glade = gtk.glade.XML(pkg_resources.resource_filename("queue",
@ -81,8 +72,8 @@ class GtkUI:
menu = menu_glade.get_widget("menu_queue") menu = menu_glade.get_widget("menu_queue")
# Connect to the 'torrent_queue_changed' signal # Connect to the 'torrent_queue_changed' signal
self.core.connect_to_signal("torrent_queue_changed", #self.core.connect_to_signal("torrent_queue_changed",
self.torrent_queue_changed_signal) # self.torrent_queue_changed_signal)
# Get the torrentview component from the plugin manager # Get the torrentview component from the plugin manager
self.torrentview = self.plugin.get_torrentview() self.torrentview = self.plugin.get_torrentview()

View File

@ -298,6 +298,20 @@ def get_num_connections():
set_core_uri(None) set_core_uri(None)
num_connections = 0 num_connections = 0
return num_connections 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): def open_url_in_browser(url):
"""Opens link in the desktop's default browser""" """Opens link in the desktop's default browser"""

View File

@ -46,6 +46,9 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase):
# Register a callback with the client # Register a callback with the client
client.connect_on_new_core(self.start) client.connect_on_new_core(self.start)
deluge.pluginmanagerbase.PluginManagerBase.__init__(
self, "gtkui.conf", "deluge.plugin.gtkui")
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

View File

@ -437,9 +437,9 @@ class Preferences(component.Component):
value = self.plugin_liststore.get_value(row, 1) value = self.plugin_liststore.get_value(row, 1)
self.plugin_liststore.set_value(row, 1, not value) self.plugin_liststore.set_value(row, 1, not value)
if not value: if not value:
functions.enable_plugin(name) client.enable_plugin(name)
else: else:
functions.disable_plugin(name) client.disable_plugin(name)
def on_plugin_selection_changed(self, treeselection): def on_plugin_selection_changed(self, treeselection):
log.debug("on_plugin_selection_changed") log.debug("on_plugin_selection_changed")

View File

@ -233,9 +233,9 @@ class TorrentView(listview.ListView, component.Component):
model.set_value(row, model.set_value(row,
column_index, column_index,
status[self.columns[column].status_field[0]]) status[self.columns[column].status_field[0]])
except TypeError: except (TypeError, KeyError):
log.warning("Unable to update column %s with value: %s", log.warning("Unable to update column %s",
column, status[self.columns[column].status_field[0]]) column)
else: else:
# We have more than 1 liststore column to update # We have more than 1 liststore column to update
for index in column_index: for index in column_index: