mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-28 20:25:10 +00:00
Plugins can now register 'status_fields' with core for use with
get_status(). Updates to TorrentQueue plugin.
This commit is contained in:
parent
5611037db2
commit
f185f19cfb
@ -155,8 +155,12 @@ class Core(dbus.service.Object):
|
|||||||
nkeys = []
|
nkeys = []
|
||||||
for key in keys:
|
for key in keys:
|
||||||
nkeys.append(str(key))
|
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)
|
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)
|
status = pickle.dumps(status)
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ class PluginManager:
|
|||||||
"post_torrent_remove": []
|
"post_torrent_remove": []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.status_fields = {}
|
||||||
|
|
||||||
# This will load any .eggs in the plugins folder inside the main
|
# This will load any .eggs in the plugins folder inside the main
|
||||||
# deluge egg.. Need to scan the local plugin folder too.
|
# deluge egg.. Need to scan the local plugin folder too.
|
||||||
|
|
||||||
@ -70,6 +72,21 @@ class PluginManager:
|
|||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self.plugins[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):
|
def register_hook(self, hook, function):
|
||||||
"""Register a hook function with the plugin manager"""
|
"""Register a hook function with the plugin manager"""
|
||||||
try:
|
try:
|
||||||
|
@ -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_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)
|
||||||
|
self.plugin.register_status_field("queue", self.status_field_queue)
|
||||||
|
|
||||||
log.info("Queue Core plugin initialized..")
|
log.info("Queue Core plugin initialized..")
|
||||||
|
|
||||||
@ -81,6 +82,10 @@ class Core(dbus.service.Object):
|
|||||||
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 ##
|
||||||
|
def status_field_queue(self, torrent_id):
|
||||||
|
return self.queue[torrent_id]+1
|
||||||
|
|
||||||
## Queueing functions ##
|
## Queueing functions ##
|
||||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue",
|
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge.Queue",
|
||||||
in_signature="s", out_signature="")
|
in_signature="s", out_signature="")
|
||||||
|
@ -69,7 +69,8 @@ class GtkUI:
|
|||||||
self.torrentview.add_text_column("#",
|
self.torrentview.add_text_column("#",
|
||||||
col_type=int,
|
col_type=int,
|
||||||
position=0,
|
position=0,
|
||||||
get_function=self.column_get_function)
|
get_function=self.column_get_function,
|
||||||
|
status_field=["queue"])
|
||||||
# Add a toolbar buttons
|
# Add a toolbar buttons
|
||||||
self.plugin.get_toolbar().add_separator()
|
self.plugin.get_toolbar().add_separator()
|
||||||
self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-up",
|
self.plugin.get_toolbar().add_toolbutton(stock="gtk-go-up",
|
||||||
@ -103,6 +104,8 @@ class GtkUI:
|
|||||||
signal from the core plugin.
|
signal from the core plugin.
|
||||||
"""
|
"""
|
||||||
log.debug("torrent_queue_changed signal received..")
|
log.debug("torrent_queue_changed signal received..")
|
||||||
|
# We only need to update the queue column
|
||||||
|
self.torrentview.update(["#"])
|
||||||
return
|
return
|
||||||
|
|
||||||
def column_get_function(self, torrent_id):
|
def column_get_function(self, torrent_id):
|
||||||
|
@ -126,10 +126,10 @@ class TorrentView(listview.ListView):
|
|||||||
else:
|
else:
|
||||||
# Iterate through supplied list of columns to update
|
# Iterate through supplied list of columns to update
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if self.columns[column.name].column.get_visible() is True \
|
if self.columns[column].column.get_visible() is True \
|
||||||
and self.columns[column.name].hidden is False \
|
and self.columns[column].hidden is False \
|
||||||
and self.columns[column.name].status_field is not None:
|
and self.columns[column].status_field is not None:
|
||||||
for field in self.columns[column.name].status_field:
|
for field in self.columns[column].status_field:
|
||||||
status_keys.append(field)
|
status_keys.append(field)
|
||||||
columns_to_update.append(column)
|
columns_to_update.append(column)
|
||||||
|
|
||||||
@ -169,6 +169,7 @@ class TorrentView(listview.ListView):
|
|||||||
|
|
||||||
def add_row(self, torrent_id):
|
def add_row(self, torrent_id):
|
||||||
"""Adds a new torrent row to the treeview"""
|
"""Adds a new torrent row to the treeview"""
|
||||||
|
## REWRITE TO USE STATUS FIELDS
|
||||||
# Get the status and info dictionaries
|
# Get the status and info dictionaries
|
||||||
status_keys = ["name", "total_size", "progress", "state",
|
status_keys = ["name", "total_size", "progress", "state",
|
||||||
"num_seeds", "num_peers", "download_payload_rate",
|
"num_seeds", "num_peers", "download_payload_rate",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user