aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp')
-rw-r--r--src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp87
1 files changed, 80 insertions, 7 deletions
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 cd29d5f0..5f62f99f 100644
--- a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp
+++ b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp
@@ -10,6 +10,8 @@
#include "LSession.h"
+#define DEBUG 0
+
//============
// PUBLIC
//============
@@ -116,18 +118,51 @@ RSSchannel RSSReader::readRSS(QByteArray bytes){
RSSchannel rssinfo;
//qDebug() << "Can Read XML Stream:" << !xml.hasError();
if(xml.readNextStartElement()){
- //qDebug() << " - RSS Element:" << xml.name();
- if(xml.name() == "rss" && (xml.attributes().value("version") =="2.0" || xml.attributes().value("version") =="0.91") ){
+ if(DEBUG) qDebug() << " - RSS Element:" << xml.name();
+ if(xml.name() == "rss" && (xml.attributes().value("version") =="2.0" || xml.attributes().value("version") =="0.91")) {
+ rssinfo.rss = true;
while(xml.readNextStartElement()){
//qDebug() << " - RSS Element:" << xml.name();
if(xml.name()=="channel"){ rssinfo = readRSSChannel(&xml); }
else{ xml.skipCurrentElement(); }
}
+ }else if(xml.name() == "feed") {
+ rssinfo.timetolive = -1;
+ rssinfo.rss = false;
+ while(xml.readNextStartElement()){
+ if(DEBUG) qDebug() << " - ATOM Element (channel):" << xml.name();
+ if(xml.name()=="entry") {
+ rssinfo.items << readRSSItemAtom(&xml);
+ }else if(xml.name()=="title"){
+ rssinfo.title = xml.readElementText();
+ if(DEBUG) qDebug() << "title" << rssinfo.link;
+ }else if(xml.name()=="link"){
+ QXmlStreamAttributes att = xml.attributes();
+ for(int i = 0; i < att.size(); i++) {
+ if(att[i].name() == "href") {
+ rssinfo.link = att[i].value().toString();
+ }
+ }
+ xml.readElementText();
+ if(DEBUG) qDebug() << "link" << rssinfo.link;
+ }else if(xml.name()=="subtitle"){
+ rssinfo.description = xml.readElementText();
+ }else if(xml.name()=="updated"){
+ rssinfo.lastBuildDate = ATOMDateTime(xml.readElementText());
+ }else if(xml.name()=="icon"){
+ rssinfo.icon_url = xml.readElementText();
+ if(DEBUG) qDebug() << "icon" << rssinfo.icon_url;
+ requestRSS(rssinfo.icon_url);
+ }else{
+ xml.skipCurrentElement();
+ }
+ }
}
}
- if(xml.hasError()){ qDebug() << " - XML Read Error:" << xml.errorString() << "\n" << bytes; }
+ //if(xml.hasError()){ qDebug() << " - XML Read Error:" << xml.errorString() << "\n" << bytes; }
return rssinfo;
}
+
RSSchannel RSSReader::readRSSChannel(QXmlStreamReader *rss){
RSSchannel info;
info.timetolive = -1;
@@ -151,6 +186,40 @@ RSSchannel RSSReader::readRSSChannel(QXmlStreamReader *rss){
return info;
}
+RSSitem RSSReader::readRSSItemAtom(QXmlStreamReader *rss){
+ RSSitem item;
+ while(rss->readNextStartElement()){
+ if(rss->name()=="title"){
+ item.title = rss->readElementText();
+ if(DEBUG) qDebug() << rss->name() << item.title;
+ }else if(rss->name()=="link"){
+ QXmlStreamAttributes att = rss->attributes();
+ for(int i = 0; i < att.size(); i++) {
+ if(att[i].name() == "href") {
+ item.link = att[i].value().toString();
+ }
+ }
+ rss->readElementText();
+ if(DEBUG) qDebug() << rss->name() << item.link;
+ }else if(rss->name()=="summary"){
+ item.description = rss->readElementText();
+ if(DEBUG) qDebug() << rss->name() << item.description;
+ } else if(rss->name()=="comments"){
+ item.comments_url = rss->readElementText();
+ if(DEBUG) qDebug() << rss->name() << item.comments_url;
+ } else if(rss->name()=="author"){
+ rss->readNextStartElement();
+ item.author = rss->readElementText();
+ if(DEBUG) qDebug() << "author" << item.author;
+ rss->skipCurrentElement();
+ }else if(rss->name()=="updated"){
+ item.pubdate = ATOMDateTime(rss->readElementText());
+ if(DEBUG) qDebug() << rss->name() << item.pubdate;
+ } else{ rss->skipCurrentElement(); }
+ }
+ return item;
+}
+
RSSitem RSSReader::readRSSItem(QXmlStreamReader *rss){
RSSitem item;
while(rss->readNextStartElement()){
@@ -192,17 +261,21 @@ QDateTime RSSReader::RSSDateTime(QString datetime){
return QDateTime::fromString(datetime, Qt::RFC2822Date);
}
+QDateTime RSSReader::ATOMDateTime(QString datetime){
+ return QDateTime::fromString(datetime, Qt::ISODate);
+}
+
//=================
// PRIVATE SLOTS
//=================
void RSSReader::replyFinished(QNetworkReply *reply){
QString url = reply->request().url().toString();
- //qDebug() << "Got Reply:" << url;
+ qDebug() << "Got Reply:" << url;
QString key = keyForUrl(url); //current hash key for this URL
QByteArray data = reply->readAll();
outstandingURLS.removeAll(url);
if(data.isEmpty()){
- //qDebug() << "No data returned:" << url;
+ qDebug() << "No data returned:" << url;
//see if the URL can be adjusted for known issues
bool handled = false;
QUrl redirecturl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
@@ -229,13 +302,13 @@ void RSSReader::replyFinished(QNetworkReply *reply){
//Could also be an icon fetch response
QStringList keys = hash.keys();
for(int i=0; i<keys.length(); i++){
- //qDebug() << " - Check for icon URL:" << hash[keys[i]].icon_url;
+ qDebug() << " - Check for icon URL:" << hash[keys[i]].icon_url;
if(hash[keys[i]].icon_url.toLower() == url.toLower()){ //needs to be case-insensitive
//Icon fetch response
RSSchannel info = hash[keys[i]];
QImage img = QImage::fromData(data);
info.icon = QIcon( QPixmap::fromImage(img) );
- //qDebug() << "Got Icon response:" << url << info.icon;
+ qDebug() << "Got Icon response:" << url << info.icon;
hash.insert(keys[i], info); //insert back into the hash
emit rssChanged( hash[keys[i]].originalURL );
break;
bgstack15