Added back support for RSS download rules import

Fix rule deletion
This commit is contained in:
Christophe Dumez 2010-11-13 12:33:52 +00:00
parent 265ab7bef2
commit d7b0299416
4 changed files with 43 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -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<QString, QVariant> feeds_w_downloader = qBTRSS.value("downloader_on").toHash();
const QHash<QString, QVariant> 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;

View file

@ -29,6 +29,7 @@
*/
#include <QFile>
#include <QDebug>
#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;
}

View file

@ -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();