Kgapi

about.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Andrius da Costa Ribas <andriusmao@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "about.h"
8#include "debug.h"
9#include "user.h"
10#include "utils.h"
11#include "utils_p.h"
12
13#include <QJsonDocument>
14
15using namespace KGAPI2;
16using namespace KGAPI2::Drive;
17
18///// DriveAbout::Format
19
20class Q_DECL_HIDDEN About::Format::Private
21{
22public:
23 Private();
24 Private(const Private &other);
25
26 QString source;
27 QStringList targets;
28};
29
30About::Format::Private::Private()
31{
32}
33
34About::Format::Private::Private(const Private &other)
35 : source(other.source)
36 , targets(other.targets)
37{
38}
39
40About::Format::Format()
41 : d(new Private)
42{
43}
44
45About::Format::Format(const About::Format &other)
46 : d(new Private(*(other.d)))
47{
48}
49
50About::Format::~Format()
51{
52 delete d;
53}
54
55bool About::Format::operator==(const About::Format &other) const
56{
57 GAPI_COMPARE(source)
58 GAPI_COMPARE(targets)
59 return true;
60}
61
63{
64 return d->source;
65}
66
68{
69 return d->targets;
70}
71
72///// DriveAbout::AdditionalRoleInfo::RoleSet
73
74class Q_DECL_HIDDEN About::AdditionalRoleInfo::RoleSet::Private
75{
76public:
77 Private();
78 Private(const Private &other);
79
80 QString primaryRole;
81 QStringList additionalRoles;
82};
83
84About::AdditionalRoleInfo::RoleSet::Private::Private()
85{
86}
87
88About::AdditionalRoleInfo::RoleSet::Private::Private(const Private &other)
89 : primaryRole(other.primaryRole)
90 , additionalRoles(other.additionalRoles)
91{
92}
93
94About::AdditionalRoleInfo::RoleSet::RoleSet()
95 : d(new Private)
96{
97}
98
99About::AdditionalRoleInfo::RoleSet::RoleSet(const About::AdditionalRoleInfo::RoleSet &other)
100 : d(new Private(*(other.d)))
101{
102}
103
104About::AdditionalRoleInfo::RoleSet::~RoleSet()
105{
106 delete d;
107}
108
109bool About::AdditionalRoleInfo::RoleSet::operator==(const RoleSet &other) const
110{
111 GAPI_COMPARE(primaryRole)
112 GAPI_COMPARE(additionalRoles)
113 return true;
114}
115
117{
118 return d->primaryRole;
119}
120
122{
123 return d->additionalRoles;
124}
125
126///// DriveAbout::AdditionalRoleInfo
127
128class Q_DECL_HIDDEN About::AdditionalRoleInfo::Private
129{
130public:
131 Private();
132 Private(const Private &other);
133
135 RoleSetsList roleSets;
136};
137
138About::AdditionalRoleInfo::Private::Private()
139{
140}
141
142About::AdditionalRoleInfo::Private::Private(const Private &other)
143 : type(other.type)
144 , roleSets(other.roleSets)
145{
146}
147
148About::AdditionalRoleInfo::AdditionalRoleInfo()
149 : d(new Private)
150{
151}
152
153About::AdditionalRoleInfo::AdditionalRoleInfo(const About::AdditionalRoleInfo &other)
154 : d(new Private(*(other.d)))
155{
156}
157
158About::AdditionalRoleInfo::~AdditionalRoleInfo()
159{
160 delete d;
161}
162
163bool About::AdditionalRoleInfo::operator==(const AdditionalRoleInfo &other) const
164{
165 GAPI_COMPARE(type)
166 GAPI_COMPARE_CONTAINERS(roleSets)
167 return true;
168}
169
171{
172 return d->type;
173}
174
176{
177 return d->roleSets;
178}
179
180///// DriveAbout::Feature
181
182class Q_DECL_HIDDEN About::Feature::Private
183{
184public:
185 Private();
186 Private(const Private &other);
187
188 QString featureName;
189 qreal featureRate;
190};
191
192About::Feature::Private::Private()
193 : featureRate(-1)
194{
195}
196
197About::Feature::Private::Private(const Private &other)
198 : featureName(other.featureName)
199 , featureRate(other.featureRate)
200{
201}
202
203About::Feature::Feature()
204 : d(new Private)
205{
206}
207
208About::Feature::Feature(const About::Feature &other)
209 : d(new Private(*(other.d)))
210{
211}
212
213About::Feature::~Feature()
214{
215 delete d;
216}
217
218bool About::Feature::operator==(const Feature &other) const
219{
220 GAPI_COMPARE(featureName)
221 GAPI_COMPARE(featureRate)
222 return true;
223}
224
226{
227 return d->featureName;
228}
229
231{
232 return d->featureRate;
233}
234
235///// DriveAbout::MaxUploadSize
236
237class Q_DECL_HIDDEN About::MaxUploadSize::Private
238{
239public:
240 Private();
241 Private(const Private &other);
242
243 QString type;
244 qlonglong size;
245};
246
247About::MaxUploadSize::Private::Private()
248 : size(-1)
249{
250}
251
252About::MaxUploadSize::Private::Private(const Private &other)
253 : type(other.type)
254 , size(other.size)
255{
256}
257
258About::MaxUploadSize::MaxUploadSize()
259 : d(new Private)
260{
261}
262
263About::MaxUploadSize::MaxUploadSize(const About::MaxUploadSize &other)
264 : d(new Private(*(other.d)))
265{
266}
267
268About::MaxUploadSize::~MaxUploadSize()
269{
270 delete d;
271}
272
273bool About::MaxUploadSize::operator==(const MaxUploadSize &other) const
274{
275 GAPI_COMPARE(type)
276 GAPI_COMPARE(size)
277 return true;
278}
279
281{
282 return d->type;
283}
284
286{
287 return d->size;
288}
289
290///// DriveAbout
291
292class Q_DECL_HIDDEN About::Private
293{
294public:
295 Private();
296 Private(const Private &other);
297
298 QUrl selfLink;
299 QString name;
300 qlonglong quotaBytesTotal;
301 qlonglong quotaBytesUsed;
302 qlonglong quotaBytesUsedInTrash;
303 qlonglong quotaBytesUsedAggregate;
304 qlonglong largestChangeId;
305 qlonglong remainingChangeIds;
306 QString rootFolderId;
307 QString domainSharingPolicy;
308 FormatsList importFormats;
309 FormatsList exportFormats;
310 AdditionalRoleInfosList additionalRoleInfo;
311 FeaturesList features;
312 MaxUploadSizesList maxUploadSizes;
313 QString permissionId;
314 bool isCurrentAppInstalled;
315 bool canCreateDrives;
316 UserPtr user;
317};
318
319About::Private::Private()
320 : quotaBytesTotal(-1)
321 , quotaBytesUsed(-1)
324 , largestChangeId(-1)
326 , isCurrentAppInstalled(false)
327 , canCreateDrives(false)
328{
329}
330
331About::Private::Private(const About::Private &other)
332 : selfLink(other.selfLink)
333 , name(other.name)
345 , features(other.features)
350 , user(other.user)
351{
352}
353
354const QString About::Fields::AdditionalRoleInfo = QStringLiteral("additionalRoleInfo");
355const QString About::Fields::AdditionalRoles = QStringLiteral("additionalRoles");
356const QString About::Fields::BackgroundImageLink = QStringLiteral("backgroundImageLink");
357const QString About::Fields::BytesUsed = QStringLiteral("bytesUsed");
358const QString About::Fields::CanCreateDrives = QStringLiteral("canCreateDrives");
359const QString About::Fields::ColorRgb = QStringLiteral("colorRgb");
360const QString About::Fields::DisplayName = QStringLiteral("displayName");
361const QString About::Fields::DomainSharingPolicy = QStringLiteral("domainSharingPolicy");
362const QString About::Fields::EmailAddress = QStringLiteral("emailAddress");
363const QString About::Fields::Etag = QStringLiteral("etag");
364const QString About::Fields::ExportFormats = QStringLiteral("exportFormats");
365const QString About::Fields::FeatureName = QStringLiteral("featureName");
366const QString About::Fields::FeatureRate = QStringLiteral("featureRate");
367const QString About::Fields::Features = QStringLiteral("features");
368const QString About::Fields::FolderColorPalette = QStringLiteral("folderColorPalette");
369const QString About::Fields::Id = QStringLiteral("id");
370const QString About::Fields::ImportFormats = QStringLiteral("importFormats");
371const QString About::Fields::IsAuthenticatedUser = QStringLiteral("isAuthenticatedUser");
372const QString About::Fields::IsCurrentAppInstalled = QStringLiteral("isCurrentAppInstalled");
373const QString About::Fields::Kind = QStringLiteral("kind");
374const QString About::Fields::LanguageCode = QStringLiteral("languageCode");
375const QString About::Fields::LargestChangeId = QStringLiteral("largestChangeId");
376const QString About::Fields::MaxUploadSizes = QStringLiteral("maxUploadSizes");
377const QString About::Fields::Name = QStringLiteral("name");
378const QString About::Fields::PermissionId = QStringLiteral("permissionId");
379const QString About::Fields::Picture = QStringLiteral("picture");
380const QString About::Fields::PrimaryRole = QStringLiteral("primaryRole");
381const QString About::Fields::QuotaBytesByService = QStringLiteral("quotaBytesByService");
382const QString About::Fields::QuotaBytesTotal = QStringLiteral("quotaBytesTotal");
383const QString About::Fields::QuotaBytesUsedAggregate = QStringLiteral("quotaBytesUsedAggregate");
384const QString About::Fields::QuotaBytesUsedInTrash = QStringLiteral("quotaBytesUsedInTrash");
385const QString About::Fields::QuotaBytesUsed = QStringLiteral("quotaBytesUsed");
386const QString About::Fields::QuotaType = QStringLiteral("quotaType");
387const QString About::Fields::RemainingChangeIds = QStringLiteral("remainingChangeIds");
388const QString About::Fields::RoleSets = QStringLiteral("roleSets");
389const QString About::Fields::RootFolderId = QStringLiteral("rootFolderId");
390const QString About::Fields::SelfLink = QStringLiteral("selfLink");
391const QString About::Fields::ServiceName = QStringLiteral("serviceName");
392const QString About::Fields::Size = QStringLiteral("size");
393const QString About::Fields::Source = QStringLiteral("source");
394const QString About::Fields::Targets = QStringLiteral("targets");
395const QString About::Fields::TeamDriveThemes = QStringLiteral("teamDriveThemes");
396const QString About::Fields::Type = QStringLiteral("type");
397const QString About::Fields::Url = QStringLiteral("url");
398const QString About::Fields::User = QStringLiteral("user");
399
400About::About()
401 : KGAPI2::Object()
402 , d(new Private)
403{
404}
405
406About::About(const About &other)
407 : KGAPI2::Object(other)
408 , d(new Private(*(other.d)))
409{
410}
411
412About::~About() = default;
413
414bool About::operator==(const About &other) const
415{
416 if (!Object::operator==(other)) {
417 return false;
418 }
419
420 GAPI_COMPARE(selfLink)
421 GAPI_COMPARE(name)
422 GAPI_COMPARE(quotaBytesTotal)
423 GAPI_COMPARE(quotaBytesUsed)
424 GAPI_COMPARE(quotaBytesUsedInTrash)
425 GAPI_COMPARE(quotaBytesUsedInTrash)
426 GAPI_COMPARE(largestChangeId)
427 GAPI_COMPARE(remainingChangeIds)
428 GAPI_COMPARE(rootFolderId)
429 GAPI_COMPARE(domainSharingPolicy)
430 GAPI_COMPARE_CONTAINERS(importFormats)
431 GAPI_COMPARE_CONTAINERS(exportFormats)
432 GAPI_COMPARE_CONTAINERS(additionalRoleInfo)
433 GAPI_COMPARE_CONTAINERS(features)
434 GAPI_COMPARE_CONTAINERS(maxUploadSizes)
435 GAPI_COMPARE(permissionId)
436 GAPI_COMPARE(isCurrentAppInstalled)
437 GAPI_COMPARE(canCreateDrives)
438 GAPI_COMPARE_SHAREDPTRS(user)
439 return true;
440}
441
442QUrl About::selfLink() const
443{
444 return d->selfLink;
445}
446
447QString About::name() const
448{
449 return d->name;
450}
451
452qlonglong About::quotaBytesTotal() const
453{
454 return d->quotaBytesTotal;
455}
456
457qlonglong About::quotaBytesUsed() const
458{
459 return d->quotaBytesUsed;
460}
461
462qlonglong About::quotaBytesUsedInTrash() const
463{
464 return d->quotaBytesUsedInTrash;
465}
466
467qlonglong About::quotaBytesUsedAggregate() const
468{
469 return d->quotaBytesUsedAggregate;
470}
471
472#ifndef KGAPIDRIVE_NO_DEPRECATED
473qlonglong About::quotaBytesUserAggregate() const
474{
476}
477#endif
478
479qlonglong About::largestChangeId() const
480{
481 return d->largestChangeId;
482}
483qlonglong About::remainingChangeIds() const
484{
485 return d->remainingChangeIds;
486}
487
489{
490 return d->rootFolderId;
491}
492
494{
495 return d->domainSharingPolicy;
496}
497
499{
500 return d->importFormats;
501}
502
504{
505 return d->exportFormats;
506}
507
509{
510 return d->additionalRoleInfo;
511}
512
514{
515 return d->features;
516}
517
519{
520 return d->maxUploadSizes;
521}
522
524{
525 return d->permissionId;
526}
527
529{
530 return d->isCurrentAppInstalled;
531}
532
533UserPtr About::user() const
534{
535 return d->user;
536}
537
538bool About::canCreateDrives() const
539{
540 return d->canCreateDrives;
541}
542
543AboutPtr About::fromJSON(const QByteArray &jsonData)
544{
545 QJsonDocument document = QJsonDocument::fromJson(jsonData);
546 if (document.isNull()) {
547 return AboutPtr();
548 }
549 const QVariantMap map = document.toVariant().toMap();
550
551 if (!map.contains(QLatin1StringView("kind")) || map[QStringLiteral("kind")].toString() != QLatin1StringView("drive#about")) {
552 return AboutPtr();
553 }
554
555 AboutPtr about(new About());
556 about->setEtag(map.value(QStringLiteral("etag")).toString());
557 about->d->selfLink = map.value(QStringLiteral("selfLink")).toUrl();
558 about->d->name = map.value(QStringLiteral("name")).toString();
559 about->d->quotaBytesTotal = map.value(QStringLiteral("quotaBytesTotal")).toLongLong();
560 about->d->quotaBytesUsed = map.value(QStringLiteral("quotaBytesUsed")).toLongLong();
561 about->d->quotaBytesUsedInTrash = map.value(QStringLiteral("quotaBytesUsedInTrash")).toLongLong();
562 about->d->quotaBytesUsedAggregate = map.value(QStringLiteral("quotaBytesUsedAggregate")).toLongLong();
563 about->d->largestChangeId = map.value(QStringLiteral("largestChangeId")).toLongLong();
564 about->d->remainingChangeIds = map.value(QStringLiteral("remainingChangeIds")).toLongLong();
565 about->d->rootFolderId = map.value(QStringLiteral("rootFolderId")).toString();
566 about->d->domainSharingPolicy = map.value(QStringLiteral("domainSharingPolicy")).toString();
567 about->d->permissionId = map.value(QStringLiteral("permissionId")).toString();
568 about->d->isCurrentAppInstalled = map.value(QStringLiteral("isCurrentAppInstalled")).toBool();
569 about->d->canCreateDrives = map.value(QStringLiteral("canCreateDrives")).toBool();
570
571 const QVariantList importFormats = map.value(QStringLiteral("importFormats")).toList();
572 for (const QVariant &v : importFormats) {
573 const QVariantMap importFormat = v.toMap();
574 FormatPtr format(new Format());
575 format->d->source = importFormat.value(QStringLiteral("source")).toString();
576 format->d->targets = importFormat.value(QStringLiteral("targets")).toStringList();
577
578 about->d->importFormats << format;
579 }
580
581 const QVariantList exportFormats = map.value(QStringLiteral("exportFormats")).toList();
582 for (const QVariant &v : exportFormats) {
583 const QVariantMap exportFormat = v.toMap();
584 FormatPtr format(new Format());
585 format->d->source = exportFormat.value(QStringLiteral("source")).toString();
586 format->d->targets = exportFormat.value(QStringLiteral("targets")).toStringList();
587
588 about->d->exportFormats << format;
589 }
590
591 const QVariantList additionalRoleInfos = map.value(QStringLiteral("additionalRoleInfo")).toList();
592 for (const QVariant &v : additionalRoleInfos) {
593 const QVariantMap additionalRoleInfo = v.toMap();
594 AdditionalRoleInfoPtr info(new AdditionalRoleInfo());
595 info->d->type = additionalRoleInfo.value(QStringLiteral("type")).toString();
596
597 const QVariantList roleSets = additionalRoleInfo.value(QStringLiteral("roleSets")).toList();
598 for (const QVariant &vv : roleSets) {
599 const QVariantMap roleSetData = vv.toMap();
600 AdditionalRoleInfo::RoleSetPtr roleSet(new AdditionalRoleInfo::RoleSet());
601 roleSet->d->primaryRole = roleSetData.value(QStringLiteral("primaryRole")).toString();
602 roleSet->d->additionalRoles = roleSetData.value(QStringLiteral("additionalRoles")).toStringList();
603
604 info->d->roleSets << roleSet;
605 }
606
607 about->d->additionalRoleInfo << info;
608 }
609
610 const QVariantList features = map.value(QStringLiteral("features")).toList();
611 for (const QVariant &v : features) {
612 const QVariantMap featureData = v.toMap();
613 FeaturePtr feature(new Feature());
614 feature->d->featureName = featureData.value(QStringLiteral("featureName")).toString();
615 feature->d->featureRate = featureData.value(QStringLiteral("featureRate")).toReal();
616
617 about->d->features << feature;
618 }
619
620 const QVariantList maxUploadSizes = map.value(QStringLiteral("maxUploadSizes")).toList();
621 for (const QVariant &v : maxUploadSizes) {
622 const QVariantMap maxUploadSizeData = v.toMap();
623 MaxUploadSizePtr maxUploadSize(new MaxUploadSize());
624 maxUploadSize->d->type = maxUploadSizeData.value(QStringLiteral("type")).toString();
625 maxUploadSize->d->size = maxUploadSizeData.value(QStringLiteral("size")).toLongLong();
626
627 about->d->maxUploadSizes << maxUploadSize;
628 }
629
630 about->d->user = User::fromJSON(map.value(QStringLiteral("user")).toMap());
631
632 return about;
633}
DriveAbout::AdditionalRoleInfo::Role holds the structure used for additionalRoleInfo[]....
Definition about.h:87
QStringList additionalRoles() const
Returns the supported additional roles with the primary role.
QString primaryRole() const
Returns the primary permission role.
DriveAbout::AdditionalRoleInfo holds the structure used for additionalRoleInfo[] property.
Definition about.h:80
QString type() const
Returns the content type that this additional role info applies to.
RoleSetsList roleSets() const
Returns the supported additional roles per primary role.
DriveAbout::Feature holds the structure used for features[] property.
Definition about.h:153
qreal featureRate() const
Returns the request limit rate for this feature, in queries per second.
Definition about.cpp:230
QString featureName() const
Returns the name of the feature.
Definition about.cpp:225
DriveAbout::Format holds the structure used for importFormats[] and exportFormats[] properties.
Definition about.h:43
QString source() const
Returns the content type to convert from.
Definition about.cpp:62
QStringList targets() const
Returns the possible content types to convert to.
Definition about.cpp:67
DriveAbout::MaxUploadSize holds the structure used for maxUploadSizes[] property.
Definition about.h:189
qlonglong size() const
Returns the max upload size for this type.
Definition about.cpp:285
QString type() const
Returns the file type.
Definition about.cpp:280
DriveAbout contains information about the current user along with Google Drive API settings.
Definition about.h:36
QString domainSharingPolicy() const
Returns the domain sharing policy for the current user.
KGAPIDRIVE_DEPRECATED qlonglong quotaBytesUserAggregate() const
returns the total number of quota bytes used by all Google apps (Drive, Picasa, etc....
FeaturesList features() const
Returns the list of additional features enabled on this account.
MaxUploadSizesList maxUploadSizes() const
Returns the list of max upload sizes for each file type.
FormatsList importFormats() const
Returns the allowable import formats.
qlonglong largestChangeId() const
Returns the largest change id.
static AboutPtr fromJSON(const QByteArray &jsonData)
Constructs a new DriveAbout object from given JSON data.
qlonglong remainingChangeIds() const
Returns the number of remaining change ids.
QString name() const
Returns the name of the current user.
qlonglong quotaBytesUsedAggregate() const
returns the total number of quota bytes used by all Google apps (Drive, Picasa, etc....
UserPtr user() const
Returns the authenticated user.
qlonglong quotaBytesTotal() const
Returns the total number of quota bytes.
AdditionalRoleInfosList additionalRoleInfo() const
Returns information about supported additional roles per file type.
qlonglong quotaBytesUsed() const
Returns the total number of quota bytes used.
QString rootFolderId() const
Returns the id of the root folder.
bool isCurrentAppInstalled() const
Returns whether the authenticated app is installed by the authenticated user.
QUrl selfLink() const
Returns the link back to this item.
bool canCreateDrives() const
Returns whether the user can create shared drives.
FormatsList exportFormats() const
Returns the allowable export formats.
QString permissionId() const
Returns the current user's ID as visible in the permissions collection.
qlonglong quotaBytesUsedInTrash() const
Returns the total number of quota bytes used by trashed items.
Base class for all objects.
Definition object.h:31
Type type(const QSqlDatabase &db)
char * toString(const EngineQuery &query)
const QVariantMap toMap(const MODEL &model)
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
bool isNull() const const
QVariant toVariant() const const
T value(qsizetype i) const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QMap< QString, QVariant > toMap() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.