9#include "filefetchjob.h"
11#include "driveservice.h"
13#include "filesearchquery.h"
16#include <QNetworkReply>
17#include <QNetworkRequest>
21using namespace KGAPI2::Drive;
23class Q_DECL_HIDDEN FileFetchJob::Private
26 Private(FileFetchJob *parent);
32 bool includeItemsFromAllDrives =
true;
33 bool supportsAllDrives =
true;
35 bool updateViewedDate =
false;
40 FileFetchJob *
const q;
43FileFetchJob::Private::Private(FileFetchJob *parent)
48void FileFetchJob::Private::processNext()
53 url = DriveService::fetchFilesUrl();
56 if (!searchQuery.isEmpty()) {
57 query.addQueryItem(QStringLiteral(
"q"), searchQuery.serialize());
60 query.addQueryItem(QStringLiteral(
"includeItemsFromAllDrives"), Utils::bool2Str(includeItemsFromAllDrives));
66 if (!fields.
contains(File::Fields::Kind)) {
67 fields << File::Fields::Kind;
69 Job *baseJob =
dynamic_cast<Job *
>(q);
72 File::Fields::NextLink,
73 File::Fields::NextPageToken,
74 File::Fields::SelfLink,
75 Job::buildSubfields(File::Fields::Items, fields)});
84 url = DriveService::fetchFileUrl(fileId);
88 if (!fields.
contains(File::Fields::Kind)) {
89 fields << File::Fields::Kind;
91 Job *baseJob =
dynamic_cast<Job *
>(q);
97 withDriveSupportQuery.addQueryItem(QStringLiteral(
"supportsAllDrives"), Utils::bool2Str(supportsAllDrives));
106 , d(new Private(this))
108 d->filesIDs << fileId;
113 , d(new Private(this))
115 d->filesIDs << filesIds;
120 , d(new Private(this))
127 , d(new Private(this))
130 d->searchQuery =
query;
133FileFetchJob::~FileFetchJob()
138bool FileFetchJob::updateViewedDate()
const
140 return d->updateViewedDate;
143void FileFetchJob::setUpdateViewedDate(
bool updateViewedDate)
146 qCWarning(KGAPIDebug) <<
"Can't modify updateViewedDate property when job is running.";
150 d->updateViewedDate = updateViewedDate;
153void FileFetchJob::start()
158void FileFetchJob::setFields(
const QStringList &fields)
161 qCWarning(KGAPIDebug) <<
"Called setFields() on running job. Ignoring.";
173bool FileFetchJob::includeItemsFromAllDrives()
const
175 return d->includeItemsFromAllDrives;
178void FileFetchJob::setIncludeItemsFromAllDrives(
bool includeItemsFromAllDrives)
180 d->includeItemsFromAllDrives = includeItemsFromAllDrives;
183bool FileFetchJob::supportsAllDrives()
const
185 return d->supportsAllDrives;
188void FileFetchJob::setSupportsAllDrives(
bool supportsAllDrives)
190 d->supportsAllDrives = supportsAllDrives;
193const QStringList &FileFetchJob::FieldShorthands::basicFields()
195 static const QStringList basicFields = {File::Fields::Id,
197 File::Fields::MimeType,
198 File::Fields::CreatedDate,
199 File::Fields::ModifiedDate,
200 File::Fields::FileSize,
201 File::Fields::DownloadUrl,
202 File::Fields::Permissions};
206const QStringList &FileFetchJob::FieldShorthands::accessFields()
208 static const QStringList accessFields = {File::Fields::CreatedDate,
209 File::Fields::ModifiedDate,
210 File::Fields::ModifiedByMeDate,
211 File::Fields::LastModifiedByMeDate,
212 File::Fields::LastViewedByMeDate,
213 File::Fields::MarkedViewedByMeDate};
217const QStringList &FileFetchJob::FieldShorthands::sharingFields()
219 static const QStringList sharingFields = {File::Fields::SharedWithMeDate,
220 File::Fields::WritersCanShare,
221 File::Fields::Shared,
222 File::Fields::Owners,
223 File::Fields::SharingUser,
224 File::Fields::OwnerNames};
225 return sharingFields;
233 ContentType ct = Utils::stringToContentType(contentType);
234 if (ct == KGAPI2::JSON) {
238 items << File::fromJSONFeed(rawData, feedData);
246 items << File::fromJSON(rawData);
260#include "moc_filefetchjob.cpp"
FileSearchQuery class allows simply building even complex file search queries for FileFetchJob.
Structure to store additional information about a feed.
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.
Abstract base class for all jobs in LibKGAPI.
void setErrorString(const QString &errorString)
Set job error description to errorString.
AccountPtr account() const
Returns account used to authenticate requests.
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.
bool isEmpty() const const
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
bool isValid() const const
void setQuery(const QString &query, ParsingMode mode)
QString toString() const const