From 806a4a2e6aeb9e7b627d7f0f49460071bea23833 Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Thu, 25 Jul 2013 00:39:05 +0400 Subject: [PATCH] Add setting to ignore RSS rule matches for X days --- src/rss/automatedrssdownloader.cpp | 10 +++++ src/rss/automatedrssdownloader.ui | 64 ++++++++++++++++++++++++++++++ src/rss/rssarticle.cpp | 5 +-- src/rss/rssdownloadrule.cpp | 4 ++ src/rss/rssdownloadrule.h | 7 ++++ src/rss/rssfeed.cpp | 12 ++++++ 6 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index 5833913b0..fa5562ce5 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -255,6 +255,14 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() } else { ui->comboLabel->setCurrentIndex(ui->comboLabel->findText(rule->label())); } + ui->spinIgnorePeriod->setValue(rule->ignoreDays()); + QDateTime dateTime = rule->lastMatch(); + QString lMatch = tr("Last match: "); + if (dateTime.isValid()) + lMatch += QString::number(dateTime.daysTo(QDateTime::currentDateTime())) + tr(" days ago."); + else + lMatch += tr("Unknown"); + ui->lblLastMatch->setText(lMatch); updateMustLineValidity(); updateMustNotLineValidity(); } else { @@ -281,6 +289,7 @@ void AutomatedRssDownloader::clearRuleDefinitionBox() ui->lineSavePath->clear(); ui->comboLabel->clearEditText(); ui->checkRegex->setChecked(false); + ui->spinIgnorePeriod->setValue(0); updateFieldsToolTips(ui->checkRegex->isChecked()); updateMustLineValidity(); updateMustNotLineValidity(); @@ -333,6 +342,7 @@ void AutomatedRssDownloader::saveEditedRule() // Save new label if (!rule->label().isEmpty()) Preferences::instance()->addTorrentLabel(rule->label()); + rule->setIgnoreDays(ui->spinIgnorePeriod->value()); //rule->setRssFeeds(getSelectedFeeds()); // Save it m_editableRuleList->saveRule(rule); diff --git a/src/rss/automatedrssdownloader.ui b/src/rss/automatedrssdownloader.ui index 0ad25b5c3..827e039f9 100644 --- a/src/rss/automatedrssdownloader.ui +++ b/src/rss/automatedrssdownloader.ui @@ -330,6 +330,70 @@ + + + + + + Ignore subsequent matches for (0 to disable) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + days + + + 360 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + + + + + diff --git a/src/rss/rssarticle.cpp b/src/rss/rssarticle.cpp index d82260868..a0262c1de 100644 --- a/src/rss/rssarticle.cpp +++ b/src/rss/rssarticle.cpp @@ -109,6 +109,7 @@ void RssArticle::markAsRead() { m_read = true; m_parent->decrementUnreadCount(); m_parent->markAsDirty(); + emit articleWasRead(); } const QString& RssArticle::guid() const @@ -122,8 +123,6 @@ const QString& RssArticle::title() const } void RssArticle::handleTorrentDownloadSuccess(const QString &url) { - if (url == m_torrentUrl || url == m_link) { + if (url == m_torrentUrl || url == m_link) markAsRead(); - emit articleWasRead(); - } } diff --git a/src/rss/rssdownloadrule.cpp b/src/rss/rssdownloadrule.cpp index c5c3ade38..be1df6975 100644 --- a/src/rss/rssdownloadrule.cpp +++ b/src/rss/rssdownloadrule.cpp @@ -148,6 +148,8 @@ RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_has rule->setEnabled(rule_hash.value("enabled", false).toBool()); rule->setSavePath(rule_hash.value("save_path").toString()); rule->setLabel(rule_hash.value("label_assigned").toString()); + rule->setLastMatch(rule_hash.value("last_match").toDateTime()); + rule->setIgnoreDays(rule_hash.value("ignore_days").toInt()); return rule; } @@ -163,6 +165,8 @@ QVariantHash RssDownloadRule::toVariantHash() const hash["label_assigned"] = m_label; hash["use_regex"] = m_useRegex; hash["episode_filter"] = m_episodeFilter; + hash["last_match"] = m_lastMatch; + hash["ignore_days"] = m_ignoreDays; return hash; } diff --git a/src/rss/rssdownloadrule.h b/src/rss/rssdownloadrule.h index 6078de129..2f1c0e000 100644 --- a/src/rss/rssdownloadrule.h +++ b/src/rss/rssdownloadrule.h @@ -34,6 +34,7 @@ #include #include #include +#include class RssFeed; typedef QSharedPointer RssFeedPtr; @@ -61,6 +62,10 @@ public: inline void setLabel(const QString &_label) { m_label = _label; } inline bool isEnabled() const { return m_enabled; } inline void setEnabled(bool enable) { m_enabled = enable; } + inline void setLastMatch(const QDateTime& d) { m_lastMatch = d; } + inline QDateTime lastMatch() const { return m_lastMatch; } + inline void setIgnoreDays(int d) { m_ignoreDays = d; } + inline int ignoreDays() const { return m_ignoreDays; } inline QString mustContain() const { return m_mustContain.join(" "); } inline QString mustNotContain() const { return m_mustNotContain.join(" "); } inline bool useRegex() const { return m_useRegex; } @@ -81,6 +86,8 @@ private: bool m_enabled; QStringList m_rssFeeds; bool m_useRegex; + QDateTime m_lastMatch; + int m_ignoreDays; }; #endif // RSSDOWNLOADRULE_H diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index f64687ad4..d3ad039bd 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -353,6 +353,18 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const if (!matching_rule) return; + if (matching_rule->ignoreDays() > 0) { + QDateTime lastMatch = matching_rule->lastMatch(); + if (lastMatch.isValid()) { + if (QDateTime::currentDateTime() < lastMatch.addDays(matching_rule->ignoreDays())) { + connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection); + article->markAsRead(); + return; + } + } + } + matching_rule->setLastMatch(QDateTime::currentDateTime()); + rules->saveRulesToStorage(); // Download the torrent const QString& torrent_url = article->torrentUrl(); QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(article->title()).arg(displayName()));