File indexing completed on 2024-05-12 05:46:52

0001 /*
0002     This file is part of KDE.
0003 
0004     Copyright 2010 Sebastian Kügler <sebas@kde.org>
0005 
0006     This library is free software; you can redistribute it and/or
0007     modify it under the terms of the GNU Lesser General Public
0008     License as published by the Free Software Foundation; either
0009     version 2.1 of the License, or (at your option) version 3, or any
0010     later version accepted by the membership of KDE e.V. (or its
0011     successor approved by the membership of KDE e.V.), which shall
0012     act as a proxy defined in Section 6 of version 3 of the license.
0013 
0014     This library is distributed in the hope that it will be useful,
0015     but WITHOUT ANY WARRANTY; without even the implied warranty of
0016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017     Lesser General Public License for more details.
0018 
0019     You should have received a copy of the GNU Lesser General Public
0020     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 */
0023 
0024 #include "projectparser.h"
0025 #include <qdebug.h>
0026 
0027 using namespace Attica;
0028 
0029 Project Project::Parser::parseXml(QXmlStreamReader &xml)
0030 {
0031     Project project;
0032 
0033     // For specs about the XML provided, see here:
0034     // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-draft#Projects
0035     while (!xml.atEnd()) {
0036         //qCDebug(ATTICA) << "XML returned:" << xml.text().toString();
0037         xml.readNext();
0038 
0039         if (xml.isStartElement()) {
0040             if (xml.name() == QLatin1String("projectid")) {
0041                 project.setId(xml.readElementText());
0042             } else if (xml.name() == QLatin1String("name")) {
0043                 project.setName(xml.readElementText());
0044             } else if (xml.name() == QLatin1String("version")) {
0045                 project.setVersion(xml.readElementText());
0046             } else if (xml.name() == QLatin1String("license")) {
0047                 project.setLicense(xml.readElementText());
0048             } else if (xml.name() == QLatin1String("url")) {
0049                 project.setUrl(xml.readElementText());
0050             } else if (xml.name() == QLatin1String("summary")) {
0051                 project.setSummary(xml.readElementText());
0052             } else if (xml.name() == QLatin1String("description")) {
0053                 project.setDescription(xml.readElementText());
0054             } else if (xml.name() == QLatin1String("specfile")) {
0055                 project.setSpecFile(xml.readElementText());
0056             } else if (xml.name() == QLatin1String("developers")) {
0057                 project.setDevelopers(xml.readElementText().split(QLatin1Char('\n')));
0058             } else if (xml.name() == QLatin1String("projectlist")) {
0059                 QXmlStreamReader list_xml(xml.readElementText());
0060                 while (!list_xml.atEnd()) {
0061                     list_xml.readNext();
0062                     if (xml.name() == QLatin1String("projectid")) {
0063                         project.setSpecFile(xml.readElementText());
0064                     }
0065                 }
0066 
0067             }
0068         } else if (xml.isEndElement() && (xml.name() == QLatin1String("project") || xml.name() == QLatin1String("user"))) {
0069             break;
0070         }
0071     }
0072     return project;
0073 }
0074 
0075 QStringList Project::Parser::xmlElement() const
0076 {
0077     return QStringList(QStringLiteral("project")) << QStringLiteral("user");
0078 }