get_torrent_status() now takes a list of keys and only returns the
values for those keys.
This commit is contained in:
parent
bb299f4e97
commit
bcf70c3e0f
|
@ -129,19 +129,15 @@ class Core(dbus.service.Object):
|
|||
self.torrent_paused(torrent_id)
|
||||
|
||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||
in_signature="s", out_signature="ay")
|
||||
def get_torrent_info(self, torrent_id):
|
||||
# Pickle the info dictionary from the torrent and return it
|
||||
info = self.torrents[torrent_id].get_info()
|
||||
info = pickle.dumps(info)
|
||||
return info
|
||||
|
||||
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge",
|
||||
in_signature="s",
|
||||
in_signature="sas",
|
||||
out_signature="ay")
|
||||
def get_torrent_status(self, torrent_id):
|
||||
def get_torrent_status(self, torrent_id, keys):
|
||||
# Convert the array of strings to a python list of strings
|
||||
nkeys = []
|
||||
for key in keys:
|
||||
nkeys.append(str(key))
|
||||
# Pickle the status dictionary from the torrent and return it
|
||||
status = self.torrents[torrent_id].get_status()
|
||||
status = self.torrents[torrent_id].get_status(nkeys)
|
||||
status = pickle.dumps(status)
|
||||
return status
|
||||
|
||||
|
|
|
@ -71,21 +71,15 @@ class Torrent:
|
|||
|
||||
return eta
|
||||
|
||||
def get_info(self):
|
||||
"""Returns the torrents info.. stuff that remains constant, such as
|
||||
name."""
|
||||
|
||||
return {
|
||||
"name": self.handle.torrent_info().name(),
|
||||
"total_size": self.handle.torrent_info().total_size(),
|
||||
"num_pieces": self.handle.status().num_pieces
|
||||
}
|
||||
|
||||
def get_status(self):
|
||||
"""Returns the torrent status"""
|
||||
def get_status(self, keys):
|
||||
"""Returns the status of the torrent based on the keys provided"""
|
||||
# Create the full dictionary
|
||||
status = self.handle.status()
|
||||
|
||||
return {
|
||||
full_status = {
|
||||
"name": self.handle.torrent_info().name(),
|
||||
"total_size": self.handle.torrent_info().total_size(),
|
||||
"num_pieces": self.handle.status().num_pieces,
|
||||
"state": int(status.state),
|
||||
"paused": status.paused,
|
||||
"progress": status.progress,
|
||||
|
@ -98,5 +92,14 @@ class Torrent:
|
|||
"num_seeds": status.num_seeds,
|
||||
"total_wanted": status.total_wanted,
|
||||
"eta": self.get_eta(),
|
||||
"queue": self.queue[self.torrent_id]
|
||||
"queue": self.queue[self.torrent_id]
|
||||
}
|
||||
|
||||
# Create the desired status dictionary and return it
|
||||
status_dict = {}
|
||||
|
||||
for key in keys:
|
||||
if key in full_status:
|
||||
status_dict[key] = full_status[key]
|
||||
|
||||
return status_dict
|
||||
|
|
|
@ -132,7 +132,10 @@ class TorrentManager:
|
|||
except:
|
||||
return False
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
def resume(self, torrent_id):
|
||||
pass
|
||||
|
||||
def save_state(self):
|
||||
"""Save the state of the TorrentManager to the torrents.state file"""
|
||||
|
|
|
@ -134,9 +134,9 @@ def get_torrent_info(core, torrent_id):
|
|||
info = pickle.loads(info)
|
||||
return info
|
||||
|
||||
def get_torrent_status(core, torrent_id):
|
||||
def get_torrent_status(core, torrent_id, keys):
|
||||
"""Builds the status dictionary and returns it"""
|
||||
status = core.get_torrent_status(torrent_id)
|
||||
status = core.get_torrent_status(torrent_id, keys)
|
||||
# Join the array of bytes into a string for pickle to read
|
||||
status = "".join(chr(b) for b in status)
|
||||
# De-serialize the object
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,7 @@
|
|||
<property name="tooltip" translatable="yes">Resume selected torrents.</property>
|
||||
<property name="label" translatable="yes">Resu_me</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_menuitem_resume_activate"/>
|
||||
<child internal-child="image">
|
||||
<widget class="GtkImage" id="menu-item-image13">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
@ -153,11 +153,15 @@ class TorrentView:
|
|||
|
||||
def update(self):
|
||||
"""Update the view, this is likely called by a timer"""
|
||||
|
||||
# This function is used for the foreach method of the treemodel
|
||||
def update_row(model, path, row, user_data):
|
||||
torrent_id = self.torrent_model.get_value(row, 0)
|
||||
status = functions.get_torrent_status(self.core, torrent_id)
|
||||
status_keys = ["queue", "progress", "state", "num_seeds",
|
||||
"num_peers", "download_payload_rate", "upload_payload_rate",
|
||||
"eta"]
|
||||
status = functions.get_torrent_status(self.core, torrent_id,
|
||||
status_keys)
|
||||
|
||||
# Set values for each column in the row
|
||||
self.torrent_model.set_value(row, TORRENT_VIEW_COL_QUEUE,
|
||||
status["queue"]+1)
|
||||
|
@ -186,16 +190,18 @@ class TorrentView:
|
|||
def add_row(self, torrent_id):
|
||||
"""Adds a new torrent row to the treeview"""
|
||||
# Get the status and info dictionaries
|
||||
status = functions.get_torrent_status(self.core, torrent_id)
|
||||
info = functions.get_torrent_info(self.core, torrent_id)
|
||||
|
||||
status_keys = ["queue", "name", "total_size", "progress", "state",
|
||||
"num_seeds", "num_peers", "download_payload_rate",
|
||||
"upload_payload_rate", "eta"]
|
||||
status = functions.get_torrent_status(self.core, torrent_id,
|
||||
status_keys)
|
||||
# Insert the row with info provided from core
|
||||
self.torrent_model.insert(status["queue"], [
|
||||
torrent_id,
|
||||
status["queue"]+1,
|
||||
None,
|
||||
info["name"],
|
||||
info["total_size"],
|
||||
status["name"],
|
||||
status["total_size"],
|
||||
status["progress"]*100,
|
||||
status["state"],
|
||||
status["num_seeds"],
|
||||
|
|
Loading…
Reference in New Issue