diff --git a/Changelog b/Changelog index 0cd46db1b..59bab1466 100644 --- a/Changelog +++ b/Changelog @@ -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 - v2.4.0 - FEATURE: Added actions to "Move to top/bottom" of priority queue diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index ff33230df..c16bde235 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -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() 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 +} diff --git a/src/rss/automatedrssdownloader.h b/src/rss/automatedrssdownloader.h index e32179a7c..2ca70b265 100644 --- a/src/rss/automatedrssdownloader.h +++ b/src/rss/automatedrssdownloader.h @@ -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(); diff --git a/src/rss/rssdownloadrulelist.cpp b/src/rss/rssdownloadrulelist.cpp index cbc8904ee..a6f3fd318 100644 --- a/src/rss/rssdownloadrulelist.cpp +++ b/src/rss/rssdownloadrulelist.cpp @@ -28,6 +28,8 @@ * Contact : chris@qbittorrent.org */ +#include + #include "rssdownloadrulelist.h" #include "qinisettings.h" @@ -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 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 { 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; + } +} diff --git a/src/rss/rssdownloadrulelist.h b/src/rss/rssdownloadrulelist.h index cc26cbc54..fce1528fe 100644 --- a/src/rss/rssdownloadrulelist.h +++ b/src/rss/rssdownloadrulelist.h @@ -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();