Skip to content

Commit 00e3314

Browse files
committed
Simplify save paths management
1 parent c45dfb6 commit 00e3314

File tree

10 files changed

+9
-362
lines changed

10 files changed

+9
-362
lines changed

src/base/bittorrent/session.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ namespace BitTorrent
167167
virtual bool removeCategory(const QString &name) = 0;
168168
virtual bool isSubcategoriesEnabled() const = 0;
169169
virtual void setSubcategoriesEnabled(bool value) = 0;
170-
virtual bool useCategoryPathsInManualMode() const = 0;
171-
virtual void setUseCategoryPathsInManualMode(bool value) = 0;
172-
173-
virtual Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
174-
virtual Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
175170

176171
virtual TagSet tags() const = 0;
177172
virtual bool hasTag(const Tag &tag) const = 0;
@@ -188,15 +183,8 @@ namespace BitTorrent
188183
// 1. Default save path changed
189184
// 2. Torrent category save path changed
190185
// 3. Torrent category changed
191-
// (unless otherwise is specified)
192186
virtual bool isAutoTMMDisabledByDefault() const = 0;
193187
virtual void setAutoTMMDisabledByDefault(bool value) = 0;
194-
virtual bool isDisableAutoTMMWhenCategoryChanged() const = 0;
195-
virtual void setDisableAutoTMMWhenCategoryChanged(bool value) = 0;
196-
virtual bool isDisableAutoTMMWhenDefaultSavePathChanged() const = 0;
197-
virtual void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) = 0;
198-
virtual bool isDisableAutoTMMWhenCategorySavePathChanged() const = 0;
199-
virtual void setDisableAutoTMMWhenCategorySavePathChanged(bool value) = 0;
200188

201189
virtual qreal globalMaxRatio() const = 0;
202190
virtual void setGlobalMaxRatio(qreal ratio) = 0;

src/base/bittorrent/sessionimpl.cpp

Lines changed: 3 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,7 @@ SessionImpl::SessionImpl(QObject *parent)
556556
, m_downloadPath(BITTORRENT_SESSION_KEY(u"TempPath"_s), (savePath() / Path(u"temp"_s)))
557557
, m_isDownloadPathEnabled(BITTORRENT_SESSION_KEY(u"TempPathEnabled"_s), false)
558558
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY(u"SubcategoriesEnabled"_s), false)
559-
, m_useCategoryPathsInManualMode(BITTORRENT_SESSION_KEY(u"UseCategoryPathsInManualMode"_s), false)
560559
, m_isAutoTMMDisabledByDefault(BITTORRENT_SESSION_KEY(u"DisableAutoTMMByDefault"_s), true)
561-
, m_isDisableAutoTMMWhenCategoryChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/CategoryChanged"_s), false)
562-
, m_isDisableAutoTMMWhenDefaultSavePathChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/DefaultSavePathChanged"_s), true)
563-
, m_isDisableAutoTMMWhenCategorySavePathChanged(BITTORRENT_SESSION_KEY(u"DisableAutoTMMTriggers/CategorySavePathChanged"_s), true)
564560
, m_isTrackerEnabled(BITTORRENT_KEY(u"TrackerEnabled"_s), false)
565561
, m_peerTurnover(BITTORRENT_SESSION_KEY(u"PeerTurnover"_s), 4)
566562
, m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY(u"PeerTurnoverCutOff"_s), 90)
@@ -1035,18 +1031,6 @@ bool SessionImpl::editCategory(const QString &name, const CategoryOptions &optio
10351031
if (options == currentOptions)
10361032
return false;
10371033

1038-
if (isDisableAutoTMMWhenCategorySavePathChanged())
1039-
{
1040-
// This should be done before changing the category options
1041-
// to prevent the torrent from being moved at the new save path.
1042-
1043-
for (TorrentImpl *const torrent : asConst(m_torrents))
1044-
{
1045-
if (torrent->category() == name)
1046-
torrent->setAutoTMMEnabled(false);
1047-
}
1048-
}
1049-
10501034
currentOptions = options;
10511035
storeCategories();
10521036

@@ -1124,31 +1108,6 @@ void SessionImpl::setSubcategoriesEnabled(const bool value)
11241108
emit subcategoriesSupportChanged();
11251109
}
11261110

1127-
bool SessionImpl::useCategoryPathsInManualMode() const
1128-
{
1129-
return m_useCategoryPathsInManualMode;
1130-
}
1131-
1132-
void SessionImpl::setUseCategoryPathsInManualMode(const bool value)
1133-
{
1134-
m_useCategoryPathsInManualMode = value;
1135-
}
1136-
1137-
Path SessionImpl::suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const
1138-
{
1139-
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
1140-
const auto path = (useCategoryPaths ? categorySavePath(categoryName) : savePath());
1141-
return path;
1142-
}
1143-
1144-
Path SessionImpl::suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const
1145-
{
1146-
const bool useCategoryPaths = useAutoTMM.value_or(!isAutoTMMDisabledByDefault()) || useCategoryPathsInManualMode();
1147-
const auto categoryDownloadPath = this->categoryDownloadPath(categoryName);
1148-
const auto path = ((useCategoryPaths && !categoryDownloadPath.isEmpty()) ? categoryDownloadPath : downloadPath());
1149-
return path;
1150-
}
1151-
11521111
TagSet SessionImpl::tags() const
11531112
{
11541113
return m_tags;
@@ -1196,36 +1155,6 @@ void SessionImpl::setAutoTMMDisabledByDefault(const bool value)
11961155
m_isAutoTMMDisabledByDefault = value;
11971156
}
11981157

1199-
bool SessionImpl::isDisableAutoTMMWhenCategoryChanged() const
1200-
{
1201-
return m_isDisableAutoTMMWhenCategoryChanged;
1202-
}
1203-
1204-
void SessionImpl::setDisableAutoTMMWhenCategoryChanged(const bool value)
1205-
{
1206-
m_isDisableAutoTMMWhenCategoryChanged = value;
1207-
}
1208-
1209-
bool SessionImpl::isDisableAutoTMMWhenDefaultSavePathChanged() const
1210-
{
1211-
return m_isDisableAutoTMMWhenDefaultSavePathChanged;
1212-
}
1213-
1214-
void SessionImpl::setDisableAutoTMMWhenDefaultSavePathChanged(const bool value)
1215-
{
1216-
m_isDisableAutoTMMWhenDefaultSavePathChanged = value;
1217-
}
1218-
1219-
bool SessionImpl::isDisableAutoTMMWhenCategorySavePathChanged() const
1220-
{
1221-
return m_isDisableAutoTMMWhenCategorySavePathChanged;
1222-
}
1223-
1224-
void SessionImpl::setDisableAutoTMMWhenCategorySavePathChanged(const bool value)
1225-
{
1226-
m_isDisableAutoTMMWhenCategorySavePathChanged = value;
1227-
}
1228-
12291158
bool SessionImpl::isAddTorrentToQueueTop() const
12301159
{
12311160
return m_isAddTorrentToQueueTop;
@@ -2666,8 +2595,9 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
26662595
else
26672596
loadTorrentParams.category = category;
26682597

2669-
const auto defaultSavePath = suggestedSavePath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
2670-
const auto defaultDownloadPath = suggestedDownloadPath(loadTorrentParams.category, addTorrentParams.useAutoTMM);
2598+
const auto defaultSavePath = categorySavePath(loadTorrentParams.category);
2599+
const auto categoryDownloadPath = this->categoryDownloadPath(loadTorrentParams.category);
2600+
const auto defaultDownloadPath = !categoryDownloadPath.isEmpty() ? categoryDownloadPath : downloadPath();
26712601

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

3288-
if (isDisableAutoTMMWhenDefaultSavePathChanged())
3289-
{
3290-
// This should be done before changing the save path
3291-
// to prevent the torrent from being moved at the new save path.
3292-
3293-
QSet<QString> affectedCatogories {{}}; // includes default (unnamed) category
3294-
for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it)
3295-
{
3296-
const QString &categoryName = it.key();
3297-
const CategoryOptions &categoryOptions = it.value();
3298-
if (categoryOptions.savePath.isRelative())
3299-
affectedCatogories.insert(categoryName);
3300-
}
3301-
3302-
for (TorrentImpl *const torrent : asConst(m_torrents))
3303-
{
3304-
if (affectedCatogories.contains(torrent->category()))
3305-
torrent->setAutoTMMEnabled(false);
3306-
}
3307-
}
3308-
33093218
m_savePath = newPath;
33103219
for (TorrentImpl *const torrent : asConst(m_torrents))
33113220
torrent->handleCategoryOptionsChanged();
@@ -3325,29 +3234,6 @@ void SessionImpl::setDownloadPath(const Path &path)
33253234
if (newPath == m_downloadPath)
33263235
return;
33273236

3328-
if (isDisableAutoTMMWhenDefaultSavePathChanged())
3329-
{
3330-
// This should be done before changing the save path
3331-
// to prevent the torrent from being moved at the new save path.
3332-
3333-
QSet<QString> affectedCatogories {{}}; // includes default (unnamed) category
3334-
for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it)
3335-
{
3336-
const QString &categoryName = it.key();
3337-
const CategoryOptions &categoryOptions = it.value();
3338-
const DownloadPathOption downloadPathOption =
3339-
categoryOptions.downloadPath.value_or(DownloadPathOption {isDownloadPathEnabled(), downloadPath()});
3340-
if (downloadPathOption.enabled && downloadPathOption.path.isRelative())
3341-
affectedCatogories.insert(categoryName);
3342-
}
3343-
3344-
for (TorrentImpl *const torrent : asConst(m_torrents))
3345-
{
3346-
if (affectedCatogories.contains(torrent->category()))
3347-
torrent->setAutoTMMEnabled(false);
3348-
}
3349-
}
3350-
33513237
m_downloadPath = newPath;
33523238
for (TorrentImpl *const torrent : asConst(m_torrents))
33533239
torrent->handleCategoryOptionsChanged();

src/base/bittorrent/sessionimpl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ namespace BitTorrent
158158
bool removeCategory(const QString &name) override;
159159
bool isSubcategoriesEnabled() const override;
160160
void setSubcategoriesEnabled(bool value) override;
161-
bool useCategoryPathsInManualMode() const override;
162-
void setUseCategoryPathsInManualMode(bool value) override;
163-
164-
Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
165-
Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
166161

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

172167
bool isAutoTMMDisabledByDefault() const override;
173168
void setAutoTMMDisabledByDefault(bool value) override;
174-
bool isDisableAutoTMMWhenCategoryChanged() const override;
175-
void setDisableAutoTMMWhenCategoryChanged(bool value) override;
176-
bool isDisableAutoTMMWhenDefaultSavePathChanged() const override;
177-
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) override;
178-
bool isDisableAutoTMMWhenCategorySavePathChanged() const override;
179-
void setDisableAutoTMMWhenCategorySavePathChanged(bool value) override;
180169

181170
qreal globalMaxRatio() const override;
182171
void setGlobalMaxRatio(qreal ratio) override;
@@ -755,11 +744,7 @@ namespace BitTorrent
755744
CachedSettingValue<Path> m_downloadPath;
756745
CachedSettingValue<bool> m_isDownloadPathEnabled;
757746
CachedSettingValue<bool> m_isSubcategoriesEnabled;
758-
CachedSettingValue<bool> m_useCategoryPathsInManualMode;
759747
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
760-
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
761-
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
762-
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
763748
CachedSettingValue<bool> m_isTrackerEnabled;
764749
CachedSettingValue<int> m_peerTurnover;
765750
CachedSettingValue<int> m_peerTurnoverCutoff;

src/base/bittorrent/torrentimpl.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ void TorrentImpl::setSavePath(const Path &path)
505505
if (isAutoTMMEnabled()) [[unlikely]]
506506
return;
507507

508-
const Path basePath = m_session->useCategoryPathsInManualMode()
509-
? m_session->categorySavePath(category()) : m_session->savePath();
508+
const Path basePath = m_session->categorySavePath(category());
510509
const Path resolvedPath = (path.isAbsolute() ? path : (basePath / path));
511510
if (resolvedPath == savePath())
512511
return;
@@ -534,8 +533,7 @@ void TorrentImpl::setDownloadPath(const Path &path)
534533
if (isAutoTMMEnabled()) [[unlikely]]
535534
return;
536535

537-
const Path basePath = m_session->useCategoryPathsInManualMode()
538-
? m_session->categoryDownloadPath(category()) : m_session->downloadPath();
536+
const Path basePath = m_session->categoryDownloadPath(category());
539537
const Path resolvedPath = (path.isEmpty() || path.isAbsolute()) ? path : (basePath / path);
540538
if (resolvedPath == m_downloadPath)
541539
return;
@@ -1623,13 +1621,6 @@ bool TorrentImpl::setCategory(const QString &category)
16231621
if (!category.isEmpty() && !m_session->categories().contains(category))
16241622
return false;
16251623

1626-
if (m_session->isDisableAutoTMMWhenCategoryChanged())
1627-
{
1628-
// This should be done before changing the category name
1629-
// to prevent the torrent from being moved at the path of new category.
1630-
setAutoTMMEnabled(false);
1631-
}
1632-
16331624
const QString oldCategory = m_category;
16341625
m_category = category;
16351626
deferredRequestResumeData();

src/gui/addtorrentparamswidget.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ void AddTorrentParamsWidget::populateDefaultPaths()
337337
{
338338
const auto *btSession = BitTorrent::Session::instance();
339339

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

344343
populateDefaultDownloadPath();
@@ -351,8 +350,8 @@ void AddTorrentParamsWidget::populateDefaultDownloadPath()
351350
const std::optional<bool> useDownloadPath = toOptionalBool(m_ui->useDownloadPathComboBox->currentData());
352351
if (useDownloadPath.value_or(btSession->isDownloadPathEnabled()))
353352
{
354-
const Path defaultDownloadPath = btSession->suggestedDownloadPath(
355-
m_ui->categoryComboBox->currentText(), toOptionalBool(m_ui->comboTTM->currentData()));
353+
const Path categoryDownloadPath = btSession->categoryDownloadPath(m_ui->categoryComboBox->currentText());
354+
const Path defaultDownloadPath = !categoryDownloadPath.isEmpty() ? categoryDownloadPath : btSession->downloadPath();
356355
m_ui->downloadPathEdit->setPlaceholder(defaultDownloadPath);
357356
}
358357
else

src/gui/optionsdialog.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,7 @@ void OptionsDialog::loadDownloadsTabOptions()
621621
m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());
622622

623623
m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
624-
m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
625-
m_ui->comboCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategorySavePathChanged());
626-
m_ui->comboCategoryDefaultPathChanged->setCurrentIndex(session->isDisableAutoTMMWhenDefaultSavePathChanged());
627-
628624
m_ui->checkUseSubcategories->setChecked(session->isSubcategoriesEnabled());
629-
m_ui->checkUseCategoryPaths->setChecked(session->useCategoryPathsInManualMode());
630625

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

728723
connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
729-
connect(m_ui->comboTorrentCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
730-
connect(m_ui->comboCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
731-
connect(m_ui->comboCategoryDefaultPathChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
732724

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

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

800791
session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
801-
session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);
802-
session->setDisableAutoTMMWhenCategorySavePathChanged(m_ui->comboCategoryChanged->currentIndex() == 1);
803-
session->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui->comboCategoryDefaultPathChanged->currentIndex() == 1);
804-
805792
session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked());
806-
session->setUseCategoryPathsInManualMode(m_ui->checkUseCategoryPaths->isChecked());
807-
808793
session->setSavePath(Path(m_ui->textSavePath->selectedPath()));
809794
session->setDownloadPathEnabled(m_ui->checkUseDownloadPath->isChecked());
810795
session->setDownloadPath(m_ui->textDownloadPath->selectedPath());

0 commit comments

Comments
 (0)