File indexing completed on 2024-09-01 13:19:22
0001 /* 0002 This file is part of KDE. 0003 0004 SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "putjob.h" 0010 0011 #include <QDebug> 0012 #include <QXmlStreamReader> 0013 0014 #include <QNetworkAccessManager> 0015 0016 #include "platformdependent_v2.h" 0017 0018 using namespace Attica; 0019 0020 PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, QIODevice *iodevice) 0021 : BaseJob(internals) 0022 , m_ioDevice(iodevice) 0023 , m_request(request) 0024 { 0025 } 0026 0027 Attica::PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const QByteArray &byteArray) 0028 : BaseJob(internals) 0029 , m_ioDevice(nullptr) 0030 , m_byteArray(byteArray) 0031 , m_request(request) 0032 { 0033 } 0034 0035 PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap ¶meters) 0036 : BaseJob(internals) 0037 , m_ioDevice(nullptr) 0038 , m_request(request) 0039 { 0040 // Create put data 0041 int j = 0; 0042 for (StringMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { 0043 if (j++ > 0) { 0044 m_byteArray.append('&'); 0045 } 0046 m_byteArray.append(QUrl::toPercentEncoding(i.key())); 0047 m_byteArray.append('='); 0048 m_byteArray.append(QUrl::toPercentEncoding(i.value())); 0049 } 0050 } 0051 0052 QNetworkReply *PutJob::executeRequest() 0053 { 0054 Attica::PlatformDependentV2 *platformDependentV2 = dynamic_cast<Attica::PlatformDependentV2 *>(internals()); 0055 if (!platformDependentV2) { 0056 return nullptr; 0057 } 0058 0059 if (m_ioDevice) { 0060 return platformDependentV2->put(m_request, m_ioDevice); 0061 } else { 0062 return platformDependentV2->put(m_request, m_byteArray); 0063 } 0064 } 0065 0066 void PutJob::parse(const QString &xmlString) 0067 { 0068 // qCDebug(ATTICA) << "PutJob::parse" << xmlString; 0069 QXmlStreamReader xml(xmlString); 0070 Metadata data; 0071 while (!xml.atEnd()) { 0072 xml.readNext(); 0073 0074 if (xml.isStartElement()) { 0075 if (xml.name() == QLatin1String("meta")) { 0076 while (!xml.atEnd()) { 0077 xml.readNext(); 0078 if (xml.isEndElement() && xml.name() == QLatin1String("meta")) { 0079 break; 0080 } else if (xml.isStartElement()) { 0081 if (xml.name() == QLatin1String("status")) { 0082 data.setStatusString(xml.readElementText()); 0083 } else if (xml.name() == QLatin1String("statuscode")) { 0084 data.setStatusCode(xml.readElementText().toInt()); 0085 } else if (xml.name() == QLatin1String("message")) { 0086 data.setMessage(xml.readElementText()); 0087 } else if (xml.name() == QLatin1String("totalitems")) { 0088 data.setTotalItems(xml.readElementText().toInt()); 0089 } else if (xml.name() == QLatin1String("itemsperpage")) { 0090 data.setItemsPerPage(xml.readElementText().toInt()); 0091 } 0092 } 0093 } 0094 } else if (xml.name() == QLatin1String("data")) { 0095 while (!xml.atEnd()) { 0096 xml.readNext(); 0097 if (xml.isEndElement() && xml.name() == QLatin1String("data")) { 0098 break; 0099 } else if (xml.isStartElement()) { 0100 if (xml.name() == QLatin1String("projectid")) { 0101 data.setResultingId(xml.readElementText()); 0102 } 0103 if (xml.name() == QLatin1String("buildjobid")) { 0104 data.setResultingId(xml.readElementText()); 0105 } 0106 } 0107 } 0108 } 0109 } 0110 } 0111 setMetadata(data); 0112 } 0113 0114 #include "moc_putjob.cpp"