Kgapi

revisionfetchjob.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#include "revisionfetchjob.h"
9#include "driveservice.h"
10#include "revision.h"
11#include "utils.h"
12
13#include <QNetworkReply>
14#include <QNetworkRequest>
15
16using namespace KGAPI2;
17using namespace KGAPI2::Drive;
18
19class Q_DECL_HIDDEN RevisionFetchJob::Private
20{
21public:
22 QString fileId;
23 QString revisionId;
24};
25
26RevisionFetchJob::RevisionFetchJob(const QString &fileId, const AccountPtr &account, QObject *parent)
27 : FetchJob(account, parent)
28 , d(new Private)
29{
30 d->fileId = fileId;
31}
32
33RevisionFetchJob::RevisionFetchJob(const QString &fileId, const QString &revisionId, const AccountPtr &account, QObject *parent)
34 : FetchJob(account, parent)
35 , d(new Private)
36{
37 d->fileId = fileId;
38 d->revisionId = revisionId;
39}
40
41RevisionFetchJob::~RevisionFetchJob()
42{
43 delete d;
44}
45
46void RevisionFetchJob::start()
47{
48 QUrl url;
49 if (d->revisionId.isEmpty()) {
50 url = DriveService::fetchRevisionsUrl(d->fileId);
51 } else {
52 url = DriveService::fetchRevisionUrl(d->fileId, d->revisionId);
53 }
54 QNetworkRequest request(url);
55
56 enqueueRequest(request);
57}
58
59ObjectsList RevisionFetchJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
60{
62
63 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
64 ContentType ct = Utils::stringToContentType(contentType);
65 if (ct == KGAPI2::JSON) {
66 if (d->revisionId.isEmpty()) {
67 items << Revision::fromJSONFeed(rawData);
68 } else {
69 items << Revision::fromJSON(rawData);
70 }
71 } else {
73 setErrorString(tr("Invalid response content type"));
74 }
75
77 return items;
78}
79
80#include "moc_revisionfetchjob.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 Sat Dec 21 2024 17:00:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.