mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 04:54:18 +00:00
Optimized RSS settings code
This commit is contained in:
parent
29e465d2f6
commit
6629c39f01
@ -83,14 +83,14 @@ void AutomatedRssDownloader::loadSettings()
|
|||||||
// load dialog geometry
|
// load dialog geometry
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
||||||
restoreGeometry(settings.value("RssFeedDownloader/geometry").toByteArray());
|
restoreGeometry(settings.value("RssFeedDownloader/geometry").toByteArray());
|
||||||
ui->checkEnableDownloader->setChecked(RssSettings::isRssDownloadingEnabled());
|
ui->checkEnableDownloader->setChecked(RssSettings().isRssDownloadingEnabled());
|
||||||
// Display download rules
|
// Display download rules
|
||||||
loadRulesList();
|
loadRulesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutomatedRssDownloader::saveSettings()
|
void AutomatedRssDownloader::saveSettings()
|
||||||
{
|
{
|
||||||
RssSettings::setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked());
|
RssSettings().setRssDownloadingEnabled(ui->checkEnableDownloader->isChecked());
|
||||||
// Save dialog geometry
|
// Save dialog geometry
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
||||||
settings.setValue("RssFeedDownloader/geometry", saveGeometry());
|
settings.setValue("RssFeedDownloader/geometry", saveGeometry());
|
||||||
@ -117,8 +117,9 @@ void AutomatedRssDownloader::loadRulesList()
|
|||||||
|
|
||||||
void AutomatedRssDownloader::loadFeedList()
|
void AutomatedRssDownloader::loadFeedList()
|
||||||
{
|
{
|
||||||
const QStringList feed_aliases = RssSettings::getRssFeedsAliases();
|
const RssSettings settings;
|
||||||
const QStringList feed_urls = RssSettings::getRssFeedsUrls();
|
const QStringList feed_aliases = settings.getRssFeedsAliases();
|
||||||
|
const QStringList feed_urls = settings.getRssFeedsUrls();
|
||||||
for(int i=0; i<feed_aliases.size(); ++i) {
|
for(int i=0; i<feed_aliases.size(); ++i) {
|
||||||
QListWidgetItem *item = new QListWidgetItem(feed_aliases.at(i), ui->listFeeds);
|
QListWidgetItem *item = new QListWidgetItem(feed_aliases.at(i), ui->listFeeds);
|
||||||
item->setData(Qt::UserRole, feed_urls.at(i));
|
item->setData(Qt::UserRole, feed_urls.at(i));
|
||||||
|
@ -118,9 +118,10 @@ void RSSImp::on_actionManage_cookies_triggered() {
|
|||||||
qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname));
|
qDebug("RSS Feed hostname is: %s", qPrintable(feed_hostname));
|
||||||
Q_ASSERT(!feed_hostname.isEmpty());
|
Q_ASSERT(!feed_hostname.isEmpty());
|
||||||
bool ok = false;
|
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) {
|
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() {
|
void RSSImp::on_settingsButton_clicked() {
|
||||||
RssSettingsDlg dlg(this);
|
RssSettingsDlg dlg(this);
|
||||||
if(dlg.exec())
|
if(dlg.exec())
|
||||||
updateRefreshInterval(RssSettings::getRSSRefreshInterval());
|
updateRefreshInterval(RssSettings().getRSSRefreshInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSImp::on_rssDownloaderBtn_clicked()
|
void RSSImp::on_rssDownloaderBtn_clicked()
|
||||||
|
@ -57,7 +57,7 @@ void RssDownloadRuleList::drop()
|
|||||||
|
|
||||||
RssDownloadRule RssDownloadRuleList::findMatchingRule(const QString &feed_url, const QString &article_title) const
|
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);
|
QStringList rule_names = feedRules(feed_url);
|
||||||
foreach(const QString &rule_name, rule_names) {
|
foreach(const QString &rule_name, rule_names) {
|
||||||
RssDownloadRule rule = m_rules[rule_name];
|
RssDownloadRule rule = m_rules[rule_name];
|
||||||
|
@ -290,7 +290,7 @@ short RssFeed::readDoc(QIODevice* device) {
|
|||||||
resizeList();
|
resizeList();
|
||||||
|
|
||||||
// RSS Feed Downloader
|
// RSS Feed Downloader
|
||||||
if(RssSettings::isRssDownloadingEnabled()) {
|
if(RssSettings().isRssDownloadingEnabled()) {
|
||||||
foreach(RssArticle* item, values()) {
|
foreach(RssArticle* item, values()) {
|
||||||
if(item->isRead()) continue;
|
if(item->isRead()) continue;
|
||||||
QString torrent_url;
|
QString torrent_url;
|
||||||
@ -313,7 +313,7 @@ short RssFeed::readDoc(QIODevice* device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RssFeed::resizeList() {
|
void RssFeed::resizeList() {
|
||||||
unsigned int max_articles = RssSettings::getRSSMaxArticlesPerFeed();
|
unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
||||||
unsigned int nb_articles = this->size();
|
unsigned int nb_articles = this->size();
|
||||||
if(nb_articles > max_articles) {
|
if(nb_articles > max_articles) {
|
||||||
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values());
|
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values());
|
||||||
|
@ -40,7 +40,7 @@ RssManager* RssManager::m_instance = 0;
|
|||||||
RssManager::RssManager(): RssFolder() {
|
RssManager::RssManager(): RssFolder() {
|
||||||
loadStreamList();
|
loadStreamList();
|
||||||
connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll()));
|
connect(&newsRefresher, SIGNAL(timeout()), this, SLOT(refreshAll()));
|
||||||
refreshInterval = RssSettings::getRSSRefreshInterval();
|
refreshInterval = RssSettings().getRSSRefreshInterval();
|
||||||
newsRefresher.start(refreshInterval*60000);
|
newsRefresher.start(refreshInterval*60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +60,9 @@ void RssManager::updateRefreshInterval(unsigned int val){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RssManager::loadStreamList() {
|
void RssManager::loadStreamList() {
|
||||||
const QStringList streamsUrl = RssSettings::getRssFeedsUrls();
|
RssSettings settings;
|
||||||
const QStringList aliases = RssSettings::getRssFeedsAliases();
|
const QStringList streamsUrl = settings.getRssFeedsUrls();
|
||||||
|
const QStringList aliases = settings.getRssFeedsAliases();
|
||||||
if(streamsUrl.size() != aliases.size()){
|
if(streamsUrl.size() != aliases.size()){
|
||||||
std::cerr << "Corrupted Rss list, not loading it\n";
|
std::cerr << "Corrupted Rss list, not loading it\n";
|
||||||
return;
|
return;
|
||||||
@ -120,8 +121,9 @@ void RssManager::saveStreamList(){
|
|||||||
streamsUrl << stream_path;
|
streamsUrl << stream_path;
|
||||||
aliases << stream->getName();
|
aliases << stream->getName();
|
||||||
}
|
}
|
||||||
RssSettings::setRssFeedsUrls(streamsUrl);
|
RssSettings settings;
|
||||||
RssSettings::setRssFeedsAliases(aliases);
|
settings.setRssFeedsUrls(streamsUrl);
|
||||||
|
settings.setRssFeedsAliases(aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RssManager::insertSortElem(QList<RssArticle*> &list, RssArticle *item) {
|
void RssManager::insertSortElem(QList<RssArticle*> &list, RssArticle *item) {
|
||||||
|
@ -33,80 +33,68 @@
|
|||||||
|
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
|
||||||
class RssSettings {
|
class RssSettings: public QIniSettings{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
RssSettings() : QIniSettings("qBittorrent", "qBittorrent") {}
|
||||||
|
|
||||||
static bool isRSSEnabled() {
|
bool isRSSEnabled() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool();
|
||||||
return settings.value(QString::fromUtf8("Preferences/RSS/RSSEnabled"), false).toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRSSEnabled(bool enabled) {
|
void setRSSEnabled(bool enabled) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue(QString::fromUtf8("Preferences/RSS/RSSEnabled"), enabled);
|
||||||
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSEnabled"), enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int getRSSRefreshInterval() {
|
unsigned int getRSSRefreshInterval() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toUInt();
|
||||||
return settings.value(QString::fromUtf8("Preferences/RSS/RSSRefresh"), 5).toUInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRSSRefreshInterval(uint interval) {
|
void setRSSRefreshInterval(uint interval) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue(QString::fromUtf8("Preferences/RSS/RSSRefresh"), interval);
|
||||||
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSRefresh"), interval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getRSSMaxArticlesPerFeed() {
|
int getRSSMaxArticlesPerFeed() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
|
||||||
return settings.value(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), 50).toInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRSSMaxArticlesPerFeed(int nb) {
|
void setRSSMaxArticlesPerFeed(int nb) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), nb);
|
||||||
settings.setValue(QString::fromUtf8("Preferences/RSS/RSSMaxArticlesPerFeed"), nb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isRssDownloadingEnabled() {
|
bool isRssDownloadingEnabled() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value("Preferences/RSS/RssDownloading", true).toBool();
|
||||||
return settings.value("Preferences/RSS/RssDownloading", true).toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRssDownloadingEnabled(bool b) {
|
void setRssDownloadingEnabled(bool b) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue("Preferences/RSS/RssDownloading", b);
|
||||||
settings.setValue("Preferences/RSS/RssDownloading", b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList getRssFeedsUrls() {
|
QStringList getRssFeedsUrls() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value("Rss/streamList").toStringList();
|
||||||
return settings.value("Rss/streamList").toStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRssFeedsUrls(const QStringList &rssFeeds) {
|
void setRssFeedsUrls(const QStringList &rssFeeds) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue("Rss/streamList", rssFeeds);
|
||||||
settings.setValue("Rss/streamList", rssFeeds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList getRssFeedsAliases() {
|
QStringList getRssFeedsAliases() const {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
return value("Rss/streamAlias").toStringList();
|
||||||
return settings.value("Rss/streamAlias").toStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setRssFeedsAliases(const QStringList &rssAliases) {
|
void setRssFeedsAliases(const QStringList &rssAliases) {
|
||||||
QIniSettings settings("qBittorrent", "qBittorrent");
|
setValue("Rss/streamAlias", rssAliases);
|
||||||
settings.setValue("Rss/streamAlias", rssAliases);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<QByteArray> getHostNameCookies(const QString &host_name) {
|
QList<QByteArray> getHostNameCookies(const QString &host_name) const {
|
||||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
||||||
QMap<QString, QVariant> hosts_table = qBTRSS.value("hosts_cookies", QMap<QString, QVariant>()).toMap();
|
|
||||||
if(!hosts_table.contains(host_name)) return QList<QByteArray>();
|
if(!hosts_table.contains(host_name)) return QList<QByteArray>();
|
||||||
QByteArray raw_cookies = hosts_table.value(host_name).toByteArray();
|
QByteArray raw_cookies = hosts_table.value(host_name).toByteArray();
|
||||||
return raw_cookies.split(':');
|
return raw_cookies.split(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setHostNameCookies(QString host_name, const QList<QByteArray> &cookies) {
|
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
|
||||||
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
|
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
|
||||||
QMap<QString, QVariant> hosts_table = qBTRSS.value("hosts_cookies", QMap<QString, QVariant>()).toMap();
|
|
||||||
QByteArray raw_cookies = "";
|
QByteArray raw_cookies = "";
|
||||||
foreach(const QByteArray& cookie, cookies) {
|
foreach(const QByteArray& cookie, cookies) {
|
||||||
raw_cookies += cookie + ":";
|
raw_cookies += cookie + ":";
|
||||||
@ -114,7 +102,7 @@ public:
|
|||||||
if(raw_cookies.endsWith(":"))
|
if(raw_cookies.endsWith(":"))
|
||||||
raw_cookies.chop(1);
|
raw_cookies.chop(1);
|
||||||
hosts_table.insert(host_name, raw_cookies);
|
hosts_table.insert(host_name, raw_cookies);
|
||||||
qBTRSS.setValue("hosts_cookies", hosts_table);
|
setValue("Rss/hosts_cookies", hosts_table);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,8 +38,9 @@ RssSettingsDlg::RssSettingsDlg(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
// Load settings
|
// Load settings
|
||||||
ui->spinRSSRefresh->setValue(RssSettings::getRSSRefreshInterval());
|
const RssSettings settings;
|
||||||
ui->spinRSSMaxArticlesPerFeed->setValue(RssSettings::getRSSMaxArticlesPerFeed());
|
ui->spinRSSRefresh->setValue(settings.getRSSRefreshInterval());
|
||||||
|
ui->spinRSSMaxArticlesPerFeed->setValue(settings.getRSSMaxArticlesPerFeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
RssSettingsDlg::~RssSettingsDlg()
|
RssSettingsDlg::~RssSettingsDlg()
|
||||||
@ -50,6 +51,7 @@ RssSettingsDlg::~RssSettingsDlg()
|
|||||||
|
|
||||||
void RssSettingsDlg::on_buttonBox_accepted() {
|
void RssSettingsDlg::on_buttonBox_accepted() {
|
||||||
// Save settings
|
// Save settings
|
||||||
RssSettings::setRSSRefreshInterval(ui->spinRSSRefresh->value());
|
RssSettings settings;
|
||||||
RssSettings::setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value());
|
settings.setRSSRefreshInterval(ui->spinRSSRefresh->value());
|
||||||
|
settings.setRSSMaxArticlesPerFeed(ui->spinRSSMaxArticlesPerFeed->value());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user