Kgapi

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

KDE's Doxygen guidelines are available online.