Browse Source

Add checkbox for "Excluded file names"

PR #17206.
adaptive-webui-19844
thalieht 2 years ago committed by GitHub
parent
commit
d1515456bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      src/base/bittorrent/session.cpp
  2. 3
      src/base/bittorrent/session.h
  3. 3
      src/gui/addnewtorrentdialog.cpp
  4. 3
      src/gui/optionsdialog.cpp
  5. 19
      src/gui/optionsdialog.ui
  6. 5
      src/webui/api/appcontroller.cpp
  7. 2
      src/webui/webapplication.h
  8. 18
      src/webui/www/private/views/preferences.html

28
src/base/bittorrent/session.cpp

@ -414,6 +414,7 @@ Session::Session(QObject *parent)
, m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY(u"PeerTurnoverCutOff"_qs), 90) , m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY(u"PeerTurnoverCutOff"_qs), 90)
, m_peerTurnoverInterval(BITTORRENT_SESSION_KEY(u"PeerTurnoverInterval"_qs), 300) , m_peerTurnoverInterval(BITTORRENT_SESSION_KEY(u"PeerTurnoverInterval"_qs), 300)
, m_requestQueueSize(BITTORRENT_SESSION_KEY(u"RequestQueueSize"_qs), 500) , m_requestQueueSize(BITTORRENT_SESSION_KEY(u"RequestQueueSize"_qs), 500)
, m_isExcludedFileNamesEnabled(BITTORRENT_KEY(u"ExcludedFileNamesEnabled"_qs), false)
, m_excludedFileNames(BITTORRENT_SESSION_KEY(u"ExcludedFileNames"_qs)) , m_excludedFileNames(BITTORRENT_SESSION_KEY(u"ExcludedFileNames"_qs))
, m_bannedIPs(u"State/BannedIPs"_qs , m_bannedIPs(u"State/BannedIPs"_qs
, QStringList() , QStringList()
@ -467,6 +468,7 @@ Session::Session(QObject *parent)
enqueueRefresh(); enqueueRefresh();
updateSeedingLimitTimer(); updateSeedingLimitTimer();
populateAdditionalTrackers(); populateAdditionalTrackers();
if (isExcludedFileNamesEnabled())
populateExcludedFileNamesRegExpList(); populateExcludedFileNamesRegExpList();
enableTracker(isTrackerEnabled()); enableTracker(isTrackerEnabled());
@ -2256,7 +2258,9 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
// Use qBittorrent default priority rather than libtorrent's (4) // Use qBittorrent default priority rather than libtorrent's (4)
p.file_priorities = std::vector(internalFilesCount, LT::toNative(DownloadPriority::Normal)); p.file_priorities = std::vector(internalFilesCount, LT::toNative(DownloadPriority::Normal));
if (addTorrentParams.filePriorities.size() == 0) if (addTorrentParams.filePriorities.isEmpty())
{
if (isExcludedFileNamesEnabled())
{ {
// Check file name blacklist when priorities are not explicitly set // Check file name blacklist when priorities are not explicitly set
for (int i = 0; i < filePaths.size(); ++i) for (int i = 0; i < filePaths.size(); ++i)
@ -2265,6 +2269,7 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = lt::dont_download; p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = lt::dont_download;
} }
} }
}
else else
{ {
for (int i = 0; i < addTorrentParams.filePriorities.size(); ++i) for (int i = 0; i < addTorrentParams.filePriorities.size(); ++i)
@ -3091,6 +3096,24 @@ void Session::setIPFilterFile(const Path &path)
} }
} }
bool Session::isExcludedFileNamesEnabled() const
{
return m_isExcludedFileNamesEnabled;
}
void Session::setExcludedFileNamesEnabled(const bool enabled)
{
if (m_isExcludedFileNamesEnabled == enabled)
return;
m_isExcludedFileNamesEnabled = enabled;
if (enabled)
populateExcludedFileNamesRegExpList();
else
m_excludedFileNamesRegExpList.clear();
}
QStringList Session::excludedFileNames() const QStringList Session::excludedFileNames() const
{ {
return m_excludedFileNames; return m_excludedFileNames;
@ -3122,6 +3145,9 @@ void Session::populateExcludedFileNamesRegExpList()
bool Session::isFilenameExcluded(const QString &fileName) const bool Session::isFilenameExcluded(const QString &fileName) const
{ {
if (!isExcludedFileNamesEnabled())
return false;
return std::any_of(m_excludedFileNamesRegExpList.begin(), m_excludedFileNamesRegExpList.end(), [&fileName](const QRegularExpression &re) return std::any_of(m_excludedFileNamesRegExpList.begin(), m_excludedFileNamesRegExpList.end(), [&fileName](const QRegularExpression &re)
{ {
return re.match(fileName).hasMatch(); return re.match(fileName).hasMatch();

3
src/base/bittorrent/session.h

@ -455,6 +455,8 @@ namespace BitTorrent
void setBlockPeersOnPrivilegedPorts(bool enabled); void setBlockPeersOnPrivilegedPorts(bool enabled);
bool isTrackerFilteringEnabled() const; bool isTrackerFilteringEnabled() const;
void setTrackerFilteringEnabled(bool enabled); void setTrackerFilteringEnabled(bool enabled);
bool isExcludedFileNamesEnabled() const;
void setExcludedFileNamesEnabled(const bool enabled);
QStringList excludedFileNames() const; QStringList excludedFileNames() const;
void setExcludedFileNames(const QStringList &newList); void setExcludedFileNames(const QStringList &newList);
bool isFilenameExcluded(const QString &fileName) const; bool isFilenameExcluded(const QString &fileName) const;
@ -782,6 +784,7 @@ namespace BitTorrent
CachedSettingValue<int> m_peerTurnoverCutoff; CachedSettingValue<int> m_peerTurnoverCutoff;
CachedSettingValue<int> m_peerTurnoverInterval; CachedSettingValue<int> m_peerTurnoverInterval;
CachedSettingValue<int> m_requestQueueSize; CachedSettingValue<int> m_requestQueueSize;
CachedSettingValue<bool> m_isExcludedFileNamesEnabled;
CachedSettingValue<QStringList> m_excludedFileNames; CachedSettingValue<QStringList> m_excludedFileNames;
CachedSettingValue<QStringList> m_bannedIPs; CachedSettingValue<QStringList> m_bannedIPs;
CachedSettingValue<ResumeDataStorageType> m_resumeDataStorageType; CachedSettingValue<ResumeDataStorageType> m_resumeDataStorageType;

3
src/gui/addnewtorrentdialog.cpp

@ -976,6 +976,8 @@ void AddNewTorrentDialog::setupTreeview()
m_ui->contentTreeView->setExpanded(currentIndex, true); m_ui->contentTreeView->setExpanded(currentIndex, true);
} }
if (BitTorrent::Session::instance()->isExcludedFileNamesEnabled())
{
// Check file name blacklist for torrents that are manually added // Check file name blacklist for torrents that are manually added
QVector<BitTorrent::DownloadPriority> priorities = m_contentModel->model()->getFilePriorities(); QVector<BitTorrent::DownloadPriority> priorities = m_contentModel->model()->getFilePriorities();
Q_ASSERT(priorities.size() == m_torrentInfo.filesCount()); Q_ASSERT(priorities.size() == m_torrentInfo.filesCount());
@ -991,6 +993,7 @@ void AddNewTorrentDialog::setupTreeview()
m_contentModel->model()->updateFilesPriorities(priorities); m_contentModel->model()->updateFilesPriorities(priorities);
} }
}
updateDiskSpaceLabel(); updateDiskSpaceLabel();
} }

3
src/gui/optionsdialog.cpp

@ -375,6 +375,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, m_ui->textDownloadPath, &QWidget::setEnabled); connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, m_ui->textDownloadPath, &QWidget::setEnabled);
connect(m_ui->addWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton); connect(m_ui->addWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
connect(m_ui->groupExcludedFileNames, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->textExcludedFileNames, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->textExcludedFileNames, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton); connect(m_ui->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
@ -758,6 +759,7 @@ void OptionsDialog::saveOptions()
session->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex())); session->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex()));
auto watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model()); auto watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
watchedFoldersModel->apply(); watchedFoldersModel->apply();
session->setExcludedFileNamesEnabled(m_ui->groupExcludedFileNames->isChecked());
session->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts)); session->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts));
session->setTorrentExportDirectory(getTorrentExportDir()); session->setTorrentExportDirectory(getTorrentExportDir());
session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir()); session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
@ -1018,6 +1020,7 @@ void OptionsDialog::loadOptions()
m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled()); m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled()); m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled()); m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled());
m_ui->groupExcludedFileNames->setChecked(session->isExcludedFileNamesEnabled());
m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n')); m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n'));
if (session->torrentExportDirectory().isEmpty()) if (session->torrentExportDirectory().isEmpty())

19
src/gui/optionsdialog.ui

@ -1112,12 +1112,12 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkUseCategoryPaths"> <widget class="QCheckBox" name="checkUseCategoryPaths">
<property name="text">
<string>Use Category paths in Manual Mode</string>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Resolve relative Save Path against appropriate Category path instead of Default one</string> <string>Resolve relative Save Path against appropriate Category path instead of Default one</string>
</property> </property>
<property name="text">
<string>Use Category paths in Manual Mode</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -1266,14 +1266,13 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<property name="title"> <property name="title">
<string>Excluded file names</string> <string>Excluded file names</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_311"> <property name="checkable">
<item> <bool>true</bool>
<widget class="QLabel" name="label_1">
<property name="text">
<string>Filters:</string>
</property> </property>
</widget> <property name="checked">
</item> <bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_311">
<item> <item>
<widget class="QPlainTextEdit" name="textExcludedFileNames"> <widget class="QPlainTextEdit" name="textExcludedFileNames">
<property name="toolTip"> <property name="toolTip">

5
src/webui/api/appcontroller.cpp

@ -141,6 +141,8 @@ void AppController::preferencesAction()
data[u"scan_dirs"_qs] = nativeDirs; data[u"scan_dirs"_qs] = nativeDirs;
// === END DEPRECATED CODE === // // === END DEPRECATED CODE === //
// Excluded file names
data[u"excluded_file_names_enabled"_qs] = session->isExcludedFileNamesEnabled();
data[u"excluded_file_names"_qs] = session->excludedFileNames().join(u'\n'); data[u"excluded_file_names"_qs] = session->excludedFileNames().join(u'\n');
// Email notification upon download completion // Email notification upon download completion
@ -478,6 +480,9 @@ void AppController::setPreferencesAction()
} }
// === END DEPRECATED CODE === // // === END DEPRECATED CODE === //
// Excluded file names
if (hasKey(u"excluded_file_names_enabled"_qs))
session->setExcludedFileNamesEnabled(it.value().toBool());
if (hasKey(u"excluded_file_names"_qs)) if (hasKey(u"excluded_file_names"_qs))
session->setExcludedFileNames(it.value().toString().split(u'\n')); session->setExcludedFileNames(it.value().toString().split(u'\n'));

2
src/webui/webapplication.h

@ -48,7 +48,7 @@
#include "base/utils/version.h" #include "base/utils/version.h"
#include "api/isessionmanager.h" #include "api/isessionmanager.h"
inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 12}; inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 13};
class APIController; class APIController;
class AuthController; class AuthController;

18
src/webui/www/private/views/preferences.html

@ -131,8 +131,10 @@
</fieldset> </fieldset>
<fieldset class="settings"> <fieldset class="settings">
<legend>QBT_TR(Excluded file names)QBT_TR[CONTEXT=OptionsDialog]</legend> <legend>
<label for="excludedFileNamesTextarea">QBT_TR(Filters:)QBT_TR[CONTEXT=OptionsDialog]</label><br> <input type="checkbox" id="excludedFileNamesCheckbox" onclick="qBittorrent.Preferences.updateExcludedFileNamesEnabled();" />
<label for="excludedFileNamesCheckbox">QBT_TR(Excluded file names)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend>
<textarea id="excludedFileNamesTextarea" rows="6" cols="70"></textarea> <textarea id="excludedFileNamesTextarea" rows="6" cols="70"></textarea>
</fieldset> </fieldset>
@ -1326,6 +1328,7 @@
updateExportDirEnabled: updateExportDirEnabled, updateExportDirEnabled: updateExportDirEnabled,
updateExportDirFinEnabled: updateExportDirFinEnabled, updateExportDirFinEnabled: updateExportDirFinEnabled,
addWatchFolder: addWatchFolder, addWatchFolder: addWatchFolder,
updateExcludedFileNamesEnabled: updateExcludedFileNamesEnabled,
changeWatchFolderSelect: changeWatchFolderSelect, changeWatchFolderSelect: changeWatchFolderSelect,
updateMailNotification: updateMailNotification, updateMailNotification: updateMailNotification,
updateMailAuthSettings: updateMailAuthSettings, updateMailAuthSettings: updateMailAuthSettings,
@ -1423,6 +1426,11 @@
return folders; return folders;
}; };
const updateExcludedFileNamesEnabled = function() {
const isAExcludedFileNamesEnabled = $('excludedFileNamesCheckbox').getProperty('checked');
$('excludedFileNamesTextarea').setProperty('disabled', !isAExcludedFileNamesEnabled);
};
const updateExportDirEnabled = function() { const updateExportDirEnabled = function() {
const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked'); const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked');
$('exportdir_text').setProperty('disabled', !isExportDirEnabled); $('exportdir_text').setProperty('disabled', !isExportDirEnabled);
@ -1739,6 +1747,9 @@
addWatchFolder(folder, sel, other); addWatchFolder(folder, sel, other);
} }
addWatchFolder(); addWatchFolder();
// Excluded file names
$('excludedFileNamesCheckbox').setProperty('checked', pref.excluded_file_names_enabled);
$('excludedFileNamesTextarea').setProperty('value', pref.excluded_file_names); $('excludedFileNamesTextarea').setProperty('value', pref.excluded_file_names);
// Email notification upon download completion // Email notification upon download completion
@ -2060,6 +2071,9 @@
// Automatically add torrents from // Automatically add torrents from
settings.set('scan_dirs', getWatchedFolders()); settings.set('scan_dirs', getWatchedFolders());
// Excluded file names
settings.set('excluded_file_names_enabled', $('excludedFileNamesCheckbox').getProperty('checked'));
settings.set('excluded_file_names', $('excludedFileNamesTextarea').getProperty('value')); settings.set('excluded_file_names', $('excludedFileNamesTextarea').getProperty('value'));
// Email notification upon download completion // Email notification upon download completion

Loading…
Cancel
Save