1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-03 05:25:52 +00:00

Qt: Correct 'Sort by Progress' for seeding torrents (#3814)

This commit is contained in:
OscarCunningham 2022-09-16 18:38:32 +01:00 committed by GitHub
parent fe9aba702e
commit b2b82a952c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 11 deletions

View file

@ -54,27 +54,53 @@ bool Torrent::includesTracker(QString const& sitename) const
return std::binary_search(std::begin(sitenames_), std::end(sitenames_), sitename); return std::binary_search(std::begin(sitenames_), std::end(sitenames_), sitename);
} }
int Torrent::compareSeedRatio(Torrent const& that) const int Torrent::compareSeedProgress(Torrent const& that) const
{ {
auto const a = getSeedRatioLimit(); auto const a_ratio_limit = getSeedRatioLimit();
auto const b = that.getSeedRatioLimit(); auto const b_ratio_limit = that.getSeedRatioLimit();
if (!a && !b) if (!a_ratio_limit && !b_ratio_limit)
{ {
return 0; return compareRatio(that);
} }
if (!a || !b) auto const a_ratio = ratio();
auto const b_ratio = that.ratio();
if (!a_ratio_limit)
{ {
return a ? -1 : 1; return b_ratio < *b_ratio_limit ? 1 : -1;
} }
if (*a < *b) if (!b_ratio_limit)
{
return a_ratio < *a_ratio_limit ? -1 : 1;
}
if (!(*a_ratio_limit > 0) && !(*b_ratio_limit > 0))
{
return compareRatio(that);
}
if (!(*a_ratio_limit > 0))
{
return 1;
}
if (!(*b_ratio_limit > 0))
{ {
return -1; return -1;
} }
if (*a > *b) double const a_progress = a_ratio / *a_ratio_limit;
double const b_progress = b_ratio / *b_ratio_limit;
if (a_progress < b_progress)
{
return -1;
}
if (a_progress > b_progress)
{ {
return 1; return 1;
} }

View file

@ -325,7 +325,7 @@ public:
return failed_ever_; return failed_ever_;
} }
int compareSeedRatio(Torrent const&) const; int compareSeedProgress(Torrent const&) const;
int compareRatio(Torrent const&) const; int compareRatio(Torrent const&) const;
int compareETA(Torrent const&) const; int compareETA(Torrent const&) const;

View file

@ -182,7 +182,7 @@ bool TorrentFilter::lessThan(QModelIndex const& left, QModelIndex const& right)
if (val == 0) if (val == 0)
{ {
val = a->compareSeedRatio(*b); val = a->compareSeedProgress(*b);
} }
if (val == 0) if (val == 0)