File indexing completed on 2024-12-08 06:36:42

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2009 Eckhart Wörner <ewoerner@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "eventparser.h"
0010 
0011 #include <QRegularExpression>
0012 
0013 using namespace Attica;
0014 
0015 Event Event::Parser::parseXml(QXmlStreamReader &xml)
0016 {
0017     Event event;
0018 
0019     while (!xml.atEnd()) {
0020         xml.readNext();
0021 
0022         if (xml.isStartElement()) {
0023             if (xml.name() == QLatin1String("id")) {
0024                 event.setId(xml.readElementText());
0025             } else if (xml.name() == QLatin1String("name")) {
0026                 event.setName(xml.readElementText());
0027             } else if (xml.name() == QLatin1String("description")) {
0028                 event.setDescription(xml.readElementText());
0029             } else if (xml.name() == QLatin1String("user")) {
0030                 event.setUser(xml.readElementText());
0031             } else if (xml.name() == QLatin1String("startdate")) {
0032                 QString date = xml.readElementText().remove(QRegularExpression(QStringLiteral("\\+.*$")));
0033                 event.setStartDate(QDate::fromString(date, Qt::ISODate));
0034             } else if (xml.name() == QLatin1String("enddate")) {
0035                 QString date = xml.readElementText().remove(QRegularExpression(QStringLiteral("\\+.*$")));
0036                 event.setEndDate(QDate::fromString(date, Qt::ISODate));
0037             } else if (xml.name() == QLatin1String("latitude")) {
0038                 event.setLatitude(xml.readElementText().toFloat());
0039             } else if (xml.name() == QLatin1String("longitude")) {
0040                 event.setLongitude(xml.readElementText().toFloat());
0041             } else if (xml.name() == QLatin1String("homepage")) {
0042                 event.setHomepage(QUrl(xml.readElementText()));
0043             } else if (xml.name() == QLatin1String("country")) {
0044                 event.setCountry(xml.readElementText());
0045             } else if (xml.name() == QLatin1String("city")) {
0046                 event.setCity(xml.readElementText());
0047             } else {
0048                 event.addExtendedAttribute(xml.name().toString(), xml.readElementText());
0049             }
0050         } else if (xml.isEndElement() && xml.name() == QLatin1String("event")) {
0051             break;
0052         }
0053     }
0054 
0055     return event;
0056 }
0057 
0058 QStringList Event::Parser::xmlElement() const
0059 {
0060     return QStringList(QStringLiteral("event"));
0061 }