9#include "drivesfetchjob.h"
12#include "driveservice.h"
15#include <QNetworkReply>
16#include <QNetworkRequest>
21static const QString MaxResultsAttr = QStringLiteral(
"maxResults");
22static const QString UseDomainAdminAccessAttr = QStringLiteral(
"useDomainAdminAccess");
25using namespace KGAPI2::Drive;
27class Q_DECL_HIDDEN DrivesFetchJob::Private
30 Private(DrivesFetchJob *parent);
32 DrivesSearchQuery searchQuery;
36 QVariant useDomainAdminAccess;
41 DrivesFetchJob *
const q;
44DrivesFetchJob::Private::Private(DrivesFetchJob *parent)
49DrivesFetchJob::DrivesFetchJob(
const QString &drivesId,
const AccountPtr &account,
QObject *parent)
51 , d(new Private(this))
53 d->drivesId = drivesId;
58 , d(new Private(this))
60 d->searchQuery =
query;
63DrivesFetchJob::DrivesFetchJob(
const AccountPtr &account,
QObject *parent)
65 , d(new Private(this))
69DrivesFetchJob::~DrivesFetchJob() =
default;
71void DrivesFetchJob::setMaxResults(
int maxResults)
74 qCWarning(KGAPIDebug) <<
"Can't modify maxResults property when job is running";
78 d->maxResults = maxResults;
81int DrivesFetchJob::maxResults()
const
86void DrivesFetchJob::setUseDomainAdminAccess(
bool useDomainAdminAccess)
89 qCWarning(KGAPIDebug) <<
"Can't modify useDomainAdminAccess property when job is running";
93 d->useDomainAdminAccess = useDomainAdminAccess;
96bool DrivesFetchJob::useDomainAdminAccess()
const
98 return d->useDomainAdminAccess.toBool();
101void DrivesFetchJob::setFields(
const QStringList &fields)
104 qCWarning(KGAPIDebug) <<
"Called setFields() on running job. Ignoring.";
111QStringList DrivesFetchJob::fields()
const
116void DrivesFetchJob::start()
119 if (d->drivesId.isEmpty()) {
120 url = DriveService::fetchDrivesUrl();
121 applyRequestParameters(url);
123 url = DriveService::fetchDrivesUrl(d->drivesId);
124 if (!d->fields.isEmpty()) {
126 if (!d->fields.contains(Drives::Fields::Kind)) {
127 d->fields << Drives::Fields::Kind;
133 QNetworkRequest request(url);
137ObjectsList DrivesFetchJob::handleReplyWithItems(
const QNetworkReply *reply,
const QByteArray &rawData)
145 ContentType ct = Utils::stringToContentType(contentType);
146 if (ct == KGAPI2::JSON) {
147 if (d->drivesId.isEmpty()) {
148 items << Drives::fromJSONFeed(rawData, feedData);
150 items << Drives::fromJSON(rawData);
169void DrivesFetchJob::applyRequestParameters(QUrl &url)
171 QUrlQuery
query(url);
172 if (d->maxResults != 0) {
175 if (!d->useDomainAdminAccess.isNull()) {
176 query.addQueryItem(UseDomainAdminAccessAttr, Utils::bool2Str(d->useDomainAdminAccess.toBool()));
178 if (!d->searchQuery.isEmpty()) {
179 query.addQueryItem(QStringLiteral(
"q"), d->searchQuery.serialize());
181 if (!d->fields.isEmpty()) {
183 if (!d->fields.contains(Drives::Fields::Kind)) {
184 d->fields << Drives::Fields::Kind;
186 QString itemFields = Job::buildSubfields(Drives::Fields::Items, d->fields);
187 Job::setFields({Drives::Fields::Kind, Drives::Fields::NextPageToken, itemFields});
192#include "moc_drivesfetchjob.cpp"
DrivesSearchQuery class allows simply building even complex shared drive search queries for DrivesFet...
QUrl requestUrl
Original URL of the request.
QUrl nextPageUrl
Link to next page of feed.
Abstract superclass for all jobs that fetch resources from Google.
virtual ObjectsList items() const
Returns all items fetched by this job.
void setErrorString(const QString &errorString)
Set job error description to errorString.
QStringList fields() const
Returns fields selector.
void setFields(const QStringList &fields)
Set subset of fields to include in the response.
virtual void emitFinished()
Emits Job::finished() signal.
void setError(KGAPI2::Error error)
Set job error to error.
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
bool isRunning
Whether the job is running.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
A job to fetch a single map tile described by a StaticMapUrl.
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString number(double n, char format, int precision)
bool isValid() const const
void setQuery(const QString &query, ParsingMode mode)
QString toString() const const