From 24c0bbf46bd1caad0935fe31925380caa1bf34e1 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 11 Nov 2023 12:01:56 +0300 Subject: [PATCH] Add option to enable ".unwanted" folder --- src/base/bittorrent/session.h | 2 ++ src/base/bittorrent/sessionimpl.cpp | 18 ++++++++++++++++++ src/base/bittorrent/sessionimpl.h | 3 +++ src/base/bittorrent/torrentimpl.cpp | 14 ++++++++++++-- src/base/bittorrent/torrentimpl.h | 1 + src/gui/optionsdialog.cpp | 3 +++ src/gui/optionsdialog.ui | 8 ++++++++ src/webui/api/appcontroller.cpp | 3 +++ src/webui/www/private/views/preferences.html | 8 ++++++++ 9 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 6e88d2d603e5..6dd3b6c22286 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -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; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 091109d71b68..4f6e0d46712e 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -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; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index 01374542c741..a0124d7d3bcf 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -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 m_torrentStopCondition; CachedSettingValue m_torrentContentLayout; CachedSettingValue m_isAppendExtensionEnabled; + CachedSettingValue m_isUnwantedFolderEnabled; CachedSettingValue m_refreshInterval; CachedSettingValue m_isPreallocationEnabled; CachedSettingValue m_torrentExportDirectory; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 10160e1a0aa6..6c19491b7d39 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -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(); } diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index b119d62a50f9..dada6664ae81 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -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); diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 02d7ff2f34fe..53331c224cc4 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -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); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index ac6778ff8fbe..7d1d95910ea7 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1094,6 +1094,13 @@ + + + + Keep unselected files in ".unwanted" folder + + + @@ -3906,6 +3913,7 @@ Use ';' to split multiple entries. Can use wildcard '*'. checkUseDownloadPath textDownloadPath checkAppendqB + checkUnwantedFolder scanFoldersView addWatchedFolderButton editWatchedFolderButton diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index a99c8d1813e7..4f917409af36 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -130,6 +130,7 @@ void AppController::preferencesAction() data[u"auto_delete_mode"_s] = static_cast(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)) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index aa4a9e4111c2..e33cdecd4b82 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -86,6 +86,12 @@ +
+ + + + +
QBT_TR(Saving Management)QBT_TR[CONTEXT=HttpServer] @@ -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); @@ -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'));