Browse Source

Added back support for RSS download rules export

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
265ab7bef2
  1. 1
      Changelog
  2. 24
      src/rss/automatedrssdownloader.cpp
  3. 4
      src/rss/automatedrssdownloader.h
  4. 20
      src/rss/rssdownloadrulelist.cpp
  5. 2
      src/rss/rssdownloadrulelist.h

1
Changelog

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
- FEATURE: Bring up the connection settings when clicking on the connection status icon
- COSMETIC: Replaced message box by on-screen notification for download errors
- COSMETIC: Improved the torrent creation tool appearance
- OTHERS: Dropped support for Qt <= 4.4
* Tue Aug 24 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.4.0
- FEATURE: Added actions to "Move to top/bottom" of priority queue

24
src/rss/automatedrssdownloader.cpp

@ -216,7 +216,7 @@ void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item) @@ -216,7 +216,7 @@ void AutomatedRssDownloader::saveCurrentRule(QListWidgetItem * item)
rule.setLabel(ui->comboLabel->currentText());
// Save new label
if(!rule.label().isEmpty())
Preferences::addTorrentLabel(rule.label());
Preferences::addTorrentLabel(rule.label());
rule.setRssFeeds(getSelectedFeeds());
// Save it
m_ruleList->saveRule(rule);
@ -259,3 +259,25 @@ void AutomatedRssDownloader::on_browseSP_clicked() @@ -259,3 +259,25 @@ void AutomatedRssDownloader::on_browseSP_clicked()
if(!save_path.isEmpty())
ui->lineSavePath->setText(save_path);
}
void AutomatedRssDownloader::on_exportBtn_clicked()
{
if(m_ruleList->isEmpty()) {
QMessageBox::warning(this, tr("Invalid action"), tr("The list is empty, there is nothing to export."));
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)"));
if(save_path.isEmpty()) return;
if(!save_path.endsWith(".rssrules", Qt::CaseInsensitive))
save_path += ".rssrules";
if(!m_ruleList->serialize(save_path)) {
QMessageBox::warning(this, tr("I/O Error"), tr("Failed to create the destination file"));
return;
}
}
void AutomatedRssDownloader::on_importBtn_clicked()
{
// TODO
}

4
src/rss/automatedrssdownloader.h

@ -64,6 +64,10 @@ private slots: @@ -64,6 +64,10 @@ private slots:
void on_removeRuleBtn_clicked();
void on_browseSP_clicked();
void on_exportBtn_clicked();
void on_importBtn_clicked();
private:
RssDownloadRule getCurrentRule() const;
void initLabelCombobox();

20
src/rss/rssdownloadrulelist.cpp

@ -28,6 +28,8 @@ @@ -28,6 +28,8 @@
* Contact : chris@qbittorrent.org
*/
#include <QFile>
#include "rssdownloadrulelist.h"
#include "qinisettings.h"
@ -135,7 +137,7 @@ void RssDownloadRuleList::removeRule(const QString &name) @@ -135,7 +137,7 @@ void RssDownloadRuleList::removeRule(const QString &name)
const RssDownloadRule rule = m_rules.take(name);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].removeOne(rule.name());
m_feedRules[feed_url].removeOne(rule.name());
}
// Save rules
saveRulesToStorage();
@ -158,7 +160,7 @@ void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new @@ -158,7 +160,7 @@ void RssDownloadRuleList::renameRule(const QString &old_name, const QString &new
m_rules.insert(new_name, rule);
// Update feedRules hashtable
foreach(const QString &feed_url, rule.rssFeeds()) {
m_feedRules[feed_url].replace(m_feedRules[feed_url].indexOf(old_name), new_name);
m_feedRules[feed_url].replace(m_feedRules[feed_url].indexOf(old_name), new_name);
}
// Save rules
saveRulesToStorage();
@ -168,3 +170,17 @@ RssDownloadRule RssDownloadRuleList::getRule(const QString &name) const @@ -168,3 +170,17 @@ RssDownloadRule RssDownloadRuleList::getRule(const QString &name) const
{
return m_rules.value(name);
}
bool RssDownloadRuleList::serialize(const QString& path)
{
QFile f(path);
if(f.open(QIODevice::WriteOnly)) {
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_5);
out << toVariantHash();
f.close();
return true;
} else {
return false;
}
}

2
src/rss/rssdownloadrulelist.h

@ -57,6 +57,8 @@ public: @@ -57,6 +57,8 @@ public:
void renameRule(const QString &old_name, const QString &new_name);
RssDownloadRule getRule(const QString &name) const;
inline QStringList ruleNames() const { return m_rules.keys(); }
inline bool isEmpty() const { return m_rules.isEmpty(); }
bool serialize(const QString& path);
private:
void loadRulesFromStorage();

Loading…
Cancel
Save