Correctly handle changing of global save paths

This commit is contained in:
Vladimir Golovnev 2022-03-04 14:07:58 +03:00 committed by GitHub
commit 5d161d2477
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 18 deletions

View file

@ -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<QString> 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<QString> 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))

View file

@ -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);

View file

@ -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();

View file

@ -1015,7 +1015,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<item row="2" column="0">
<widget class="QLabel" name="labelCategoryDefaultPathChanged">
<property name="text">
<string>When Default Save Path changed:</string>
<string>When Default Save/Incomplete Path changed:</string>
</property>
</widget>
</item>