Attica

eventparser.cpp
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{
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(QRegularExpression(QStringLiteral("\\+.*$")));
33 event.setStartDate(QDate::fromString(date, Qt::ISODate));
34 } else if (xml.name() == QLatin1String("enddate")) {
35 QString date = xml.readElementText().remove(QRegularExpression(QStringLiteral("\\+.*$")));
36 event.setEndDate(QDate::fromString(date, 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(xml.name().toString(), 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}
Represents a single event.
Definition event.h:28
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
The Attica namespace,.
QDate fromString(QStringView string, QStringView format, QCalendar cal)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
float toFloat(bool *ok) const const
QString toString() const const
bool atEnd() const const
bool isEndElement() const const
bool isStartElement() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
TokenType readNext()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.