Kgapi

modifyjob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "modifyjob.h"
10#include "debug.h"
11#include "object.h"
12
13#include <QBuffer>
14#include <QNetworkAccessManager>
15#include <QNetworkRequest>
16
17using namespace KGAPI2;
18
19class Q_DECL_HIDDEN ModifyJob::Private
20{
21public:
22 ObjectsList items;
23 QBuffer buffer;
24};
25
27 : Job(parent)
28 , d(new Private)
29{
30}
31
32ModifyJob::ModifyJob(const AccountPtr &account, QObject *parent)
33 : Job(account, parent)
34 , d(new Private)
35{
36}
37
39{
40 delete d;
41}
42
44{
45 return d->items;
46}
47
48void ModifyJob::dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType)
49{
50 QNetworkRequest r = request;
51 if (!r.hasRawHeader("Content-Type")) {
53 }
54
55 if (!r.hasRawHeader("If-Match")) {
56 r.setRawHeader("If-Match", "*");
57 }
58
59 // Note: there is a problem with PUT when using QNAM - it
60 // doesn't transfer the body correctly.
61 // Using sendCustomRequest() works just fine.
62 // accessManager->put(r, data);
63 if (!data.isEmpty()) {
65
66 d->buffer.close();
67 d->buffer.setData(data);
68 d->buffer.open(QIODevice::ReadOnly);
69 accessManager->sendCustomRequest(r, "PUT", &d->buffer);
70 } else {
71 accessManager->sendCustomRequest(r, "PUT");
72 }
73}
74
75void ModifyJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
76{
77 d->buffer.close();
78 d->items << handleReplyWithItems(reply, rawData);
79}
80
82{
83 d->items.clear();
84
86}
87
89{
90 Q_UNUSED(reply)
91 Q_UNUSED(rawData)
92
93 return ObjectsList();
94}
95
96#include "moc_modifyjob.cpp"
Abstract base class for all jobs in LibKGAPI.
Definition job.h:41
virtual void aboutToStart()
This method is invoked right before Job::start() is called.
Definition job.cpp:539
Abstract superclass for all jobs that somehow modify resources on Google.
Definition modifyjob.h:25
ModifyJob(QObject *parent=nullptr)
Constructor for jobs that don't require authentication.
Definition modifyjob.cpp:26
~ModifyJob() override
Destructor.
Definition modifyjob.cpp:38
virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
A reply handler that returns items parsed from @ rawData.
Definition modifyjob.cpp:88
void aboutToStart() override
KGAPI2::Job::aboutToStart() implementation.
Definition modifyjob.cpp:81
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI2::Job::dispatchRequest implementation.
Definition modifyjob.cpp:48
ObjectsList items() const
Definition modifyjob.cpp:43
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition modifyjob.cpp:75
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
virtual void close() override
virtual bool open(OpenMode flags) override
void setData(const QByteArray &data)
bool isEmpty() const const
qsizetype size() const const
void clear()
QNetworkReply * sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart)
bool hasRawHeader(const QByteArray &headerName) const const
void setHeader(KnownHeaders header, const QVariant &value)
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.