Browse Source

Merge pull request #802 from Gelmir/rss_match_time_limit

Add setting to ignore RSS rule matches for X days
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
b9ce4d48a0
  1. 10
      src/rss/automatedrssdownloader.cpp
  2. 64
      src/rss/automatedrssdownloader.ui
  3. 5
      src/rss/rssarticle.cpp
  4. 4
      src/rss/rssdownloadrule.cpp
  5. 7
      src/rss/rssdownloadrule.h
  6. 12
      src/rss/rssfeed.cpp

10
src/rss/automatedrssdownloader.cpp

@ -255,6 +255,14 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -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() @@ -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() @@ -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);

64
src/rss/automatedrssdownloader.ui

@ -330,6 +330,70 @@ @@ -330,6 +330,70 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="lblIgnoreDays">
<property name="text">
<string comment="... X days">Ignore subsequent matches for (0 to disable)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinIgnorePeriod">
<property name="enabled">
<bool>true</bool>
</property>
<property name="suffix">
<string> days</string>
</property>
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblLastMatch">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

5
src/rss/rssarticle.cpp

@ -109,6 +109,7 @@ void RssArticle::markAsRead() { @@ -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 @@ -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();
}
}

4
src/rss/rssdownloadrule.cpp

@ -148,6 +148,8 @@ RssDownloadRulePtr RssDownloadRule::fromVariantHash(const QVariantHash &rule_has @@ -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 @@ -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;
}

7
src/rss/rssdownloadrule.h

@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
#include <QStringList>
#include <QVariantHash>
#include <QSharedPointer>
#include <QDateTime>
class RssFeed;
typedef QSharedPointer<RssFeed> RssFeedPtr;
@ -61,6 +62,10 @@ public: @@ -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: @@ -81,6 +86,8 @@ private:
bool m_enabled;
QStringList m_rssFeeds;
bool m_useRegex;
QDateTime m_lastMatch;
int m_ignoreDays;
};
#endif // RSSDOWNLOADRULE_H

12
src/rss/rssfeed.cpp

@ -353,6 +353,18 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const @@ -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()));

Loading…
Cancel
Save