From 844f76c2cadf7b2aa321dfe25efc2609b7977b61 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 18 May 2018 14:41:52 +0300 Subject: [PATCH] Make "Ignoring days" to behave like other filters This prevents confusing in GUI when it shows matched RSS articles which be really ignored by the rule. --- src/base/rss/rss_autodownloader.cpp | 14 +---------- src/base/rss/rss_autodownloadrule.cpp | 32 ++++++++++++++++++-------- src/base/rss/rss_autodownloadrule.h | 4 ++-- src/gui/rss/automatedrssdownloader.cpp | 4 +++- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index 1e070f26f..007bbae54 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -365,19 +365,7 @@ void AutoDownloader::processJob(const QSharedPointer &job) for (AutoDownloadRule &rule: m_rules) { if (!rule.isEnabled()) continue; if (!rule.feedURLs().contains(job->feedURL)) continue; - if (!rule.matches(job->articleData.value(Article::KeyTitle).toString())) continue; - - auto articleDate = job->articleData.value(Article::KeyDate).toDateTime(); - // if rule is in ignoring state do nothing with matched torrent - if (rule.ignoreDays() > 0) { - if (rule.lastMatch().isValid()) { - if (articleDate < rule.lastMatch().addDays(rule.ignoreDays())) - return; - } - } - - rule.setLastMatch(articleDate); - rule.appendLastComputedEpisode(); + if (!rule.accepts(job->articleData)) continue; m_dirty = true; storeDeferred(); diff --git a/src/base/rss/rss_autodownloadrule.cpp b/src/base/rss/rss_autodownloadrule.cpp index e6755dd18..643abbde0 100644 --- a/src/base/rss/rss_autodownloadrule.cpp +++ b/src/base/rss/rss_autodownloadrule.cpp @@ -351,8 +351,15 @@ bool AutoDownloadRule::matchesSmartEpisodeFilter(const QString& articleTitle) co return true; } -bool AutoDownloadRule::matches(const QString &articleTitle) const +bool AutoDownloadRule::matches(const QVariantHash &articleData) const { + const QDateTime articleDate {articleData[Article::KeyDate].toDateTime()}; + if (ignoreDays() > 0) { + if (lastMatch().isValid() && (articleDate < lastMatch().addDays(ignoreDays()))) + return false; + } + + const QString articleTitle {articleData[Article::KeyTitle].toString()}; if (!matchesMustContainExpression(articleTitle)) return false; if (!matchesMustNotContainExpression(articleTitle)) @@ -365,6 +372,20 @@ bool AutoDownloadRule::matches(const QString &articleTitle) const return true; } +bool AutoDownloadRule::accepts(const QVariantHash &articleData) +{ + if (!matches(articleData)) + return false; + + setLastMatch(articleData[Article::KeyDate].toDateTime()); + + if (!m_dataPtr->lastComputedEpisode.isEmpty()) { + // TODO: probably need to add a marker for PROPER/REPACK to avoid duplicate downloads + m_dataPtr->previouslyMatchedEpisodes.append(m_dataPtr->lastComputedEpisode); + m_dataPtr->lastComputedEpisode.clear(); + } +} + AutoDownloadRule &AutoDownloadRule::operator=(const AutoDownloadRule &other) { m_dataPtr = other.m_dataPtr; @@ -621,15 +642,6 @@ void AutoDownloadRule::setPreviouslyMatchedEpisodes(const QStringList &previousl m_dataPtr->previouslyMatchedEpisodes = previouslyMatchedEpisodes; } -void AutoDownloadRule::appendLastComputedEpisode() -{ - if (!m_dataPtr->lastComputedEpisode.isEmpty()) { - // TODO: probably need to add a marker for PROPER/REPACK to avoid duplicate downloads - m_dataPtr->previouslyMatchedEpisodes.append(m_dataPtr->lastComputedEpisode); - m_dataPtr->lastComputedEpisode.clear(); - } -} - QString AutoDownloadRule::episodeFilter() const { return m_dataPtr->episodeFilter; diff --git a/src/base/rss/rss_autodownloadrule.h b/src/base/rss/rss_autodownloadrule.h index 2802f38be..15fd113fb 100644 --- a/src/base/rss/rss_autodownloadrule.h +++ b/src/base/rss/rss_autodownloadrule.h @@ -71,7 +71,6 @@ namespace RSS QString episodeFilter() const; void setEpisodeFilter(const QString &e); - void appendLastComputedEpisode(); QStringList previouslyMatchedEpisodes() const; void setPreviouslyMatchedEpisodes(const QStringList &previouslyMatchedEpisodes); @@ -82,7 +81,8 @@ namespace RSS QString assignedCategory() const; void setCategory(const QString &category); - bool matches(const QString &articleTitle) const; + bool matches(const QVariantHash &articleData) const; + bool accepts(const QVariantHash &articleData); AutoDownloadRule &operator=(const AutoDownloadRule &other); bool operator==(const AutoDownloadRule &other) const; diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index 38d8c0867..4fd05440e 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -114,6 +114,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) connect(m_ui->checkRegex, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::updateMustLineValidity); connect(m_ui->checkRegex, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::updateMustNotLineValidity); connect(m_ui->checkSmart, &QCheckBox::stateChanged, this, &AutomatedRssDownloader::handleRuleDefinitionChanged); + connect(m_ui->spinIgnorePeriod, static_cast(&QSpinBox::valueChanged) + , this, &AutomatedRssDownloader::handleRuleDefinitionChanged); connect(m_ui->listFeeds, &QListWidget::itemChanged, this, &AutomatedRssDownloader::handleFeedCheckStateChange); @@ -581,7 +583,7 @@ void AutomatedRssDownloader::updateMatchingArticles() QStringList matchingArticles; foreach (auto article, feed->articles()) - if (rule.matches(article->title())) + if (rule.matches(article->data())) matchingArticles << article->title(); if (!matchingArticles.isEmpty()) addFeedArticlesToTree(feed, matchingArticles);