Attica

activityparser.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 "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(QRegularExpression(QStringLiteral("\\+.*$")));
38  QDateTime timestamp = QDateTime::fromString(timestampString, 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 }
void setAssociatedPerson(const Person &associatedPerson)
Sets the user bound to the Activity.
Definition: activity.cpp:55
bool isEndElement() const const
void setId(const QString &id)
Sets the id of the Activity.
Definition: activity.cpp:45
QStringRef name() const const
void setMessage(const QString &message)
Sets the message of the Activity.
Definition: activity.cpp:75
QXmlStreamReader::TokenType readNext()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QDateTime fromString(const QString &string, Qt::DateFormat format)
QString & remove(int position, int n)
void setTimestamp(const QDateTime &timestamp)
Sets the timestamp the Activity has been published.
Definition: activity.cpp:65
The Attica namespace,.
bool isStartElement() const const
bool atEnd() const const
void setLink(const QUrl &link)
Sets the link to further information about this Activity.
Definition: activity.cpp:85
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Dec 11 2023 04:05:13 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.