Attempt to fix issues where torrents would not update correctly in the

torrent view.  Also an attempt at improving performance.
This commit is contained in:
Andrew Resch 2008-01-14 09:00:13 +00:00
parent eaddaaa844
commit f9a664b9c7
1 changed files with 20 additions and 42 deletions

View File

@ -284,69 +284,47 @@ class TorrentView(listview.ListView, component.Component):
"""Callback function for get_torrents_status(). 'status' should be a """Callback function for get_torrents_status(). 'status' should be a
dictionary of {torrent_id: {key, value}}.""" dictionary of {torrent_id: {key, value}}."""
status = pickle.loads(status) status = pickle.loads(status)
# Extract differences in this batch against the previous one.
# This is to prevent updating stuff we don't need to and should save
# GTK from redrawing needlessly.
new_status = {}
for torrent_id in status.keys():
if torrent_id in self.previous_batched_status.keys():
old = self.previous_batched_status[torrent_id]
new = status[torrent_id]
diff = {}
for key in new.keys():
if not key in old.keys():
diff[key] = new[key]
continue
# There is a difference, so lets add it to our new dict
if new[key] != old[key]:
diff[key] = new[key]
if len(diff.keys()) > 0:
new_status[torrent_id] = diff
else:
# The torrent_id is not in the previous status
new_status[torrent_id] = status[torrent_id]
self.previous_batched_status = status
row = self.liststore.get_iter_first() row = self.liststore.get_iter_first()
while row != None: while row != None:
torrent_id = self.liststore.get_value( torrent_id = self.liststore.get_value(
row, self.columns["torrent_id"].column_indices[0]) row, self.columns["torrent_id"].column_indices[0])
if torrent_id in new_status.keys(): if torrent_id in status.keys():
# Set values for each column in the row # Set values for each column in the row
for column in self.columns_to_update: for column in self.columns_to_update:
column_index = self.get_column_index(column) column_index = self.get_column_index(column)
if type(column_index) is not list: if type(column_index) is not list:
# We only have a single list store column we need to # We only have a single list store column we need to
# update # update
if self.columns[column].status_field[0] in \ try:
new_status[torrent_id]: # Only update if different
try: if self.liststore.get_value(row, column_index) != \
status[torrent_id][
self.columns[column].status_field[0]]:
self.liststore.set_value(row, self.liststore.set_value(row,
column_index, column_index,
new_status[torrent_id][ status[torrent_id][
self.columns[column].status_field[0]]) self.columns[column].status_field[0]])
except (TypeError, KeyError), e: except (TypeError, KeyError), e:
log.warning("Unable to update column %s: %s", log.warning("Unable to update column %s: %s",
column, e) column, e)
else: else:
# We have more than 1 liststore column to update # We have more than 1 liststore column to update
for index in column_index: for index in column_index:
# Only update the column if the status field exists # Only update the column if the status field exists
if self.columns[column].status_field[ try:
column_index.index(index)] in \ # Only update if different
new_status[torrent_id]: if self.liststore.get_value(row, index) != \
try: status[torrent_id][
self.columns[column].status_field[
column_index.index(index)]]:
self.liststore.set_value(row, self.liststore.set_value(row,
index, index,
new_status[torrent_id][ status[torrent_id][
self.columns[column].status_field[ self.columns[column].status_field[
column_index.index(index)]]) column_index.index(index)]])
except: except:
pass pass
row = self.liststore.iter_next(row) row = self.liststore.iter_next(row)
self.status_signal_received = True self.status_signal_received = True