1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-23 04:54:18 +00:00

Rss code clean up

This commit is contained in:
Christophe Dumez 2011-09-26 20:25:59 +03:00
parent bf746be692
commit 452a8b2ae2
2 changed files with 36 additions and 23 deletions

View File

@ -43,10 +43,44 @@ RssFeed::RssFeed(RssFolder* parent, const QString &url): m_parent(parent), m_ico
m_refreshed(false), m_downloadFailure(false), m_loading(false) { m_refreshed(false), m_downloadFailure(false), m_loading(false) {
qDebug() << Q_FUNC_INFO << url; qDebug() << Q_FUNC_INFO << url;
m_url = QUrl::fromEncoded(url.toUtf8()).toString(); m_url = QUrl::fromEncoded(url.toUtf8()).toString();
// Listen for new RSS downloads
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFinished(QString,QString)), SLOT(handleFinishedDownload(QString,QString)));
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFailure(QString,QString)), SLOT(handleDownloadFailure(QString,QString)));
// Download the RSS Feed icon
m_iconUrl = iconUrl();
RssManager::instance()->rssDownloader()->downloadUrl(m_iconUrl);
// Load old RSS articles
loadItemsFromDisk();
}
RssFeed::~RssFeed(){
// Saving current articles to hard disk
if(m_refreshed) {
saveItemsToDisk();
}
if(!m_icon.startsWith(":/") && QFile::exists(m_icon))
misc::safeRemove(m_icon);
}
void RssFeed::saveItemsToDisk() {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QVariantList old_items;
foreach(const RssArticle &item, m_articles.values()) {
old_items << item.toHash();
}
qDebug("Saving %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data());
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
all_old_items[m_url] = old_items;
qBTRSS.setValue("old_items", all_old_items);
}
void RssFeed::loadItemsFromDisk() {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss"); QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
const QVariantList old_items = all_old_items.value(m_url, QVariantList()).toList(); const QVariantList old_items = all_old_items.value(m_url, QVariantList()).toList();
qDebug("Loading %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data()); qDebug("Loading %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) { foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash(); QHash<QString, QVariant> item = var_it.toHash();
const RssArticle rss_item = hashToRssArticle(this, item); const RssArticle rss_item = hashToRssArticle(this, item);
@ -54,29 +88,6 @@ RssFeed::RssFeed(RssFolder* parent, const QString &url): m_parent(parent), m_ico
m_articles.insert(rss_item.guid(), rss_item); m_articles.insert(rss_item.guid(), rss_item);
} }
} }
// Listen for new RSS downloads
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFinished(QString,QString)), SLOT(handleFinishedDownload(QString,QString)));
connect(RssManager::instance()->rssDownloader(), SIGNAL(downloadFailure(QString,QString)), SLOT(handleDownloadFailure(QString,QString)));
// Download the RSS Feed icon
m_iconUrl = iconUrl();
RssManager::instance()->rssDownloader()->downloadUrl(m_iconUrl);
}
RssFeed::~RssFeed(){
// Saving current articles to hard disk
if(m_refreshed) {
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
QVariantList old_items;
foreach(const RssArticle &item, m_articles.values()) {
old_items << item.toHash();
}
qDebug("Saving %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data());
QHash<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).toHash();
all_old_items[m_url] = old_items;
qBTRSS.setValue("old_items", all_old_items);
}
if(!m_icon.startsWith(":/") && QFile::exists(m_icon))
misc::safeRemove(m_icon);
} }
IRssFile::FileType RssFeed::type() const { IRssFile::FileType RssFeed::type() const {

View File

@ -77,6 +77,8 @@ private:
bool parseXmlFile(const QString &file_path); bool parseXmlFile(const QString &file_path);
void downloadMatchingArticleTorrents(); void downloadMatchingArticleTorrents();
QString iconUrl() const; QString iconUrl() const;
void saveItemsToDisk();
void loadItemsFromDisk();
private: private:
QHash<QString, RssArticle> m_articles; QHash<QString, RssArticle> m_articles;