Browse Source

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.
adaptive-webui-19844
Vladimir Golovnev (Glassez) 7 years ago
parent
commit
844f76c2ca
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 14
      src/base/rss/rss_autodownloader.cpp
  2. 32
      src/base/rss/rss_autodownloadrule.cpp
  3. 4
      src/base/rss/rss_autodownloadrule.h
  4. 4
      src/gui/rss/automatedrssdownloader.cpp

14
src/base/rss/rss_autodownloader.cpp

@ -365,19 +365,7 @@ void AutoDownloader::processJob(const QSharedPointer<ProcessingJob> &job) @@ -365,19 +365,7 @@ void AutoDownloader::processJob(const QSharedPointer<ProcessingJob> &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();

32
src/base/rss/rss_autodownloadrule.cpp

@ -351,8 +351,15 @@ bool AutoDownloadRule::matchesSmartEpisodeFilter(const QString& articleTitle) co @@ -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 @@ -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 @@ -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;

4
src/base/rss/rss_autodownloadrule.h

@ -71,7 +71,6 @@ namespace RSS @@ -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 @@ -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;

4
src/gui/rss/automatedrssdownloader.cpp

@ -114,6 +114,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) @@ -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<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged)
, this, &AutomatedRssDownloader::handleRuleDefinitionChanged);
connect(m_ui->listFeeds, &QListWidget::itemChanged, this, &AutomatedRssDownloader::handleFeedCheckStateChange);
@ -581,7 +583,7 @@ void AutomatedRssDownloader::updateMatchingArticles() @@ -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);

Loading…
Cancel
Save