Kgapi

aboutfetchjob.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 "aboutfetchjob.h"
10#include "about.h"
11#include "debug.h"
12#include "driveservice.h"
13#include "utils.h"
14
15#include <QNetworkReply>
16#include <QNetworkRequest>
17
18using namespace KGAPI2;
19using namespace KGAPI2::Drive;
20
21class Q_DECL_HIDDEN AboutFetchJob::Private
22{
23public:
24 Private();
25
26 bool includeSubscribed = true;
27 qlonglong maxChangeIdCount = 0;
28 qlonglong startChangeId = 0;
29};
30
31AboutFetchJob::Private::Private()
32{
33}
34
40
41AboutFetchJob::~AboutFetchJob()
42{
43 delete d;
44}
45
46void AboutFetchJob::setIncludeSubscribed(bool includeSubscribed)
47{
48 if (isRunning()) {
49 qCWarning(KGAPIDebug) << "Can't modify includeSubscribed property when job is running";
50 return;
51 }
52
53 d->includeSubscribed = includeSubscribed;
54}
55
57{
58 return d->includeSubscribed;
59}
60
61void AboutFetchJob::setMaxChangeIdCount(qlonglong maxChangeIdCount)
62{
63 if (isRunning()) {
64 qCWarning(KGAPIDebug) << "Can't modify maxChangeIdCount property when job is running";
65 return;
66 }
67
68 d->maxChangeIdCount = maxChangeIdCount;
69}
70
72{
73 return d->maxChangeIdCount;
74}
75
76void AboutFetchJob::setStartChangeId(qlonglong startChangeId)
77{
78 if (isRunning()) {
79 qCWarning(KGAPIDebug) << "Can't modify startChangeId property when job is running";
80 return;
81 }
82
83 d->startChangeId = startChangeId;
84}
85
87{
88 return d->startChangeId;
89}
90
92{
93 if (isRunning() || items().count() == 0) {
94 return AboutPtr();
95 }
96
97 return items().at(0).dynamicCast<About>();
98}
99
101{
102 QUrl url = DriveService::fetchAboutUrl(d->includeSubscribed, d->maxChangeIdCount, d->startChangeId);
103 QNetworkRequest request(url);
104
105 enqueueRequest(request);
106}
107
109{
111
112 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
113 ContentType ct = Utils::stringToContentType(contentType);
114 if (ct == KGAPI2::JSON) {
115 AboutPtr about = About::fromJSON(rawData);
116 items << about;
117 } else {
119 setErrorString(tr("Invalid response content type"));
120 }
121
122 emitFinished();
123 return items;
124}
125
126#include "moc_aboutfetchjob.cpp"
A fetch job that retrieves DriveAbout data.
bool includeSubscribed
Whether to include shared and public files to change IDs count.
qlonglong maxChangeIdCount
Maximum number of remaining change IDs to count.
void setIncludeSubscribed(bool includeSubscribed)
Sets whether to include shared and public files to change IDs count.
void setMaxChangeIdCount(qlonglong maxChangeIdCount)
Sets maximum number of remaining change IDs to count.
void setStartChangeId(qlonglong startChangeId)
Sets change ID to start counting from when calculating number of remaining change IDs.
void start() override
KGAPI2::Job::start implementation.
qlonglong startChangeId
Change ID to start counting from when calculating number of remaining change IDs.
AboutFetchJob(const AccountPtr &account, QObject *parent=nullptr)
Constructs a new fetch job.
AboutPtr aboutData() const
Returns the retrieved DriveAbout object.
KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
DriveAbout contains information about the current user along with Google Drive API settings.
Definition about.h:36
static AboutPtr fromJSON(const QByteArray &jsonData)
Constructs a new DriveAbout object from given JSON data.
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
AccountPtr account() const
Returns account used to authenticate requests.
Definition job.cpp:436
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
bool isRunning
Whether the job is running.
Definition job.h:67
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
const_reference at(qsizetype i) const const
QVariant header(QNetworkRequest::KnownHeaders header) const const
QObject * parent() 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 Fri Nov 8 2024 12:01:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.