]> git.sur5r.net Git - minitube/blob - lib/updater/src/impl/appcastparser.cpp
New upstream version 3.5
[minitube] / lib / updater / src / impl / appcastparser.cpp
1 #include "appcastparser.h"
2
3 #include "defaultupdater.h"
4
5 namespace updater {
6
7 AppcastParser::AppcastParser() {}
8
9 void AppcastParser::parse(const QByteArray &bytes) {
10     error = false;
11     errorMessage.clear();
12
13     const QLatin1String sparkleNS("http://www.andymatuschak.org/xml-namespaces/sparkle");
14
15     QXmlStreamReader reader(bytes);
16     while (!reader.atEnd()) {
17         reader.readNext();
18         if (reader.name() == QLatin1String("item")) {
19             while (reader.readNextStartElement()) {
20                 if (reader.name() == QLatin1String("enclosure")) {
21                     auto attrs = reader.attributes();
22                     QString url = attrs.value(QLatin1String("url")).toString();
23                     updater->setDownloadUrl(url);
24
25                     QString version = attrs.value(sparkleNS, QLatin1String("version")).toString();
26                     updater->setVersion(version);
27
28                     QString shortVersionString =
29                             attrs.value(sparkleNS, QLatin1String("shortVersionString")).toString();
30                     updater->setDisplayVersion(shortVersionString);
31                 }
32                 reader.skipCurrentElement();
33             }
34         }
35     }
36
37     if (reader.hasError()) {
38         error = true;
39         errorMessage = reader.errorString();
40     }
41 }
42
43 } // namespace updater