mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
Modify common.TORRENT_STATE to be a list instead of a dictionary. The
state is now sent as a string instead of an int. This will break UIs.
This commit is contained in:
parent
eb15b5da37
commit
87a59662e4
@ -51,14 +51,16 @@ LT_TORRENT_STATE = {
|
|||||||
"Paused": 8
|
"Paused": 8
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_STATE = {
|
TORRENT_STATE = [
|
||||||
"Allocating": 0,
|
"Allocating",
|
||||||
"Checking": 1,
|
"Checking",
|
||||||
"Downloading": 2,
|
"Downloading",
|
||||||
"Seeding": 3,
|
"Seeding",
|
||||||
"Paused": 4,
|
"Paused",
|
||||||
"Error": 5
|
"Error",
|
||||||
}
|
"Queued"
|
||||||
|
]
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
"""Returns the program version from the egg metadata"""
|
"""Returns the program version from the egg metadata"""
|
||||||
return pkg_resources.require("Deluge")[0].version.split("r")[0]
|
return pkg_resources.require("Deluge")[0].version.split("r")[0]
|
||||||
|
@ -67,7 +67,7 @@ class Torrent:
|
|||||||
# Where the torrent is being saved to
|
# Where the torrent is being saved to
|
||||||
self.save_path = save_path
|
self.save_path = save_path
|
||||||
# The state of the torrent
|
# The state of the torrent
|
||||||
self.state = None
|
self.state = "Paused"
|
||||||
|
|
||||||
# Holds status info so that we don't need to keep getting it from lt
|
# Holds status info so that we don't need to keep getting it from lt
|
||||||
self.status = self.handle.status()
|
self.status = self.handle.status()
|
||||||
@ -146,15 +146,16 @@ class Torrent:
|
|||||||
def set_state(self, state):
|
def set_state(self, state):
|
||||||
"""Accepts state strings, ie, "Paused", "Seeding", etc."""
|
"""Accepts state strings, ie, "Paused", "Seeding", etc."""
|
||||||
|
|
||||||
|
if state not in TORRENT_STATE:
|
||||||
|
log.debug("Trying to set an invalid state %s", state)
|
||||||
|
return
|
||||||
|
|
||||||
# Only set 'Downloading' or 'Seeding' state if not paused
|
# Only set 'Downloading' or 'Seeding' state if not paused
|
||||||
if state == "Downloading" or state == "Seeding":
|
if state == "Downloading" or state == "Seeding":
|
||||||
if self.handle.is_paused():
|
if self.handle.is_paused():
|
||||||
state = "Paused"
|
state = "Paused"
|
||||||
|
|
||||||
try:
|
self.state = state
|
||||||
self.state = TORRENT_STATE[state]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_eta(self):
|
def get_eta(self):
|
||||||
"""Returns the ETA in seconds for this torrent"""
|
"""Returns the ETA in seconds for this torrent"""
|
||||||
@ -308,7 +309,7 @@ class Torrent:
|
|||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
"""Resumes this torrent"""
|
"""Resumes this torrent"""
|
||||||
if self.state != TORRENT_STATE["Paused"]:
|
if self.state != "Paused":
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -40,7 +40,17 @@ class TorrentQueue(component.Component):
|
|||||||
component.Component.__init__(self, "TorrentQueue", depend=["TorrentManager"])
|
component.Component.__init__(self, "TorrentQueue", depend=["TorrentManager"])
|
||||||
# This is a list of torrent_ids in the queueing order
|
# This is a list of torrent_ids in the queueing order
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
|
||||||
|
self.torrents = component.get("TorrentManager")
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
pass
|
||||||
|
# seeding = []
|
||||||
|
# downloading = []
|
||||||
|
|
||||||
|
# for torrent_id in self.torrents.get_torrent_list():
|
||||||
|
# if self.torrents[torrent_id].get_status(["state"],
|
||||||
|
|
||||||
def set_size(self, size):
|
def set_size(self, size):
|
||||||
"""Clear and set the self.queue list to the length of size"""
|
"""Clear and set the self.queue list to the length of size"""
|
||||||
log.debug("Setting queue size to %s..", size)
|
log.debug("Setting queue size to %s..", size)
|
||||||
|
@ -462,7 +462,7 @@ class ListView:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_texticon_column(self, header, col_types=[int, str],
|
def add_texticon_column(self, header, col_types=[str, str],
|
||||||
sortid=1,
|
sortid=1,
|
||||||
hidden=False,
|
hidden=False,
|
||||||
position=None,
|
position=None,
|
||||||
|
@ -38,8 +38,6 @@ import deluge.component as component
|
|||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
TORRENT_STATE = deluge.common.TORRENT_STATE
|
|
||||||
|
|
||||||
class SideBar(component.Component):
|
class SideBar(component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
component.Component.__init__(self, "SideBar")
|
component.Component.__init__(self, "SideBar")
|
||||||
@ -104,11 +102,11 @@ class SideBar(component.Component):
|
|||||||
component.get("TorrentView").set_filter(None, None)
|
component.get("TorrentView").set_filter(None, None)
|
||||||
if value == "Downloading":
|
if value == "Downloading":
|
||||||
component.get("TorrentView").set_filter("state",
|
component.get("TorrentView").set_filter("state",
|
||||||
TORRENT_STATE["Downloading"])
|
"Downloading")
|
||||||
if value == "Seeding":
|
if value == "Seeding":
|
||||||
component.get("TorrentView").set_filter("state",
|
component.get("TorrentView").set_filter("state",
|
||||||
TORRENT_STATE["Seeding"])
|
"Seeding")
|
||||||
if value == "Paused":
|
if value == "Paused":
|
||||||
component.get("TorrentView").set_filter("state",
|
component.get("TorrentView").set_filter("state",
|
||||||
TORRENT_STATE["Paused"])
|
"Paused")
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ class ToolBar(component.Component):
|
|||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
log.debug("Error getting torrent state: %s", e)
|
log.debug("Error getting torrent state: %s", e)
|
||||||
continue
|
continue
|
||||||
if status == TORRENT_STATE["Paused"]:
|
if status == "Paused":
|
||||||
resume = True
|
resume = True
|
||||||
else:
|
else:
|
||||||
pause = True
|
pause = True
|
||||||
|
@ -48,8 +48,6 @@ from deluge.ui.client import aclient as client
|
|||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.ui.gtkui.listview as listview
|
import deluge.ui.gtkui.listview as listview
|
||||||
|
|
||||||
TORRENT_STATE = deluge.common.TORRENT_STATE
|
|
||||||
|
|
||||||
# Status icons.. Create them from file only once to avoid constantly
|
# Status icons.. Create them from file only once to avoid constantly
|
||||||
# re-creating them.
|
# re-creating them.
|
||||||
icon_downloading = gtk.gdk.pixbuf_new_from_file(
|
icon_downloading = gtk.gdk.pixbuf_new_from_file(
|
||||||
@ -60,35 +58,37 @@ icon_inactive = gtk.gdk.pixbuf_new_from_file(
|
|||||||
deluge.common.get_pixmap("inactive16.png"))
|
deluge.common.get_pixmap("inactive16.png"))
|
||||||
icon_alert = gtk.gdk.pixbuf_new_from_file(
|
icon_alert = gtk.gdk.pixbuf_new_from_file(
|
||||||
deluge.common.get_pixmap("alert16.png"))
|
deluge.common.get_pixmap("alert16.png"))
|
||||||
|
icon_queued = gtk.gdk.pixbuf_new_from_file(
|
||||||
|
deluge.common.get_pixmap("queued16.png"))
|
||||||
|
|
||||||
# Holds the info for which status icon to display based on state
|
# Holds the info for which status icon to display based on state
|
||||||
ICON_STATE = [
|
ICON_STATE = {
|
||||||
icon_inactive,
|
"Allocating": icon_inactive,
|
||||||
icon_inactive,
|
"Checking": icon_inactive,
|
||||||
icon_downloading,
|
"Downloading": icon_downloading,
|
||||||
icon_seeding,
|
"Seeding": icon_seeding,
|
||||||
icon_inactive,
|
"Paused": icon_inactive,
|
||||||
icon_alert
|
"Error": icon_alert,
|
||||||
]
|
"Queued": icon_queued
|
||||||
|
}
|
||||||
|
|
||||||
def cell_data_statusicon(column, cell, model, row, data):
|
def cell_data_statusicon(column, cell, model, row, data):
|
||||||
"""Display text with an icon"""
|
"""Display text with an icon"""
|
||||||
icon = ICON_STATE[model.get_value(row, data)]
|
try:
|
||||||
if cell.get_property("pixbuf") != icon:
|
icon = ICON_STATE[model.get_value(row, data)]
|
||||||
cell.set_property("pixbuf", icon)
|
if cell.get_property("pixbuf") != icon:
|
||||||
|
cell.set_property("pixbuf", icon)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def cell_data_progress(column, cell, model, row, data):
|
def cell_data_progress(column, cell, model, row, data):
|
||||||
"""Display progress bar with text"""
|
"""Display progress bar with text"""
|
||||||
(value, text) = model.get(row, *data)
|
(value, state_str) = model.get(row, *data)
|
||||||
if cell.get_property("value") != value:
|
if cell.get_property("value") != value:
|
||||||
cell.set_property("value", value)
|
cell.set_property("value", value)
|
||||||
state_str = ""
|
|
||||||
for key in TORRENT_STATE.keys():
|
|
||||||
if TORRENT_STATE[key] == text:
|
|
||||||
state_str = key
|
|
||||||
break
|
|
||||||
textstr = "%s" % state_str
|
textstr = "%s" % state_str
|
||||||
if state_str != "Seeding" and state_str != "Finished" and value < 100:
|
if state_str != "Seeding" and value < 100:
|
||||||
textstr = textstr + " %.2f%%" % value
|
textstr = textstr + " %.2f%%" % value
|
||||||
if cell.get_property("text") != textstr:
|
if cell.get_property("text") != textstr:
|
||||||
cell.set_property("text", textstr)
|
cell.set_property("text", textstr)
|
||||||
@ -125,7 +125,7 @@ class TorrentView(listview.ListView, component.Component):
|
|||||||
status_field=["total_size"])
|
status_field=["total_size"])
|
||||||
self.add_progress_column(_("Progress"),
|
self.add_progress_column(_("Progress"),
|
||||||
status_field=["progress", "state"],
|
status_field=["progress", "state"],
|
||||||
col_types=[float, int],
|
col_types=[float, str],
|
||||||
function=cell_data_progress)
|
function=cell_data_progress)
|
||||||
self.add_func_column(_("Seeders"),
|
self.add_func_column(_("Seeders"),
|
||||||
listview.cell_data_peer,
|
listview.cell_data_peer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user