From 2cbbd6ef50d012fece84e9fbef0620db4d123674 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 21 Aug 2009 14:48:33 +0000 Subject: [PATCH] - Slightly improved RSS feeds loading: Saved news can be displayed before the Feed is effectively updated --- src/rss.h | 27 ++++++++++++++------------- src/rss_imp.cpp | 9 +++++---- src/rss_imp.h | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/rss.h b/src/rss.h index a4054a7f9..812f3d8e1 100644 --- a/src/rss.h +++ b/src/rss.h @@ -367,9 +367,11 @@ public slots : void processDownloadedFile(QString file_path) { filePath = file_path; downloadFailure = false; + lastRefresh.start(); if(openRss() >= 0) { - lastRefresh.start(); refreshed = true; + } else { + qDebug("OpenRss: Feed update Failed"); } } @@ -381,6 +383,16 @@ void setDownloadFailed(){ public: RssStream(bittorrent *BTSession, QString _url): BTSession(BTSession), url(_url), alias(""), iconPath(":/Icons/rss16.png"), refreshed(false), downloadFailure(false), currently_loading(false) { qDebug("RSSStream constructed"); + QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); + QHash all_old_items = qBTRSS.value("old_items", QHash()).toHash(); + QVariantList old_items = all_old_items.value(url, QVariantList()).toList(); + qDebug("Loading %d old items for feed %s", old_items.size(), getAliasOrUrl().toLocal8Bit().data()); + foreach(const QVariant &var_it, old_items) { + QHash item = var_it.toHash(); + RssItem *rss_item = RssItem::fromHash(item); + if(rss_item->isValid()) + listItem << rss_item; + } } ~RssStream(){ @@ -537,18 +549,6 @@ QString getIconUrl() { private: // read and create items from a rss document short readDoc(const QDomDocument& doc) { - if(!refreshed) { - QSettings qBTRSS("qBittorrent", "qBittorrent-rss"); - QHash all_old_items = qBTRSS.value("old_items", QHash()).toHash(); - QVariantList old_items = all_old_items.value(url, QVariantList()).toList(); - qDebug("Loading %d old items for feed %s", old_items.size(), getAliasOrUrl().toLocal8Bit().data()); - foreach(const QVariant &var_it, old_items) { - QHash item = var_it.toHash(); - RssItem *rss_item = RssItem::fromHash(item); - if(rss_item->isValid()) - listItem << rss_item; - } - } // is it a rss file ? QDomElement root = doc.documentElement(); if(root.tagName() == QString::fromUtf8("html")){ @@ -890,6 +890,7 @@ void refreshAll(){ } void refresh(QString url) { + qDebug("Refreshing feed: %s", url.toLocal8Bit().data()); Q_ASSERT(streams.contains(url)); RssStream *stream = streams[url]; if(stream->isLoading()) return; diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 3fefa0a5c..739f782b9 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -188,7 +188,7 @@ void RSSImp::on_actionMark_all_as_read_triggered() { item->setData(0, Qt::DisplayRole, feed->getAliasOrUrl()+ QString::fromUtf8(" (0)")); } if(selectedItems.size()) - refreshNewsList(selectedItems.last(), 0); + refreshNewsList(selectedItems.last()); } //right-click somewhere, refresh all the streams @@ -257,7 +257,8 @@ void RSSImp::updateLastRefreshedTimeForStreams() { } // fills the newsList -void RSSImp::refreshNewsList(QTreeWidgetItem* item, int) { +void RSSImp::refreshNewsList(QTreeWidgetItem* item) { + if(!item) return; selectedFeedUrl = item->text(1); RssStream *stream = rssmanager->getFeed(selectedFeedUrl); qDebug("Getting the list of news"); @@ -352,7 +353,7 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr item->setToolTip(0, QString::fromUtf8("")+tr("Description:")+QString::fromUtf8(" ")+stream->getDescription()+QString::fromUtf8("
")+tr("url:")+QString::fromUtf8(" ")+stream->getUrl()+QString::fromUtf8("
")+tr("Last refresh:")+QString::fromUtf8(" ")+stream->getLastRefreshElapsedString()); // If the feed is selected, update the displayed news if(selectedFeedUrl == url){ - refreshNewsList(getTreeItemFromUrl(url), 0); + refreshNewsList(item); } } @@ -392,7 +393,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){ connect(actionOpen_news_URL, SIGNAL(triggered()), this, SLOT(openNewsUrl())); connect(actionDownload_torrent, SIGNAL(triggered()), this, SLOT(downloadTorrent())); - connect(listStreams, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(refreshNewsList(QTreeWidgetItem*,int))); + connect(listStreams, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(refreshNewsList(QTreeWidgetItem*))); connect(listNews, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(refreshTextBrowser(QListWidgetItem *))); connect(listNews, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(downloadTorrent())); refreshTimeTimer = new QTimer(this); diff --git a/src/rss_imp.h b/src/rss_imp.h index b8f3b15a2..aac36650e 100644 --- a/src/rss_imp.h +++ b/src/rss_imp.h @@ -60,7 +60,7 @@ class RSSImp : public QWidget, public Ui::RSS{ void copySelectedFeedsURL(); void createStream(); void refreshAllStreams(); - void refreshNewsList(QTreeWidgetItem* item, int); + void refreshNewsList(QTreeWidgetItem* item); void refreshTextBrowser(QListWidgetItem *); void updateLastRefreshedTimeForStreams(); void updateFeedIcon(QString url, QString icon_path);