| 1 | /* |
| 2 | This file is part of KDE. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2010 Sebastian Kügler <sebas@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #include "projectparser.h" |
| 10 | #include <qdebug.h> |
| 11 | |
| 12 | using namespace Attica; |
| 13 | |
| 14 | Project Project::Parser::parseXml(QXmlStreamReader &xml) |
| 15 | { |
| 16 | Project project; |
| 17 | |
| 18 | // For specs about the XML provided, see here: |
| 19 | // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-draft#Projects |
| 20 | while (!xml.atEnd()) { |
| 21 | // qCDebug(ATTICA) << "XML returned:" << xml.text().toString(); |
| 22 | xml.readNext(); |
| 23 | |
| 24 | if (xml.isStartElement()) { |
| 25 | if (xml.name() == QLatin1String("projectid" )) { |
| 26 | project.setId(xml.readElementText()); |
| 27 | } else if (xml.name() == QLatin1String("name" )) { |
| 28 | project.setName(xml.readElementText()); |
| 29 | } else if (xml.name() == QLatin1String("version" )) { |
| 30 | project.setVersion(xml.readElementText()); |
| 31 | } else if (xml.name() == QLatin1String("license" )) { |
| 32 | project.setLicense(xml.readElementText()); |
| 33 | } else if (xml.name() == QLatin1String("url" )) { |
| 34 | project.setUrl(xml.readElementText()); |
| 35 | } else if (xml.name() == QLatin1String("summary" )) { |
| 36 | project.setSummary(xml.readElementText()); |
| 37 | } else if (xml.name() == QLatin1String("description" )) { |
| 38 | project.setDescription(xml.readElementText()); |
| 39 | } else if (xml.name() == QLatin1String("specfile" )) { |
| 40 | project.setSpecFile(xml.readElementText()); |
| 41 | } else if (xml.name() == QLatin1String("developers" )) { |
| 42 | project.setDevelopers(xml.readElementText().split(sep: QLatin1Char('\n'))); |
| 43 | } else if (xml.name() == QLatin1String("projectlist" )) { |
| 44 | QXmlStreamReader list_xml(xml.readElementText()); |
| 45 | while (!list_xml.atEnd()) { |
| 46 | list_xml.readNext(); |
| 47 | if (xml.name() == QLatin1String("projectid" )) { |
| 48 | project.setSpecFile(xml.readElementText()); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } else if (xml.isEndElement() && (xml.name() == QLatin1String("project" ) || xml.name() == QLatin1String("user" ))) { |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | return project; |
| 57 | } |
| 58 | |
| 59 | QStringList Project::Parser::xmlElement() const |
| 60 | { |
| 61 | return QStringList(QStringLiteral("project" )) << QStringLiteral("user" ); |
| 62 | } |
| 63 | |