-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRss.cpp
108 lines (87 loc) · 2.69 KB
/
getRss.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "getRss.h"
#include <QCoreApplication>
#include <QXmlStreamReader>
#include <QDebug>
#include <QStringList>
#include <algorithm>
bool onlyCountry;
GetRss::GetRss(QObject *parent) : QObject(parent)
{
manager = new QNetworkAccessManager(this);
reply = NULL;
}
void GetRss::getRss(QString countries)
{
if (countries == "countries.xml"){
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/.database/.rss/" + countries));
onlyCountry = false;
reply = manager->get(request);
} else{
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/.database/.rss/" + countries));
onlyCountry = true;
reply = manager->get(request);
}
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void GetRss::replyFinished()
{
if (reply->error() == QNetworkReply::NoError)
{
QByteArray data = reply->readAll();
processXmlData(data);
}
else
{
qDebug() << "Error downloading XML: " << reply->errorString();
}
reply->deleteLater();
reply = NULL;
emit dataProcessed();
}
void GetRss::processXmlData(const QByteArray &xmlData)
{
QStringList appInfoList; // Èñïîëüçóåì QStringList
QXmlStreamReader xml(xmlData);
while (!xml.hasError() && !xml.atEnd())
{
if (xml.isStartElement())
{
if (xml.name() == "country")
{
if (!onlyCountry)
{
QString name = xml.attributes().value("name").toString();
QString file = xml.attributes().value("file").toString();
QString app = name + "," + file;
appInfoList.append(app);
}
}
else if (xml.name() == "rss")
{
if (onlyCountry)
{
QString name = xml.attributes().value("name").toString();
QString url = xml.attributes().value("url").toString();
QString app = name + "," + url;
appInfoList.append(app);
}
}
}
xml.readNext();
}
if (xml.hasError())
{
qDebug() << "Error parsing XML: " << xml.errorString();
}
else {
std::sort(appInfoList.begin(), appInfoList.end());
m_appInfo = appInfoList;// Ïðèñâàèâàåì ñïèñîê m_appInfo
emit appInfoChanged();
emit processFinished();
// Èçëó÷àåì ñèãíàë îá èçìåíåíèè ñâîéñòâà
}
}
QStringList GetRss::appInfoList() const
{
return m_appInfo; // Âîçâðàùàåì ñïèñîê m_appInfo
}