From bb959ba46542e95bb7deb118e57b67b29cd66341 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 27 Jul 2008 15:41:46 +0000 Subject: [PATCH] BUGFIX: Disable ETA calculation when ETA column is hidden --- Changelog | 1 + src/bittorrent.cpp | 57 ++++++++++++++++++++++++++++--------- src/bittorrent.h | 2 ++ src/downloadingTorrents.cpp | 8 ++++++ 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Changelog b/Changelog index bfce3b1c7..cae323300 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,7 @@ - FEATURE: DHT is always ON (no longer used as fallback) - FEATURE: The number of DHT nodes is displayed - FEATURE: RSS can now be disabled from program preferences + - BUGFIX: Disable ETA calculation when ETA column is hidden - COSMETIC: Transfer speed, ratio and DHT nodes are displayed in status bar - COSMETIC: RSS Tab is now hidden as a default diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 225286100..8f474876a 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -43,7 +43,7 @@ #define MAX_TRACKER_ERRORS 2 // Main constructor -bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), queueingEnabled(false) { +bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), queueingEnabled(false), calculateETA(true) { // To avoid some exceptions fs::path::default_name_check(fs::no_check); // Creating bittorrent session @@ -154,6 +154,24 @@ void bittorrent::deleteBigRatios() { } } +void bittorrent::setETACalculation(bool enable) { + if(calculateETA != enable) { + calculateETA = enable; + if(calculateETA) { + foreach(QString hash, unfinishedTorrents) { + QTorrentHandle h = getTorrentHandle(hash); + if(!h.is_paused()) { + TorrentsStartData[hash] = h.total_payload_download(); + TorrentsStartTime[hash] = QDateTime::currentDateTime(); + } + } + } else { + TorrentsStartData.clear(); + TorrentsStartTime.clear(); + } + } +} + void bittorrent::setDownloadLimit(QString hash, long val) { QTorrentHandle h = getTorrentHandle(hash); if(h.is_valid()) @@ -505,6 +523,7 @@ void bittorrent::updateDownloadQueue() { // Calculate the ETA using GASA // GASA: global Average Speed Algorithm qlonglong bittorrent::getETA(QString hash) const { + Q_ASSERT(calculateETA); QTorrentHandle h = getTorrentHandle(hash); if(!h.is_valid()) return -1; switch(h.state()) { @@ -597,8 +616,10 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { torrentBackup.remove(file); } // Remove it from TorrentsStartTime hash table - TorrentsStartTime.remove(hash); - TorrentsStartData.remove(hash); + if(calculateETA) { + TorrentsStartTime.remove(hash); + TorrentsStartData.remove(hash); + } // Remove tracker errors trackersErrors.remove(hash); // Remove it from ratio table @@ -665,8 +686,10 @@ void bittorrent::setUnfinishedTorrent(QString hash) { if(!unfinishedTorrents.contains(hash)) { unfinishedTorrents << hash; QTorrentHandle h = getTorrentHandle(hash); - TorrentsStartData[hash] = h.total_payload_download(); - TorrentsStartTime[hash] = QDateTime::currentDateTime(); + if(calculateETA) { + TorrentsStartData[hash] = h.total_payload_download(); + TorrentsStartTime[hash] = QDateTime::currentDateTime(); + } } if(queueingEnabled) { // Remove it from uploadQueue @@ -703,8 +726,10 @@ void bittorrent::setFinishedTorrent(QString hash) { unfinishedTorrents.removeAt(index); } // Remove it from TorrentsStartTime hash table - TorrentsStartTime.remove(hash); - TorrentsStartData.remove(hash); + if(calculateETA) { + TorrentsStartTime.remove(hash); + TorrentsStartData.remove(hash); + } // Remove it from if(queueingEnabled) { downloadQueue->removeAll(hash); @@ -761,8 +786,10 @@ bool bittorrent::pauseTorrent(QString hash) { paused_file.close(); } // Remove it from TorrentsStartTime hash table - TorrentsStartTime.remove(hash); - TorrentsStartData.remove(hash); + if(calculateETA) { + TorrentsStartTime.remove(hash); + TorrentsStartData.remove(hash); + } return change; } @@ -773,8 +800,10 @@ bool bittorrent::resumeTorrent(QString hash) { if(h.is_valid() && h.is_paused()) { if(!(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash)))) { // Save Addition DateTime - TorrentsStartData[hash] = h.total_payload_download(); - TorrentsStartTime[hash] = QDateTime::currentDateTime(); + if(calculateETA) { + TorrentsStartData[hash] = h.total_payload_download(); + TorrentsStartTime[hash] = QDateTime::currentDateTime(); + } h.resume(); success = true; emit resumedTorrent(hash); @@ -1702,8 +1731,10 @@ void bittorrent::readAlerts() { qDebug("%s was paused after checking", hash.toUtf8().data()); } else { // Save Addition DateTime - TorrentsStartTime[hash] = QDateTime::currentDateTime(); - TorrentsStartData[hash] = h.total_payload_download(); + if(calculateETA) { + TorrentsStartTime[hash] = QDateTime::currentDateTime(); + TorrentsStartData[hash] = h.total_payload_download(); + } } emit torrentFinishedChecking(hash); } diff --git a/src/bittorrent.h b/src/bittorrent.h index f6c2501dd..6c96278b6 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -78,6 +78,7 @@ class bittorrent : public QObject{ QStringList *queuedDownloads; QStringList *uploadQueue; QStringList *queuedUploads; + bool calculateETA; protected: QString getSavePath(QString hash); @@ -175,6 +176,7 @@ class bittorrent : public QObject{ void setTimerScanInterval(int secs); void setMaxActiveDownloads(int val); void setMaxActiveTorrents(int val); + void setETACalculation(bool enable); protected slots: void scanDirectory(); diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index e2c1afd33..57f0b39c8 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -364,11 +364,19 @@ void DownloadingTorrents::hideOrShowColumn(int index) { downloadList->setColumnHidden(index, true); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); --nbVisibleColumns; + if(index == ETA) { + BTSession->setETACalculation(false); + qDebug("Disable ETA calculation"); + } } else { // User want to display the column downloadList->setColumnHidden(index, false); getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); ++nbVisibleColumns; + if(index == ETA) { + BTSession->setETACalculation(true); + qDebug("Enable ETA calculation"); + } } //resize all others non-hidden columns for(unsigned int i=0; i