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__) log = logging.getLogger(__name__)
def sanitize_filepath(filepath, folder=False): def sanitize_filepath(filepath, folder=False):
""" """
Returns a sanitized filepath to pass to libotorrent rename_file(). Returns a sanitized filepath to pass to libotorrent rename_file().
@ -79,6 +80,7 @@ def sanitize_filepath(filepath, folder=False):
else: else:
return newfilepath return newfilepath
class TorrentOptions(dict): class TorrentOptions(dict):
def __init__(self): def __init__(self):
config = ConfigManager("core.conf").config config = ConfigManager("core.conf").config
@ -105,6 +107,7 @@ class TorrentOptions(dict):
self["file_priorities"] = [] self["file_priorities"] = []
self["mapped_files"] = {} self["mapped_files"] = {}
class Torrent(object): class Torrent(object):
"""Torrent holds information about torrents added to the libtorrent session. """Torrent holds information about torrents added to the libtorrent session.
""" """
@ -381,7 +384,7 @@ class Torrent(object):
def set_trackers(self, trackers): def set_trackers(self, trackers):
"""Sets trackers""" """Sets trackers"""
if trackers == None: if trackers is None:
trackers = [] trackers = []
for value in self.handle.trackers(): for value in self.handle.trackers():
tracker = {} tracker = {}
@ -574,7 +577,7 @@ class Torrent(object):
file_progress = self.handle.file_progress() file_progress = self.handle.file_progress()
ret = [] ret = []
for i,f in enumerate(self.get_files()): for i, f in enumerate(self.get_files()):
try: try:
ret.append(float(file_progress[i]) / float(f["size"])) ret.append(float(file_progress[i]) / float(f["size"]))
except ZeroDivisionError: except ZeroDivisionError:
@ -680,8 +683,8 @@ class Torrent(object):
"active_time": lambda: self.status.active_time, "active_time": lambda: self.status.active_time,
"all_time_download": lambda: self.status.all_time_download, "all_time_download": lambda: self.status.all_time_download,
"compact": lambda: self.options["compact_allocation"], "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 self.status.distributed_copies, # Adjust status.distributed_copies to return a non-negative value
"download_payload_rate": lambda: self.status.download_payload_rate, "download_payload_rate": lambda: self.status.download_payload_rate,
"file_priorities": lambda: self.options["file_priorities"], "file_priorities": lambda: self.options["file_priorities"],
"hash": lambda: self.torrent_id, "hash": lambda: self.torrent_id,
@ -708,8 +711,8 @@ class Torrent(object):
"remove_at_ratio": lambda: self.options["remove_at_ratio"], "remove_at_ratio": lambda: self.options["remove_at_ratio"],
"save_path": lambda: self.options["download_location"], "save_path": lambda: self.options["download_location"],
"seeding_time": lambda: self.status.seeding_time, "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 self.status.num_complete / float(self.status.num_incomplete), # Use -1.0 to signify infinity
"seed_rank": lambda: self.status.seed_rank, "seed_rank": lambda: self.status.seed_rank,
"state": lambda: self.state, "state": lambda: self.state,
"stop_at_ratio": lambda: self.options["stop_at_ratio"], "stop_at_ratio": lambda: self.options["stop_at_ratio"],
@ -734,18 +737,18 @@ class Torrent(object):
"private": lambda: self.torrent_info.priv() if self.has_metadata else False, "private": lambda: self.torrent_info.priv() if self.has_metadata else False,
"total_size": lambda: self.torrent_info.total_size() if self.has_metadata else 0, "total_size": lambda: self.torrent_info.total_size() if self.has_metadata else 0,
"eta": self.get_eta, "eta": self.get_eta,
"file_progress": self.get_file_progress, # Adjust progress to be 0-100 value "file_progress": self.get_file_progress, # Adjust progress to be 0-100 value
"files": self.get_files, "files": self.get_files,
"is_seed": lambda: self.status.is_seeding, "is_seed": lambda: self.status.is_seeding,
"peers": self.get_peers, "peers": self.get_peers,
"queue": self.handle.queue_position, "queue": self.handle.queue_position,
"ratio": self.get_ratio, "ratio": self.get_ratio,
"tracker_host": self.get_tracker_host, "tracker_host": self.get_tracker_host,
"completed_time": lambda: self.status.completed_time,
"last_seen_complete": lambda: self.status.last_seen_complete, "last_seen_complete": lambda: self.status.last_seen_complete,
"name": self.get_name, "name": self.get_name,
"pieces": self._get_pieces_info, "pieces": self._get_pieces_info,
}
}
def get_name(self): def get_name(self):
if self.has_metadata: if self.has_metadata:

View File

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