mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
Merge pull request #6184 from magao/issue5539
RSS: allow resetting rule to no category. Closes #5539.
This commit is contained in:
commit
b9b8352a31
@ -50,26 +50,45 @@ DownloadRule::DownloadRule()
|
||||
|
||||
bool DownloadRule::matches(const QString &articleTitle) const
|
||||
{
|
||||
if (!m_mustContain.empty()) {
|
||||
bool logged = false;
|
||||
|
||||
foreach (const QString &token, m_mustContain) {
|
||||
if (!token.isEmpty()) {
|
||||
if (!logged) {
|
||||
qDebug() << "Checking matching expressions:" << m_mustContain.join("|");
|
||||
logged = true;
|
||||
}
|
||||
|
||||
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if (reg.indexIn(articleTitle) < 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qDebug("Checking not matching tokens");
|
||||
// Checking not matching
|
||||
}
|
||||
|
||||
if (!m_mustNotContain.empty()) {
|
||||
bool logged = false;
|
||||
|
||||
foreach (const QString &token, m_mustNotContain) {
|
||||
if (!token.isEmpty()) {
|
||||
if (!logged) {
|
||||
qDebug() << "Checking not matching expressions:" << m_mustNotContain.join("|");
|
||||
logged = true;
|
||||
}
|
||||
|
||||
QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard);
|
||||
if (reg.indexIn(articleTitle) > -1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_episodeFilter.isEmpty()) {
|
||||
qDebug("Checking episode filter");
|
||||
qDebug() << "Checking episode filter:" << m_episodeFilter;
|
||||
QRegExp f("(^\\d{1,4})x(.*;$)");
|
||||
int pos = f.indexIn(m_episodeFilter);
|
||||
|
||||
if (pos < 0)
|
||||
return false;
|
||||
|
||||
@ -93,10 +112,13 @@ bool DownloadRule::matches(const QString &articleTitle) const
|
||||
pos = reg.indexIn(articleTitle);
|
||||
if (pos != -1) {
|
||||
int epTheirs = reg.cap(1).toInt();
|
||||
if (epTheirs >= epOurs)
|
||||
if (epTheirs >= epOurs) {
|
||||
qDebug() << "Matched episode:" << ep;
|
||||
qDebug() << "Matched article:" << articleTitle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // Normal range
|
||||
QStringList range = ep.split('-');
|
||||
Q_ASSERT(range.size() == 2);
|
||||
@ -110,19 +132,28 @@ bool DownloadRule::matches(const QString &articleTitle) const
|
||||
pos = reg.indexIn(articleTitle);
|
||||
if (pos != -1) {
|
||||
int epTheirs = reg.cap(1).toInt();
|
||||
if ((epOursFirst <= epTheirs) && (epOursLast >= epTheirs))
|
||||
if ((epOursFirst <= epTheirs) && (epOursLast >= epTheirs)) {
|
||||
qDebug() << "Matched episode:" << ep;
|
||||
qDebug() << "Matched article:" << articleTitle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // Single number
|
||||
QRegExp reg(expStr + ep + "\\D", Qt::CaseInsensitive);
|
||||
if (reg.indexIn(articleTitle) != -1)
|
||||
if (reg.indexIn(articleTitle) != -1) {
|
||||
qDebug() << "Matched episode:" << ep;
|
||||
qDebug() << "Matched article:" << articleTitle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Matched article:" << articleTitle;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -302,6 +333,7 @@ QStringList DownloadRule::findMatchingArticles(const FeedPtr &feed) const
|
||||
ArticleHash::ConstIterator artItend = feedArticles.end();
|
||||
for (; artIt != artItend; ++artIt) {
|
||||
const QString title = artIt.value()->title();
|
||||
qDebug() << "Matching article:" << title;
|
||||
if (matches(title))
|
||||
ret << title;
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ DownloadRuleList::DownloadRuleList()
|
||||
DownloadRulePtr DownloadRuleList::findMatchingRule(const QString &feedUrl, const QString &articleTitle) const
|
||||
{
|
||||
Q_ASSERT(Preferences::instance()->isRssDownloadingEnabled());
|
||||
qDebug() << "Matching article:" << articleTitle;
|
||||
QStringList ruleNames = m_feedRules.value(feedUrl);
|
||||
foreach (const QString &rule_name, ruleNames) {
|
||||
DownloadRulePtr rule = m_rules[rule_name];
|
||||
|
@ -71,10 +71,9 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<Rss::Manager>
|
||||
Q_ASSERT(ok);
|
||||
m_ruleList = manager.toStrongRef()->downloadRules();
|
||||
m_editableRuleList = new Rss::DownloadRuleList; // Read rule list from disk
|
||||
m_episodeValidator = new QRegExpValidator(
|
||||
QRegExp("^(^[1-9]{1,1}\\d{0,3}x([1-9]{1,1}\\d{0,3}(-([1-9]{1,1}\\d{0,3})?)?;){1,}){1,1}",
|
||||
Qt::CaseInsensitive),
|
||||
ui->lineEFilter);
|
||||
m_episodeRegex = new QRegExp("^(^[1-9]{1,1}\\d{0,3}x([1-9]{1,1}\\d{0,3}(-([1-9]{1,1}\\d{0,3})?)?;){1,}){1,1}",
|
||||
Qt::CaseInsensitive);
|
||||
m_episodeValidator = new QRegExpValidator(*m_episodeRegex, ui->lineEFilter);
|
||||
ui->lineEFilter->setValidator(m_episodeValidator);
|
||||
QString tip = "<p>" + tr("Matches articles based on episode filter.") + "</p><p><b>" + tr("Example: ")
|
||||
+ "1x2;8-15;5;30-;</b>" + tr(" will match 2, 5, 8 through 15, 30 and onward episodes of season one", "example X will match") + "</p>";
|
||||
@ -134,6 +133,7 @@ AutomatedRssDownloader::~AutomatedRssDownloader()
|
||||
delete ui;
|
||||
delete m_editableRuleList;
|
||||
delete m_episodeValidator;
|
||||
delete m_episodeRegex;
|
||||
}
|
||||
|
||||
void AutomatedRssDownloader::loadSettings()
|
||||
@ -253,13 +253,9 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
|
||||
ui->checkRegex->blockSignals(true);
|
||||
ui->checkRegex->setChecked(rule->useRegex());
|
||||
ui->checkRegex->blockSignals(false);
|
||||
if (rule->category().isEmpty()) {
|
||||
ui->comboCategory->setCurrentIndex(-1);
|
||||
ui->comboCategory->clearEditText();
|
||||
}
|
||||
else {
|
||||
ui->comboCategory->setCurrentIndex(ui->comboCategory->findText(rule->category()));
|
||||
}
|
||||
if (rule->category().isEmpty())
|
||||
ui->comboCategory->clearEditText();
|
||||
ui->comboAddPaused->setCurrentIndex(rule->addPaused());
|
||||
ui->spinIgnorePeriod->setValue(rule->ignoreDays());
|
||||
QDateTime dateTime = rule->lastMatch();
|
||||
@ -317,6 +313,7 @@ void AutomatedRssDownloader::initCategoryCombobox()
|
||||
// Load torrent categories
|
||||
QStringList categories = BitTorrent::Session::instance()->categories();
|
||||
std::sort(categories.begin(), categories.end(), Utils::String::naturalCompareCaseInsensitive);
|
||||
ui->comboCategory->addItem(QString(""));
|
||||
ui->comboCategory->addItems(categories);
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,7 @@ private:
|
||||
QListWidgetItem *m_editedRule;
|
||||
Rss::DownloadRuleList *m_ruleList;
|
||||
Rss::DownloadRuleList *m_editableRuleList;
|
||||
QRegExp *m_episodeRegex;
|
||||
QRegExpValidator *m_episodeValidator;
|
||||
QShortcut *editHotkey;
|
||||
QShortcut *deleteHotkey;
|
||||
|
Loading…
x
Reference in New Issue
Block a user