Browse Source

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.
adaptive-webui-19844
Vladimir Golovnev 3 years ago committed by GitHub
parent
commit
facfa26eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      src/base/bittorrent/session.cpp
  2. 5
      src/base/bittorrent/session.h
  3. 9
      src/base/bittorrent/torrentimpl.cpp
  4. 3
      src/gui/optionsdialog.cpp
  5. 10
      src/gui/optionsdialog.ui
  6. 3
      src/webui/api/appcontroller.cpp
  7. 2
      src/webui/webapplication.h

49
src/base/bittorrent/session.cpp

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

5
src/base/bittorrent/session.h

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

9
src/base/bittorrent/torrentimpl.cpp

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

3
src/gui/optionsdialog.cpp

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

10
src/gui/optionsdialog.ui

@ -1103,6 +1103,16 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</property> </property>
</widget> </widget>
</item> </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> <item>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0"> <item row="0" column="0">

3
src/webui/api/appcontroller.cpp

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

2
src/webui/webapplication.h

@ -43,7 +43,7 @@
#include "base/utils/net.h" #include "base/utils/net.h"
#include "base/utils/version.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 APIController;
class WebApplication; class WebApplication;

Loading…
Cancel
Save