Browse Source

FEATURE: Added full regex support to RSS downloader

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
92c7996ff4
  1. 1
      Changelog
  2. 3
      src/rss/automatedrssdownloader.cpp
  3. 32
      src/rss/automatedrssdownloader.ui
  4. 14
      src/rss/rssdownloadrule.cpp
  5. 3
      src/rss/rssdownloadrule.h

1
Changelog

@ -5,6 +5,7 @@ @@ -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

3
src/rss/automatedrssdownloader.cpp

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

32
src/rss/automatedrssdownloader.ui

@ -129,7 +129,7 @@ @@ -129,7 +129,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Must contain:</string>
@ -139,10 +139,10 @@ @@ -139,10 +139,10 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QLineEdit" name="lineContains"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Must not contain:</string>
@ -152,10 +152,10 @@ @@ -152,10 +152,10 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="lineNotContains"/>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Assign label:</string>
@ -165,21 +165,21 @@ @@ -165,21 +165,21 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="comboLabel">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="saveDiffDir_check">
<property name="text">
<string>Save to a different directory</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>false</bool>
@ -192,7 +192,7 @@ @@ -192,7 +192,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineSavePath">
@ -213,6 +213,20 @@ @@ -213,6 +213,20 @@
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkRegex">
<property name="text">
<string>Use regular expressions</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>

14
src/rss/rssdownloadrule.cpp

@ -37,7 +37,7 @@ @@ -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 @@ -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 @@ -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,11 +62,17 @@ bool RssDownloadRule::matches(const QString &article_title) const @@ -62,11 +62,17 @@ bool RssDownloadRule::matches(const QString &article_title) const
void RssDownloadRule::setMustContain(const QString &tokens)
{
if(m_useRegex)
m_mustContain = QStringList() << tokens;
else
m_mustContain = tokens.split(" ");
}
void RssDownloadRule::setMustNotContain(const QString &tokens)
{
if(m_useRegex)
m_mustNotContain = QStringList() << tokens;
else
m_mustNotContain = tokens.split(QRegExp("[\\s|]"));
}
@ -98,6 +104,7 @@ RssDownloadRule RssDownloadRule::fromNewFormat(const QVariantHash &rule_hash) @@ -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 @@ -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;
}

3
src/rss/rssdownloadrule.h

@ -60,6 +60,8 @@ public: @@ -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: @@ -72,6 +74,7 @@ private:
QString m_label;
bool m_enabled;
QStringList m_rssFeeds;
bool m_useRegex;
};
#endif // RSSDOWNLOADRULE_H

Loading…
Cancel
Save