Kgapi

modifyjob.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * Copyright (C) 2013 Daniel Vrátil <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
23 #include "modifyjob.h"
24 #include "../debug.h"
25 #include "object.h"
26 
27 #include <QNetworkAccessManager>
28 #include <QNetworkRequest>
29 #include <QBuffer>
30 
31 using namespace KGAPI2;
32 
33 class Q_DECL_HIDDEN ModifyJob::Private
34 {
35  public:
36  ObjectsList items;
37  QBuffer buffer;
38 };
39 
41  Job(parent),
42  d(new Private)
43 {
44 }
45 
47  Job(account, parent),
48  d(new Private)
49 {
50 }
51 
53 {
54  delete d;
55 }
56 
58 {
59  return d->items;
60 }
61 
63  const QByteArray& data, const QString& contentType)
64 {
65  QNetworkRequest r = request;
66  if (!r.hasRawHeader("Content-Type")) {
67  r.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
68  }
69 
70  if (!r.hasRawHeader("If-Match")) {
71  r.setRawHeader("If-Match", "*");
72  }
73 
74  // Note: there is a problem with PUT when using KIO::AccessManager - it
75  // doesn't transfer the body correctly.
76  // Using sendCustomRequest() works just fine.
77  //accessManager->put(r, data);
78  if (!data.isEmpty()) {
79  r.setHeader(QNetworkRequest::ContentLengthHeader, data.size());
80 
81  d->buffer.close();
82  d->buffer.setData(data);
83  d->buffer.open(QIODevice::ReadOnly);
84  accessManager->sendCustomRequest(r, "PUT", &d->buffer);
85  } else {
86  accessManager->sendCustomRequest(r, "PUT");
87  }
88 }
89 
90 void ModifyJob::handleReply( const QNetworkReply *reply, const QByteArray &rawData )
91 {
92  d->buffer.close();
93  d->items << handleReplyWithItems(reply, rawData);
94 }
95 
97 {
98  d->items.clear();
99 
101 }
102 
104  const QByteArray& rawData)
105 {
106  Q_UNUSED(reply)
107  Q_UNUSED(rawData)
108 
109  return ObjectsList();
110 }
QNetworkReply * sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data)
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:437
ModifyJob(QObject *parent=nullptr)
Constructor for jobs that don&#39;t require authentication.
Definition: modifyjob.cpp:40
bool hasRawHeader(const QByteArray &headerName) const const
bool isEmpty() const const
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI2::Job::dispatchRequest implementation.
Definition: modifyjob.cpp:62
Abstract base class for all jobs in LibKGAPI.
Definition: job.h:55
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:30
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
ObjectsList items() const
Definition: modifyjob.cpp:57
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
void aboutToStart() override
KGAPI2::Job::aboutToStart() implementation.
Definition: modifyjob.cpp:96
Abstract superclass for all jobs that somehow modify resources on Google.
Definition: modifyjob.h:38
int size() const const
QObject * parent() const const
virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
A reply handler that returns items parsed from @ rawData.
Definition: modifyjob.cpp:103
virtual void aboutToStart()
This method is invoked right before Job::start() is called.
Definition: job.cpp:535
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition: modifyjob.cpp:90
~ModifyJob() override
Destructor.
Definition: modifyjob.cpp:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 31 2020 22:38:48 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.