Importance code refactoring related to the "preferences" code - Greatly improves performance

This commit is contained in:
Christophe Dumez
2010-11-16 20:34:31 +00:00
parent a640b08414
commit e5032a52c4
26 changed files with 976 additions and 1142 deletions

View File

@@ -220,7 +220,7 @@ RssDownloadRule AutomatedRssDownloader::getCurrentRule() const
void AutomatedRssDownloader::initLabelCombobox()
{
// Load custom labels
const QStringList customLabels = Preferences::getTorrentLabels();
const QStringList customLabels = Preferences().getTorrentLabels();
foreach(const QString& label, customLabels) {
ui->comboLabel->addItem(label);
}
@@ -252,7 +252,7 @@ void AutomatedRssDownloader::saveEditedRule()
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);

View File

@@ -47,6 +47,7 @@
#include "rssfolder.h"
#include "rssarticle.h"
#include "rssfeed.h"
#include "rsssettings.h"
#include "automatedrssdownloader.h"
enum NewsCols { NEWS_ICON, NEWS_TITLE_COL, NEWS_URL_COL, NEWS_ID };
@@ -117,9 +118,9 @@ 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, Preferences::getHostNameCookies(feed_hostname), &ok);
QList<QByteArray> raw_cookies = CookiesDlg::askForCookies(this, RssSettings::getHostNameCookies(feed_hostname), &ok);
if(ok) {
Preferences::setHostNameCookies(feed_hostname, raw_cookies);
RssSettings::setHostNameCookies(feed_hostname, raw_cookies);
}
}
@@ -642,7 +643,7 @@ RSSImp::~RSSImp(){
void RSSImp::on_settingsButton_clicked() {
RssSettingsDlg dlg(this);
if(dlg.exec())
updateRefreshInterval(Preferences::getRefreshInterval());
updateRefreshInterval(RssSettings::getRSSRefreshInterval());
}
void RSSImp::on_rssDownloaderBtn_clicked()

View File

@@ -120,7 +120,7 @@ bool RssDownloadRule::operator==(const RssDownloadRule &other) {
void RssDownloadRule::setSavePath(const QString &save_path)
{
if(!save_path.isEmpty() && QDir(save_path) != QDir(Preferences::getSavePath()))
if(!save_path.isEmpty() && QDir(save_path) != QDir(Preferences().getSavePath()))
m_savePath = save_path;
else
m_savePath = QString();

View File

@@ -95,6 +95,27 @@ public:
QIniSettings settings("qBittorrent", "qBittorrent");
settings.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();
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();
QByteArray raw_cookies = "";
foreach(const QByteArray& cookie, cookies) {
raw_cookies += cookie + ":";
}
if(raw_cookies.endsWith(":"))
raw_cookies.chop(1);
hosts_table.insert(host_name, raw_cookies);
qBTRSS.setValue("hosts_cookies", hosts_table);
}
};
#endif // RSSSETTINGS_H