From 935de375b92913e8c89e660bb76f1b979d6f16f9 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 12 Jul 2009 07:27:24 +0000 Subject: [PATCH] - BUGFIX: Torrents with an infinite ratio are no longer affected by ratio_limit set in program preferences (closes #364730) --- Changelog | 1 + src/FinishedListDelegate.h | 4 +++- src/bittorrent.cpp | 18 ++++++++++-------- src/bittorrent.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 179567cc1..23f180bd5 100644 --- a/Changelog +++ b/Changelog @@ -6,6 +6,7 @@ - BUGFIX: Percentages no longer disapear with default cleanlooks style - BUGFIX: Cleanly fixed popup menus position in lists (no more workarounds) - BUGFIX: Fixed memory leak in search engine + - BUGFIX: Torrents with an infinite ratio are no longer affected by ratio_limit set in program preferences * Sun Apr 5 2009 - Christophe Dumez - v1.3.3 - BUGFIX: Fixed Web UI torrent upload form diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h index fdcc7b14b..2a678ece9 100644 --- a/src/FinishedListDelegate.h +++ b/src/FinishedListDelegate.h @@ -48,6 +48,8 @@ #define F_RATIO 4 #define F_HASH 5 +#define MAX_RATIO 100. + class FinishedListDelegate: public QItemDelegate { Q_OBJECT @@ -72,7 +74,7 @@ class FinishedListDelegate: public QItemDelegate { case F_RATIO:{ QItemDelegate::drawBackground(painter, opt, index); double ratio = index.data().toDouble(); - if(ratio > 100.) + if(ratio > MAX_RATIO) QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞")); else QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1))); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 02cacfc48..3c53a30b4 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -52,9 +52,10 @@ #include #define MAX_TRACKER_ERRORS 2 +#define MAX_RATIO 100. // Main constructor -bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false) { +bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false) { // To avoid some exceptions fs::path::default_name_check(fs::no_check); // Creating bittorrent session @@ -124,7 +125,7 @@ void bittorrent::preAllocateAllFiles(bool b) { } void bittorrent::deleteBigRatios() { - if(max_ratio == -1) return; + if(ratio_limit == -1) return; std::vector torrents = getTorrents(); std::vector::iterator torrentIT; for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { @@ -132,7 +133,8 @@ void bittorrent::deleteBigRatios() { if(!h.is_valid()) continue; if(h.is_seed()) { QString hash = h.hash(); - if(getRealRatio(hash) > max_ratio) { + float ratio = getRealRatio(hash); + if(ratio <= MAX_RATIO && ratio > ratio_limit) { QString fileName = h.name(); addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(fileName)); deleteTorrent(hash); @@ -981,19 +983,19 @@ void bittorrent::setGlobalRatio(float ratio) { // be automatically deleted void bittorrent::setDeleteRatio(float ratio) { if(ratio != -1 && ratio < 1.) ratio = 1.; - if(max_ratio == -1 && ratio != -1) { + if(ratio_limit == -1 && ratio != -1) { Q_ASSERT(!BigRatioTimer); BigRatioTimer = new QTimer(this); connect(BigRatioTimer, SIGNAL(timeout()), this, SLOT(deleteBigRatios())); BigRatioTimer->start(5000); } else { - if(max_ratio != -1 && ratio == -1) { + if(ratio_limit != -1 && ratio == -1) { delete BigRatioTimer; } } - if(max_ratio != ratio) { - max_ratio = ratio; - qDebug("* Set deleteRatio to %.1f", max_ratio); + if(ratio_limit != ratio) { + ratio_limit = ratio; + qDebug("* Set deleteRatio to %.1f", ratio_limit); deleteBigRatios(); } } diff --git a/src/bittorrent.h b/src/bittorrent.h index aebb29612..29e0e7cf0 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -67,7 +67,7 @@ class bittorrent : public QObject { bool addInPause; int maxConnecsPerTorrent; int maxUploadsPerTorrent; - float max_ratio; + float ratio_limit; bool UPnPEnabled; bool NATPMPEnabled; bool LSDEnabled;