Attica

putjob.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2011 Laszlo Papp <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 
9 #include "putjob.h"
10 
11 #include <QXmlStreamReader>
12 #include <QDebug>
13 
14 #include <QNetworkAccessManager>
15 
16 #include "platformdependent_v2.h"
17 
18 using namespace Attica;
19 
20 PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, QIODevice *iodevice)
21  : BaseJob(internals), m_ioDevice(iodevice), m_request(request)
22 {
23 }
24 
25 Attica::PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const QByteArray &byteArray)
26  : BaseJob(internals), m_ioDevice(nullptr), m_byteArray(byteArray), m_request(request)
27 {
28 }
29 
30 PutJob::PutJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap &parameters)
31  : BaseJob(internals), m_ioDevice(nullptr), m_request(request)
32 {
33  // Create put data
34  int j = 0;
35  for (StringMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
36  if (j++ > 0) {
37  m_byteArray.append('&');
38  }
39  m_byteArray.append(QUrl::toPercentEncoding(i.key()));
40  m_byteArray.append('=');
41  m_byteArray.append(QUrl::toPercentEncoding(i.value()));
42  }
43 }
44 
45 QNetworkReply *PutJob::executeRequest()
46 {
47  Attica::PlatformDependentV2 *platformDependentV2 = dynamic_cast<Attica::PlatformDependentV2 *>(internals());
48  if (!platformDependentV2) {
49  return nullptr;
50  }
51 
52  if (m_ioDevice) {
53  return platformDependentV2->put(m_request, m_ioDevice);
54  } else {
55  return platformDependentV2->put(m_request, m_byteArray);
56  }
57 }
58 
59 void PutJob::parse(const QString &xmlString)
60 {
61  //qCDebug(ATTICA) << "PutJob::parse" << xmlString;
62  QXmlStreamReader xml(xmlString);
63  Metadata data;
64  while (!xml.atEnd()) {
65  xml.readNext();
66 
67  if (xml.isStartElement()) {
68  if (xml.name() == QLatin1String("meta")) {
69  while (!xml.atEnd()) {
70  xml.readNext();
71  if (xml.isEndElement() && xml.name() == QLatin1String("meta")) {
72  break;
73  } else if (xml.isStartElement()) {
74  if (xml.name() == QLatin1String("status")) {
75  data.setStatusString(xml.readElementText());
76  } else if (xml.name() == QLatin1String("statuscode")) {
77  data.setStatusCode(xml.readElementText().toInt());
78  } else if (xml.name() == QLatin1String("message")) {
79  data.setMessage(xml.readElementText());
80  } else if (xml.name() == QLatin1String("totalitems")) {
81  data.setTotalItems(xml.readElementText().toInt());
82  } else if (xml.name() == QLatin1String("itemsperpage")) {
83  data.setItemsPerPage(xml.readElementText().toInt());
84  }
85  }
86  }
87  } else if (xml.name() == QLatin1String("data")) {
88  while (!xml.atEnd()) {
89  xml.readNext();
90  if (xml.isEndElement() && xml.name() == QLatin1String("data")) {
91  break;
92  } else if (xml.isStartElement()) {
93  if (xml.name() == QLatin1String("projectid")) {
94  data.setResultingId(xml.readElementText());
95  } if (xml.name() == QLatin1String("buildjobid")) {
96  data.setResultingId(xml.readElementText());
97  }
98 
99  }
100  }
101  }
102  }
103  }
104  setMetadata(data);
105 }
106 
Status messages from the server.
Definition: metadata.h:25
QMap::iterator end()
QMap::iterator begin()
QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 03:59:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.