diff options
author | ZackaryWelch <welch.zackary@gmail.com> | 2017-12-01 19:07:33 -0500 |
---|---|---|
committer | ZackaryWelch <welch.zackary@gmail.com> | 2017-12-04 19:20:47 -0500 |
commit | 4a5d95cb039989dc99677ce1b1203d909117e323 (patch) | |
tree | 140c3296b4876fd9ebbe733088b1bd5709210e0a /src-qt5/core/lumina-desktop/desktop-plugins/rssreader | |
parent | Oops - fix a typo in the ExternalProcess change. (diff) | |
download | lumina-4a5d95cb039989dc99677ce1b1203d909117e323.tar.gz lumina-4a5d95cb039989dc99677ce1b1203d909117e323.tar.bz2 lumina-4a5d95cb039989dc99677ce1b1203d909117e323.zip |
Preliminary ATOM parsing for the RSS reader
Diffstat (limited to 'src-qt5/core/lumina-desktop/desktop-plugins/rssreader')
-rw-r--r-- | src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp | 51 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h | 2 |
2 files changed, 51 insertions, 2 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..dab8e596 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp +++ b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.cpp @@ -116,18 +116,26 @@ 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") ){ + qDebug() << " - RSS Element:" << xml.name(); + if(xml.name() == "rss" && (xml.attributes().value("version") =="2.0" || xml.attributes().value("version") =="0.91")) { while(xml.readNextStartElement()){ //qDebug() << " - RSS Element:" << xml.name(); if(xml.name()=="channel"){ rssinfo = readRSSChannel(&xml); } else{ xml.skipCurrentElement(); } } + }else if(xml.name() == "feed") { + qDebug() << "starting feed"; + while(xml.readNextStartElement()){ + qDebug() << " - ATOM Element:" << xml.name(); + if(xml.name()=="entry"){ rssinfo = readRSSChannel(&xml); } + else{ xml.skipCurrentElement(); } + } } } 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 +159,45 @@ RSSchannel RSSReader::readRSSChannel(QXmlStreamReader *rss){ return info; } +RSSchannel RSSReader::readRSSChannelAtom(QXmlStreamReader *rss){ + RSSchannel info; + info.timetolive = -1; + while(rss->readNextStartElement()){ + qDebug() << " - RSS Element (channel):" <<rss->name(); + if(rss->name()=="entry"){ info.items << readRSSItemAtom(rss); } + else if(rss->name()=="title"){ info.title = rss->readElementText(); } + else if(rss->name()=="link"){ + QString txt = rss->readElementText(); + if(!txt.isEmpty()){ info.link = txt; } + } + else if(rss->name()=="subtitle"){ info.description = rss->readElementText(); } + else if(rss->name()=="updated"){ info.lastBuildDate = RSSDateTime(rss->readElementText()); } + else{ rss->skipCurrentElement(); } + } + return info; +} + +RSSitem RSSReader::readRSSItemAtom(QXmlStreamReader *rss){ + RSSitem item; + while(rss->readNextStartElement()){ + qDebug() << " - RSS Element (Item):" << rss->name(); + if(rss->name()=="title"){ item.title = rss->readElementText(); } + else if(rss->name()=="link"){ item.link = rss->readElementText(); } + else if(rss->name()=="summary"){ item.description = rss->readElementText(); } + else if(rss->name()=="comments"){ item.comments_url = rss->readElementText(); } + else if(rss->name()=="author"){ + //Special handling - this field can contain both email and name + rss->skipCurrentElement(); + item.author = rss->readElementText(); + qDebug() << item.author; + rss->skipCurrentElement(); + } + else if(rss->name()=="updated"){ item.pubdate = RSSDateTime(rss->readElementText()); } + else{ rss->skipCurrentElement(); } + } + return item; +} + RSSitem RSSReader::readRSSItem(QXmlStreamReader *rss){ RSSitem item; while(rss->readNextStartElement()){ 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 3069bf8d..eb37dab3 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h +++ b/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h @@ -88,7 +88,9 @@ private: //RSS parsing functions RSSchannel readRSS(QByteArray bytes); RSSchannel readRSSChannel(QXmlStreamReader *rss); + RSSchannel readRSSChannelAtom(QXmlStreamReader *rss); RSSitem readRSSItem(QXmlStreamReader *rss); + RSSitem readRSSItemAtom(QXmlStreamReader *rss); void readRSSImage(RSSchannel *item, QXmlStreamReader *rss); QDateTime RSSDateTime(QString datetime); |