1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
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
12using namespace Attica;
13
14Forum 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(str: 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
48QList<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(t: forum);
59 }
60 } else if (xml.isEndElement() && xml.name() == QLatin1String("children")) {
61 break;
62 }
63 }
64
65 return children;
66}
67
68QStringList Forum::Parser::xmlElement() const
69{
70 return QStringList(QStringLiteral("forum"));
71}
72

source code of attica/src/forumparser.cpp