Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRssReader.cpp
Go to the documentation of this file.
1/**************************************************************************
2**
3** This file is part of Qt Creator
4**
5** SPDX-FileCopyrightText: 2011 Nokia Corporation and /or its subsidiary(-ies).
6**
7** Contact: Nokia Corporation (qt-info@nokia.com)
8**
9**
10** SPDX-License-Identifier: LGPL-2.1-only
11**
12** In addition, as a special exception, Nokia gives you certain additional
13** rights. These rights are described in the Nokia Qt LGPL Exception
14** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
15**
16** Other Usage
17**
18** Alternatively, this file may be used in accordance with the terms and
19** conditions contained in a signed written agreement between you and Nokia.
20**
21** If you have questions regarding the use of this file, please contact
22** Nokia at qt-info@nokia.com.
23**
24**************************************************************************/
25
26#include "KisRssReader.h"
27
28#include <QString>
29#include <QFile>
30#include <QXmlStreamReader>
31#include <QUrl>
32
33QString shortenHtml(QString html)
34{
35 html.replace(QLatin1String("<a"), QLatin1String("<i"));
36 html.replace(QLatin1String("</a"), QLatin1String("</i"));
37 uint firstParaEndXhtml = (uint) html.indexOf(QLatin1String("</p>"));
38 uint firstParaEndHtml = (uint) html.indexOf(QLatin1String("<p>"), html.indexOf(QLatin1String("<p>"))+1);
39 uint firstParaEndBr = (uint) html.indexOf(QLatin1String("<br"));
40 uint firstParaEnd = qMin(firstParaEndXhtml, firstParaEndHtml);
41 firstParaEnd = qMin(firstParaEnd, firstParaEndBr);
42 return html.left(firstParaEnd);
43}
44
45
50
52 RssItem item;
53 item.source = requestUrl;
54 item.blogIcon = blogIcon;
55 item.blogName = blogName;
56 while (!m_streamReader.atEnd()) {
57 switch (m_streamReader.readNext()) {
58 case QXmlStreamReader::StartElement:
59 if (m_streamReader.name() == QLatin1String("title"))
60 item.title = m_streamReader.readElementText();
61 else if (m_streamReader.name() == QLatin1String("link"))
62 item.link = m_streamReader.readElementText();
63 else if (m_streamReader.name() == QLatin1String("pubDate")) {
64 QString dateStr = m_streamReader.readElementText();
65 item.pubDate = QDateTime::fromString(dateStr, Qt::RFC2822Date);
66 }
67 else if (m_streamReader.name() == QLatin1String("category"))
68 item.category = m_streamReader.readElementText();
69 else if (m_streamReader.name() == QLatin1String("description"))
70 item.description = m_streamReader.readElementText(); //shortenHtml(streamReader.readElementText());
71 break;
72 case QXmlStreamReader::EndElement:
73 if (m_streamReader.name() == QLatin1String("item"))
74 return item;
75 break;
76 default:
77 break;
78
79 }
80 }
81 return RssItem();
82}
83
84RssItemList KisRssReader::parseStream(QXmlStreamReader &streamReader) {
85 RssItemList list;
86 while (!streamReader.atEnd()) {
87 switch (streamReader.readNext()) {
88 case QXmlStreamReader::StartElement:
89 if (streamReader.name() == QLatin1String("item"))
90 list.append(parseItem());
91 else if (streamReader.name() == QLatin1String("title"))
92 blogName = streamReader.readElementText();
93 else if (streamReader.name() == QLatin1String("link")) {
94 if (!streamReader.namespaceUri().isEmpty())
95 break;
96 QString favIconString(streamReader.readElementText());
97 QUrl favIconUrl(favIconString);
98 favIconUrl.setPath(QLatin1String("favicon.ico"));
99 blogIcon = favIconUrl.toString();
100 blogIcon = QString(); // XXX: fix the favicon on krita.org!
101 }
102 break;
103 default:
104 break;
105 }
106 }
107 return list;
108}
109
110RssItemList KisRssReader::parse(QNetworkReply *reply) {
111 QUrl source = reply->request().url();
112 requestUrl = source.toString();
113 m_streamReader.setDevice(reply);
114
116}
117
119 requestUrl = file.fileName();
120 file.open(QIODevice::ReadOnly);
121 m_streamReader.setDevice(&file);
122
124
125 file.close();
126 return itemList;
127}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
QString shortenHtml(QString html)
unsigned int uint
QXmlStreamReader m_streamReader
RssItemList parseStream(QXmlStreamReader &streamReader)
QString blogName
QString requestUrl
RssItem parseItem()
QString blogIcon
RssItemList parse(QNetworkReply *reply)
QString title
QString category
QString blogName
QString blogIcon
QDateTime pubDate
QString source
QString description
QString link