From 1557bf8882bc5979f3b174864df8476f5de7ae64 Mon Sep 17 00:00:00 2001 From: bendikro Date: Thu, 17 Sep 2015 19:36:36 +0200 Subject: [PATCH] [#2754] [GTKUI] Fix Deluge isn't sorting torrents properly --- deluge/ui/gtkui/listview.py | 4 ++-- deluge/ui/gtkui/torrentview.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 5a0c42e51..d6f489b7c 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -597,14 +597,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", - tooltip=None, default=True): + tooltip=None, 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, - tooltip=tooltip, default=default) + tooltip=tooltip, sort_func=sort_func, default=default) return True diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 6febbf32e..726d0da71 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -71,6 +71,17 @@ def seed_peer_column_sort(model, iter1, iter2, data): 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 SearchBox(object): def __init__(self, torrentview): self.torrentview = torrentview @@ -244,7 +255,8 @@ class TorrentView(ListView, component.Component): self.add_progress_column(_("Progress"), status_field=["progress", "state"], col_types=[float, str], - function=funcs.cell_data_progress) + function=funcs.cell_data_progress, + sort_func=progress_sort) self.add_func_column(_("Seeds"), funcs.cell_data_peer, [int, int], status_field=["num_seeds", "total_seeds"], sort_func=seed_peer_column_sort, default=False)