Fixes for #607 : Add completed_time to core and Completed column in GTK UI

This commit is contained in:
Calum Lind 2013-11-20 23:55:22 +00:00
parent 0da6739f94
commit 169b9b9898
2 changed files with 28 additions and 17 deletions

View File

@ -54,6 +54,7 @@ TORRENT_STATE = deluge.common.TORRENT_STATE
log = logging.getLogger(__name__)
def sanitize_filepath(filepath, folder=False):
"""
Returns a sanitized filepath to pass to libotorrent rename_file().
@ -79,6 +80,7 @@ def sanitize_filepath(filepath, folder=False):
else:
return newfilepath
class TorrentOptions(dict):
def __init__(self):
config = ConfigManager("core.conf").config
@ -105,6 +107,7 @@ class TorrentOptions(dict):
self["file_priorities"] = []
self["mapped_files"] = {}
class Torrent(object):
"""Torrent holds information about torrents added to the libtorrent session.
"""
@ -381,7 +384,7 @@ class Torrent(object):
def set_trackers(self, trackers):
"""Sets trackers"""
if trackers == None:
if trackers is None:
trackers = []
for value in self.handle.trackers():
tracker = {}
@ -680,7 +683,7 @@ class Torrent(object):
"active_time": lambda: self.status.active_time,
"all_time_download": lambda: self.status.all_time_download,
"compact": lambda: self.options["compact_allocation"],
"distributed_copies": lambda: 0.0 if self.status.distributed_copies < 0 else \
"distributed_copies": lambda: 0.0 if self.status.distributed_copies < 0 else
self.status.distributed_copies, # Adjust status.distributed_copies to return a non-negative value
"download_payload_rate": lambda: self.status.download_payload_rate,
"file_priorities": lambda: self.options["file_priorities"],
@ -708,7 +711,7 @@ class Torrent(object):
"remove_at_ratio": lambda: self.options["remove_at_ratio"],
"save_path": lambda: self.options["download_location"],
"seeding_time": lambda: self.status.seeding_time,
"seeds_peers_ratio": lambda: -1.0 if self.status.num_incomplete == 0 else \
"seeds_peers_ratio": lambda: -1.0 if self.status.num_incomplete == 0 else
self.status.num_complete / float(self.status.num_incomplete), # Use -1.0 to signify infinity
"seed_rank": lambda: self.status.seed_rank,
"state": lambda: self.state,
@ -741,10 +744,10 @@ class Torrent(object):
"queue": self.handle.queue_position,
"ratio": self.get_ratio,
"tracker_host": self.get_tracker_host,
"completed_time": lambda: self.status.completed_time,
"last_seen_complete": lambda: self.status.last_seen_complete,
"name": self.get_name,
"pieces": self._get_pieces_info,
}
def get_name(self):

View File

@ -54,6 +54,7 @@ import torrentview_data_funcs as funcs
log = logging.getLogger(__name__)
def queue_peer_seed_sort_function(v1, v2):
if v1 == v2:
return 0
@ -66,6 +67,7 @@ def queue_peer_seed_sort_function(v1, v2):
if v2 > v1:
return -1
def queue_column_sort(model, iter1, iter2, data):
v1 = model[iter1][data]
v2 = model[iter2][data]
@ -86,6 +88,7 @@ def eta_column_sort(model, iter1, iter2, data):
if v2 > v1:
return -1
def seed_peer_column_sort(model, iter1, iter2, data):
v1 = model[iter1][data] # num seeds/peers
v3 = model[iter2][data] # num seeds/peers
@ -95,6 +98,7 @@ def seed_peer_column_sort(model, iter1, iter2, data):
return queue_peer_seed_sort_function(v2, v4)
return queue_peer_seed_sort_function(v1, v3)
class SearchBox(object):
def __init__(self, torrentview):
self.torrentview = torrentview
@ -183,7 +187,6 @@ class SearchBox(object):
self.prefiltered.pop(self.prefiltered.index(torrent_id))
row[filter_column] = not row[filter_column]
if not row[filter_column]:
# Row is not visible(filtered out, but not by our filter), skip it
continue
@ -294,6 +297,9 @@ class TorrentView(listview.ListView, component.Component):
status_field=["distributed_copies"], default=False)
self.add_func_column(_("Added"), funcs.cell_data_date, [float],
status_field=["time_added"], default=False)
self.add_func_column(_("Completed"),
funcs.cell_data_date_or_never, [float],
status_field=["completed_time"], default=False)
self.add_func_column(_("Last Seen Complete"),
funcs.cell_data_date_or_never, [float],
status_field=["last_seen_complete"], default=False)
@ -393,7 +399,7 @@ class TorrentView(listview.ListView, component.Component):
"""
self.treeview.get_selection().unselect_all()
search_filter = self.filter and self.filter.get('name', None) or None
self.filter = dict(filter_dict) #copied version of filter_dict.
self.filter = dict(filter_dict) # Copied version of filter_dict.
if search_filter and 'name' not in filter_dict:
self.filter['name'] = search_filter
self.update()
@ -478,7 +484,7 @@ class TorrentView(listview.ListView, component.Component):
if torrent_status == self.prev_status[torrent_id]:
# The status dict is the same, so do nothing to update for this torrent
continue
except KeyError, e:
except KeyError:
pass
if not torrent_id_in_status:
@ -544,7 +550,8 @@ class TorrentView(listview.ListView, component.Component):
if not torrent_id or row[self.columns["torrent_id"].column_indices[0]] == torrent_id:
#log.debug("marking %s dirty", torrent_id)
row[self.columns["dirty"].column_indices[0]] = True
if torrent_id: break
if torrent_id:
break
def get_selected_torrent(self):
"""Returns a torrent_id or None. If multiple torrents are selected,
@ -610,7 +617,8 @@ class TorrentView(listview.ListView, component.Component):
row = self.model_filter.get_iter(path[0])
if self.get_selected_torrents():
if self.model_filter.get_value(row, self.columns["torrent_id"].column_indices[0]) not in self.get_selected_torrents():
if self.model_filter.get_value(row, self.columns["torrent_id"].column_indices[0]) \
not in self.get_selected_torrents():
self.treeview.get_selection().unselect_all()
self.treeview.get_selection().select_iter(row)
else: