Browse Source

Some progress on new RSS download rules (still unused)

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
8597689a52
  1. 24
      src/rss/rssdownloadrule.cpp
  2. 2
      src/rss/rssdownloadrule.h
  3. 41
      src/rss/rssdownloadrulelist.cpp
  4. 4
      src/rss/rssdownloadrulelist.h

24
src/rss/rssdownloadrule.cpp

@ -82,6 +82,30 @@ RssDownloadRule RssDownloadRule::fromOldFormat(const QHash<QString, QVariant> &r @@ -82,6 +82,30 @@ RssDownloadRule RssDownloadRule::fromOldFormat(const QHash<QString, QVariant> &r
return rule;
}
RssDownloadRule RssDownloadRule::fromNewFormat(const QHash<QString, QVariant> &rule_hash)
{
RssDownloadRule rule;
rule.setName(rule_hash.value("name").toString());
rule.setMustContain(rule_hash.value("must_contain").toString());
rule.setMustNotContain(rule_hash.value("must_not_contain").toString());
rule.setRssFeeds(rule_hash.value("affected_feeds").toStringList());
rule.setEnabled(rule_hash.value("enabled", false).toBool());
rule.setLabel(rule_hash.value("label_assigned").toString());
return rule;
}
QHash<QString, QVariant> RssDownloadRule::toHash() const
{
QHash<QString, QVariant> hash;
hash["name"] = m_name;
hash["must_contain"] = m_mustContain.join(" ");
hash["must_not_contain"] = m_mustNotContain.join(" ");
hash["affected_feeds"] = m_rssFeeds;
hash["enabled"] = m_enabled;
hash["label_assigned"] = m_label;
return hash;
}
bool RssDownloadRule::operator==(const RssDownloadRule &other) {
return m_name == other.name();
}

2
src/rss/rssdownloadrule.h

@ -40,6 +40,8 @@ class RssDownloadRule @@ -40,6 +40,8 @@ class RssDownloadRule
public:
explicit RssDownloadRule();
static RssDownloadRule fromOldFormat(const QHash<QString, QVariant>& rule_hash, const QString &feed_url, const QString &rule_name); // Before v2.5.0
static RssDownloadRule fromNewFormat(const QHash<QString, QVariant> &rule_hash);
QHash<QString, QVariant> toHash() const;
bool matches(const QString &article_title) const;
void setMustContain(const QString &tokens);
void setMustNotContain(const QString &tokens);

41
src/rss/rssdownloadrulelist.cpp

@ -59,12 +59,25 @@ const RssDownloadRule * RssDownloadRuleList::findMatchingRule(const QString &fee @@ -59,12 +59,25 @@ const RssDownloadRule * RssDownloadRuleList::findMatchingRule(const QString &fee
return 0;
}
void RssDownloadRuleList::saveRulesToStorage()
{
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
qBTRSS.setValue("download_rules", toVariantList());
}
void RssDownloadRuleList::loadRulesFromStorage()
{
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
if(qBTRSS.contains("feed_filters")) {
importRulesInOldFormat(qBTRSS.value("feed_filters").toHash());
// Remove outdated rules
qBTRSS.remove("feed_filters");
// Save to new format
saveRulesToStorage();
return;
}
// Load from new format
loadRulesFromVariantList(qBTRSS.value("download_rules").toList());
}
void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant> &rules)
@ -72,7 +85,12 @@ void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant> @@ -72,7 +85,12 @@ void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant>
foreach(const QString &feed_url, rules.keys()) {
const QHash<QString, QVariant> feed_rules = rules.value(feed_url).toHash();
foreach(const QString &rule_name, feed_rules.keys()) {
const RssDownloadRule rule = RssDownloadRule::fromOldFormat(feed_rules.value(rule_name).toHash(), feed_url, rule_name);
RssDownloadRule rule = RssDownloadRule::fromOldFormat(feed_rules.value(rule_name).toHash(), feed_url, rule_name);
// Check for rule name clash
while(contains(rule)) {
rule.setName(rule.name()+"_");
}
// Add the rule to the list
append(rule);
}
}
@ -82,7 +100,28 @@ void RssDownloadRuleList::append(const RssDownloadRule &rule) @@ -82,7 +100,28 @@ void RssDownloadRuleList::append(const RssDownloadRule &rule)
{
Q_ASSERT(!contains(rule));
QList<RssDownloadRule>::append(rule);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].append(&last());
}
}
QVariantList RssDownloadRuleList::toVariantList() const
{
QVariantList l;
QList<RssDownloadRule>::const_iterator it;
for(it = begin(); it != end(); it++) {
l << it->toHash();
}
return l;
}
void RssDownloadRuleList::loadRulesFromVariantList(const QVariantList &l)
{
QVariantList::const_iterator it;
for(it=l.begin(); it !=l.end(); it++) {
RssDownloadRule rule = RssDownloadRule::fromNewFormat(it->toHash());
if(!rule.name().isEmpty())
append(rule);
}
}

4
src/rss/rssdownloadrulelist.h

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
#include <QList>
#include <QHash>
#include <QVariantList>
#include "rssdownloadrule.h"
@ -50,11 +51,14 @@ public: @@ -50,11 +51,14 @@ public:
static void drop();
const RssDownloadRule* findMatchingRule(const QString &feed_url, const QString &article_title) const;
inline QList<RssDownloadRule*> feedRules(const QString &feed_url) const { return m_feedRules.value(feed_url); }
QVariantList toVariantList() const;
void append(const RssDownloadRule& rule);
void saveRulesToStorage();
private:
void loadRulesFromStorage();
void importRulesInOldFormat(const QHash<QString, QVariant> &rules); // Before v2.5.0
void loadRulesFromVariantList(const QVariantList& l);
private:
QHash<QString, QList<RssDownloadRule*> > m_feedRules;

Loading…
Cancel
Save