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 | |
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(string: xml.readElementText(), format: 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(key: xml.name().toString(), value: 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 | } |
66 | |