From 6dd034b8266c3e5a909108f8994eb25af8cfc5ec Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 30 Mar 2017 04:22:01 +0200 Subject: [PATCH 1/3] Fix sorting by progress (Qt client) Magnet transfers caused the by-progress sorting to become non-stable, as their percentComplete() could return NaN. This patch fixes this by preferring active downloads over magnet transfers, then sorting them by percentComplete(). --- qt/TorrentFilter.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qt/TorrentFilter.cc b/qt/TorrentFilter.cc index 07e4ca116..6fa78541f 100644 --- a/qt/TorrentFilter.cc +++ b/qt/TorrentFilter.cc @@ -155,6 +155,11 @@ bool TorrentFilter::lessThan(QModelIndex const& left, QModelIndex const& right) // fall through case SortMode::SORT_BY_PROGRESS: + if (a->isMagnet() != b->isMagnet()) + { + val = -compare(a->isMagnet(), b->isMagnet()); + } + if (val == 0) { val = compare(a->percentComplete(), b->percentComplete()); From c5e730c63a66342203a985057bca6ceac79bac7b Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 21 Apr 2017 00:43:35 +0300 Subject: [PATCH 2/3] Only compare magnet state if not yet different --- qt/TorrentFilter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt/TorrentFilter.cc b/qt/TorrentFilter.cc index 6fa78541f..5238ac7f2 100644 --- a/qt/TorrentFilter.cc +++ b/qt/TorrentFilter.cc @@ -155,7 +155,7 @@ bool TorrentFilter::lessThan(QModelIndex const& left, QModelIndex const& right) // fall through case SortMode::SORT_BY_PROGRESS: - if (a->isMagnet() != b->isMagnet()) + if (val == 0) { val = -compare(a->isMagnet(), b->isMagnet()); } From f1656bc2096f650b2441e9abc3d6609d535c61d4 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Mon, 1 May 2017 12:55:29 +0300 Subject: [PATCH 3/3] Don't return NaN from Torrent::percentComplete (Qt client) --- qt/Torrent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt/Torrent.h b/qt/Torrent.h index 84e2ad8c9..cd4cc0902 100644 --- a/qt/Torrent.h +++ b/qt/Torrent.h @@ -314,7 +314,7 @@ public: double percentComplete() const { - return haveTotal() / static_cast(totalSize()); + return totalSize() != 0 ? haveTotal() / static_cast(totalSize()) : 0; } double percentDone() const