diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 283c77fd0..3615c246e 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -429,8 +429,6 @@ class ListView: if self.liststore is not None: self.liststore.foreach(copy_row, (new_list, self.columns)) self.liststore = new_list - self.create_model_filter() - return def update_treeview_column(self, header, add=True): """Update TreeViewColumn based on ListView column mappings""" @@ -503,6 +501,8 @@ class ListView: del self.liststore_columns[index] # Create a new liststore self.create_new_liststore() + # Create new model for the treeview + self.create_model_filter() # Re-create the menu self.create_checklist_menu() @@ -547,7 +547,11 @@ class ListView: # Create a new list with the added column self.create_new_liststore() - if column_type == None: + # Happens only on columns added after the torrent list has been loaded + if self.model_filter: + self.create_model_filter() + + if column_type is None: return self.update_treeview_column(header) @@ -630,15 +634,14 @@ class ListView: def add_progress_column(self, header, col_types=[float, str], sortid=0, hidden=False, position=None, status_field=None, function=None, column_type="progress", - default=True): + sort_func=None, default=True): """Add a progress column to the listview.""" render = gtk.CellRendererProgress() self.add_column(header, render, col_types, hidden, position, status_field, sortid, function=function, column_type=column_type, value=0, text=1, - default=default) - + sort_func=sort_func, default=default) return True def add_texticon_column(self, header, col_types=[str, str], sortid=1, diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index c6eec1c3d..80f49fbc5 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -210,6 +210,17 @@ def seed_peer_column_sort(model, iter1, iter2, data): return queue_peer_seed_sort_function(v2, v4) return queue_peer_seed_sort_function(v1, v3) +def progress_sort(model, iter1, iter2, sort_column_id): + progress1 = model[iter1][sort_column_id] + progress2 = model[iter2][sort_column_id] + # Progress value is equal, so sort on state + if progress1 == progress2: + state1 = model[iter1][sort_column_id + 1] + state2 = model[iter2][sort_column_id + 1] + return cmp(state1, state2) + return cmp(progress1, progress2) + + class TorrentView(listview.ListView, component.Component): """TorrentView handles the listing of torrents.""" def __init__(self): @@ -256,7 +267,8 @@ class TorrentView(listview.ListView, component.Component): self.add_progress_column(_("Progress"), status_field=["progress", "state"], col_types=[float, str], - function=cell_data_progress) + function=cell_data_progress, + sort_func=progress_sort) self.add_func_column(_("Seeders"), listview.cell_data_peer, [int, int], status_field=["num_seeds", "total_seeds"], sort_func=seed_peer_column_sort, default=False)