Warning, file /frameworks/attica/src/publisherparser.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 Sebastian K├╝gler <sebas@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "publisherparser.h"
0010 #include <qdebug.h>
0011 
0012 using namespace Attica;
0013 
0014 Publisher Publisher::Parser::parseXml(QXmlStreamReader &xml)
0015 {
0016     // For specs about the XML provided, see here:
0017     // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-draft
0018 
0019     Publisher publisher;
0020     QStringList fields;
0021 
0022     while (!xml.atEnd()) {
0023         // qCDebug(ATTICA) << "XML returned:" << xml.text().toString();
0024         xml.readNext();
0025 
0026         if (xml.isStartElement()) {
0027             if (xml.name() == QLatin1String("id")) {
0028                 publisher.setId(xml.readElementText());
0029             } else if (xml.name() == QLatin1String("name")) {
0030                 publisher.setName(xml.readElementText());
0031             } else if (xml.name() == QLatin1String("registrationurl")) {
0032                 publisher.setUrl(xml.readElementText());
0033             } else if (xml.name() == QLatin1String("fields")) {
0034                 while (!xml.atEnd()) {
0035                     xml.readNextStartElement();
0036                     if (xml.isStartElement()) {
0037                         if (xml.name() == QLatin1String("field")) {
0038                             Field t;
0039                             while (!xml.atEnd()) {
0040                                 xml.readNextStartElement();
0041                                 if (xml.isStartElement()) {
0042                                     if (xml.name() == QLatin1String("fieldtype")) {
0043                                         t.type = xml.readElementText();
0044                                     } else if (xml.name() == QLatin1String("name")) {
0045                                         t.name = xml.readElementText();
0046                                     } else if (xml.name() == QLatin1String("fieldsize")) {
0047                                         t.fieldsize = xml.readElementText().toInt();
0048                                     } else if (xml.name() == QLatin1String("required")) {
0049                                         t.required = xml.readElementText() == QLatin1String("true");
0050                                     } else if (xml.name() == QLatin1String("options")) {
0051                                         while (!xml.atEnd()) {
0052                                             xml.readNextStartElement();
0053                                             if (xml.isStartElement()) {
0054                                                 if (xml.name() == QLatin1String("option")) {
0055                                                     t.options << xml.readElementText();
0056                                                 }
0057                                             } else if (xml.isEndElement() && xml.name() == QLatin1String("options")) {
0058                                                 xml.readNext();
0059                                                 break;
0060                                             }
0061                                         }
0062                                     }
0063                                 } else if (xml.isEndElement() && (xml.name() == QLatin1String("field"))) {
0064                                     xml.readNext();
0065                                     break;
0066                                 }
0067                             }
0068                             publisher.addField(t);
0069                         }
0070                     } else if (xml.isEndElement() && (xml.name() == QLatin1String("fields"))) {
0071                         xml.readNext();
0072                         break;
0073                     }
0074                 }
0075             } else if (xml.name() == QLatin1String("supportedtargets")) {
0076                 while (!xml.atEnd()) {
0077                     xml.readNextStartElement();
0078                     if (xml.isStartElement()) {
0079                         if (xml.name() == QLatin1String("target")) {
0080                             Target t;
0081                             t.name = xml.readElementText();
0082                             publisher.addTarget(t);
0083                         }
0084                     } else if (xml.isEndElement() && (xml.name() == QLatin1String("supportedtargets"))) {
0085                         xml.readNext();
0086                         break;
0087                     }
0088                 }
0089             }
0090         } else if (xml.isEndElement() //
0091                    && (xml.name() == QLatin1String("publisher") || xml.name() == QLatin1String("user"))) {
0092             break;
0093         }
0094     }
0095     return publisher;
0096 }
0097 
0098 QStringList Publisher::Parser::xmlElement() const
0099 {
0100     return QStringList(QStringLiteral("publisher")) << QStringLiteral("user");
0101 }