mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-26 19:32:21 +00:00
Some plugin updates.
This commit is contained in:
parent
ff1391b8bf
commit
5d3275de01
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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")
|
||||
|
@ -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()
|
||||
|
@ -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"""
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user