diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index c16bde235..4cc19f589 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -199,6 +199,7 @@ void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item) { qDebug() << Q_FUNC_INFO << item; if(!item) return; + if(!ui->listRules->findItems(item->text(), Qt::MatchExactly).isEmpty()) return; RssDownloadRule rule = m_ruleList->getRule(item->text()); if(!rule.isValid()) { rule.setName(item->text()); @@ -245,10 +246,12 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked() QListWidgetItem * item = ui->listRules->currentItem(); if(!item) return; // Ask for confirmation - if(QMessageBox::question(this, tr("Rule deletion confirmation"), tr("Are you sure you want to remove the download rule named %1?").arg(item->text())) != QMessageBox::Yes) + if(QMessageBox::question(this, tr("Rule deletion confirmation"), tr("Are you sure you want to remove the download rule named %1?").arg(item->text()), QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) return; // Actually remove the item ui->listRules->removeItemWidget(item); + // Remove it from the m_ruleList + m_ruleList->removeRule(item->text()); // Clean up memory delete item; } @@ -267,7 +270,7 @@ void AutomatedRssDownloader::on_exportBtn_clicked() return; } // Ask for a save path - QString save_path = QFileDialog::getSaveFileName(this, tr("Where would you like to save the list?"), QDir::homePath(), tr("Rule list (*.rssrules *.filters)")); + QString save_path = QFileDialog::getSaveFileName(this, tr("Where would you like to save the list?"), QDir::homePath(), tr("Rules list (*.rssrules)")); if(save_path.isEmpty()) return; if(!save_path.endsWith(".rssrules", Qt::CaseInsensitive)) save_path += ".rssrules"; @@ -279,5 +282,12 @@ void AutomatedRssDownloader::on_exportBtn_clicked() void AutomatedRssDownloader::on_importBtn_clicked() { - // TODO + // Ask for filter path + QString load_path = QFileDialog::getOpenFileName(this, tr("Please point to the RSS download rules file"), QDir::homePath(), tr("Rules list (*.rssrules *.filters)")); + if(load_path.isEmpty() || !QFile::exists(load_path)) return; + // Load it + if(m_ruleList->unserialize(load_path)) { + QMessageBox::warning(this, tr("Import Error"), tr("Failed to import the selected rules file")); + return; + } } diff --git a/src/rss/rssdownloadrule.cpp b/src/rss/rssdownloadrule.cpp index c3efe0a9c..588bd859e 100644 --- a/src/rss/rssdownloadrule.cpp +++ b/src/rss/rssdownloadrule.cpp @@ -77,7 +77,7 @@ RssDownloadRule RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, co rule.setSavePath(rule_hash.value("save_path", "").toString()); // Is enabled? QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - const QHash feeds_w_downloader = qBTRSS.value("downloader_on").toHash(); + const QHash feeds_w_downloader = qBTRSS.value("downloader_on", true).toHash(); rule.setEnabled(feeds_w_downloader.value(feed_url, false).toBool()); // label was unsupported < 2.5.0 return rule; diff --git a/src/rss/rssdownloadrulelist.cpp b/src/rss/rssdownloadrulelist.cpp index a6f3fd318..dbd3991b1 100644 --- a/src/rss/rssdownloadrulelist.cpp +++ b/src/rss/rssdownloadrulelist.cpp @@ -29,6 +29,7 @@ */ #include +#include #include "rssdownloadrulelist.h" #include "qinisettings.h" @@ -133,6 +134,7 @@ void RssDownloadRuleList::saveRule(const RssDownloadRule &rule) void RssDownloadRuleList::removeRule(const QString &name) { + qDebug() << Q_FUNC_INFO << name; if(!m_rules.contains(name)) return; const RssDownloadRule rule = m_rules.take(name); // Update feedRules hashtable @@ -184,3 +186,29 @@ bool RssDownloadRuleList::serialize(const QString& path) return false; } } + +bool RssDownloadRuleList::unserialize(const QString &path) +{ + QFile f(path); + if(f.open(QIODevice::ReadOnly)) { + QDataStream in(&f); + if(path.endsWith(".filters")) { + // Old format (< 2.5.0) + in.setVersion(QDataStream::Qt_4_3); + QVariantHash tmp; + in >> tmp; + f.close(); + if(tmp.isEmpty()) return false; + importRulesInOldFormat(tmp); + } else { + in.setVersion(QDataStream::Qt_4_5); + QVariantHash tmp; + in >> tmp; + f.close(); + if(tmp.isEmpty()) return false; + loadRulesFromVariantHash(tmp); + } + return true; + } + return false; +} diff --git a/src/rss/rssdownloadrulelist.h b/src/rss/rssdownloadrulelist.h index fce1528fe..e28b18a98 100644 --- a/src/rss/rssdownloadrulelist.h +++ b/src/rss/rssdownloadrulelist.h @@ -59,6 +59,7 @@ public: inline QStringList ruleNames() const { return m_rules.keys(); } inline bool isEmpty() const { return m_rules.isEmpty(); } bool serialize(const QString& path); + bool unserialize(const QString& path); private: void loadRulesFromStorage();