|
|
@ -61,39 +61,9 @@ void RssDownloadRuleList::saveRulesToStorage() |
|
|
|
void RssDownloadRuleList::loadRulesFromStorage() |
|
|
|
void RssDownloadRuleList::loadRulesFromStorage() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); |
|
|
|
if (qBTRSS.contains("feed_filters")) { |
|
|
|
|
|
|
|
importFeedsInOldFormat(qBTRSS.value("feed_filters").toHash()); |
|
|
|
|
|
|
|
// Remove outdated rules
|
|
|
|
|
|
|
|
qBTRSS.remove("feed_filters"); |
|
|
|
|
|
|
|
// Save to new format
|
|
|
|
|
|
|
|
saveRulesToStorage(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Load from new format
|
|
|
|
|
|
|
|
loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash()); |
|
|
|
loadRulesFromVariantHash(qBTRSS.value("download_rules").toHash()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RssDownloadRuleList::importFeedsInOldFormat(const QHash<QString, QVariant> &rules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (const QString &feed_url, rules.keys()) { |
|
|
|
|
|
|
|
importFeedRulesInOldFormat(feed_url, rules.value(feed_url).toHash()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RssDownloadRuleList::importFeedRulesInOldFormat(const QString &feed_url, const QHash<QString, QVariant> &rules) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (const QString &rule_name, rules.keys()) { |
|
|
|
|
|
|
|
RssDownloadRulePtr rule = RssDownloadRule::fromOldFormat(rules.value(rule_name).toHash(), feed_url, rule_name); |
|
|
|
|
|
|
|
if (!rule) continue; |
|
|
|
|
|
|
|
// Check for rule name clash
|
|
|
|
|
|
|
|
while(m_rules.contains(rule->name())) { |
|
|
|
|
|
|
|
rule->setName(rule->name()+"_"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add the rule to the list
|
|
|
|
|
|
|
|
saveRule(rule); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QVariantHash RssDownloadRuleList::toVariantHash() const |
|
|
|
QVariantHash RssDownloadRuleList::toVariantHash() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
QVariantHash ret; |
|
|
|
QVariantHash ret; |
|
|
@ -105,12 +75,11 @@ QVariantHash RssDownloadRuleList::toVariantHash() const |
|
|
|
|
|
|
|
|
|
|
|
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h) |
|
|
|
void RssDownloadRuleList::loadRulesFromVariantHash(const QVariantHash &h) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const QVariant& v, h.values()) { |
|
|
|
for (QVariantHash::ConstIterator it = h.begin(); it != h.end(); it++) { |
|
|
|
RssDownloadRulePtr rule = RssDownloadRule::fromNewFormat(v.toHash()); |
|
|
|
RssDownloadRulePtr rule = RssDownloadRule::fromVariantHash(it.value().toHash()); |
|
|
|
if (rule && !rule->name().isEmpty()) { |
|
|
|
if (rule && !rule->name().isEmpty()) |
|
|
|
saveRule(rule); |
|
|
|
saveRule(rule); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule) |
|
|
|
void RssDownloadRuleList::saveRule(const RssDownloadRulePtr &rule) |
|
|
@ -182,30 +151,18 @@ bool RssDownloadRuleList::unserialize(const QString &path) |
|
|
|
QFile f(path); |
|
|
|
QFile f(path); |
|
|
|
if (f.open(QIODevice::ReadOnly)) { |
|
|
|
if (f.open(QIODevice::ReadOnly)) { |
|
|
|
QDataStream in(&f); |
|
|
|
QDataStream in(&f); |
|
|
|
if (path.endsWith(".filters", Qt::CaseInsensitive)) { |
|
|
|
|
|
|
|
// Old format (< 2.5.0)
|
|
|
|
|
|
|
|
qDebug("Old serialization format detected, processing..."); |
|
|
|
|
|
|
|
in.setVersion(QDataStream::Qt_4_3); |
|
|
|
|
|
|
|
QVariantHash tmp; |
|
|
|
|
|
|
|
in >> tmp; |
|
|
|
|
|
|
|
f.close(); |
|
|
|
|
|
|
|
if (tmp.isEmpty()) return false; |
|
|
|
|
|
|
|
qDebug("Processing was successful!"); |
|
|
|
|
|
|
|
// Unfortunately the feed_url is lost
|
|
|
|
|
|
|
|
importFeedRulesInOldFormat("", tmp); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qDebug("New serialization format detected, processing..."); |
|
|
|
|
|
|
|
in.setVersion(QDataStream::Qt_4_5); |
|
|
|
in.setVersion(QDataStream::Qt_4_5); |
|
|
|
QVariantHash tmp; |
|
|
|
QVariantHash tmp; |
|
|
|
in >> tmp; |
|
|
|
in >> tmp; |
|
|
|
f.close(); |
|
|
|
f.close(); |
|
|
|
if (tmp.isEmpty()) return false; |
|
|
|
if (tmp.isEmpty()) |
|
|
|
|
|
|
|
return false; |
|
|
|
qDebug("Processing was successful!"); |
|
|
|
qDebug("Processing was successful!"); |
|
|
|
loadRulesFromVariantHash(tmp); |
|
|
|
loadRulesFromVariantHash(tmp); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
qDebug("Error: could not open file at %s", qPrintable(path)); |
|
|
|
qDebug("Error: could not open file at %s", qPrintable(path)); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|