Attica

postjob.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2008 Cornelius Schumacher <[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 "postjob.h"
10 
11 #include <QXmlStreamReader>
12 #include <QDebug>
13 
14 #include <QNetworkAccessManager>
15 
16 #include "platformdependent.h"
17 
18 using namespace Attica;
19 
20 PostJob::PostJob(PlatformDependent *internals, const QNetworkRequest &request, QIODevice *iodevice)
21  : BaseJob(internals), m_ioDevice(iodevice), m_request(request)
22 {
23 }
24 
25 Attica::PostJob::PostJob(PlatformDependent *internals, const QNetworkRequest &request, const QByteArray &byteArray)
26  : BaseJob(internals), m_ioDevice(nullptr), m_byteArray(byteArray), m_request(request)
27 {
28 }
29 
30 PostJob::PostJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap &parameters)
31  : BaseJob(internals), m_ioDevice(nullptr), m_request(request)
32 {
33  // Create post 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 *PostJob::executeRequest()
46 {
47  if (m_ioDevice) {
48  return internals()->post(m_request, m_ioDevice);
49  } else {
50  return internals()->post(m_request, m_byteArray);
51  }
52 }
53 
54 void PostJob::parse(const QString &xmlString)
55 {
56  //qCDebug(ATTICA) << "PostJob::parse" << xmlString;
57  QXmlStreamReader xml(xmlString);
58  Metadata data;
59  while (!xml.atEnd()) {
60  xml.readNext();
61 
62  if (xml.isStartElement()) {
63  if (xml.name() == QLatin1String("meta")) {
64  while (!xml.atEnd()) {
65  xml.readNext();
66  if (xml.isEndElement() && xml.name() == QLatin1String("meta")) {
67  break;
68  } else if (xml.isStartElement()) {
69  if (xml.name() == QLatin1String("status")) {
70  data.setStatusString(xml.readElementText());
71  } else if (xml.name() == QLatin1String("statuscode")) {
72  data.setStatusCode(xml.readElementText().toInt());
73  } else if (xml.name() == QLatin1String("message")) {
74  data.setMessage(xml.readElementText());
75  } else if (xml.name() == QLatin1String("totalitems")) {
76  data.setTotalItems(xml.readElementText().toInt());
77  } else if (xml.name() == QLatin1String("itemsperpage")) {
78  data.setItemsPerPage(xml.readElementText().toInt());
79  }
80  }
81  }
82  } else if (xml.name() == QLatin1String("data")) {
83  while (!xml.atEnd()) {
84  xml.readNext();
85  if (xml.isEndElement() && xml.name() == QLatin1String("data")) {
86  break;
87  } else if (xml.isStartElement()) {
88  if (xml.name() == QLatin1String("projectid")) {
89  data.setResultingId(xml.readElementText());
90  } if (xml.name() == QLatin1String("buildjobid")) {
91  data.setResultingId(xml.readElementText());
92  }
93 
94  }
95  }
96  }
97  }
98  }
99  setMetadata(data);
100 }
101 
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 Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.