diff options
Diffstat (limited to 'deluge/ui/gtkui/torrentview.py')
-rw-r--r-- | deluge/ui/gtkui/torrentview.py | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 79fd99831..b75f593fc 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -452,18 +452,12 @@ class TorrentView(listview.ListView, component.Component): {}, status_fields).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(load_new_list=True) def stop(self): """Stops the torrentview""" @@ -551,43 +545,66 @@ 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, load_new_list=False): + """Update the torrent view model with data we've received.""" filter_column = self.columns["filter"].column_indices[0] - # Update the torrent view model with data we've received status = self.status + if not load_new_list: + # Freeze notications while updating + self.treeview.freeze_child_notify() + + # Get the columns to update from one of the torrents + if status: + torrent_id = status.keys()[0] + 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): + # Only use columns that the torrent has in the state + if status_field in status[torrent_id]: + fields_to_update.append((column_index[i], status_field)) + for row in self.liststore: torrent_id = row[self.columns["torrent_id"].column_indices[0]] + # 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 - 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 + torrent_id_in_status = False + try: + torrent_status = status[torrent_id] + torrent_id_in_status = True + 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: + 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("Error while updating row for column " - "index %d, status field %r, value %r:" - " %s", column_index[0], status_field, - row_value, 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 + + # Find the fields to update + to_update = [] + for i, status_field in fields_to_update: + row_value = status[torrent_id][status_field] + if row[i] != row_value: + to_update.append(i) + to_update.append(row_value) + # Update fields in the liststore + if to_update: + self.liststore.set(row.iter, *to_update) + + if load_new_list: + # Create the model filter. This sets the model for the treeview and enables sorting. + self.create_model_filter() + else: + self.treeview.thaw_child_notify() component.get("MenuBar").update_menu() - self.prev_status = status def _on_get_torrents_status(self, status): @@ -602,6 +619,16 @@ class TorrentView(listview.ListView, component.Component): return gobject.idle_add(self.update_view) + 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] + filter_column = self.columns["filter"].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, filter_column, True) + def add_row(self, torrent_id, update=True): """Adds a new torrent row to the treeview""" # Make sure this torrent isn't already in the list |