Warning, file /frameworks/attica/src/commentparser.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of KDE. 0003 0004 SPDX-FileCopyrightText: 2010 Intel Corporation 0005 SPDX-FileContributor: Mateu Batle Sastre <mbatle@collabora.co.uk> 0006 0007 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0008 */ 0009 0010 #include "commentparser.h" 0011 #include "atticautils.h" 0012 #include <QDebug> 0013 0014 using namespace Attica; 0015 0016 Comment Comment::Parser::parseXml(QXmlStreamReader &xml) 0017 { 0018 Comment comment; 0019 0020 while (!xml.atEnd()) { 0021 xml.readNext(); 0022 0023 if (xml.isStartElement()) { 0024 if (xml.name() == QLatin1String("id")) { 0025 comment.setId(xml.readElementText()); 0026 } else if (xml.name() == QLatin1String("subject")) { 0027 comment.setSubject(xml.readElementText()); 0028 } else if (xml.name() == QLatin1String("text")) { 0029 comment.setText(xml.readElementText()); 0030 } else if (xml.name() == QLatin1String("childcount")) { 0031 comment.setChildCount(xml.readElementText().toInt()); 0032 } else if (xml.name() == QLatin1String("user")) { 0033 comment.setUser(xml.readElementText()); 0034 } else if (xml.name() == QLatin1String("date")) { 0035 comment.setDate(Utils::parseQtDateTimeIso8601(xml.readElementText())); 0036 } else if (xml.name() == QLatin1String("score")) { 0037 comment.setScore(xml.readElementText().toInt()); 0038 } else if (xml.name() == QLatin1String("children")) { 0039 // This may seem strange, however we are dealing with a situation where we may 0040 // receive multiple children subsections (the standard accepts this, and certain 0041 // server implementations do do this) 0042 QList<Comment> children = comment.children(); 0043 children += parseXmlChildren(xml); 0044 comment.setChildren(children); 0045 } 0046 } else if (xml.isEndElement() && xml.name() == QLatin1String("comment")) { 0047 break; 0048 } 0049 } 0050 0051 return comment; 0052 } 0053 0054 QList<Comment> Comment::Parser::parseXmlChildren(QXmlStreamReader &xml) 0055 { 0056 QList<Comment> children; 0057 0058 while (!xml.atEnd()) { 0059 xml.readNext(); 0060 0061 if (xml.isStartElement()) { 0062 if (xml.name() == QLatin1String("comment")) { 0063 Comment comment = parseXml(xml); 0064 children.append(comment); 0065 } 0066 } else if (xml.isEndElement() && xml.name() == QLatin1String("children")) { 0067 break; 0068 } 0069 } 0070 0071 return children; 0072 } 0073 0074 QStringList Comment::Parser::xmlElement() const 0075 { 0076 return QStringList(QStringLiteral("comment")); 0077 }