when sorting by activity and both torrents' upload and download speed is zero, use how many peers we're ready to upload to / download from as a secondary key.

This commit is contained in:
Jordan Lee 2013-01-30 00:20:51 +00:00
parent fdcba2a7fa
commit 4a059b79b8
2 changed files with 14 additions and 9 deletions

View File

@ -468,7 +468,6 @@ compare_by_activity (GtkTreeModel * m,
{
int ret = 0;
tr_torrent *ta, *tb;
const tr_stat *sa, *sb;
double aUp, aDown, bUp, bDown;
gtk_tree_model_get (m, a, MC_SPEED_UP, &aUp,
@ -479,15 +478,19 @@ compare_by_activity (GtkTreeModel * m,
MC_SPEED_DOWN, &bDown,
MC_TORRENT, &tb,
-1);
sa = tr_torrentStatCached (ta);
sb = tr_torrentStatCached (tb);
ret = compare_double (aUp+aDown, bUp+bDown);
if (!ret)
ret = compare_double (aUp+aDown, bUp+bDown);
{
const tr_stat * const sa = tr_torrentStatCached (ta);
const tr_stat * const sb = tr_torrentStatCached (tb);
ret = compare_uint64 (sa->peersSendingToUs + sa->peersGettingFromUs,
sb->peersSendingToUs + sb->peersGettingFromUs);
}
if (!ret)
ret = compare_uint64 (sa->uploadedEver, sb->uploadedEver);
if (!ret)
ret = compare_by_queue (m, a, b, user_data);
ret = compare_by_activity (m, a, b, user_data);
return ret;
}

View File

@ -100,12 +100,14 @@ TorrentFilter :: lessThan( const QModelIndex& left, const QModelIndex& right ) c
break;
case SortMode :: SORT_BY_ACTIVITY:
if( !val ) val = compare( a->downloadSpeed() + a->uploadSpeed(), b->downloadSpeed() + b->uploadSpeed() );
if( !val ) val = compare( a->uploadedEver(), b->uploadedEver() );
if( !val ) val = compare( a->peersWeAreUploadingTo() + a->webseedsWeAreDownloadingFrom(),
b->peersWeAreUploadingTo() + b->webseedsWeAreDownloadingFrom());
// fall through
case SortMode :: SORT_BY_STATE:
if( !val ) val = compare( a->hasError(), b->hasError() );
if( !val ) val = -compare( a->isPaused(), b->isPaused() );
if( !val ) val = compare( a->getActivity(), b->getActivity() );
if( !val ) val = -compare( a->queuePosition(), b->queuePosition() );
if( !val ) val = compare( a->hasError(), b->hasError() );
// fall through
case SortMode :: SORT_BY_PROGRESS:
if( !val ) val = compare( a->percentComplete(), b->percentComplete() );