File indexing completed on 2023-09-24 07:57:24

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 "buildservicejobparser.h"
0010 #include <qdebug.h>
0011 
0012 using namespace Attica;
0013 
0014 BuildServiceJob BuildServiceJob::Parser::parseXml(QXmlStreamReader &xml)
0015 {
0016     BuildServiceJob buildservicejob;
0017 
0018     // For specs about the XML provided, see here:
0019     // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-draft#BuildServiceJobs
0020     while (!xml.atEnd()) {
0021         // qCDebug(ATTICA) << "XML returned:" << xml.text().toString();
0022         xml.readNext();
0023 
0024         if (xml.isStartElement()) {
0025             if (xml.name() == QLatin1String("id")) { // FIXME: server should give "id" here ...
0026                 buildservicejob.setId(xml.readElementText());
0027             } else if (xml.name() == QLatin1String("project")) {
0028                 buildservicejob.setProjectId(xml.readElementText());
0029             } else if (xml.name() == QLatin1String("buildservice")) {
0030                 buildservicejob.setBuildServiceId(xml.readElementText());
0031             } else if (xml.name() == QLatin1String("target")) {
0032                 buildservicejob.setTarget(xml.readElementText());
0033             } else if (xml.name() == QLatin1String("name")) {
0034                 buildservicejob.setName(xml.readElementText());
0035             } else if (xml.name() == QLatin1String("status")) {
0036                 int status = xml.readElementText().toInt();
0037                 buildservicejob.setStatus(status);
0038             } else if (xml.name() == QLatin1String("progress")) {
0039                 qreal progress = (qreal)(xml.readElementText().toFloat());
0040                 buildservicejob.setProgress(progress);
0041             } else if (xml.name() == QLatin1String("message")) {
0042                 buildservicejob.setMessage(xml.readElementText());
0043             } else if (xml.name() == QLatin1String("url")) {
0044                 buildservicejob.setUrl(xml.readElementText());
0045             }
0046         } else if (xml.isEndElement() && (xml.name() == QLatin1String("buildjob") || xml.name() == QLatin1String("user"))) {
0047             break;
0048         }
0049     }
0050     return buildservicejob;
0051 }
0052 
0053 QStringList BuildServiceJob::Parser::xmlElement() const
0054 {
0055     return QStringList(QStringLiteral("buildjob")) << QStringLiteral("user");
0056 }