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) @@ -414,6 +414,7 @@ Session::Session(QObject *parent)
, m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY(u"PeerTurnoverCutOff"_qs), 90)
, m_peerTurnoverInterval(BITTORRENT_SESSION_KEY(u"PeerTurnoverInterval"_qs), 300)
, 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_bannedIPs(u"State/BannedIPs"_qs
, QStringList()
@ -467,6 +468,7 @@ Session::Session(QObject *parent) @@ -467,6 +468,7 @@ Session::Session(QObject *parent)
enqueueRefresh();
updateSeedingLimitTimer();
populateAdditionalTrackers();
if (isExcludedFileNamesEnabled())
populateExcludedFileNamesRegExpList();
enableTracker(isTrackerEnabled());
@ -2256,7 +2258,9 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source @@ -2256,7 +2258,9 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
// Use qBittorrent default priority rather than libtorrent's (4)
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
for (int i = 0; i < filePaths.size(); ++i)
@ -2265,6 +2269,7 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source @@ -2265,6 +2269,7 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = lt::dont_download;
}
}
}
else
{
for (int i = 0; i < addTorrentParams.filePriorities.size(); ++i)
@ -3091,6 +3096,24 @@ void Session::setIPFilterFile(const Path &path) @@ -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
{
return m_excludedFileNames;
@ -3122,6 +3145,9 @@ void Session::populateExcludedFileNamesRegExpList() @@ -3122,6 +3145,9 @@ void Session::populateExcludedFileNamesRegExpList()
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 re.match(fileName).hasMatch();

3
src/base/bittorrent/session.h

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

3
src/gui/addnewtorrentdialog.cpp

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

3
src/gui/optionsdialog.cpp

@ -375,6 +375,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -375,6 +375,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, m_ui->textDownloadPath, &QWidget::setEnabled);
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->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
@ -758,6 +759,7 @@ void OptionsDialog::saveOptions() @@ -758,6 +759,7 @@ void OptionsDialog::saveOptions()
session->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex()));
auto watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
watchedFoldersModel->apply();
session->setExcludedFileNamesEnabled(m_ui->groupExcludedFileNames->isChecked());
session->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts));
session->setTorrentExportDirectory(getTorrentExportDir());
session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
@ -1018,6 +1020,7 @@ void OptionsDialog::loadOptions() @@ -1018,6 +1020,7 @@ void OptionsDialog::loadOptions()
m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled());
m_ui->groupExcludedFileNames->setChecked(session->isExcludedFileNamesEnabled());
m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n'));
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 @@ -1112,12 +1112,12 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</item>
<item>
<widget class="QCheckBox" name="checkUseCategoryPaths">
<property name="text">
<string>Use Category paths in Manual Mode</string>
</property>
<property name="toolTip">
<string>Resolve relative Save Path against appropriate Category path instead of Default one</string>
</property>
<property name="text">
<string>Use Category paths in Manual Mode</string>
</property>
</widget>
</item>
<item>
@ -1266,14 +1266,13 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s @@ -1266,14 +1266,13 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
<property name="title">
<string>Excluded file names</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_311">
<item>
<widget class="QLabel" name="label_1">
<property name="text">
<string>Filters:</string>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_311">
<item>
<widget class="QPlainTextEdit" name="textExcludedFileNames">
<property name="toolTip">

5
src/webui/api/appcontroller.cpp

@ -141,6 +141,8 @@ void AppController::preferencesAction() @@ -141,6 +141,8 @@ void AppController::preferencesAction()
data[u"scan_dirs"_qs] = nativeDirs;
// === 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');
// Email notification upon download completion
@ -478,6 +480,9 @@ void AppController::setPreferencesAction() @@ -478,6 +480,9 @@ void AppController::setPreferencesAction()
}
// === 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))
session->setExcludedFileNames(it.value().toString().split(u'\n'));

2
src/webui/webapplication.h

@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
#include "base/utils/version.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 AuthController;

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

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

Loading…
Cancel
Save