Attica

forumparser.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2011 Laszlo Papp <[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 "forumparser.h"
10 #include "atticautils.h"
11 
12 using namespace Attica;
13 
14 Forum Forum::Parser::parseXml(QXmlStreamReader &xml)
15 {
16  Forum forum;
17 
18  while (!xml.atEnd()) {
19  xml.readNext();
20 
21  if (xml.isStartElement()) {
22  if (xml.name() == QLatin1String("id")) {
23  forum.setId(xml.readElementText());
24  } else if (xml.name() == QLatin1String("name")) {
25  forum.setName(xml.readElementText());
26  } else if (xml.name() == QLatin1String("description")) {
27  forum.setDescription(xml.readElementText());
28  } else if (xml.name() == QLatin1String("date")) {
29  forum.setDate(Utils::parseQtDateTimeIso8601(xml.readElementText()));
30  } else if (xml.name() == QLatin1String("icon")) {
31  forum.setIcon(QUrl(xml.readElementText()));
32  } else if (xml.name() == QLatin1String("childcount")) {
33  forum.setChildCount(xml.readElementText().toInt());
34  } else if (xml.name() == QLatin1String("children")) {
35  QList<Forum> children = parseXmlChildren(xml);
36  forum.setChildren(children);
37  } else if (xml.name() == QLatin1String("topics")) {
38  forum.setTopics(xml.readElementText().toInt());
39  }
40  } else if (xml.isEndElement() && xml.name() == QLatin1String("forum")) {
41  break;
42  }
43  }
44 
45  return forum;
46 }
47 
48 QList<Forum> Forum::Parser::parseXmlChildren(QXmlStreamReader &xml)
49 {
50  QList<Forum> children;
51 
52  while (!xml.atEnd()) {
53  xml.readNext();
54 
55  if (xml.isStartElement()) {
56  if (xml.name() == QLatin1String("forum")) {
57  Forum forum = parseXml(xml);
58  children.append(forum);
59  }
60  } else if (xml.isEndElement() && xml.name() == QLatin1String("children")) {
61  break;
62  }
63  }
64 
65  return children;
66 }
67 
68 QStringList Forum::Parser::xmlElement() const
69 {
70  return QStringList(QStringLiteral("forum"));
71 }
bool atEnd() const const
void append(const T &value)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
int toInt(bool *ok, int base) const const
QXmlStreamReader::TokenType readNext()
bool isStartElement() const const
QStringRef name() const const
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.