diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 3d8d8040a..19ff9714d 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1998,6 +1998,8 @@ void Session::increaseTorrentsPriority(const QStringList &hashes) torrentQueuePositionUp(torrent->nativeHandle()); torrentQueue.pop(); } + + handleTorrentsPrioritiesChanged(); } void Session::decreaseTorrentsPriority(const QStringList &hashes) @@ -2022,6 +2024,8 @@ void Session::decreaseTorrentsPriority(const QStringList &hashes) for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key())); + + handleTorrentsPrioritiesChanged(); } void Session::topTorrentsPriority(const QStringList &hashes) @@ -2043,6 +2047,8 @@ void Session::topTorrentsPriority(const QStringList &hashes) torrentQueuePositionTop(torrent->nativeHandle()); torrentQueue.pop(); } + + handleTorrentsPrioritiesChanged(); } void Session::bottomTorrentsPriority(const QStringList &hashes) @@ -2067,6 +2073,8 @@ void Session::bottomTorrentsPriority(const QStringList &hashes) for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key())); + + handleTorrentsPrioritiesChanged(); } QHash Session::torrents() const @@ -2360,7 +2368,7 @@ void Session::generateResumeData(bool final) if (!final && !torrent->needSaveResumeData()) continue; if (torrent->hasMissingFiles() || torrent->hasError()) continue; - saveTorrentResumeData(torrent, final); + saveTorrentResumeData(torrent); } } @@ -3531,10 +3539,22 @@ void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent) updateSeedingLimitTimer(); } -void Session::saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave) +void Session::handleTorrentsPrioritiesChanged() +{ + // Save fastresume for the torrents that changed queue position + for (TorrentHandle *const torrent : torrents()) { + if (!torrent->isSeed()) { + // cached vs actual queue position, qBt starts queue at 1 + if (torrent->queuePosition() != (torrent->nativeHandle().queue_position() + 1)) + saveTorrentResumeData(torrent); + } + } +} + +void Session::saveTorrentResumeData(TorrentHandle *const torrent) { qDebug("Saving fastresume data for %s", qUtf8Printable(torrent->name())); - torrent->saveResumeData(finalSave); + torrent->saveResumeData(); ++m_numResumeData; } @@ -3653,8 +3673,11 @@ void Session::handleTorrentChecked(TorrentHandle *const torrent) void Session::handleTorrentFinished(TorrentHandle *const torrent) { - if (!torrent->hasError() && !torrent->hasMissingFiles()) + if (!torrent->hasError() && !torrent->hasMissingFiles()) { saveTorrentResumeData(torrent); + if (isQueueingSystemEnabled()) + handleTorrentsPrioritiesChanged(); + } emit torrentFinished(torrent); qDebug("Checking if the torrent contains torrent files to download"); diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 03859ae5b..c4cd2185f 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -481,6 +481,7 @@ namespace BitTorrent // TorrentHandle interface void handleTorrentShareLimitChanged(TorrentHandle *const torrent); + void handleTorrentsPrioritiesChanged(); void handleTorrentNameChanged(TorrentHandle *const torrent); void handleTorrentSavePathChanged(TorrentHandle *const torrent); void handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory); @@ -606,7 +607,7 @@ namespace BitTorrent void updateSeedingLimitTimer(); void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular); - void saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave = false); + void saveTorrentResumeData(TorrentHandle *const torrent); void handleAlert(libtorrent::alert *a); void dispatchTorrentAlert(libtorrent::alert *a); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 7fa4015e9..aa09fd355 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -504,11 +504,8 @@ bool TorrentHandle::needSaveResumeData() const return m_nativeHandle.need_save_resume_data(); } -void TorrentHandle::saveResumeData(bool updateStatus) +void TorrentHandle::saveResumeData() { - if (updateStatus) // to update queue_position, see discussion in PR #6154 - this->updateStatus(); - m_nativeHandle.save_resume_data(); } @@ -1646,7 +1643,7 @@ void TorrentHandle::handleSaveResumeDataAlert(const libtorrent::save_resume_data resumeData["qBt-name"] = m_name.toStdString(); resumeData["qBt-seedStatus"] = m_hasSeedStatus; resumeData["qBt-tempPathDisabled"] = m_tempPathDisabled; - resumeData["qBt-queuePosition"] = queuePosition(); + resumeData["qBt-queuePosition"] = (nativeHandle().queue_position() + 1); // qBt starts queue at 1 resumeData["qBt-hasRootFolder"] = m_hasRootFolder; m_session->handleTorrentResumeDataReady(this, resumeData); diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 88fe62946..3569ad91c 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -372,7 +372,7 @@ namespace BitTorrent void handleTempPathChanged(); void handleCategorySavePathChanged(); void handleAppendExtensionToggled(); - void saveResumeData(bool updateStatus = false); + void saveResumeData(); /** * @brief fraction of file pieces that are available at least from one peer