mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Some progress on new RSS download rules (still unused)
This commit is contained in:
parent
41a61ced89
commit
8597689a52
@ -82,6 +82,30 @@ RssDownloadRule RssDownloadRule::fromOldFormat(const QHash<QString, QVariant> &r
|
|||||||
return rule;
|
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) {
|
bool RssDownloadRule::operator==(const RssDownloadRule &other) {
|
||||||
return m_name == other.name();
|
return m_name == other.name();
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ class RssDownloadRule
|
|||||||
public:
|
public:
|
||||||
explicit RssDownloadRule();
|
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 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;
|
bool matches(const QString &article_title) const;
|
||||||
void setMustContain(const QString &tokens);
|
void setMustContain(const QString &tokens);
|
||||||
void setMustNotContain(const QString &tokens);
|
void setMustNotContain(const QString &tokens);
|
||||||
|
@ -59,12 +59,25 @@ const RssDownloadRule * RssDownloadRuleList::findMatchingRule(const QString &fee
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RssDownloadRuleList::saveRulesToStorage()
|
||||||
|
{
|
||||||
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
||||||
|
qBTRSS.setValue("download_rules", toVariantList());
|
||||||
|
}
|
||||||
|
|
||||||
void RssDownloadRuleList::loadRulesFromStorage()
|
void RssDownloadRuleList::loadRulesFromStorage()
|
||||||
{
|
{
|
||||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
||||||
if(qBTRSS.contains("feed_filters")) {
|
if(qBTRSS.contains("feed_filters")) {
|
||||||
importRulesInOldFormat(qBTRSS.value("feed_filters").toHash());
|
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)
|
void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant> &rules)
|
||||||
@ -72,7 +85,12 @@ void RssDownloadRuleList::importRulesInOldFormat(const QHash<QString, QVariant>
|
|||||||
foreach(const QString &feed_url, rules.keys()) {
|
foreach(const QString &feed_url, rules.keys()) {
|
||||||
const QHash<QString, QVariant> feed_rules = rules.value(feed_url).toHash();
|
const QHash<QString, QVariant> feed_rules = rules.value(feed_url).toHash();
|
||||||
foreach(const QString &rule_name, feed_rules.keys()) {
|
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);
|
append(rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +100,28 @@ void RssDownloadRuleList::append(const RssDownloadRule &rule)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(!contains(rule));
|
Q_ASSERT(!contains(rule));
|
||||||
QList<RssDownloadRule>::append(rule);
|
QList<RssDownloadRule>::append(rule);
|
||||||
|
// Update feedRules hashtable
|
||||||
foreach(const QString &feed_url, rule.rssFeeds()) {
|
foreach(const QString &feed_url, rule.rssFeeds()) {
|
||||||
m_feedRules[feed_url].append(&last());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QVariantList>
|
||||||
|
|
||||||
#include "rssdownloadrule.h"
|
#include "rssdownloadrule.h"
|
||||||
|
|
||||||
@ -50,11 +51,14 @@ public:
|
|||||||
static void drop();
|
static void drop();
|
||||||
const RssDownloadRule* findMatchingRule(const QString &feed_url, const QString &article_title) const;
|
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); }
|
inline QList<RssDownloadRule*> feedRules(const QString &feed_url) const { return m_feedRules.value(feed_url); }
|
||||||
|
QVariantList toVariantList() const;
|
||||||
void append(const RssDownloadRule& rule);
|
void append(const RssDownloadRule& rule);
|
||||||
|
void saveRulesToStorage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadRulesFromStorage();
|
void loadRulesFromStorage();
|
||||||
void importRulesInOldFormat(const QHash<QString, QVariant> &rules); // Before v2.5.0
|
void importRulesInOldFormat(const QHash<QString, QVariant> &rules); // Before v2.5.0
|
||||||
|
void loadRulesFromVariantList(const QVariantList& l);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QString, QList<RssDownloadRule*> > m_feedRules;
|
QHash<QString, QList<RssDownloadRule*> > m_feedRules;
|
||||||
|
Loading…
Reference in New Issue
Block a user