Attica

personparser.cpp
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2008 Cornelius Schumacher <schumacher@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 "personparser.h"
10
11using namespace Attica;
12
13Person Person::Parser::parseXml(QXmlStreamReader &xml)
14{
15 Person person;
16 bool hasAvatarPic = false;
17
18 while (!xml.atEnd()) {
19 xml.readNext();
20
21 if (xml.isStartElement()) {
22 if (xml.name() == QLatin1String("personid")) {
23 person.setId(xml.readElementText());
24 } else if (xml.name() == QLatin1String("firstname")) {
25 person.setFirstName(xml.readElementText());
26 } else if (xml.name() == QLatin1String("lastname")) {
27 person.setLastName(xml.readElementText());
28 } else if (xml.name() == QLatin1String("homepage")) {
29 person.setHomepage(xml.readElementText());
30 } else if (xml.name() == QLatin1String("avatarpic")) {
31 person.setAvatarUrl(QUrl(xml.readElementText()));
32 } else if (xml.name() == QLatin1String("avatarpicfound")) {
33 QString value = xml.readElementText();
34 if (value.toInt()) {
35 hasAvatarPic = true;
36 }
37 } else if (xml.name() == QLatin1String("birthday")) {
38 person.setBirthday(QDate::fromString(xml.readElementText(), Qt::ISODate));
39 } else if (xml.name() == QLatin1String("city")) {
40 person.setCity(xml.readElementText());
41 } else if (xml.name() == QLatin1String("country")) {
42 person.setCountry(xml.readElementText());
43 } else if (xml.name() == QLatin1String("latitude")) {
44 person.setLatitude(xml.readElementText().toFloat());
45 } else if (xml.name() == QLatin1String("longitude")) {
46 person.setLongitude(xml.readElementText().toFloat());
47 } else {
48 person.addExtendedAttribute(xml.name().toString(), xml.readElementText());
49 }
50 } else if (xml.isEndElement() && (xml.name() == QLatin1String("person") || xml.name() == QLatin1String("user"))) {
51 break;
52 }
53 }
54
55 if (!hasAvatarPic) {
56 person.setAvatarUrl(QUrl());
57 }
58
59 return person;
60}
61
62QStringList Person::Parser::xmlElement() const
63{
64 return QStringList(QStringLiteral("person")) << QStringLiteral("user");
65}
Represents a person.
Definition person.h:29
The Attica namespace,.
QDate fromString(QStringView string, QStringView format, QCalendar cal)
float toFloat(bool *ok) const const
int toInt(bool *ok, int base) 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 Fri Jul 19 2024 11:58:29 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.