Modified update() in TorrentView. It is now able to update only the

requested columns and only columns which are visible.
This commit is contained in:
Andrew Resch 2007-08-22 06:23:16 +00:00
parent 810c0813ce
commit 5611037db2
2 changed files with 31 additions and 31 deletions

View File

@ -71,13 +71,16 @@ class Torrent:
# Create the full dictionary # Create the full dictionary
status = self.handle.status() status = self.handle.status()
# Adjust progress to be 0-100 value
progress = status.progress*100
full_status = { full_status = {
"name": self.handle.torrent_info().name(), "name": self.handle.torrent_info().name(),
"total_size": self.handle.torrent_info().total_size(), "total_size": self.handle.torrent_info().total_size(),
"num_pieces": self.handle.status().num_pieces, "num_pieces": self.handle.status().num_pieces,
"state": int(status.state), "state": int(status.state),
"paused": status.paused, "paused": status.paused,
"progress": status.progress, "progress": progress,
"next_announce": status.next_announce.seconds, "next_announce": status.next_announce.seconds,
"total_payload_download": status.total_payload_download, "total_payload_download": status.total_payload_download,
"total_payload_upload": status.total_payload_upload, "total_payload_upload": status.total_payload_upload,
@ -86,7 +89,8 @@ class Torrent:
"num_peers": status.num_peers, "num_peers": status.num_peers,
"num_seeds": status.num_seeds, "num_seeds": status.num_seeds,
"total_wanted": status.total_wanted, "total_wanted": status.total_wanted,
"eta": self.get_eta() "eta": self.get_eta(),
"ratio": 0.0
} }
# Create the desired status dictionary and return it # Create the desired status dictionary and return it

View File

@ -107,7 +107,10 @@ class TorrentView(listview.ListView):
# This function is used for the foreach method of the treemodel # This function is used for the foreach method of the treemodel
def update_row(model, path, row, user_data): def update_row(model, path, row, user_data):
torrent_id = self.liststore.get_value(row, 0) torrent_id = self.liststore.get_value(row, 0)
# Store the 'status_fields' we need to send to core
status_keys = [] status_keys = []
# Store the actual columns we will be updating
columns_to_update = []
if columns is None: if columns is None:
# Iterate through the list of columns and only add the # Iterate through the list of columns and only add the
# 'status-fields' of the visible ones. # 'status-fields' of the visible ones.
@ -119,6 +122,7 @@ class TorrentView(listview.ListView):
and column.status_field is not None: and column.status_field is not None:
for field in column.status_field: for field in column.status_field:
status_keys.append(field) status_keys.append(field)
columns_to_update.append(column.name)
else: else:
# Iterate through supplied list of columns to update # Iterate through supplied list of columns to update
for column in columns: for column in columns:
@ -127,6 +131,7 @@ class TorrentView(listview.ListView):
and self.columns[column.name].status_field is not None: and self.columns[column.name].status_field is not None:
for field in self.columns[column.name].status_field: for field in self.columns[column.name].status_field:
status_keys.append(field) status_keys.append(field)
columns_to_update.append(column)
# If there is nothing in status_keys then we must not continue # If there is nothing in status_keys then we must not continue
if status_keys is []: if status_keys is []:
@ -138,34 +143,25 @@ class TorrentView(listview.ListView):
status_keys) status_keys)
# Set values for each column in the row # Set values for each column in the row
# FIXME: Need to update based on 'status_keys' for column in columns_to_update:
if type(self.get_column_index(column)) is not list:
# We only have a single list store column we need to update
self.liststore.set_value(row, self.liststore.set_value(row,
self.get_column_index("Progress")[0], self.get_column_index(column),
status["progress"]*100) status[self.columns[column].status_field[0]])
else:
# We have more than 1 liststore column to update
i = 0
for index in self.get_column_index(column):
# Only update the column if the status field exists
try:
self.liststore.set_value(row, self.liststore.set_value(row,
self.get_column_index("Progress")[1], index,
status["state"]) status[self.columns[column].status_field[i]])
self.liststore.set_value(row, except:
self.get_column_index("Seeders")[0], pass
status["num_seeds"]) i = i + 1
self.liststore.set_value(row,
self.get_column_index("Seeders")[1],
status["num_seeds"])
self.liststore.set_value(row,
self.get_column_index("Peers")[0],
status["num_peers"])
self.liststore.set_value(row,
self.get_column_index("Peers")[1],
status["num_peers"])
self.liststore.set_value(row,
self.get_column_index("Down Speed"),
status["download_payload_rate"])
self.liststore.set_value(row,
self.get_column_index("Up Speed"),
status["upload_payload_rate"])
self.liststore.set_value(row,
self.get_column_index("ETA"),
status["eta"])
# Iterates through every row and updates them accordingly # Iterates through every row and updates them accordingly
if self.liststore is not None: if self.liststore is not None: