diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 916e4571c..1d7454033 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -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 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)) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 9c6eae3d1..2a49c937b 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -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 tags() const; @@ -740,8 +742,9 @@ namespace BitTorrent CachedSettingValue m_maxRatioAction; CachedSettingValue m_savePath; CachedSettingValue m_downloadPath; - CachedSettingValue m_isSubcategoriesEnabled; CachedSettingValue m_isDownloadPathEnabled; + CachedSettingValue m_isSubcategoriesEnabled; + CachedSettingValue m_useCategoryPathsInManualMode; CachedSettingValue m_isAutoTMMDisabledByDefault; CachedSettingValue m_isDisableAutoTMMWhenCategoryChanged; CachedSettingValue m_isDisableAutoTMMWhenDefaultSavePathChanged; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index f89a88e98..645a5e761 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -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; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 915c14b37..89f3e21b7 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -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()); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index a53b10df6..091a80926 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1103,6 +1103,16 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually + + + + Use Category paths in Manual Mode + + + Resolve relative Save Path against appropriate Category path instead of Default one + + + diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 7bed59982..726573af5 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -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")) diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index a6514fcaa..77c5f2c3d 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -43,7 +43,7 @@ #include "base/utils/net.h" #include "base/utils/version.h" -inline const Utils::Version API_VERSION {2, 8, 5}; +inline const Utils::Version API_VERSION {2, 8, 6}; class APIController; class WebApplication;