File indexing completed on 2024-07-14 14:25:37

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "forumparser.h"
0010 #include "atticautils.h"
0011 
0012 using namespace Attica;
0013 
0014 Forum Forum::Parser::parseXml(QXmlStreamReader &xml)
0015 {
0016     Forum forum;
0017 
0018     while (!xml.atEnd()) {
0019         xml.readNext();
0020 
0021         if (xml.isStartElement()) {
0022             if (xml.name() == QLatin1String("id")) {
0023                 forum.setId(xml.readElementText());
0024             } else if (xml.name() == QLatin1String("name")) {
0025                 forum.setName(xml.readElementText());
0026             } else if (xml.name() == QLatin1String("description")) {
0027                 forum.setDescription(xml.readElementText());
0028             } else if (xml.name() == QLatin1String("date")) {
0029                 forum.setDate(Utils::parseQtDateTimeIso8601(xml.readElementText()));
0030             } else if (xml.name() == QLatin1String("icon")) {
0031                 forum.setIcon(QUrl(xml.readElementText()));
0032             } else if (xml.name() == QLatin1String("childcount")) {
0033                 forum.setChildCount(xml.readElementText().toInt());
0034             } else if (xml.name() == QLatin1String("children")) {
0035                 QList<Forum> children = parseXmlChildren(xml);
0036                 forum.setChildren(children);
0037             } else if (xml.name() == QLatin1String("topics")) {
0038                 forum.setTopics(xml.readElementText().toInt());
0039             }
0040         } else if (xml.isEndElement() && xml.name() == QLatin1String("forum")) {
0041             break;
0042         }
0043     }
0044 
0045     return forum;
0046 }
0047 
0048 QList<Forum> Forum::Parser::parseXmlChildren(QXmlStreamReader &xml)
0049 {
0050     QList<Forum> children;
0051 
0052     while (!xml.atEnd()) {
0053         xml.readNext();
0054 
0055         if (xml.isStartElement()) {
0056             if (xml.name() == QLatin1String("forum")) {
0057                 Forum forum = parseXml(xml);
0058                 children.append(forum);
0059             }
0060         } else if (xml.isEndElement() && xml.name() == QLatin1String("children")) {
0061             break;
0062         }
0063     }
0064 
0065     return children;
0066 }
0067 
0068 QStringList Forum::Parser::xmlElement() const
0069 {
0070     return QStringList(QStringLiteral("forum"));
0071 }