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 }
bool atEnd() const const
void setId(const QString &id)
Sets the id of the Activity.
Definition: activity.cpp:44
Represents a single news item (also known as activity)
Definition: activity.h:26
void setLink(const QUrl &link)
Sets the link to further information about this Activity.
Definition: activity.cpp:84
void setTimestamp(const QDateTime &timestamp)
Sets the timestamp the Activity has been published.
Definition: activity.cpp:64
QString & remove(int position, int n)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QXmlStreamReader::TokenType readNext()
QDateTime fromString(const QString &string, Qt::DateFormat format)
bool isStartElement() const const
QStringRef name() const const
void setAssociatedPerson(const Person &associatedPerson)
Sets the user bound to the Activity.
Definition: activity.cpp:54
void setMessage(const QString &message)
Sets the message of the Activity.
Definition: activity.cpp:74
bool isEndElement() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 03:59:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.