mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-13 04:54:23 +00:00
Merge remote-tracking branch 'bro/1.3-stable-torrentview' into 1.3-stable
This commit is contained in:
commit
8d25a5e691
@ -313,18 +313,12 @@ class TorrentView(listview.ListView, component.Component):
|
||||
component.get("SessionProxy").get_torrents_status({}, []).addCallback(self._on_session_state)
|
||||
|
||||
def _on_session_state(self, state):
|
||||
self.treeview.freeze_child_notify()
|
||||
model = self.treeview.get_model()
|
||||
for torrent_id in state:
|
||||
self.add_row(torrent_id, update=False)
|
||||
self.mark_dirty(torrent_id)
|
||||
self.treeview.set_model(model)
|
||||
self.treeview.thaw_child_notify()
|
||||
self.add_rows(state)
|
||||
self.got_state = True
|
||||
# Update the view right away with our status
|
||||
self.status = state
|
||||
self.set_columns_to_update()
|
||||
self.update_view()
|
||||
self.update_view(first_run=True)
|
||||
|
||||
def stop(self):
|
||||
"""Stops the torrentview"""
|
||||
@ -399,40 +393,77 @@ class TorrentView(listview.ListView, component.Component):
|
||||
# Send a status request
|
||||
gobject.idle_add(self.send_status_request)
|
||||
|
||||
def update_view(self, columns=None):
|
||||
"""Update the view. If columns is not None, it will attempt to only
|
||||
update those columns selected.
|
||||
"""
|
||||
|
||||
def update_view(self, first_run=False):
|
||||
"""Update the view."""
|
||||
filter_column = self.columns["filter"].column_indices[0]
|
||||
# Update the torrent view model with data we've received
|
||||
status = self.status
|
||||
sort_settings = (None, None)
|
||||
model = self.treeview.get_model()
|
||||
|
||||
self.treeview.freeze_child_notify()
|
||||
|
||||
if first_run:
|
||||
# Disable sort if it's the first run.
|
||||
sort_settings = model.get_sort_column_id()
|
||||
model.set_sort_column_id(-1, gtk.SORT_ASCENDING)
|
||||
|
||||
# Create a list of tuples with the index of the column, and the column name
|
||||
fields_to_update = []
|
||||
for column in self.columns_to_update:
|
||||
column_index = self.get_column_index(column)
|
||||
for i, status_field in enumerate(self.columns[column].status_field):
|
||||
fields_to_update.append((column_index[i], status_field))
|
||||
|
||||
for row in self.liststore:
|
||||
torrent_id = row[self.columns["torrent_id"].column_indices[0]]
|
||||
|
||||
if not torrent_id in status.keys():
|
||||
row[filter_column] = False
|
||||
else:
|
||||
row[filter_column] = True
|
||||
if torrent_id in self.prev_status and status[torrent_id] == self.prev_status[torrent_id]:
|
||||
# The status dict is the same, so do not update
|
||||
# Do not test if the torrent_id is in status. Instead
|
||||
# we expect the torrent_id to be in status and prev_status,
|
||||
# as it will be as long as the list isn't changed by the user
|
||||
torrent_id_in_status = False
|
||||
try:
|
||||
torrent_status = status[torrent_id]
|
||||
torrent_id_in_status = True
|
||||
if torrent_status == self.prev_status[torrent_id]:
|
||||
if row[filter_column] is False:
|
||||
row[filter_column] = True
|
||||
# The status dict is the same, so do not update this torrent
|
||||
continue
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# Set values for each column in the row
|
||||
for column in self.columns_to_update:
|
||||
column_index = self.get_column_index(column)
|
||||
for i, status_field in enumerate(self.columns[column].status_field):
|
||||
if status_field in status[torrent_id]:
|
||||
try:
|
||||
# Only update if different
|
||||
row_value = status[torrent_id][status_field]
|
||||
if row[column_index[i]] != row_value:
|
||||
row[column_index[i]] = row_value
|
||||
except Exception, e:
|
||||
log.debug("%s", e)
|
||||
if not torrent_id_in_status:
|
||||
if row[filter_column] is True:
|
||||
row[filter_column] = False
|
||||
else:
|
||||
if row[filter_column] is False:
|
||||
row[filter_column] = True
|
||||
to_update = []
|
||||
# Add all the values that have changed to the list
|
||||
for i, status_field in fields_to_update:
|
||||
try:
|
||||
if not status[torrent_id].has_key(status_field):
|
||||
continue
|
||||
row_value = status[torrent_id][status_field]
|
||||
if row[i] != row_value:
|
||||
to_update.append(i)
|
||||
to_update.append(row_value)
|
||||
except KeyError, e:
|
||||
# if status_field in status[torrent_id] -> False
|
||||
field_value_key_error_count += 1
|
||||
pass
|
||||
except Exception, e:
|
||||
log.debug("%s", e)
|
||||
# Update all the changed values of the row
|
||||
if to_update:
|
||||
self.liststore.set(row.iter, *to_update)
|
||||
|
||||
if sort_settings[0] is not None:
|
||||
# Reenable sorting
|
||||
model.set_sort_column_id(*sort_settings)
|
||||
|
||||
self.treeview.thaw_child_notify()
|
||||
component.get("MenuBar").update_menu()
|
||||
|
||||
self.prev_status = status
|
||||
|
||||
def _on_get_torrents_status(self, status):
|
||||
@ -462,6 +493,15 @@ class TorrentView(listview.ListView, component.Component):
|
||||
if update:
|
||||
self.update()
|
||||
|
||||
def add_rows(self, state):
|
||||
"""Adds all the torrents from state to self.liststore"""
|
||||
torrent_id_column = self.columns["torrent_id"].column_indices[0]
|
||||
dirty_column = self.columns["dirty"].column_indices[0]
|
||||
for i, torrent_id in enumerate(state):
|
||||
# Insert a new row to the liststore
|
||||
row = self.liststore.append()
|
||||
self.liststore.set(row, torrent_id_column, torrent_id, dirty_column, True)
|
||||
|
||||
def remove_row(self, torrent_id):
|
||||
"""Removes a row with torrent_id"""
|
||||
for row in self.liststore:
|
||||
|
Loading…
x
Reference in New Issue
Block a user