diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index 27f40b87a..aed5620b1 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -83,14 +83,14 @@ void AutomatedRssDownloader::loadSettings() // load dialog geometry QIniSettings settings("qBittorrent", "qBittorrent"); restoreGeometry(settings.value("RssFeedDownloader/geometry").toByteArray()); - ui->checkEnableDownloader->setChecked(RssSettings::isRssDownloadingEnabled()); + ui->checkEnableDownloader->setChecked(RssSettings().isRssDownloadingEnabled()); // Display download rules loadRulesList(); } void AutomatedRssDownloader::saveSettings() { - RssSettings::setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked()); + RssSettings().setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked()); // Save dialog geometry QIniSettings settings("qBittorrent", "qBittorrent"); settings.setValue("RssFeedDownloader/geometry", saveGeometry()); @@ -117,8 +117,9 @@ void AutomatedRssDownloader::loadRulesList() void AutomatedRssDownloader::loadFeedList() { - const QStringList feed_aliases = RssSettings::getRssFeedsAliases(); - const QStringList feed_urls = RssSettings::getRssFeedsUrls(); + const RssSettings settings; + const QStringList feed_aliases = settings.getRssFeedsAliases(); + const QStringList feed_urls = settings.getRssFeedsUrls(); for(int i=0; ilistFeeds); item->setData(Qt::UserRole, feed_urls.at(i)); diff --git a/src/rss/rss_imp.cpp b/src/rss/rss_imp.cpp index 77c2f7135..253a6faee 100644 --- a/src/rss/rss_imp.cpp +++ b/src/rss/rss_imp.cpp @@ -118,9 +118,10 @@ void RSSImp::on_actionManage_cookies_triggered() { qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname)); Q_ASSERT(!feed_hostname.isEmpty()); bool ok = false; - QList raw_cookies = CookiesDlg::askForCookies(this, RssSettings::getHostNameCookies(feed_hostname), &ok); + RssSettings settings; + QList raw_cookies = CookiesDlg::askForCookies(this, settings.getHostNameCookies(feed_hostname), &ok); if(ok) { - RssSettings::setHostNameCookies(feed_hostname, raw_cookies); + settings.setHostNameCookies(feed_hostname, raw_cookies); } } @@ -643,7 +644,7 @@ RSSImp::~RSSImp(){ void RSSImp::on_settingsButton_clicked() { RssSettingsDlg dlg(this); if(dlg.exec()) - updateRefreshInterval(RssSettings::getRSSRefreshInterval()); + updateRefreshInterval(RssSettings().getRSSRefreshInterval()); } void RSSImp::on_rssDownloaderBtn_clicked() diff --git a/src/rss/rssdownloadrulelist.cpp b/src/rss/rssdownloadrulelist.cpp index 7172bcc0c..62c05feb6 100644 --- a/src/rss/rssdownloadrulelist.cpp +++ b/src/rss/rssdownloadrulelist.cpp @@ -57,7 +57,7 @@ void RssDownloadRuleList::drop() RssDownloadRule RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const { - Q_ASSERT(RssSettings::isRssDownloadingEnabled()); + Q_ASSERT(RssSettings().isRssDownloadingEnabled()); QStringList rule_names = feedRules(feed_url); foreach(const QString &rule_name, rule_names) { RssDownloadRule rule = m_rules[rule_name]; diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index e0b85bd67..d618426dc 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -290,7 +290,7 @@ short RssFeed::readDoc(QIODevice* device) { resizeList(); // RSS Feed Downloader - if(RssSettings::isRssDownloadingEnabled()) { + if(RssSettings().isRssDownloadingEnabled()) { foreach(RssArticle* item, values()) { if(item->isRead()) continue; QString torrent_url; @@ -313,7 +313,7 @@ short RssFeed::readDoc(QIODevice* device) { } void RssFeed::resizeList() { - unsigned int max_articles = RssSettings::getRSSMaxArticlesPerFeed(); + unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed(); unsigned int nb_articles = this->size(); if(nb_articles > max_articles) { QList listItem = RssManager::sortNewsList(this->values()); diff --git a/src/rss/rssmanager.cpp b/src/rss/rssmanager.cpp index 285e9c064..d17169419 100644 --- a/src/rss/rssmanager.cpp +++ b/src/rss/rssmanager.cpp @@ -40,7 +40,7 @@ RssManager* RssManager::m_instance = 0; RssManager::RssManager(): RssFolder() { loadStreamList(); connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll())); - refreshInterval = RssSettings::getRSSRefreshInterval(); + refreshInterval = RssSettings().getRSSRefreshInterval(); newsRefresher.start(refreshInterval*60000); } @@ -60,8 +60,9 @@ void RssManager::updateRefreshInterval(unsigned int val){ } void RssManager::loadStreamList() { - const QStringList streamsUrl = RssSettings::getRssFeedsUrls(); - const QStringList aliases = RssSettings::getRssFeedsAliases(); + RssSettings settings; + const QStringList streamsUrl = settings.getRssFeedsUrls(); + const QStringList aliases = settings.getRssFeedsAliases(); if(streamsUrl.size() != aliases.size()){ std::cerr << "Corrupted Rss list, not loading it\n"; return; @@ -120,8 +121,9 @@ void RssManager::saveStreamList(){ streamsUrl << stream_path; aliases << stream->getName(); } - RssSettings::setRssFeedsUrls(streamsUrl); - RssSettings::setRssFeedsAliases(aliases); + RssSettings settings; + settings.setRssFeedsUrls(streamsUrl); + settings.setRssFeedsAliases(aliases); } void RssManager::insertSortElem(QList &list, RssArticle *item) { diff --git a/src/rss/rsssettings.h b/src/rss/rsssettings.h index 4800d6654..4fb1ce481 100644 --- a/src/rss/rsssettings.h +++ b/src/rss/rsssettings.h @@ -33,80 +33,68 @@ #include "qinisettings.h" -class RssSettings { +class RssSettings: public QIniSettings{ + public: + RssSettings() : QIniSettings("qBittorrent", "qBittorrent") {} - static bool isRSSEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool(); + bool isRSSEnabled() const { + return value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool(); } - static void setRSSEnabled(bool enabled) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/RSS/RSSEnabled"), enabled); + void setRSSEnabled(bool enabled) { + setValue(QString::fromUtf8("Preferences/RSS/RSSEnabled"), enabled); } - static unsigned int getRSSRefreshInterval() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toUInt(); + unsigned int getRSSRefreshInterval() const { + return value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toUInt(); } - static void setRSSRefreshInterval(uint interval) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/RSS/RSSRefresh"), interval); + void setRSSRefreshInterval(uint interval) { + setValue(QString::fromUtf8("Preferences/RSS/RSSRefresh"), interval); } - static int getRSSMaxArticlesPerFeed() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt(); + int getRSSMaxArticlesPerFeed() const { + return value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt(); } - static void setRSSMaxArticlesPerFeed(int nb) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), nb); + void setRSSMaxArticlesPerFeed(int nb) { + setValue(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), nb); } - static bool isRssDownloadingEnabled() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Preferences/RSS/RssDownloading", true).toBool(); + bool isRssDownloadingEnabled() const { + return value("Preferences/RSS/RssDownloading", true).toBool(); } - static void setRssDownloadingEnabled(bool b) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Preferences/RSS/RssDownloading", b); + void setRssDownloadingEnabled(bool b) { + setValue("Preferences/RSS/RssDownloading", b); } - static QStringList getRssFeedsUrls() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Rss/streamList").toStringList(); + QStringList getRssFeedsUrls() const { + return value("Rss/streamList").toStringList(); } - static void setRssFeedsUrls(const QStringList &rssFeeds) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Rss/streamList", rssFeeds); + void setRssFeedsUrls(const QStringList &rssFeeds) { + setValue("Rss/streamList", rssFeeds); } - static QStringList getRssFeedsAliases() { - QIniSettings settings("qBittorrent", "qBittorrent"); - return settings.value("Rss/streamAlias").toStringList(); + QStringList getRssFeedsAliases() const { + return value("Rss/streamAlias").toStringList(); } - static void setRssFeedsAliases(const QStringList &rssAliases) { - QIniSettings settings("qBittorrent", "qBittorrent"); - settings.setValue("Rss/streamAlias", rssAliases); + void setRssFeedsAliases(const QStringList &rssAliases) { + setValue("Rss/streamAlias", rssAliases); } - static QList getHostNameCookies(const QString &host_name) { - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); + QList getHostNameCookies(const QString &host_name) const { + QMap hosts_table = value("Rss/hosts_cookies").toMap(); if(!hosts_table.contains(host_name)) return QList(); QByteArray raw_cookies = hosts_table.value(host_name).toByteArray(); return raw_cookies.split(':'); } - static void setHostNameCookies(QString host_name, const QList &cookies) { - QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QMap hosts_table = qBTRSS.value("hosts_cookies", QMap()).toMap(); + void setHostNameCookies(const QString &host_name, const QList &cookies) { + QMap hosts_table = value("Rss/hosts_cookies").toMap(); QByteArray raw_cookies = ""; foreach(const QByteArray& cookie, cookies) { raw_cookies += cookie + ":"; @@ -114,7 +102,7 @@ public: if(raw_cookies.endsWith(":")) raw_cookies.chop(1); hosts_table.insert(host_name, raw_cookies); - qBTRSS.setValue("hosts_cookies", hosts_table); + setValue("Rss/hosts_cookies", hosts_table); } }; diff --git a/src/rss/rsssettingsdlg.cpp b/src/rss/rsssettingsdlg.cpp index e975210b0..524f5fbf6 100644 --- a/src/rss/rsssettingsdlg.cpp +++ b/src/rss/rsssettingsdlg.cpp @@ -38,8 +38,9 @@ RssSettingsDlg::RssSettingsDlg(QWidget *parent) : { ui->setupUi(this); // Load settings - ui->spinRSSRefresh->setValue(RssSettings::getRSSRefreshInterval()); - ui->spinRSSMaxArticlesPerFeed->setValue(RssSettings::getRSSMaxArticlesPerFeed()); + const RssSettings settings; + ui->spinRSSRefresh->setValue(settings.getRSSRefreshInterval()); + ui->spinRSSMaxArticlesPerFeed->setValue(settings.getRSSMaxArticlesPerFeed()); } RssSettingsDlg::~RssSettingsDlg() @@ -50,6 +51,7 @@ RssSettingsDlg::~RssSettingsDlg() void RssSettingsDlg::on_buttonBox_accepted() { // Save settings - RssSettings::setRSSRefreshInterval(ui->spinRSSRefresh->value()); - RssSettings::setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value()); + RssSettings settings; + settings.setRSSRefreshInterval(ui->spinRSSRefresh->value()); + settings.setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value()); }