1 |
#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 |
ModuleType ScreenXmlHandler::stringToModule(QString name) { |
44 |
ModuleType type; |
45 |
|
46 |
if (name == "info_image") { |
47 |
type = ModuleImage; |
48 |
} else if ( name == "info_web") { |
49 |
type = ModuleWeb; |
50 |
} else if (name == "info_video") { |
51 |
type = ModuleVideo; |
52 |
} else if (name == "info_svg") { |
53 |
type = ModuleSvg; |
54 |
} else { |
55 |
type = ModuleUnknown; |
56 |
qDebug() << "Unknown module " << name; |
57 |
} |
58 |
return type; |
59 |
} |
60 |
|
61 |
bool ScreenXmlHandler::endElement(const QString &namespaceURI, const QString &localName, const QString &qName) |
62 |
{ |
63 |
Q_UNUSED(namespaceURI); |
64 |
Q_UNUSED(localName); |
65 |
//qDebug() << "XML-stop:" << qName; |
66 |
|
67 |
if (qName == "module") { |
68 |
tempItem.module = stringToModule(currentText); |
69 |
} |
70 |
if (qName == "elementid") { |
71 |
tempItem.elementid = currentText.toInt(); |
72 |
} |
73 |
if (qName == "url") { |
74 |
tempItem.url = currentText; |
75 |
} |
76 |
if (qName == "runtime") { |
77 |
tempItem.runtime = currentText.toInt(); |
78 |
} |
79 |
if (qName == "timestart") { |
80 |
tempItem.start = QTime::fromString(currentText, "hh:mm:ss"); |
81 |
} |
82 |
if (qName == "timestop") { |
83 |
tempItem.stop = QTime::fromString(currentText, "hh:mm:ss"); |
84 |
} |
85 |
|
86 |
|
87 |
if (qName == "screen") { |
88 |
screenSet.append(tempItem); |
89 |
} |
90 |
|
91 |
return true; |
92 |
} |
93 |
|
94 |
bool ScreenXmlHandler::characters(const QString &str) |
95 |
{ |
96 |
currentText += str; |
97 |
return true; |
98 |
} |