Kgapi

childreferencefetchjob.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 "childreferencefetchjob.h"
10#include "childreference.h"
11#include "driveservice.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 ChildReferenceFetchJob::Private
21{
22public:
23 Private(ChildReferenceFetchJob *parent);
24
25 QString folderId;
26 QString childId;
27
28private:
29 ChildReferenceFetchJob *const q;
30};
31
32ChildReferenceFetchJob::Private::Private(ChildReferenceFetchJob *parent)
33 : q(parent)
34{
35}
36
37ChildReferenceFetchJob::ChildReferenceFetchJob(const QString &folderId, const AccountPtr &account, QObject *parent)
38 : FetchJob(account, parent)
39 , d(new Private(this))
40{
41 d->folderId = folderId;
42}
43
44ChildReferenceFetchJob::ChildReferenceFetchJob(const QString &folderId, const QString &childId, const AccountPtr &account, QObject *parent)
45 : FetchJob(account, parent)
46 , d(new Private(this))
47{
48 d->folderId = folderId;
49 d->childId = childId;
50}
51
52ChildReferenceFetchJob::~ChildReferenceFetchJob()
53{
54 delete d;
55}
56
57void ChildReferenceFetchJob::start()
58{
59 QUrl url;
60 if (d->childId.isEmpty()) {
61 url = DriveService::fetchChildReferences(d->folderId);
62 } else {
63 url = DriveService::fetchParentReferenceUrl(d->folderId, d->childId);
64 }
65
66 QNetworkRequest request(url);
67 enqueueRequest(request);
68}
69
70ObjectsList ChildReferenceFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
71{
73 FeedData feedData;
74
75 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
76 ContentType ct = Utils::stringToContentType(contentType);
77 if (ct == KGAPI2::JSON) {
78 if (d->childId.isEmpty()) {
79 items << ChildReference::fromJSONFeed(rawData, feedData);
80 } else {
81 items << ChildReference::fromJSON(rawData);
82 }
83 } else {
85 setErrorString(tr("Invalid response content type"));
87 return items;
88 }
89
90 if (feedData.nextPageUrl.isValid()) {
91 QNetworkRequest request(feedData.nextPageUrl);
92 enqueueRequest(request);
93 }
94
95 return items;
96}
97
98#include "moc_childreferencefetchjob.cpp"
Structure to store additional information about a feed.
Definition types.h:24
QUrl nextPageUrl
Link to next page of feed.
Definition types.h:38
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
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:54:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.