Browse Source

Optimized RSS settings code

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
6629c39f01
  1. 9
      src/rss/automatedrssdownloader.cpp
  2. 7
      src/rss/rss_imp.cpp
  3. 2
      src/rss/rssdownloadrulelist.cpp
  4. 4
      src/rss/rssfeed.cpp
  5. 12
      src/rss/rssmanager.cpp
  6. 76
      src/rss/rsssettings.h
  7. 10
      src/rss/rsssettingsdlg.cpp

9
src/rss/automatedrssdownloader.cpp

@ -83,14 +83,14 @@ void AutomatedRssDownloader::loadSettings() @@ -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() @@ -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; i<feed_aliases.size(); ++i) {
QListWidgetItem *item = new QListWidgetItem(feed_aliases.at(i), ui->listFeeds);
item->setData(Qt::UserRole, feed_urls.at(i));

7
src/rss/rss_imp.cpp

@ -118,9 +118,10 @@ void RSSImp::on_actionManage_cookies_triggered() { @@ -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<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, RssSettings::getHostNameCookies(feed_hostname), &ok);
RssSettings settings;
QList<QByteArray> 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(){ @@ -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()

2
src/rss/rssdownloadrulelist.cpp

@ -57,7 +57,7 @@ void RssDownloadRuleList::drop() @@ -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];

4
src/rss/rssfeed.cpp

@ -290,7 +290,7 @@ short RssFeed::readDoc(QIODevice* device) { @@ -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) { @@ -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<RssArticle*> listItem = RssManager::sortNewsList(this->values());

12
src/rss/rssmanager.cpp

@ -40,7 +40,7 @@ RssManager* RssManager::m_instance = 0; @@ -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){ @@ -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(){ @@ -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<RssArticle*> &list, RssArticle *item) {

76
src/rss/rsssettings.h

@ -33,80 +33,68 @@ @@ -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<QByteArray> getHostNameCookies(const QString &host_name) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QMap<QString, QVariant> hosts_table = qBTRSS.value("hosts_cookies", QMap<QString, QVariant>()).toMap();
QList<QByteArray> getHostNameCookies(const QString &host_name) const {
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
if(!hosts_table.contains(host_name)) return QList<QByteArray>();
QByteArray raw_cookies = hosts_table.value(host_name).toByteArray();
return raw_cookies.split(':');
}
static void setHostNameCookies(QString host_name, const QList<QByteArray> &cookies) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QMap<QString, QVariant> hosts_table = qBTRSS.value("hosts_cookies", QMap<QString, QVariant>()).toMap();
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
QByteArray raw_cookies = "";
foreach(const QByteArray& cookie, cookies) {
raw_cookies += cookie + ":";
@ -114,7 +102,7 @@ public: @@ -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);
}
};

10
src/rss/rsssettingsdlg.cpp

@ -38,8 +38,9 @@ RssSettingsDlg::RssSettingsDlg(QWidget *parent) : @@ -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() @@ -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());
}

Loading…
Cancel
Save