Browse Source

Rss code clean up

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
452a8b2ae2
  1. 51
      src/rss/rssfeed.cpp
  2. 2
      src/rss/rssfeed.h

51
src/rss/rssfeed.cpp

@ -43,42 +43,53 @@ RssFeed::RssFeed(RssFolder* parent, const QString &url): m_parent(parent), m_ico @@ -43,42 +43,53 @@ RssFeed::RssFeed(RssFolder* parent, const QString &url): m_parent(parent), m_ico
m_refreshed(false), m_downloadFailure(false), m_loading(false) {
qDebug() << Q_FUNC_INFO << url;
m_url = QUrl::fromEncoded(url.toUtf8()).toString();
QIniSettings qBTRSS("qBittorrent", "qBittorrent-rss");
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();
qDebug("Loading %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash();
const RssArticle rss_item = hashToRssArticle(this, item);
if(rss_item.isValid()) {
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);
// Load old RSS articles
loadItemsFromDisk();
}
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);
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");
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();
qDebug("Loading %d old items for feed %s", old_items.size(), displayName().toLocal8Bit().data());
foreach(const QVariant &var_it, old_items) {
QHash<QString, QVariant> item = var_it.toHash();
const RssArticle rss_item = hashToRssArticle(this, item);
if(rss_item.isValid()) {
m_articles.insert(rss_item.guid(), rss_item);
}
}
}
IRssFile::FileType RssFeed::type() const {
return IRssFile::FEED;
}

2
src/rss/rssfeed.h

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

Loading…
Cancel
Save