mirror of
https://github.com/transmission/transmission
synced 2025-01-03 13:35:36 +00:00
Qt: Correct 'Sort by Progress' for seeding torrents (#3814)
This commit is contained in:
parent
fe9aba702e
commit
b2b82a952c
3 changed files with 37 additions and 11 deletions
|
@ -54,27 +54,53 @@ bool Torrent::includesTracker(QString const& sitename) const
|
|||
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 b = that.getSeedRatioLimit();
|
||||
auto const a_ratio_limit = 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ public:
|
|||
return failed_ever_;
|
||||
}
|
||||
|
||||
int compareSeedRatio(Torrent const&) const;
|
||||
int compareSeedProgress(Torrent const&) const;
|
||||
int compareRatio(Torrent const&) const;
|
||||
int compareETA(Torrent const&) const;
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ bool TorrentFilter::lessThan(QModelIndex const& left, QModelIndex const& right)
|
|||
|
||||
if (val == 0)
|
||||
{
|
||||
val = a->compareSeedRatio(*b);
|
||||
val = a->compareSeedProgress(*b);
|
||||
}
|
||||
|
||||
if (val == 0)
|
||||
|
|
Loading…
Reference in a new issue