-
Notifications
You must be signed in to change notification settings - Fork 0
/
getApps.cpp
137 lines (107 loc) · 3.79 KB
/
getApps.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "getApps.h"
#include <QCoreApplication>
#include <QXmlStreamReader>
#include <QDebug>
#include <QStringList>
#include <algorithm>
bool dispIcon;
bool rss;
GetApps::GetApps(QObject *parent) : QObject(parent)
{
manager = new QNetworkAccessManager(this);
reply = NULL;
}
void GetApps::getApps()
{
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/openrepos/catalog_new.xml"));
reply = manager->get(request);
dispIcon = true;
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void GetApps::getGames()
{
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/openrepos/games.xml"));
reply = manager->get(request);
dispIcon = true;
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void GetApps::getTools()
{
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/openrepos/catalog.xml"));
reply = manager->get(request);
dispIcon = true;
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void GetApps::getLibs()
{
QNetworkRequest request(QUrl("http://wunderwungiel.pl/MeeGo/openrepos/libs.xml"));
reply = manager->get(request);
dispIcon = false;
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void GetApps::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 GetApps::processXmlData(const QByteArray &xmlData)
{
QStringList appInfoList; // Èñïîëüçóåì QStringList
QXmlStreamReader xml(xmlData);
while (!xml.atEnd() && !xml.hasError())
{
if (xml.isStartElement() && xml.name() == "app")
{
while (!(xml.isEndElement() && xml.name() == "app"))
{
xml.readNext();
if (xml.isStartElement() && xml.name() == "data")
{
if (!dispIcon){
QString name = xml.attributes().value("name").toString();
QString size = xml.attributes().value("size").toString();
QString ver = xml.attributes().value("ver").toString();
QString package = xml.attributes().value("package").toString();
QString app = name + "," + size + "," + ver + "," + package;
appInfoList.append(app);
}
else {
QString name = xml.attributes().value("name").toString();
QString size = xml.attributes().value("size").toString();
QString ver = xml.attributes().value("ver").toString();
QString icon = xml.attributes().value("icon").toString();
QString package = xml.attributes().value("package").toString();
QString app = name + "," + size + "," + ver + "," + icon + "," + package;
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 GetApps::appInfoList() const
{
return m_appInfo; // Âîçâðàùàåì ñïèñîê m_appInfo
}