1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2009 Eckhart Wörner <ewoerner@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "eventparser.h"
10
11#include <QRegularExpression>
12
13using namespace Attica;
14
15Event Event::Parser::parseXml(QXmlStreamReader &xml)
16{
17 Event event;
18
19 while (!xml.atEnd()) {
20 xml.readNext();
21
22 if (xml.isStartElement()) {
23 if (xml.name() == QLatin1String("id")) {
24 event.setId(xml.readElementText());
25 } else if (xml.name() == QLatin1String("name")) {
26 event.setName(xml.readElementText());
27 } else if (xml.name() == QLatin1String("description")) {
28 event.setDescription(xml.readElementText());
29 } else if (xml.name() == QLatin1String("user")) {
30 event.setUser(xml.readElementText());
31 } else if (xml.name() == QLatin1String("startdate")) {
32 QString date = xml.readElementText().remove(re: QRegularExpression(QStringLiteral("\\+.*$")));
33 event.setStartDate(QDate::fromString(string: date, format: Qt::ISODate));
34 } else if (xml.name() == QLatin1String("enddate")) {
35 QString date = xml.readElementText().remove(re: QRegularExpression(QStringLiteral("\\+.*$")));
36 event.setEndDate(QDate::fromString(string: date, format: Qt::ISODate));
37 } else if (xml.name() == QLatin1String("latitude")) {
38 event.setLatitude(xml.readElementText().toFloat());
39 } else if (xml.name() == QLatin1String("longitude")) {
40 event.setLongitude(xml.readElementText().toFloat());
41 } else if (xml.name() == QLatin1String("homepage")) {
42 event.setHomepage(QUrl(xml.readElementText()));
43 } else if (xml.name() == QLatin1String("country")) {
44 event.setCountry(xml.readElementText());
45 } else if (xml.name() == QLatin1String("city")) {
46 event.setCity(xml.readElementText());
47 } else {
48 event.addExtendedAttribute(key: xml.name().toString(), value: xml.readElementText());
49 }
50 } else if (xml.isEndElement() && xml.name() == QLatin1String("event")) {
51 break;
52 }
53 }
54
55 return event;
56}
57
58QStringList Event::Parser::xmlElement() const
59{
60 return QStringList(QStringLiteral("event"));
61}
62

source code of attica/src/eventparser.cpp