Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable ".unwanted" folder #19926

Merged
merged 1 commit into from
Nov 13, 2023
Merged
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
2 changes: 2 additions & 0 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -2304,7 +2305,16 @@ void TorrentImpl::handleCategoryOptionsChanged()

void TorrentImpl::handleAppendExtensionToggled()
{
if (!hasMetadata()) return;
if (!hasMetadata())
return;

manageActualFilePaths();
}

void TorrentImpl::handleUnwantedFolderToggled()
{
if (!hasMetadata())
return;

manageActualFilePaths();
}
Expand Down
1 change: 1 addition & 0 deletions src/base/bittorrent/torrentimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/gui/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUnwantedFolder">
<property name="text">
<string>Keep unselected files in ".unwanted" folder</string>
glassez marked this conversation as resolved.
Show resolved Hide resolved
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkRecursiveDownload">
<property name="toolTip">
Expand Down Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -1997,6 +2003,7 @@

$('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);
Expand Down Expand Up @@ -2374,6 +2381,7 @@

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'));
Expand Down
Loading