Kgapi

parentreferencefetchjob.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 "parentreferencefetchjob.h"
10#include "driveservice.h"
11#include "parentreference.h"
12#include "utils.h"
13
14#include <QNetworkReply>
15#include <QNetworkRequest>
16
17using namespace KGAPI2;
18using namespace KGAPI2::Drive;
19
20class Q_DECL_HIDDEN ParentReferenceFetchJob::Private
21{
22public:
23 QString fileId;
24 QString referenceId;
25};
26
27ParentReferenceFetchJob::ParentReferenceFetchJob(const QString &fileId, const AccountPtr &account, QObject *parent)
28 : FetchJob(account, parent)
29 , d(new Private)
30{
31 d->fileId = fileId;
32}
33
34ParentReferenceFetchJob::ParentReferenceFetchJob(const QString &fileId, const QString &referenceId, const AccountPtr &account, QObject *parent)
35 : FetchJob(account, parent)
36 , d(new Private)
37{
38 d->fileId = fileId;
39 d->referenceId = referenceId;
40}
41
42ParentReferenceFetchJob::~ParentReferenceFetchJob()
43{
44 delete d;
45}
46
47void ParentReferenceFetchJob::start()
48{
49 QUrl url;
50 if (d->referenceId.isEmpty()) {
51 url = DriveService::fetchParentReferencesUrl(d->fileId);
52 } else {
53 url = DriveService::fetchParentReferenceUrl(d->fileId, d->referenceId);
54 }
55 QNetworkRequest request(url);
56
57 enqueueRequest(request);
58}
59
60ObjectsList ParentReferenceFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
61{
63
64 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
65 ContentType ct = Utils::stringToContentType(contentType);
66 if (ct == KGAPI2::JSON) {
67 if (d->referenceId.isEmpty()) {
68 items << ParentReference::fromJSONFeed(rawData);
69 } else {
70 items << ParentReference::fromJSON(rawData);
71 }
72 } else {
74 setErrorString(tr("Invalid response content type"));
75 }
76
78 return items;
79}
80
81#include "moc_parentreferencefetchjob.cpp"
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition fetchjob.cpp:41
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
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)
bool isEmpty() const const
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.