Browse Source

- Slightly improved RSS feeds loading: Saved news can be displayed before the Feed is effectively updated

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
2cbbd6ef50
  1. 27
      src/rss.h
  2. 9
      src/rss_imp.cpp
  3. 2
      src/rss_imp.h

27
src/rss.h

@ -367,9 +367,11 @@ public slots : @@ -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(){ @@ -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<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).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<QString, QVariant> item = var_it.toHash();
RssItem *rss_item = RssItem::fromHash(item);
if(rss_item->isValid())
listItem << rss_item;
}
}
~RssStream(){
@ -537,18 +549,6 @@ QString getIconUrl() { @@ -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<QString, QVariant> all_old_items = qBTRSS.value("old_items", QHash<QString, QVariant>()).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<QString, QVariant> 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(){ @@ -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;

9
src/rss_imp.cpp

@ -188,7 +188,7 @@ void RSSImp::on_actionMark_all_as_read_triggered() { @@ -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() { @@ -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 @@ -352,7 +353,7 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr
item->setToolTip(0, QString::fromUtf8("<b>")+tr("Description:")+QString::fromUtf8("</b> ")+stream->getDescription()+QString::fromUtf8("<br/><b>")+tr("url:")+QString::fromUtf8("</b> ")+stream->getUrl()+QString::fromUtf8("<br/><b>")+tr("Last refresh:")+QString::fromUtf8("</b> ")+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){ @@ -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);

2
src/rss_imp.h

@ -60,7 +60,7 @@ class RSSImp : public QWidget, public Ui::RSS{ @@ -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);

Loading…
Cancel
Save