#include "screenxmlhandler.h" #include "httpwrapper.h" #include ScreenXmlHandler::ScreenXmlHandler() { } bool ScreenXmlHandler::readXml(QString uri) { screenSet.clear(); QXmlSimpleReader reader; reader.setContentHandler(this); reader.setErrorHandler(this); QByteArray data = HttpWrapper::getSyncData(uri); QXmlInputSource xmlInputSource; xmlInputSource.setData(data); return reader.parse(xmlInputSource); } bool ScreenXmlHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes) { Q_UNUSED(namespaceURI); Q_UNUSED(localName); Q_UNUSED(attributes); //qDebug() << "XML-start:" << qName; currentText = ""; if (qName == "screen") { tempItem = ScreenItem(); } return true; } ModuleType ScreenXmlHandler::stringToModule(QString name) { ModuleType type; if (name == "info_image") { type = ModuleImage; } else if ( name == "info_web") { type = ModuleWeb; } else if (name == "info_video") { type = ModuleVideo; } else if (name == "info_svg") { type = ModuleSvg; } else { type = ModuleUnknown; qDebug() << "Unknown module " << name; } return type; } bool ScreenXmlHandler::endElement(const QString &namespaceURI, const QString &localName, const QString &qName) { Q_UNUSED(namespaceURI); Q_UNUSED(localName); //qDebug() << "XML-stop:" << qName; if (qName == "module") { tempItem.module = stringToModule(currentText); } if (qName == "elementid") { tempItem.elementid = currentText.toInt(); } if (qName == "url") { tempItem.url = currentText; } if (qName == "runtime") { tempItem.runtime = currentText.toInt(); } if (qName == "timestart") { tempItem.start = QTime::fromString(currentText, "hh:mm:ss"); } if (qName == "timestop") { tempItem.stop = QTime::fromString(currentText, "hh:mm:ss"); } if (qName == "screen") { screenSet.append(tempItem); } return true; } bool ScreenXmlHandler::characters(const QString &str) { currentText += str; return true; }