Kgapi

pagemodifyjob.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7#include "pagemodifyjob.h"
8#include "bloggerservice.h"
9#include "page.h"
10#include "utils.h"
11
12#include <QNetworkReply>
13#include <QNetworkRequest>
14
15using namespace KGAPI2;
16using namespace KGAPI2::Blogger;
17
18class Q_DECL_HIDDEN PageModifyJob::Private
19{
20public:
21 Private(const PagePtr &page);
22
23 const PagePtr page;
24};
25
26PageModifyJob::Private::Private(const PagePtr &page_)
27 : page(page_)
28{
29}
30
31PageModifyJob::PageModifyJob(const PagePtr &page, const AccountPtr &account, QObject *parent)
32 : ModifyJob(account, parent)
33 , d(new Private(page))
34{
35}
36
37PageModifyJob::~PageModifyJob()
38{
39 delete d;
40}
41
42void PageModifyJob::start()
43{
44 const QUrl url = BloggerService::modifyPageUrl(d->page->blogId(), d->page->id());
45 QNetworkRequest request(url);
46
47 const QByteArray rawData = Page::toJSON(d->page);
48 enqueueRequest(request, rawData, QStringLiteral("application/json"));
49}
50
51ObjectsList PageModifyJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
52{
53 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
54 ContentType ct = Utils::stringToContentType(contentType);
56 if (ct != KGAPI2::JSON) {
58 setErrorString(tr("Invalid response content type"));
60 return items;
61 }
62
63 items << Page::fromJSON(rawData);
65 return items;
66}
67
68#include "moc_pagemodifyjob.cpp"
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition job.cpp:401
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
void setError(KGAPI2::Error error)
Set job error to error.
Definition job.cpp:386
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
Abstract superclass for all jobs that somehow modify resources on Google.
Definition modifyjob.h:25
ObjectsList items() const
Definition modifyjob.cpp:43
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.