1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Allow to use Category paths in "Manual" mode

If the option is enabled any relative save path will be resolved against an appropriate Category path instead of Global default one.

PR #16330.
This commit is contained in:
Vladimir Golovnev 2022-02-02 09:24:09 +03:00 committed by GitHub
parent 0012a3ede7
commit facfa26eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 21 deletions

View File

@ -396,8 +396,9 @@ Session::Session(QObject *parent)
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
, m_savePath(BITTORRENT_SESSION_KEY("DefaultSavePath"), specialFolderLocation(SpecialFolder::Downloads), Utils::Fs::toUniformPath)
, m_downloadPath(BITTORRENT_SESSION_KEY("TempPath"), specialFolderLocation(SpecialFolder::Downloads) + QLatin1String("/temp"), Utils::Fs::toUniformPath)
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY("SubcategoriesEnabled"), false)
, m_isDownloadPathEnabled(BITTORRENT_SESSION_KEY("TempPathEnabled"), false)
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY("SubcategoriesEnabled"), false)
, m_useCategoryPathsInManualMode(BITTORRENT_SESSION_KEY("UseCategoryPathsInManualMode"), false)
, m_isAutoTMMDisabledByDefault(BITTORRENT_SESSION_KEY("DisableAutoTMMByDefault"), true)
, m_isDisableAutoTMMWhenCategoryChanged(BITTORRENT_SESSION_KEY("DisableAutoTMMTriggers/CategoryChanged"), false)
, m_isDisableAutoTMMWhenDefaultSavePathChanged(BITTORRENT_SESSION_KEY("DisableAutoTMMTriggers/DefaultSavePathChanged"), true)
@ -821,6 +822,16 @@ void Session::setSubcategoriesEnabled(const bool value)
emit subcategoriesSupportChanged();
}
bool Session::useCategoryPathsInManualMode() const
{
return m_useCategoryPathsInManualMode;
}
void Session::setUseCategoryPathsInManualMode(const bool value)
{
m_useCategoryPathsInManualMode = value;
}
QSet<QString> Session::tags() const
{
return m_tags;
@ -2060,27 +2071,39 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
loadTorrentParams.ratioLimit = addTorrentParams.ratioLimit;
loadTorrentParams.seedingTimeLimit = addTorrentParams.seedingTimeLimit;
if (!loadTorrentParams.useAutoTMM)
{
loadTorrentParams.savePath = (QDir::isAbsolutePath(addTorrentParams.savePath)
? addTorrentParams.savePath
: Utils::Fs::resolvePath(addTorrentParams.savePath, savePath()));
const bool useDownloadPath = addTorrentParams.useDownloadPath.value_or(isDownloadPathEnabled());
if (useDownloadPath)
{
loadTorrentParams.downloadPath = (QDir::isAbsolutePath(addTorrentParams.downloadPath)
? addTorrentParams.downloadPath
: Utils::Fs::resolvePath(addTorrentParams.downloadPath, downloadPath()));
}
}
const QString category = addTorrentParams.category;
if (!category.isEmpty() && !m_categories.contains(category) && !addCategory(category))
loadTorrentParams.category = "";
else
loadTorrentParams.category = category;
if (!loadTorrentParams.useAutoTMM)
{
if (QDir::isAbsolutePath(addTorrentParams.savePath))
{
loadTorrentParams.savePath = addTorrentParams.savePath;
}
else
{
const QString basePath = useCategoryPathsInManualMode() ? categorySavePath(loadTorrentParams.category) : savePath();
loadTorrentParams.savePath = Utils::Fs::resolvePath(addTorrentParams.savePath, basePath);
}
const bool useDownloadPath = addTorrentParams.useDownloadPath.value_or(isDownloadPathEnabled());
if (useDownloadPath)
{
if (QDir::isAbsolutePath(addTorrentParams.downloadPath))
{
loadTorrentParams.downloadPath = addTorrentParams.downloadPath;
}
else
{
const QString basePath = useCategoryPathsInManualMode() ? categoryDownloadPath(loadTorrentParams.category) : downloadPath();
loadTorrentParams.downloadPath = Utils::Fs::resolvePath(addTorrentParams.downloadPath, basePath);
}
}
}
for (const QString &tag : addTorrentParams.tags)
{
if (hasTag(tag) || addTag(tag))

View File

@ -232,6 +232,8 @@ namespace BitTorrent
bool removeCategory(const QString &name);
bool isSubcategoriesEnabled() const;
void setSubcategoriesEnabled(bool value);
bool useCategoryPathsInManualMode() const;
void setUseCategoryPathsInManualMode(bool value);
static bool isValidTag(const QString &tag);
QSet<QString> tags() const;
@ -740,8 +742,9 @@ namespace BitTorrent
CachedSettingValue<int> m_maxRatioAction;
CachedSettingValue<QString> m_savePath;
CachedSettingValue<QString> m_downloadPath;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_isDownloadPathEnabled;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_useCategoryPathsInManualMode;
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;

View File

@ -405,7 +405,9 @@ void TorrentImpl::setSavePath(const QString &path)
{
Q_ASSERT(!isAutoTMMEnabled());
const QString resolvedPath = (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, m_session->savePath()));
const QString basePath = m_session->useCategoryPathsInManualMode()
? m_session->categorySavePath(category()) : m_session->savePath();
const QString resolvedPath = (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, basePath));
if (resolvedPath == savePath())
return;
@ -427,8 +429,9 @@ void TorrentImpl::setDownloadPath(const QString &path)
{
Q_ASSERT(!isAutoTMMEnabled());
const QString resolvedPath = ((path.isEmpty() || QDir::isAbsolutePath(path))
? path : Utils::Fs::resolvePath(path, m_session->downloadPath()));
const QString basePath = m_session->useCategoryPathsInManualMode()
? m_session->categoryDownloadPath(category()) : m_session->downloadPath();
const QString resolvedPath = ((path.isEmpty() || QDir::isAbsolutePath(path)) ? path : Utils::Fs::resolvePath(path, basePath));
if (resolvedPath == m_downloadPath)
return;

View File

@ -350,6 +350,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
// Downloads tab
connect(m_ui->textSavePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseSubcategories, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseCategoryPaths, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboTorrentCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboCategoryDefaultPathChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
@ -733,6 +734,7 @@ void OptionsDialog::saveOptions()
// Downloads preferences
session->setSavePath(Utils::Fs::expandPathAbs(m_ui->textSavePath->selectedPath()));
session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked());
session->setUseCategoryPathsInManualMode(m_ui->checkUseCategoryPaths->isChecked());
session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);
session->setDisableAutoTMMWhenCategorySavePathChanged(m_ui->comboCategoryChanged->currentIndex() == 1);
@ -999,6 +1001,7 @@ void OptionsDialog::loadOptions()
m_ui->textSavePath->setSelectedPath(session->savePath());
m_ui->checkUseSubcategories->setChecked(session->isSubcategoriesEnabled());
m_ui->checkUseCategoryPaths->setChecked(session->useCategoryPathsInManualMode());
m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
m_ui->comboCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategorySavePathChanged());

View File

@ -1103,6 +1103,16 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUseCategoryPaths">
<property name="text">
<string>Use Category paths in Manual Mode</string>
</property>
<property name="toolTip">
<string>Resolve relative Save Path against appropriate Category path instead of Default one</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">

View File

@ -115,6 +115,7 @@ void AppController::preferencesAction()
data["save_path"] = Utils::Fs::toNativePath(session->savePath());
data["temp_path_enabled"] = session->isDownloadPathEnabled();
data["temp_path"] = Utils::Fs::toNativePath(session->downloadPath());
data["use_category_paths_in_manual_mode"] = session->useCategoryPathsInManualMode();
data["export_dir"] = Utils::Fs::toNativePath(session->torrentExportDirectory());
data["export_dir_fin"] = Utils::Fs::toNativePath(session->finishedTorrentExportDirectory());
@ -404,6 +405,8 @@ void AppController::setPreferencesAction()
session->setDownloadPathEnabled(it.value().toBool());
if (hasKey("temp_path"))
session->setDownloadPath(it.value().toString());
if (hasKey("use_category_paths_in_manual_mode"))
session->setUseCategoryPathsInManualMode(it.value().toBool());
if (hasKey("export_dir"))
session->setTorrentExportDirectory(it.value().toString());
if (hasKey("export_dir_fin"))

View File

@ -43,7 +43,7 @@
#include "base/utils/net.h"
#include "base/utils/version.h"
inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 5};
inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 6};
class APIController;
class WebApplication;