From 568b2ddf752f9a1531dae4671d2114733f6f3b8f Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 28 Jun 2007 21:54:07 +0000 Subject: [PATCH] Progress of paused torrents is now correct on restart --- Changelog | 1 + src/GUI.cpp | 12 +++++++++++- src/bittorrent.cpp | 13 +++++++++++-- src/bittorrent.h | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index 8e015a673..efbe15991 100644 --- a/Changelog +++ b/Changelog @@ -18,6 +18,7 @@ - FEATURE: Better systems integration (buttons, dialogs...) - FEATURE: Filtered files are not allocated on the hard-drive anymore (if FS is compatible) - FEATURE: Added a way to link against static libtorrent (useful for deb packages) + - BUGFIX: Progress of paused torrents is now correct on restart - COSMETIC: Redesigned torrent properties a little - COSMETIC: Redesigned options a little - COSMETIC: Display more logs messages concerning features diff --git a/src/GUI.cpp b/src/GUI.cpp index 85e54f4fd..94589ab9a 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -478,9 +478,19 @@ void GUI::updateDlList(bool force){ try{ torrent_status torrentStatus = h.status(); QString fileHash = QString(misc::toString(h.info_hash()).c_str()); + int row = getRowFromHash(fileHash); + if(BTSession.getTorrentsToPauseAfterChecking().indexOf(fileHash) != -1){ + // Pause torrent if it finished checking and it is was supposed to be paused. + // This is a trick to see the progress of the pause torrents on startup + if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){ + qDebug("Paused torrent finished checking with state: %d", torrentStatus.state); + DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress)); + BTSession.pauseTorrent(fileHash); + continue; + } + } if(h.is_paused()) continue; if(finishedSHAs.indexOf(fileHash) != -1) continue; - int row = getRowFromHash(fileHash); if(row == -1){ qDebug("Info: Could not find filename in download list, adding it..."); restoreInDownloadList(h); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index bee8d63ea..af965a7f7 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -125,6 +125,11 @@ void bittorrent::pauseTorrent(const QString& hash){ QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); paused_file.open(QIODevice::WriteOnly | QIODevice::Text); paused_file.close(); + int index = torrentsToPauseAfterChecking.indexOf(hash); + if(index != -1) { + torrentsToPauseAfterChecking.removeAt(index); + qDebug("A torrent was paused just after checking, good"); + } } } @@ -240,10 +245,10 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString // Copy it to torrentBackup directory QFile::copy(file, newFile); } - //qDebug("Copied to torrent backup directory"); // Pause torrent if it was paused last time if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")){ - h.pause(); + torrentsToPauseAfterChecking << hash; + qDebug("Adding a torrent to the torrentsToPauseAfterChecking list"); } // Incremental download if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")){ @@ -296,6 +301,10 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString } } +QStringList bittorrent::getTorrentsToPauseAfterChecking() const{ + return torrentsToPauseAfterChecking; +} + // Set the maximum number of opened connections void bittorrent::setMaxConnections(int maxConnec){ s->set_max_connections(maxConnec); diff --git a/src/bittorrent.h b/src/bittorrent.h index 27005b084..a83660111 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -57,6 +57,7 @@ class bittorrent : public QObject{ downloadThread *downloader; QStringList supported_preview_extensions; QString defaultSavePath; + QStringList torrentsToPauseAfterChecking; protected: QString getSavePath(const QString& hash); @@ -76,6 +77,7 @@ class bittorrent : public QObject{ QList getFinishedTorrentHandles() const; session_status getSessionStatus() const; int getListenPort() const; + QStringList getTorrentsToPauseAfterChecking() const; public slots: void addTorrent(const QString& path, bool fromScanDir = false, const QString& from_url = QString());