Add option to enable ".unwanted" folder

PR #19926.
This commit is contained in:
Vladimir Golovnev 2023-11-13 14:25:27 +03:00 committed by GitHub
parent 9d6d3a30eb
commit 2a20764d39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 2 deletions

View file

@ -225,6 +225,8 @@ namespace BitTorrent
virtual void setTrackerEnabled(bool enabled) = 0;
virtual bool isAppendExtensionEnabled() const = 0;
virtual void setAppendExtensionEnabled(bool enabled) = 0;
virtual bool isUnwantedFolderEnabled() const = 0;
virtual void setUnwantedFolderEnabled(bool enabled) = 0;
virtual int refreshInterval() const = 0;
virtual void setRefreshInterval(int value) = 0;
virtual bool isPreallocationEnabled() const = 0;

View file

@ -455,6 +455,7 @@ SessionImpl::SessionImpl(QObject *parent)
, m_torrentStopCondition(BITTORRENT_SESSION_KEY(u"TorrentStopCondition"_s), Torrent::StopCondition::None)
, m_torrentContentLayout(BITTORRENT_SESSION_KEY(u"TorrentContentLayout"_s), TorrentContentLayout::Original)
, m_isAppendExtensionEnabled(BITTORRENT_SESSION_KEY(u"AddExtensionToIncompleteFiles"_s), false)
, m_isUnwantedFolderEnabled(BITTORRENT_SESSION_KEY(u"UseUnwantedFolder"_s), false)
, m_refreshInterval(BITTORRENT_SESSION_KEY(u"RefreshInterval"_s), 1500)
, m_isPreallocationEnabled(BITTORRENT_SESSION_KEY(u"Preallocation"_s), false)
, m_torrentExportDirectory(BITTORRENT_SESSION_KEY(u"TorrentExportDirectory"_s))
@ -695,6 +696,23 @@ void SessionImpl::setAppendExtensionEnabled(const bool enabled)
}
}
bool SessionImpl::isUnwantedFolderEnabled() const
{
return m_isUnwantedFolderEnabled;
}
void SessionImpl::setUnwantedFolderEnabled(const bool enabled)
{
if (isUnwantedFolderEnabled() != enabled)
{
m_isUnwantedFolderEnabled = enabled;
// append or remove .!qB extension for incomplete files
for (TorrentImpl *const torrent : asConst(m_torrents))
torrent->handleUnwantedFolderToggled();
}
}
int SessionImpl::refreshInterval() const
{
return m_refreshInterval;

View file

@ -194,6 +194,8 @@ namespace BitTorrent
void setTrackerEnabled(bool enabled) override;
bool isAppendExtensionEnabled() const override;
void setAppendExtensionEnabled(bool enabled) override;
bool isUnwantedFolderEnabled() const override;
void setUnwantedFolderEnabled(bool enabled) override;
int refreshInterval() const override;
void setRefreshInterval(int value) override;
bool isPreallocationEnabled() const override;
@ -656,6 +658,7 @@ namespace BitTorrent
CachedSettingValue<Torrent::StopCondition> m_torrentStopCondition;
CachedSettingValue<TorrentContentLayout> m_torrentContentLayout;
CachedSettingValue<bool> m_isAppendExtensionEnabled;
CachedSettingValue<bool> m_isUnwantedFolderEnabled;
CachedSettingValue<int> m_refreshInterval;
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<Path> m_torrentExportDirectory;

View file

@ -573,7 +573,8 @@ Path TorrentImpl::makeActualPath(int index, const Path &path) const
actualPath += QB_EXT;
}
if (m_filePriorities[index] == DownloadPriority::Ignored)
if (m_session->isUnwantedFolderEnabled()
&& (m_filePriorities[index] == DownloadPriority::Ignored))
{
const Path parentPath = actualPath.parentPath();
const QString fileName = actualPath.filename();
@ -2304,7 +2305,16 @@ void TorrentImpl::handleCategoryOptionsChanged()
void TorrentImpl::handleAppendExtensionToggled()
{
if (!hasMetadata()) return;
if (!hasMetadata())
return;
manageActualFilePaths();
}
void TorrentImpl::handleUnwantedFolderToggled()
{
if (!hasMetadata())
return;
manageActualFilePaths();
}

View file

@ -263,6 +263,7 @@ namespace BitTorrent
void handleStateUpdate(const lt::torrent_status &nativeStatus);
void handleCategoryOptionsChanged();
void handleAppendExtensionToggled();
void handleUnwantedFolderToggled();
void saveResumeData(lt::resume_data_flags_t flags = {});
void handleMoveStorageJobFinished(const Path &path, MoveStorageContext context, bool hasOutstandingJob);
void fileSearchFinished(const Path &savePath, const PathList &fileNames);

View file

@ -563,6 +563,7 @@ void OptionsDialog::loadDownloadsTabOptions()
m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
m_ui->checkUnwantedFolder->setChecked(session->isUnwantedFolderEnabled());
m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());
m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
@ -666,6 +667,7 @@ void OptionsDialog::loadDownloadsTabOptions()
connect(m_ui->checkPreallocateAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkAppendqB, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUnwantedFolder, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkRecursiveDownload, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
@ -732,6 +734,7 @@ void OptionsDialog::saveDownloadsTabOptions() const
session->setPreallocationEnabled(preAllocateAllFiles());
session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked());
session->setUnwantedFolderEnabled(m_ui->checkUnwantedFolder->isChecked());
pref->setRecursiveDownloadEnabled(m_ui->checkRecursiveDownload->isChecked());
session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);

View file

@ -1094,6 +1094,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUnwantedFolder">
<property name="text">
<string>Keep unselected files in ".unwanted" folder</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkRecursiveDownload">
<property name="toolTip">
@ -3906,6 +3913,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>checkUseDownloadPath</tabstop>
<tabstop>textDownloadPath</tabstop>
<tabstop>checkAppendqB</tabstop>
<tabstop>checkUnwantedFolder</tabstop>
<tabstop>scanFoldersView</tabstop>
<tabstop>addWatchedFolderButton</tabstop>
<tabstop>editWatchedFolderButton</tabstop>

View file

@ -130,6 +130,7 @@ void AppController::preferencesAction()
data[u"auto_delete_mode"_s] = static_cast<int>(TorrentFileGuard::autoDeleteMode());
data[u"preallocate_all"_s] = session->isPreallocationEnabled();
data[u"incomplete_files_ext"_s] = session->isAppendExtensionEnabled();
data[u"use_unwanted_folder"_s] = session->isUnwantedFolderEnabled();
// Saving Management
data[u"auto_tmm_enabled"_s] = !session->isAutoTMMDisabledByDefault();
data[u"torrent_changed_tmm_enabled"_s] = !session->isDisableAutoTMMWhenCategoryChanged();
@ -513,6 +514,8 @@ void AppController::setPreferencesAction()
session->setPreallocationEnabled(it.value().toBool());
if (hasKey(u"incomplete_files_ext"_s))
session->setAppendExtensionEnabled(it.value().toBool());
if (hasKey(u"use_unwanted_folder"_s))
session->setUnwantedFolderEnabled(it.value().toBool());
// Saving Management
if (hasKey(u"auto_tmm_enabled"_s))

View file

@ -86,6 +86,12 @@
<label for="appendext_checkbox">QBT_TR(Append .!qB extension to incomplete files)QBT_TR[CONTEXT=OptionsDialog]</label>
</span>
</div>
<div class="formRow">
<span id="unwantedfoldertr">
<input type="checkbox" id="unwantedfolder_checkbox" />
<label for="unwantedfolder_checkbox">QBT_TR(Keep unselected files in ".unwanted" folder)QBT_TR[CONTEXT=OptionsDialog]</label>
</span>
</div>
<fieldset class="settings">
<legend>QBT_TR(Saving Management)QBT_TR[CONTEXT=HttpServer]</legend>
@ -1997,6 +2003,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
$('preallocateall_checkbox').setProperty('checked', pref.preallocate_all);
$('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext);
$('unwantedfolder_checkbox').setProperty('checked', pref.use_unwanted_folder);
// Saving Management
$('default_tmm_combobox').setProperty('value', pref.auto_tmm_enabled);
@ -2374,6 +2381,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
settings.set('preallocate_all', $('preallocateall_checkbox').getProperty('checked'));
settings.set('incomplete_files_ext', $('appendext_checkbox').getProperty('checked'));
settings.set('use_unwanted_folder', $('unwantedfolder_checkbox').getProperty('checked'));
// Saving Management
settings.set('auto_tmm_enabled', $('default_tmm_combobox').getProperty('value'));