Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ namespace BitTorrent
virtual bool removeCategory(const QString &name) = 0;
virtual bool isSubcategoriesEnabled() const = 0;
virtual void setSubcategoriesEnabled(bool value) = 0;
virtual bool useCategoryPathsInManualMode() const = 0;
virtual void setUseCategoryPathsInManualMode(bool value) = 0;

virtual Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
virtual Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;

virtual TagSet tags() const = 0;
virtual bool hasTag(const Tag &tag) const = 0;
Expand All @@ -188,15 +183,8 @@ namespace BitTorrent
// 1. Default save path changed
// 2. Torrent category save path changed
// 3. Torrent category changed
// (unless otherwise is specified)
virtual bool isAutoTMMDisabledByDefault() const = 0;
virtual void setAutoTMMDisabledByDefault(bool value) = 0;
virtual bool isDisableAutoTMMWhenCategoryChanged() const = 0;
virtual void setDisableAutoTMMWhenCategoryChanged(bool value) = 0;
virtual bool isDisableAutoTMMWhenDefaultSavePathChanged() const = 0;
virtual void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) = 0;
virtual bool isDisableAutoTMMWhenCategorySavePathChanged() const = 0;
virtual void setDisableAutoTMMWhenCategorySavePathChanged(bool value) = 0;

virtual qreal globalMaxRatio() const = 0;
virtual void setGlobalMaxRatio(qreal ratio) = 0;
Expand Down
120 changes: 3 additions & 117 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,7 @@ SessionImpl::SessionImpl(QObject *parent)
, m_downloadPath(BITTORRENT_SESSION_KEY(u"TempPath"_s), (savePath() / Path(u"temp"_s)))
, m_isDownloadPathEnabled(BITTORRENT_SESSION_KEY(u"TempPathEnabled"_s), false)
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY(u"SubcategoriesEnabled"_s), false)
, m_useCategoryPathsInManualMode(BITTORRENT_SESSION_KEY(u"UseCategoryPathsInManualMode"_s), false)
, m_isAutoTMMDisabledByDefault(BITTORRENT_SESSION_KEY(u"DisableAutoTMMByDefault"_s), true)
, m_isDisableAutoTMMWhenCategoryChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/CategoryChanged"_s), false)
, m_isDisableAutoTMMWhenDefaultSavePathChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/DefaultSavePathChanged"_s), true)
, m_isDisableAutoTMMWhenCategorySavePathChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/CategorySavePathChanged"_s), true)
, m_isTrackerEnabled(BITTORRENT_KEY(u"TrackerEnabled"_s), false)
, m_peerTurnover(BITTORRENT_SESSION_KEY(u"PeerTurnover"_s), 4)
, m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY(u"PeerTurnoverCutOff"_s), 90)
Expand Down Expand Up @@ -1035,18 +1031,6 @@ bool SessionImpl::editCategory(const QString &name, const CategoryOptions &optio
if (options == currentOptions)
return false;

if (isDisableAutoTMMWhenCategorySavePathChanged())
{
// This should be done before changing the category options
// to prevent the torrent from being moved at the new save path.

for (TorrentImpl *const torrent : asConst(m_torrents))
{
if (torrent->category() == name)
torrent->setAutoTMMEnabled(false);
}
}

currentOptions = options;
storeCategories();

Expand Down Expand Up @@ -1124,31 +1108,6 @@ void SessionImpl::setSubcategoriesEnabled(const bool value)
emit subcategoriesSupportChanged();
}

bool SessionImpl::useCategoryPathsInManualMode() const
{
return m_useCategoryPathsInManualMode;
}

void SessionImpl::setUseCategoryPathsInManualMode(const bool value)
{
m_useCategoryPathsInManualMode = value;
}

Path SessionImpl::suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const
{
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
const auto path = (useCategoryPaths ? categorySavePath(categoryName) : savePath());
return path;
}

Path SessionImpl::suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const
{
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
const auto categoryDownloadPath = this->categoryDownloadPath(categoryName);
const auto path = ((useCategoryPaths && !categoryDownloadPath.isEmpty()) ? categoryDownloadPath : downloadPath());
return path;
}

TagSet SessionImpl::tags() const
{
return m_tags;
Expand Down Expand Up @@ -1196,36 +1155,6 @@ void SessionImpl::setAutoTMMDisabledByDefault(const bool value)
m_isAutoTMMDisabledByDefault = value;
}

bool SessionImpl::isDisableAutoTMMWhenCategoryChanged() const
{
return m_isDisableAutoTMMWhenCategoryChanged;
}

void SessionImpl::setDisableAutoTMMWhenCategoryChanged(const bool value)
{
m_isDisableAutoTMMWhenCategoryChanged = value;
}

bool SessionImpl::isDisableAutoTMMWhenDefaultSavePathChanged() const
{
return m_isDisableAutoTMMWhenDefaultSavePathChanged;
}

void SessionImpl::setDisableAutoTMMWhenDefaultSavePathChanged(const bool value)
{
m_isDisableAutoTMMWhenDefaultSavePathChanged = value;
}

bool SessionImpl::isDisableAutoTMMWhenCategorySavePathChanged() const
{
return m_isDisableAutoTMMWhenCategorySavePathChanged;
}

void SessionImpl::setDisableAutoTMMWhenCategorySavePathChanged(const bool value)
{
m_isDisableAutoTMMWhenCategorySavePathChanged = value;
}

bool SessionImpl::isAddTorrentToQueueTop() const
{
return m_isAddTorrentToQueueTop;
Expand Down Expand Up @@ -2666,8 +2595,9 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
else
loadTorrentParams.category = category;

const auto defaultSavePath = suggestedSavePath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
const auto defaultDownloadPath = suggestedDownloadPath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
const auto defaultSavePath = categorySavePath(loadTorrentParams.category);
const auto categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
const auto defaultDownloadPath = !categoryDownloadPath.isEmpty() ? categoryDownloadPath : downloadPath();

loadTorrentParams.useAutoTMM = addTorrentParams.useAutoTMM.value_or(
addTorrentParams.savePath.isEmpty() && addTorrentParams.downloadPath.isEmpty() && !isAutoTMMDisabledByDefault());
Expand Down Expand Up @@ -3285,27 +3215,6 @@ void SessionImpl::setSavePath(const Path &path)
if (newPath == m_savePath)
return;

if (isDisableAutoTMMWhenDefaultSavePathChanged())
{
// This should be done before changing the save path
// to prevent the torrent from being moved at the new save path.

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 (categoryOptions.savePath.isRelative())
affectedCatogories.insert(categoryName);
}

for (TorrentImpl *const torrent : asConst(m_torrents))
{
if (affectedCatogories.contains(torrent->category()))
torrent->setAutoTMMEnabled(false);
}
}

m_savePath = newPath;
for (TorrentImpl *const torrent : asConst(m_torrents))
torrent->handleCategoryOptionsChanged();
Expand All @@ -3325,29 +3234,6 @@ void SessionImpl::setDownloadPath(const Path &path)
if (newPath == m_downloadPath)
return;

if (isDisableAutoTMMWhenDefaultSavePathChanged())
{
// This should be done before changing the save path
// to prevent the torrent from being moved at the new save path.

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 DownloadPathOption downloadPathOption =
categoryOptions.downloadPath.value_or(DownloadPathOption {isDownloadPathEnabled(), downloadPath()});
if (downloadPathOption.enabled && downloadPathOption.path.isRelative())
affectedCatogories.insert(categoryName);
}

for (TorrentImpl *const torrent : asConst(m_torrents))
{
if (affectedCatogories.contains(torrent->category()))
torrent->setAutoTMMEnabled(false);
}
}

m_downloadPath = newPath;
for (TorrentImpl *const torrent : asConst(m_torrents))
torrent->handleCategoryOptionsChanged();
Expand Down
15 changes: 0 additions & 15 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ namespace BitTorrent
bool removeCategory(const QString &name) override;
bool isSubcategoriesEnabled() const override;
void setSubcategoriesEnabled(bool value) override;
bool useCategoryPathsInManualMode() const override;
void setUseCategoryPathsInManualMode(bool value) override;

Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;

TagSet tags() const override;
bool hasTag(const Tag &tag) const override;
Expand All @@ -171,12 +166,6 @@ namespace BitTorrent

bool isAutoTMMDisabledByDefault() const override;
void setAutoTMMDisabledByDefault(bool value) override;
bool isDisableAutoTMMWhenCategoryChanged() const override;
void setDisableAutoTMMWhenCategoryChanged(bool value) override;
bool isDisableAutoTMMWhenDefaultSavePathChanged() const override;
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) override;
bool isDisableAutoTMMWhenCategorySavePathChanged() const override;
void setDisableAutoTMMWhenCategorySavePathChanged(bool value) override;

qreal globalMaxRatio() const override;
void setGlobalMaxRatio(qreal ratio) override;
Expand Down Expand Up @@ -755,11 +744,7 @@ namespace BitTorrent
CachedSettingValue<Path> m_downloadPath;
CachedSettingValue<bool> m_isDownloadPathEnabled;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_useCategoryPathsInManualMode;
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
CachedSettingValue<bool> m_isTrackerEnabled;
CachedSettingValue<int> m_peerTurnover;
CachedSettingValue<int> m_peerTurnoverCutoff;
Expand Down
13 changes: 2 additions & 11 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ void TorrentImpl::setSavePath(const Path &path)
if (isAutoTMMEnabled()) [[unlikely]]
return;

const Path basePath = m_session->useCategoryPathsInManualMode()
? m_session->categorySavePath(category()) : m_session->savePath();
const Path basePath = m_session->categorySavePath(category());
const Path resolvedPath = (path.isAbsolute() ? path : (basePath / path));
if (resolvedPath == savePath())
return;
Expand Down Expand Up @@ -534,8 +533,7 @@ void TorrentImpl::setDownloadPath(const Path &path)
if (isAutoTMMEnabled()) [[unlikely]]
return;

const Path basePath = m_session->useCategoryPathsInManualMode()
? m_session->categoryDownloadPath(category()) : m_session->downloadPath();
const Path basePath = m_session->categoryDownloadPath(category());
const Path resolvedPath = (path.isEmpty() || path.isAbsolute()) ? path : (basePath / path);
if (resolvedPath == m_downloadPath)
return;
Expand Down Expand Up @@ -1623,13 +1621,6 @@ bool TorrentImpl::setCategory(const QString &category)
if (!category.isEmpty() && !m_session->categories().contains(category))
return false;

if (m_session->isDisableAutoTMMWhenCategoryChanged())
{
// This should be done before changing the category name
// to prevent the torrent from being moved at the path of new category.
setAutoTMMEnabled(false);
}

const QString oldCategory = m_category;
m_category = category;
deferredRequestResumeData();
Expand Down
7 changes: 3 additions & 4 deletions src/gui/addtorrentparamswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ void AddTorrentParamsWidget::populateDefaultPaths()
{
const auto *btSession = BitTorrent::Session::instance();

const Path defaultSavePath = btSession->suggestedSavePath(
m_ui->categoryComboBox->currentText(), toOptionalBool(m_ui->comboTTM->currentData()));
const Path defaultSavePath = btSession->categorySavePath(m_ui->categoryComboBox->currentText());
m_ui->savePathEdit->setPlaceholder(defaultSavePath);

populateDefaultDownloadPath();
Expand All @@ -351,8 +350,8 @@ void AddTorrentParamsWidget::populateDefaultDownloadPath()
const std::optional<bool> useDownloadPath = toOptionalBool(m_ui->useDownloadPathComboBox->currentData());
if (useDownloadPath.value_or(btSession->isDownloadPathEnabled()))
{
const Path defaultDownloadPath = btSession->suggestedDownloadPath(
m_ui->categoryComboBox->currentText(), toOptionalBool(m_ui->comboTTM->currentData()));
const Path categoryDownloadPath = btSession->categoryDownloadPath(m_ui->categoryComboBox->currentText());
const Path defaultDownloadPath = !categoryDownloadPath.isEmpty() ? categoryDownloadPath : btSession->downloadPath();
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
}
else
Expand Down
15 changes: 0 additions & 15 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,7 @@ void OptionsDialog::loadDownloadsTabOptions()
m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());

m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
m_ui->comboCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategorySavePathChanged());
m_ui->comboCategoryDefaultPathChanged->setCurrentIndex(session->isDisableAutoTMMWhenDefaultSavePathChanged());

m_ui->checkUseSubcategories->setChecked(session->isSubcategoriesEnabled());
m_ui->checkUseCategoryPaths->setChecked(session->useCategoryPathsInManualMode());

m_ui->textSavePath->setDialogCaption(tr("Choose a save directory"));
m_ui->textSavePath->setMode(FileSystemPathEdit::Mode::DirectorySave);
Expand Down Expand Up @@ -726,12 +721,8 @@ void OptionsDialog::loadDownloadsTabOptions()
connect(m_ui->checkRecursiveDownload, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);

connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboTorrentCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->comboCategoryDefaultPathChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);

connect(m_ui->checkUseSubcategories, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseCategoryPaths, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);

connect(m_ui->textSavePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
connect(m_ui->textDownloadPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
Expand Down Expand Up @@ -798,13 +789,7 @@ void OptionsDialog::saveDownloadsTabOptions() const
pref->setRecursiveDownloadEnabled(m_ui->checkRecursiveDownload->isChecked());

session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);
session->setDisableAutoTMMWhenCategorySavePathChanged(m_ui->comboCategoryChanged->currentIndex() == 1);
session->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui->comboCategoryDefaultPathChanged->currentIndex() == 1);

session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked());
session->setUseCategoryPathsInManualMode(m_ui->checkUseCategoryPaths->isChecked());

session->setSavePath(Path(m_ui->textSavePath->selectedPath()));
session->setDownloadPathEnabled(m_ui->checkUseDownloadPath->isChecked());
session->setDownloadPath(m_ui->textDownloadPath->selectedPath());
Expand Down
Loading
Loading