mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-27 11:49:01 +03:00
Added back support for RSS download rules import
Fix rule deletion
This commit is contained in:
parent
265ab7bef2
commit
d7b0299416
4 changed files with 43 additions and 4 deletions
|
@ -199,6 +199,7 @@ void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << item;
|
qDebug() << Q_FUNC_INFO << item;
|
||||||
if(!item) return;
|
if(!item) return;
|
||||||
|
if(!ui->listRules->findItems(item->text(), Qt::MatchExactly).isEmpty()) return;
|
||||||
RssDownloadRule rule = m_ruleList->getRule(item->text());
|
RssDownloadRule rule = m_ruleList->getRule(item->text());
|
||||||
if(!rule.isValid()) {
|
if(!rule.isValid()) {
|
||||||
rule.setName(item->text());
|
rule.setName(item->text());
|
||||||
|
@ -245,10 +246,12 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked()
|
||||||
QListWidgetItem * item = ui->listRules->currentItem();
|
QListWidgetItem * item = ui->listRules->currentItem();
|
||||||
if(!item) return;
|
if(!item) return;
|
||||||
// Ask for confirmation
|
// 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;
|
return;
|
||||||
// Actually remove the item
|
// Actually remove the item
|
||||||
ui->listRules->removeItemWidget(item);
|
ui->listRules->removeItemWidget(item);
|
||||||
|
// Remove it from the m_ruleList
|
||||||
|
m_ruleList->removeRule(item->text());
|
||||||
// Clean up memory
|
// Clean up memory
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +270,7 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Ask for a save path
|
// 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.isEmpty()) return;
|
||||||
if(!save_path.endsWith(".rssrules", Qt::CaseInsensitive))
|
if(!save_path.endsWith(".rssrules", Qt::CaseInsensitive))
|
||||||
save_path += ".rssrules";
|
save_path += ".rssrules";
|
||||||
|
@ -279,5 +282,12 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
|
||||||
|
|
||||||
void AutomatedRssDownloader::on_importBtn_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ RssDownloadRule RssDownloadRule::fromOldFormat(const QVariantHash &rule_hash, co
|
||||||
rule.setSavePath(rule_hash.value("save_path", "").toString());
|
rule.setSavePath(rule_hash.value("save_path", "").toString());
|
||||||
// Is enabled?
|
// Is enabled?
|
||||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
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());
|
rule.setEnabled(feeds_w_downloader.value(feed_url, false).toBool());
|
||||||
// label was unsupported < 2.5.0
|
// label was unsupported < 2.5.0
|
||||||
return rule;
|
return rule;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "rssdownloadrulelist.h"
|
#include "rssdownloadrulelist.h"
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
@ -133,6 +134,7 @@ void RssDownloadRuleList::saveRule(const RssDownloadRule &rule)
|
||||||
|
|
||||||
void RssDownloadRuleList::removeRule(const QString &name)
|
void RssDownloadRuleList::removeRule(const QString &name)
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << name;
|
||||||
if(!m_rules.contains(name)) return;
|
if(!m_rules.contains(name)) return;
|
||||||
const RssDownloadRule rule = m_rules.take(name);
|
const RssDownloadRule rule = m_rules.take(name);
|
||||||
// Update feedRules hashtable
|
// Update feedRules hashtable
|
||||||
|
@ -184,3 +186,29 @@ bool RssDownloadRuleList::serialize(const QString& path)
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public:
|
||||||
inline QStringList ruleNames() const { return m_rules.keys(); }
|
inline QStringList ruleNames() const { return m_rules.keys(); }
|
||||||
inline bool isEmpty() const { return m_rules.isEmpty(); }
|
inline bool isEmpty() const { return m_rules.isEmpty(); }
|
||||||
bool serialize(const QString& path);
|
bool serialize(const QString& path);
|
||||||
|
bool unserialize(const QString& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadRulesFromStorage();
|
void loadRulesFromStorage();
|
||||||
|
|
Loading…
Reference in a new issue