From 9776a41d691068b48e03fd9f8a213dca413ced21 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Sat, 11 Jun 2016 07:42:14 -0400 Subject: Fix up the RSS reader plugin a bit so that it handles all the feeds by the original URL (in case of multiple redirects or invalid forwards - such as a capture portal on the network). --- .../desktop-plugins/rssreader/RSSObjects.cpp | 50 ++++++++++++++-------- .../desktop-plugins/rssreader/RSSObjects.h | 4 ++ 2 files changed, 35 insertions(+), 19 deletions(-) (limited to 'src-qt5/core/lumina-desktop/desktop-plugins') diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp index 654a005d..0a805252 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp +++ b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp @@ -37,7 +37,7 @@ QStringList RSSReader::channels(){ for(int i=0; irequest().url().toString(); //qDebug() << "Got Reply:" << url; + QString key = keyForUrl(url); //current hash key for this URL QByteArray data = reply->readAll(); outstandingURLS.removeAll(url); if(data.isEmpty()){ @@ -198,20 +209,20 @@ void RSSReader::replyFinished(QNetworkReply *reply){ //New URL redirect - make the change and send a new request QString newurl = redirecturl.toString(); //qDebug() << " - Redirect to:" << newurl; - if(hash.contains(url) && !hash.contains(newurl)){ - hash.insert(newurl, hash.take(url) ); //just move the data over to the new url + if(hash.contains(key) && !hash.contains(newurl)){ + hash.insert(newurl, hash.take(key) ); //just move the data over to the new url requestRSS(newurl); emit newChannelsAvailable(); handled = true; } } - if(!handled && hash.contains(url) ){ - emit rssChanged(url); + if(!handled && hash.contains(key) ){ + emit rssChanged(hash[key].originalURL); } return; } - if(!hash.contains(url)){ + if(!hash.contains(key)){ //qDebug() << " - hash does not contain URL:" << url; //URL removed from list while a request was outstanding? //Could also be an icon fetch response @@ -225,7 +236,7 @@ void RSSReader::replyFinished(QNetworkReply *reply){ info.icon = QIcon( QPixmap::fromImage(img) ); //qDebug() << "Got Icon response:" << url << info.icon; hash.insert(keys[i], info); //insert back into the hash - emit rssChanged(keys[i]); + emit rssChanged( hash[keys[i]].originalURL ); break; } } @@ -244,13 +255,14 @@ void RSSReader::replyFinished(QNetworkReply *reply){ if(info.timetolive <=0){ info.timetolive = 60; } //error in integer conversion from settings? info.lastsync = QDateTime::currentDateTime(); info.nextsync = info.lastsync.addSecs(info.timetolive * 60); //Now see if anything changed and save the info into the hash - bool changed = (hash[url].lastBuildDate.isNull() || (hash[url].lastBuildDate < info.lastBuildDate) ); + bool changed = (hash[key].lastBuildDate.isNull() || (hash[key].lastBuildDate < info.lastBuildDate) ); bool newinfo = false; - if(changed){ newinfo = hash[url].title.isEmpty(); } //no previous info from this URL - info.originalURL = hash[url].originalURL; //make sure this info gets preserved across updates - hash.insert(url, info); + if(changed){ newinfo = hash[key].title.isEmpty(); } //no previous info from this URL + info.originalURL = hash[key].originalURL; //make sure this info gets preserved across updates + if(!hash[key].icon.isNull()){ info.icon = hash[key].icon; } //copy over the icon from the previous reply + hash.insert(key, info); if(newinfo){ emit newChannelsAvailable(); } //new channel - else if(changed){ emit rssChanged(url); } //update to existing channel + else if(changed){ emit rssChanged(info.originalURL); } //update to existing channel } } diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h index c0e72e18..3069bf8d 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h +++ b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h @@ -78,6 +78,10 @@ private: QNetworkAccessManager *NMAN; QStringList outstandingURLS; + + //Simple hash data search functions + QString keyForUrl(QString url); + //Network request function void requestRSS(QString url); -- cgit