Browse Source

Fix RSS parsing

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
12280c6a0f
  1. 43
      src/rss/rssarticle.cpp
  2. 47
      src/rss/rssfeed.cpp

43
src/rss/rssarticle.cpp

@ -221,28 +221,29 @@ RssArticlePtr xmlToRssArticle(RssFeed* parent, QXmlStreamReader& xml)
QDateTime date; QDateTime date;
QString author; QString author;
Q_ASSERT(xml.isStartElement() && xml.name() == "item"); while(!xml.atEnd()) {
xml.readNext();
while (xml.readNextStartElement()) { if(xml.isEndElement() && xml.name() == "item")
if (xml.name() == "title") break;
title = xml.readElementText();
else if (xml.name() == "enclosure") { if (xml.isStartElement()) {
if (xml.attributes().value("type") == "application/x-bittorrent") if (xml.name() == "title")
torrentUrl = xml.attributes().value("url").toString(); title = xml.readElementText();
} else if (xml.name() == "enclosure") {
else if (xml.name() == "link") if (xml.attributes().value("type") == "application/x-bittorrent")
link = xml.readElementText(); torrentUrl = xml.attributes().value("url").toString();
else if (xml.name() == "description") }
description = xml.readElementText(); else if (xml.name() == "link")
else if (xml.name() == "pubDate") link = xml.readElementText();
date = RssArticle::parseDate(xml.readElementText()); else if (xml.name() == "description")
else if (xml.name() == "author") description = xml.readElementText();
author = xml.readElementText(); else if (xml.name() == "pubDate")
else if (xml.name() == "guid") date = RssArticle::parseDate(xml.readElementText());
guid = xml.readElementText(); else if (xml.name() == "author")
else { author = xml.readElementText();
qDebug() << "Skipping item tag: " << xml.name(); else if (xml.name() == "guid")
xml.skipCurrentElement(); guid = xml.readElementText();
} }
} }

47
src/rss/rssfeed.cpp

@ -214,31 +214,32 @@ void RssFeed::parseRSSChannel(QXmlStreamReader& xml)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
Q_ASSERT(xml.isStartElement() && xml.name() == "channel"); Q_ASSERT(xml.isStartElement() && xml.name() == "channel");
while (xml.readNextStartElement()) { while(!xml.atEnd()) {
if (xml.name() == "title") { xml.readNext();
m_title = xml.readElementText();
if (m_alias == url()) if (xml.isStartElement()) {
rename(m_title); if (xml.name() == "title") {
} m_title = xml.readElementText();
else if (xml.name() == "image") { if (m_alias == url())
QString icon_path = xml.attributes().value("url").toString(); rename(m_title);
if (!icon_path.isEmpty()) {
m_iconUrl = icon_path;
m_manager->rssDownloader()->downloadUrl(m_iconUrl);
} }
} else if (xml.name() == "image") {
else if (xml.name() == "item") { QString icon_path = xml.attributes().value("url").toString();
RssArticlePtr article = xmlToRssArticle(this, xml); if (!icon_path.isEmpty()) {
qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False"); m_iconUrl = icon_path;
if (article) { m_manager->rssDownloader()->downloadUrl(m_iconUrl);
QString guid = article->guid(); }
if (m_articles.contains(guid) && m_articles[guid]->isRead()) }
article->markAsRead(); else if (xml.name() == "item") {
m_articles[guid] = article; RssArticlePtr article = xmlToRssArticle(this, xml);
qDebug() << "Found RSS Item, valid: " << (article ? "True" : "False");
if (article) {
QString guid = article->guid();
if (m_articles.contains(guid) && m_articles[guid]->isRead())
article->markAsRead();
m_articles[guid] = article;
}
} }
} else {
qDebug() << "Skipping RSS tag: " << xml.name();
xml.skipCurrentElement();
} }
} }
} }

Loading…
Cancel
Save