Add file name filter/blacklist

Blacklist filtered file names from being downloaded from torrent(s).
Files matching any of the filters in this list will have their priority automatically set to "Do not download".
See Options > Downloads >Do not download.

Closes #3369.
PR #17106.
This commit is contained in:
mxtsdev
2022-06-09 22:37:46 -07:00
committed by GitHub
parent c47e29c7c8
commit 5e6174c087
9 changed files with 144 additions and 17 deletions

View File

@@ -975,6 +975,21 @@ void AddNewTorrentDialog::setupTreeview()
currentIndex = m_contentModel->index(0, 0, currentIndex);
m_ui->contentTreeView->setExpanded(currentIndex, true);
}
// 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());
for (int i = 0; i < priorities.size(); ++i)
{
if (priorities[i] == BitTorrent::DownloadPriority::Ignored)
continue;
if (BitTorrent::Session::instance()->isFilenameExcluded(m_torrentInfo.filePath(i).filename()))
priorities[i] = BitTorrent::DownloadPriority::Ignored;
}
m_contentModel->model()->updateFilesPriorities(priorities);
}
updateDiskSpaceLabel();

View File

@@ -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->textExcludedFileNames, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->senderEmailTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
@@ -757,6 +758,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->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts));
session->setTorrentExportDirectory(getTorrentExportDir());
session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked());
@@ -1016,6 +1018,7 @@ void OptionsDialog::loadOptions()
m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
m_ui->checkRecursiveDownload->setChecked(!pref->recursiveDownloadDisabled());
m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n'));
if (session->torrentExportDirectory().isEmpty())
{

View File

@@ -1261,6 +1261,44 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupExcludedFileNames">
<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>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="textExcludedFileNames">
<property name="toolTip">
<string>Blacklist filtered file names from being downloaded from torrent(s).
Files matching any of the filters in this list will have their priority automatically set to &quot;Do not download&quot;.
Use newlines to separate multiple entries. Can use wildcards as outlined below.
*: matches zero or more of any characters.
?: matches any single character.
[...]: sets of characters can be represented in square brackets.
Examples
*.exe: filter '.exe' file extension.
readme.txt: filter exact file name.
?.txt: filter 'a.txt', 'b.txt' but not 'aa.txt'.
readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</string>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupMailNotification">
<property name="title">