1 |
torben |
528 |
#include "screenxmlhandler.h" |
2 |
|
|
|
3 |
|
|
#include "httpwrapper.h" |
4 |
|
|
|
5 |
|
|
//#include <QDebug> |
6 |
|
|
|
7 |
|
|
ScreenXmlHandler::ScreenXmlHandler() |
8 |
|
|
{ |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
bool ScreenXmlHandler::readXml(QString uri) |
13 |
|
|
{ |
14 |
|
|
screenSet.clear(); |
15 |
|
|
|
16 |
|
|
QXmlSimpleReader reader; |
17 |
|
|
reader.setContentHandler(this); |
18 |
|
|
reader.setErrorHandler(this); |
19 |
|
|
|
20 |
|
|
QByteArray data = HttpWrapper::getSyncData(uri); |
21 |
|
|
|
22 |
|
|
QXmlInputSource xmlInputSource; |
23 |
|
|
xmlInputSource.setData(data); |
24 |
|
|
return reader.parse(xmlInputSource); |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
bool ScreenXmlHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes) |
29 |
|
|
{ |
30 |
|
|
Q_UNUSED(namespaceURI); |
31 |
|
|
Q_UNUSED(localName); |
32 |
|
|
Q_UNUSED(attributes); |
33 |
|
|
//qDebug() << "XML-start:" << qName; |
34 |
|
|
currentText = ""; |
35 |
|
|
|
36 |
|
|
if (qName == "screen") { |
37 |
|
|
tempItem = ScreenItem(); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
return true; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
bool ScreenXmlHandler::endElement(const QString &namespaceURI, const QString &localName, const QString &qName) |
44 |
|
|
{ |
45 |
|
|
Q_UNUSED(namespaceURI); |
46 |
|
|
Q_UNUSED(localName); |
47 |
|
|
//qDebug() << "XML-stop:" << qName; |
48 |
|
|
|
49 |
|
|
if (qName == "module") { |
50 |
|
|
tempItem.module = currentText; |
51 |
|
|
} |
52 |
|
|
if (qName == "elementid") { |
53 |
|
|
tempItem.elementid = currentText.toInt(); |
54 |
|
|
} |
55 |
|
|
if (qName == "url") { |
56 |
|
|
tempItem.url = currentText; |
57 |
|
|
} |
58 |
|
|
if (qName == "runtime") { |
59 |
|
|
tempItem.runtime = currentText.toInt(); |
60 |
|
|
} |
61 |
|
|
if (qName == "timestart") { |
62 |
|
|
tempItem.start = QTime::fromString(currentText, "hh:mm:ss"); |
63 |
|
|
} |
64 |
|
|
if (qName == "timestop") { |
65 |
|
|
tempItem.stop = QTime::fromString(currentText, "hh:mm:ss"); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
if (qName == "screen") { |
70 |
|
|
screenSet.append(tempItem); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
return true; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
bool ScreenXmlHandler::characters(const QString &str) |
77 |
|
|
{ |
78 |
|
|
currentText += str; |
79 |
|
|
return true; |
80 |
|
|
} |