Plugins can now register 'status_fields' with core for use with

get_status().
Updates to TorrentQueue plugin.
This commit is contained in:
Andrew Resch 2007-08-22 08:24:40 +00:00
parent 5611037db2
commit f185f19cfb
5 changed files with 37 additions and 7 deletions

View File

@ -155,8 +155,12 @@ class Core(dbus.service.Object):
nkeys = []
for key in keys:
nkeys.append(str(key))
# Pickle the status dictionary from the torrent and return it
# Pickle the status dictionary from the torrent
status = self.torrents[torrent_id].get_status(nkeys)
# Get the leftover fields and ask the plugin manager to fill them
leftover_fields = list(set(nkeys) - set(status.keys()))
if len(leftover_fields) > 0:
status.update(self.plugins.get_status(torrent_id, leftover_fields))
status = pickle.dumps(status)
return status

View File

@ -47,6 +47,8 @@ class PluginManager:
"post_torrent_remove": []
}
self.status_fields = {}
# This will load any .eggs in the plugins folder inside the main
# deluge egg.. Need to scan the local plugin folder too.
@ -70,6 +72,21 @@ class PluginManager:
def __getitem__(self, key):
return self.plugins[key]
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."""
self.status_fields[field] = function
def get_status(self, torrent_id, fields):
status = {}
for field in fields:
try:
status[field] = self.status_fields[field](torrent_id)
except KeyError:
log.warning("Status field %s is not registered with the\
PluginManager.")
return status
def register_hook(self, hook, function):
"""Register a hook function with the plugin manager"""
try:

View File

@ -69,6 +69,7 @@ class Core(dbus.service.Object):
self.plugin.register_hook("post_torrent_add", self.post_torrent_add)
self.plugin.register_hook("post_torrent_remove",
self.post_torrent_remove)
self.plugin.register_status_field("queue", self.status_field_queue)
log.info("Queue Core plugin initialized..")
@ -81,6 +82,10 @@ class Core(dbus.service.Object):
if torrent_id is not None:
self.queue.remove(torrent_id)
## Status field function ##
def status_field_queue(self, torrent_id):
return self.queue[torrent_id]+1
## Queueing functions ##
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue",
in_signature="s", out_signature="")

View File

@ -69,7 +69,8 @@ class GtkUI:
self.torrentview.add_text_column("#",
col_type=int,
position=0,
get_function=self.column_get_function)
get_function=self.column_get_function,
status_field=["queue"])
# Add a toolbar buttons
self.plugin.get_toolbar().add_separator()
self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-up",
@ -103,6 +104,8 @@ class GtkUI:
signal from the core plugin.
"""
log.debug("torrent_queue_changed signal received..")
# We only need to update the queue column
self.torrentview.update(["#"])
return
def column_get_function(self, torrent_id):

View File

@ -126,10 +126,10 @@ class TorrentView(listview.ListView):
else:
# Iterate through supplied list of columns to update
for column in columns:
if self.columns[column.name].column.get_visible() is True \
and self.columns[column.name].hidden is False \
and self.columns[column.name].status_field is not None:
for field in self.columns[column.name].status_field:
if self.columns[column].column.get_visible() is True \
and self.columns[column].hidden is False \
and self.columns[column].status_field is not None:
for field in self.columns[column].status_field:
status_keys.append(field)
columns_to_update.append(column)
@ -169,6 +169,7 @@ class TorrentView(listview.ListView):
def add_row(self, torrent_id):
"""Adds a new torrent row to the treeview"""
## REWRITE TO USE STATUS FIELDS
# Get the status and info dictionaries
status_keys = ["name", "total_size", "progress", "state",
"num_seeds", "num_peers", "download_payload_rate",