Kgapi

appfetchjob.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 "appfetchjob.h"
10#include "app.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 AppFetchJob::Private
21{
22public:
23 QString appId;
24};
25
26AppFetchJob::AppFetchJob(const AccountPtr &account, QObject *parent)
27 : FetchJob(account, parent)
28 , d(new Private)
29{
30}
31
32AppFetchJob::AppFetchJob(const QString &appId, const AccountPtr &account, QObject *parent)
33 : FetchJob(account, parent)
34 , d(new Private)
35{
36 d->appId = appId;
37}
38
39AppFetchJob::~AppFetchJob()
40{
41 delete d;
42}
43
44void AppFetchJob::start()
45{
46 QUrl url;
47 if (d->appId.isEmpty()) {
48 url = DriveService::fetchAppsUrl();
49 } else {
50 url = DriveService::fetchAppUrl(d->appId);
51 }
52 QNetworkRequest request(url);
53
54 enqueueRequest(request);
55}
56
57ObjectsList AppFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
58{
60
61 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
62 ContentType ct = Utils::stringToContentType(contentType);
63 if (ct == KGAPI2::JSON) {
64 if (d->appId.isEmpty()) {
65 items << App::fromJSONFeed(rawData);
66 } else {
67 items << App::fromJSON(rawData);
68 }
69 } else {
71 setErrorString(tr("Invalid response content type"));
72 }
73
75 return items;
76}
77
78#include "moc_appfetchjob.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 Fri Dec 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.