From 5d161d2477d48bc6b3f5abcde21aa4401662fecf Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Fri, 4 Mar 2022 14:07:58 +0300 Subject: [PATCH] Correctly handle changing of global save paths --- src/base/bittorrent/session.cpp | 50 ++++++++++++++++++++++------- src/base/bittorrent/torrentimpl.cpp | 5 --- src/base/bittorrent/torrentimpl.h | 1 - src/gui/optionsdialog.ui | 2 +- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index eaf18588f..5f27f4437 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -563,7 +563,7 @@ void Session::setDownloadPathEnabled(const bool enabled) { m_isDownloadPathEnabled = enabled; for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleDownloadPathChanged(); + torrent->handleCategoryOptionsChanged(); } } @@ -2452,18 +2452,27 @@ void Session::setSavePath(const QString &path) const QString resolvedPath = (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, baseSavePath)); if (resolvedPath == m_savePath) return; - m_savePath = resolvedPath; - if (isDisableAutoTMMWhenDefaultSavePathChanged()) { + QSet affectedCatogories {{}}; // includes default (unnamed) category + for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) + { + const QString &categoryName = it.key(); + const CategoryOptions &categoryOptions = it.value(); + if (QDir::isRelativePath(categoryOptions.savePath)) + affectedCatogories.insert(categoryName); + } + for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->setAutoTMMEnabled(false); - } - else - { - for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleCategoryOptionsChanged(); + { + if (affectedCatogories.contains(torrent->category())) + torrent->setAutoTMMEnabled(false); + } } + + m_savePath = resolvedPath; + for (TorrentImpl *const torrent : asConst(m_torrents)) + torrent->handleCategoryOptionsChanged(); } void Session::setDownloadPath(const QString &path) @@ -2471,12 +2480,31 @@ void Session::setDownloadPath(const QString &path) const QString baseDownloadPath = specialFolderLocation(SpecialFolder::Downloads) + QLatin1String("/temp"); const QString resolvedPath = (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, baseDownloadPath)); if (resolvedPath != m_downloadPath) + return; + + if (isDisableAutoTMMWhenDefaultSavePathChanged()) { - m_downloadPath = resolvedPath; + QSet affectedCatogories {{}}; // includes default (unnamed) category + for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) + { + const QString &categoryName = it.key(); + const CategoryOptions &categoryOptions = it.value(); + const CategoryOptions::DownloadPathOption downloadPathOption = + categoryOptions.downloadPath.value_or(CategoryOptions::DownloadPathOption {isDownloadPathEnabled(), downloadPath()}); + if (downloadPathOption.enabled && QDir::isRelativePath(downloadPathOption.path)) + affectedCatogories.insert(categoryName); + } for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleDownloadPathChanged(); + { + if (affectedCatogories.contains(torrent->category())) + torrent->setAutoTMMEnabled(false); + } } + + m_downloadPath = resolvedPath; + for (TorrentImpl *const torrent : asConst(m_torrents)) + torrent->handleCategoryOptionsChanged(); } #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 7068083df..3ea3326ff 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1646,11 +1646,6 @@ void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus) updateStatus(nativeStatus); } -void TorrentImpl::handleDownloadPathChanged() -{ - adjustStorageLocation(); -} - void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob) { m_session->handleTorrentNeedSaveResumeData(this); diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index adbb8d5c1..d84020406 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -232,7 +232,6 @@ namespace BitTorrent void handleAlert(const lt::alert *a); void handleStateUpdate(const lt::torrent_status &nativeStatus); - void handleDownloadPathChanged(); void handleCategoryOptionsChanged(); void handleAppendExtensionToggled(); void saveResumeData(); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index a53b10df6..6681ac553 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1015,7 +1015,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually - When Default Save Path changed: + When Default Save/Incomplete Path changed: