From 92c7996ff46e58c493d4881890d68a5646ff164e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 18 Apr 2011 10:36:19 +0000 Subject: [PATCH] FEATURE: Added full regex support to RSS downloader --- Changelog | 1 + src/rss/automatedrssdownloader.cpp | 3 +++ src/rss/automatedrssdownloader.ui | 32 +++++++++++++++++++++--------- src/rss/rssdownloadrule.cpp | 18 ++++++++++++----- src/rss/rssdownloadrule.h | 3 +++ 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Changelog b/Changelog index 83a6b7180..d7a60b2e4 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ - FEATURE: Added UPnP/NAT-PMP port forward for the Web UI port - FEATURE: qBittorrent can update dynamic DNS services (DynDNS, no-ip) - FEATURE: Display peer connection type in peer list (BT, uTP, Web) + - FEATURE: Added full regex support to RSS downloader - BUGFIX: Change systray icon on the fly (no restart needed) - BUGFIX: Remember peer-level rate limits (requires libtorrent v0.16) - COSMETIC: Added monochrome icon for light themes diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index b19be39bc..458856d54 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -197,6 +197,7 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() ui->lineNotContains->setText(rule.mustNotContain()); ui->saveDiffDir_check->setChecked(!rule.savePath().isEmpty()); ui->lineSavePath->setText(rule.savePath()); + ui->checkRegex->setChecked(rule.useRegex()); if(rule.label().isEmpty()) { ui->comboLabel->setCurrentIndex(-1); ui->comboLabel->clearEditText(); @@ -225,6 +226,7 @@ void AutomatedRssDownloader::clearRuleDefinitionBox() ui->saveDiffDir_check->setChecked(false); ui->lineSavePath->clear(); ui->comboLabel->clearEditText(); + ui->checkRegex->setChecked(false); } RssDownloadRule AutomatedRssDownloader::getCurrentRule() const @@ -261,6 +263,7 @@ void AutomatedRssDownloader::saveEditedRule() rule.setEnabled(false); else rule.setEnabled(true); + rule.setUseRegex(ui->checkRegex->isChecked()); rule.setMustContain(ui->lineContains->text()); rule.setMustNotContain(ui->lineNotContains->text()); if(ui->saveDiffDir_check->isChecked()) diff --git a/src/rss/automatedrssdownloader.ui b/src/rss/automatedrssdownloader.ui index fc377f80c..7a8c1356d 100644 --- a/src/rss/automatedrssdownloader.ui +++ b/src/rss/automatedrssdownloader.ui @@ -129,7 +129,7 @@ 0 - + Must contain: @@ -139,10 +139,10 @@ - + - + Must not contain: @@ -152,10 +152,10 @@ - + - + Assign label: @@ -165,21 +165,21 @@ - + true - + Save to a different directory - + false @@ -192,7 +192,7 @@ - + @@ -213,6 +213,20 @@ + + + + Use regular expressions + + + + + + + Qt::Horizontal + + + diff --git a/src/rss/rssdownloadrule.cpp b/src/rss/rssdownloadrule.cpp index 7c1718de6..78843b7f9 100644 --- a/src/rss/rssdownloadrule.cpp +++ b/src/rss/rssdownloadrule.cpp @@ -37,7 +37,7 @@ #include "rssfeed.h" #include "rssarticle.h" -RssDownloadRule::RssDownloadRule() +RssDownloadRule::RssDownloadRule(): m_enabled(false), m_useRegex(false) { } @@ -46,7 +46,7 @@ bool RssDownloadRule::matches(const QString &article_title) const foreach(const QString& token, m_mustContain) { if(token.isEmpty() || token == "") continue; - QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard); + QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard); //reg.setMinimal(false); if(reg.indexIn(article_title) < 0) return false; } @@ -54,7 +54,7 @@ bool RssDownloadRule::matches(const QString &article_title) const // Checking not matching foreach(const QString& token, m_mustNotContain) { if(token.isEmpty()) continue; - QRegExp reg(token, Qt::CaseInsensitive, QRegExp::Wildcard); + QRegExp reg(token, Qt::CaseInsensitive, m_useRegex ? QRegExp::RegExp : QRegExp::Wildcard); if(reg.indexIn(article_title) > -1) return false; } return true; @@ -62,12 +62,18 @@ bool RssDownloadRule::matches(const QString &article_title) const void RssDownloadRule::setMustContain(const QString &tokens) { - m_mustContain = tokens.split(" "); + if(m_useRegex) + m_mustContain = QStringList() << tokens; + else + m_mustContain = tokens.split(" "); } void RssDownloadRule::setMustNotContain(const QString &tokens) { - m_mustNotContain = tokens.split(QRegExp("[\\s|]")); + if(m_useRegex) + m_mustNotContain = QStringList() << tokens; + else + m_mustNotContain = tokens.split(QRegExp("[\\s|]")); } RssDownloadRule RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, const QString &feed_url, const QString &rule_name) @@ -98,6 +104,7 @@ RssDownloadRule RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash) 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.setUseRegex(rule_hash.value("use_regex", false).toBool()); return rule; } @@ -111,6 +118,7 @@ QVariantHash RssDownloadRule::toVariantHash() const hash["affected_feeds"] = m_rssFeeds; hash["enabled"] = m_enabled; hash["label_assigned"] = m_label; + hash["use_regex"] = m_useRegex; return hash; } diff --git a/src/rss/rssdownloadrule.h b/src/rss/rssdownloadrule.h index c9ac46f05..b90f4dfaa 100644 --- a/src/rss/rssdownloadrule.h +++ b/src/rss/rssdownloadrule.h @@ -60,6 +60,8 @@ public: inline bool isValid() const { return !m_name.isEmpty(); } inline QString mustContain() const { return m_mustContain.join(" "); } inline QString mustNotContain() const { return m_mustNotContain.join(" "); } + inline bool useRegex() const { return m_useRegex; } + inline void setUseRegex(bool enabled) { m_useRegex = enabled; } QStringList findMatchingArticles(const RssFeed* feed) const; // Operators bool operator==(const RssDownloadRule &other); @@ -72,6 +74,7 @@ private: QString m_label; bool m_enabled; QStringList m_rssFeeds; + bool m_useRegex; }; #endif // RSSDOWNLOADRULE_H