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 "activityparser.h" |
10 | |
11 | #include <QDateTime> |
12 | #include <QRegularExpression> |
13 | |
14 | using namespace Attica; |
15 | |
16 | Activity Activity::Parser::parseXml(QXmlStreamReader &xml) |
17 | { |
18 | Activity activity; |
19 | Person person; |
20 | |
21 | while (!xml.atEnd()) { |
22 | xml.readNext(); |
23 | |
24 | if (xml.isStartElement()) { |
25 | if (xml.name() == QLatin1String("id" )) { |
26 | activity.setId(xml.readElementText()); |
27 | } else if (xml.name() == QLatin1String("personid" )) { |
28 | person.setId(xml.readElementText()); |
29 | } else if (xml.name() == QLatin1String("avatarpic" )) { |
30 | person.setAvatarUrl(QUrl(xml.readElementText())); |
31 | } else if (xml.name() == QLatin1String("firstname" )) { |
32 | person.setFirstName(xml.readElementText()); |
33 | } else if (xml.name() == QLatin1String("lastname" )) { |
34 | person.setLastName(xml.readElementText()); |
35 | } else if (xml.name() == QLatin1String("timestamp" )) { |
36 | QString timestampString = xml.readElementText(); |
37 | timestampString.remove(re: QRegularExpression(QStringLiteral("\\+.*$" ))); |
38 | QDateTime timestamp = QDateTime::fromString(string: timestampString, format: Qt::ISODate); |
39 | activity.setTimestamp(timestamp); |
40 | } else if (xml.name() == QLatin1String("message" )) { |
41 | activity.setMessage(xml.readElementText()); |
42 | } else if (xml.name() == QLatin1String("link" )) { |
43 | activity.setLink(QUrl(xml.readElementText())); |
44 | } |
45 | } else if (xml.isEndElement() && xml.name() == QLatin1String("activity" )) { |
46 | break; |
47 | } |
48 | } |
49 | |
50 | activity.setAssociatedPerson(person); |
51 | return activity; |
52 | } |
53 | |
54 | QStringList Activity::Parser::xmlElement() const |
55 | { |
56 | return QStringList(QStringLiteral("activity" )); |
57 | } |
58 | |