Attica

activityparser.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 "activityparser.h"
10
11#include <QDateTime>
12#include <QRegularExpression>
13
14using namespace Attica;
15
16Activity 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(QRegularExpression(QStringLiteral("\\+.*$")));
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
54QStringList Activity::Parser::xmlElement() const
55{
56 return QStringList(QStringLiteral("activity"));
57}
Represents a single news item (also known as activity)
Definition activity.h:28
void setAssociatedPerson(const Person &associatedPerson)
Sets the user bound to the Activity.
Definition activity.cpp:55
void setLink(const QUrl &link)
Sets the link to further information about this Activity.
Definition activity.cpp:85
void setMessage(const QString &message)
Sets the message of the Activity.
Definition activity.cpp:75
void setTimestamp(const QDateTime &timestamp)
Sets the timestamp the Activity has been published.
Definition activity.cpp:65
QDateTime timestamp() const
Gets the timestamp the Activity has been published.
Definition activity.cpp:70
void setId(const QString &id)
Sets the id of the Activity.
Definition activity.cpp:45
Represents a person.
Definition person.h:29
The Attica namespace,.
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
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 Tue Mar 26 2024 11:19:48 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.