diff --git a/deluge/common.py b/deluge/common.py index 22f1526cb..7361c0183 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -51,14 +51,16 @@ LT_TORRENT_STATE = { "Paused": 8 } -TORRENT_STATE = { - "Allocating": 0, - "Checking": 1, - "Downloading": 2, - "Seeding": 3, - "Paused": 4, - "Error": 5 -} +TORRENT_STATE = [ + "Allocating", + "Checking", + "Downloading", + "Seeding", + "Paused", + "Error", + "Queued" +] + def get_version(): """Returns the program version from the egg metadata""" return pkg_resources.require("Deluge")[0].version.split("r")[0] diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 1553c75cc..f6f2ce569 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -67,7 +67,7 @@ class Torrent: # Where the torrent is being saved to self.save_path = save_path # 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 self.status = self.handle.status() @@ -146,15 +146,16 @@ class Torrent: def set_state(self, state): """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 if state == "Downloading" or state == "Seeding": if self.handle.is_paused(): state = "Paused" - try: - self.state = TORRENT_STATE[state] - except: - pass + self.state = state def get_eta(self): """Returns the ETA in seconds for this torrent""" @@ -308,7 +309,7 @@ class Torrent: def resume(self): """Resumes this torrent""" - if self.state != TORRENT_STATE["Paused"]: + if self.state != "Paused": return False try: diff --git a/deluge/core/torrentqueue.py b/deluge/core/torrentqueue.py index 687150d1b..08922fbe2 100644 --- a/deluge/core/torrentqueue.py +++ b/deluge/core/torrentqueue.py @@ -40,7 +40,17 @@ class TorrentQueue(component.Component): component.Component.__init__(self, "TorrentQueue", depend=["TorrentManager"]) # This is a list of torrent_ids in the queueing order 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): """Clear and set the self.queue list to the length of size""" log.debug("Setting queue size to %s..", size) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 75bc1dcc2..8da2ac506 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -462,7 +462,7 @@ class ListView: return True - def add_texticon_column(self, header, col_types=[int, str], + def add_texticon_column(self, header, col_types=[str, str], sortid=1, hidden=False, position=None, diff --git a/deluge/ui/gtkui/sidebar.py b/deluge/ui/gtkui/sidebar.py index 3e8ad2379..1af71b4e2 100644 --- a/deluge/ui/gtkui/sidebar.py +++ b/deluge/ui/gtkui/sidebar.py @@ -38,8 +38,6 @@ import deluge.component as component import deluge.common from deluge.log import LOG as log -TORRENT_STATE = deluge.common.TORRENT_STATE - class SideBar(component.Component): def __init__(self): component.Component.__init__(self, "SideBar") @@ -104,11 +102,11 @@ class SideBar(component.Component): component.get("TorrentView").set_filter(None, None) if value == "Downloading": component.get("TorrentView").set_filter("state", - TORRENT_STATE["Downloading"]) + "Downloading") if value == "Seeding": component.get("TorrentView").set_filter("state", - TORRENT_STATE["Seeding"]) + "Seeding") if value == "Paused": component.get("TorrentView").set_filter("state", - TORRENT_STATE["Paused"]) + "Paused") diff --git a/deluge/ui/gtkui/toolbar.py b/deluge/ui/gtkui/toolbar.py index 230c33fe6..5f00e6727 100644 --- a/deluge/ui/gtkui/toolbar.py +++ b/deluge/ui/gtkui/toolbar.py @@ -182,7 +182,7 @@ class ToolBar(component.Component): except KeyError, e: log.debug("Error getting torrent state: %s", e) continue - if status == TORRENT_STATE["Paused"]: + if status == "Paused": resume = True else: pause = True diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 959f4c171..5ccdbf335 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -48,8 +48,6 @@ from deluge.ui.client import aclient as client from deluge.log import LOG as log import deluge.ui.gtkui.listview as listview -TORRENT_STATE = deluge.common.TORRENT_STATE - # Status icons.. Create them from file only once to avoid constantly # re-creating them. 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")) icon_alert = gtk.gdk.pixbuf_new_from_file( 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 -ICON_STATE = [ - icon_inactive, - icon_inactive, - icon_downloading, - icon_seeding, - icon_inactive, - icon_alert -] +ICON_STATE = { + "Allocating": icon_inactive, + "Checking": icon_inactive, + "Downloading": icon_downloading, + "Seeding": icon_seeding, + "Paused": icon_inactive, + "Error": icon_alert, + "Queued": icon_queued +} def cell_data_statusicon(column, cell, model, row, data): """Display text with an icon""" - icon = ICON_STATE[model.get_value(row, data)] - if cell.get_property("pixbuf") != icon: - cell.set_property("pixbuf", icon) - + try: + icon = ICON_STATE[model.get_value(row, data)] + if cell.get_property("pixbuf") != icon: + cell.set_property("pixbuf", icon) + except KeyError: + pass + def cell_data_progress(column, cell, model, row, data): """Display progress bar with text""" - (value, text) = model.get(row, *data) + (value, state_str) = model.get(row, *data) if cell.get_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 - if state_str != "Seeding" and state_str != "Finished" and value < 100: + if state_str != "Seeding" and value < 100: textstr = textstr + " %.2f%%" % value if cell.get_property("text") != textstr: cell.set_property("text", textstr) @@ -125,7 +125,7 @@ class TorrentView(listview.ListView, component.Component): status_field=["total_size"]) self.add_progress_column(_("Progress"), status_field=["progress", "state"], - col_types=[float, int], + col_types=[float, str], function=cell_data_progress) self.add_func_column(_("Seeders"), listview.cell_data_peer,