Attica

personparser.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2008 Cornelius Schumacher <[email protected]>
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 
11 using namespace Attica;
12 
13 Person 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 
62 QStringList Person::Parser::xmlElement() const
63 {
64  return QStringList(QStringLiteral("person")) << QStringLiteral("user");
65 }
bool atEnd() const const
QString toString() const const
QDate fromString(const QString &string, Qt::DateFormat format)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
int toInt(bool *ok, int base) const const
QXmlStreamReader::TokenType readNext()
bool isStartElement() const const
float toFloat(bool *ok) const const
QStringRef name() const const
bool isEndElement() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.