Kgapi

teamdrive.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 David Barchiesi <[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 "driveservice.h"
8 #include "teamdrive.h"
9 #include "utils_p.h"
10 
11 #include <QVariant>
12 #include <QUrlQuery>
13 #include <QJsonDocument>
14 
15 namespace {
16  static const QString ApiKind = QStringLiteral("drive#teamDrive");
17  static const QString ApiKindList = QStringLiteral("drive#teamDriveList");
18 }
19 
20 using namespace KGAPI2;
21 using namespace KGAPI2::Drive;
22 
23 ///// DriveTeamdrive::Restrictions
24 
25 class Q_DECL_HIDDEN Teamdrive::Restrictions::Private
26 {
27  public:
28  Private() = default;
29  Private(const Private &other) = default;
30 
31  bool adminManagedRestrictions = false;
32  bool copyRequiresWriterPermission = false;
33  bool domainUsersOnly = false;
34  bool teamMembersOnly = false;
35 };
36 
37 Teamdrive::Restrictions::Restrictions():
38  d(new Private)
39 {
40 }
41 
42 Teamdrive::Restrictions::Restrictions(const Teamdrive::Restrictions &other):
43  d(new Private(*(other.d)))
44 {
45 }
46 
47 Teamdrive::Restrictions::~Restrictions() = default;
48 
49 bool Teamdrive::Restrictions::operator==(const Teamdrive::Restrictions &other) const
50 {
51  GAPI_COMPARE(adminManagedRestrictions);
52  GAPI_COMPARE(copyRequiresWriterPermission);
53  GAPI_COMPARE(domainUsersOnly);
54  GAPI_COMPARE(teamMembersOnly);
55  return true;
56 }
57 
58 bool Teamdrive::Restrictions::adminManagedRestrictions() const
59 {
60  return d->adminManagedRestrictions;
61 }
62 
63 void Teamdrive::Restrictions::setAdminManagedRestrictions(bool adminManagedRestrictions) const
64 {
65  d->adminManagedRestrictions = adminManagedRestrictions;
66 }
67 
68 bool Teamdrive::Restrictions::copyRequiresWriterPermission() const
69 {
70  return d->copyRequiresWriterPermission;
71 }
72 
73 void Teamdrive::Restrictions::setCopyRequiresWriterPermission(bool copyRequiresWriterPermission) const
74 {
75  d->copyRequiresWriterPermission = copyRequiresWriterPermission;
76 }
77 
78 bool Teamdrive::Restrictions::domainUsersOnly() const
79 {
80  return d->domainUsersOnly;
81 }
82 
83 void Teamdrive::Restrictions::setDomainUsersOnly(bool domainUsersOnly) const
84 {
85  d->domainUsersOnly = domainUsersOnly;
86 }
87 
88 bool Teamdrive::Restrictions::teamMembersOnly() const
89 {
90  return d->teamMembersOnly;
91 }
92 
93 void Teamdrive::Restrictions::setTeamMembersOnly(bool teamMembersOnly) const
94 {
95  d->teamMembersOnly = teamMembersOnly;
96 }
97 
98 ///// DriveTeamdrive::Capabilities
99 
100 class Q_DECL_HIDDEN Teamdrive::Capabilities::Private
101 {
102  public:
103  Private() = default;
104  Private(const Private &other) = default;
105 
106  bool canAddChildren = false;
107  bool canChangeCopyRequiresWriterPermissionRestriction = false;
108  bool canChangeDomainUsersOnlyRestriction = false;
109  bool canChangeTeamDriveBackground = false;
110  bool canChangeTeamMembersOnlyRestriction = false;
111  bool canComment = false;
112  bool canCopy = false;
113  bool canDeleteChildren = false;
114  bool canDeleteTeamDrive = false;
115  bool canDownload = false;
116  bool canEdit = false;
117  bool canListChildren = false;
118  bool canManageMembers = false;
119  bool canReadRevisions = false;
120  bool canRename = false;
121  bool canRenameTeamDrive = false;
122  bool canShare = false;
123  bool canTrashChildren = false;
124 };
125 
126 Teamdrive::Capabilities::Capabilities():
127  d(new Private)
128 {
129 }
130 
131 Teamdrive::Capabilities::Capabilities(const Teamdrive::Capabilities &other):
132  d(new Private(*(other.d)))
133 {
134 }
135 
136 Teamdrive::Capabilities::~Capabilities() = default;
137 
138 bool Teamdrive::Capabilities::operator==(const Teamdrive::Capabilities &other) const
139 {
140  GAPI_COMPARE(canAddChildren);
141  GAPI_COMPARE(canChangeCopyRequiresWriterPermissionRestriction);
142  GAPI_COMPARE(canChangeDomainUsersOnlyRestriction);
143  GAPI_COMPARE(canChangeTeamDriveBackground);
144  GAPI_COMPARE(canChangeTeamMembersOnlyRestriction);
145  GAPI_COMPARE(canComment);
146  GAPI_COMPARE(canCopy);
147  GAPI_COMPARE(canDeleteChildren);
148  GAPI_COMPARE(canDeleteTeamDrive);
149  GAPI_COMPARE(canDownload);
150  GAPI_COMPARE(canEdit);
151  GAPI_COMPARE(canListChildren);
152  GAPI_COMPARE(canManageMembers);
153  GAPI_COMPARE(canReadRevisions);
154  GAPI_COMPARE(canRename);
155  GAPI_COMPARE(canRenameTeamDrive);
156  GAPI_COMPARE(canShare);
157  GAPI_COMPARE(canTrashChildren);
158  return true;
159 }
160 
161 bool Teamdrive::Capabilities::canAddChildren() const
162 {
163  return d->canAddChildren;
164 }
165 
166 bool Teamdrive::Capabilities::canChangeCopyRequiresWriterPermissionRestriction() const
167 {
168  return d->canChangeCopyRequiresWriterPermissionRestriction;
169 }
170 
171 bool Teamdrive::Capabilities::canChangeDomainUsersOnlyRestriction() const
172 {
173  return d->canChangeDomainUsersOnlyRestriction;
174 }
175 
176 bool Teamdrive::Capabilities::canChangeTeamDriveBackground() const
177 {
178  return d->canChangeTeamDriveBackground;
179 }
180 
181 bool Teamdrive::Capabilities::canChangeTeamMembersOnlyRestriction() const
182 {
183  return d->canChangeTeamMembersOnlyRestriction;
184 }
185 
186 bool Teamdrive::Capabilities::canComment() const
187 {
188  return d->canComment;
189 }
190 
191 bool Teamdrive::Capabilities::canCopy() const
192 {
193  return d->canCopy;
194 }
195 
196 bool Teamdrive::Capabilities::canDeleteChildren() const
197 {
198  return d->canDeleteChildren;
199 }
200 
201 bool Teamdrive::Capabilities::canDeleteTeamDrive() const
202 {
203  return d->canDeleteTeamDrive;
204 }
205 
206 bool Teamdrive::Capabilities::canDownload() const
207 {
208  return d->canDownload;
209 }
210 
211 bool Teamdrive::Capabilities::canEdit() const
212 {
213  return d->canEdit;
214 }
215 
216 bool Teamdrive::Capabilities::canListChildren() const
217 {
218  return d->canListChildren;
219 }
220 
221 bool Teamdrive::Capabilities::canManageMembers() const
222 {
223  return d->canManageMembers;
224 }
225 
226 bool Teamdrive::Capabilities::canReadRevisions() const
227 {
228  return d->canReadRevisions;
229 }
230 
231 bool Teamdrive::Capabilities::canRename() const
232 {
233  return d->canRename;
234 }
235 
236 bool Teamdrive::Capabilities::canRenameTeamDrive() const
237 {
238  return d->canRenameTeamDrive;
239 }
240 
241 bool Teamdrive::Capabilities::canShare() const
242 {
243  return d->canShare;
244 }
245 
246 bool Teamdrive::Capabilities::canTrashChildren() const
247 {
248  return d->canTrashChildren;
249 }
250 
251 ///// DriveTeamdrive::BackgroundImageFile
252 
253 class Q_DECL_HIDDEN Teamdrive::BackgroundImageFile::Private
254 {
255  public:
256  Private() = default;
257  Private(const Private &other) = default;
258 
259  QString id;
260  float xCoordinate = 0.0f;
261  float yCoordinate = 0.0f;
262  float width = 0.0f;
263 };
264 
265 Teamdrive::BackgroundImageFile::BackgroundImageFile():
266  d(new Private)
267 {
268 }
269 
270 Teamdrive::BackgroundImageFile::BackgroundImageFile(const Teamdrive::BackgroundImageFile &other):
271  d(new Private(*(other.d)))
272 {
273 }
274 
275 Teamdrive::BackgroundImageFile::~BackgroundImageFile() = default;
276 
277 bool Teamdrive::BackgroundImageFile::operator==(const Teamdrive::BackgroundImageFile &other) const
278 {
279  GAPI_COMPARE(id);
280  GAPI_COMPARE(xCoordinate);
281  GAPI_COMPARE(yCoordinate);
282  GAPI_COMPARE(width);
283  return true;
284 }
285 
286 QString Teamdrive::BackgroundImageFile::id() const
287 {
288  return d->id;
289 }
290 
291 void Teamdrive::BackgroundImageFile::setId(const QString &id) const
292 {
293  d->id = id;
294 }
295 
296 float Teamdrive::BackgroundImageFile::xCoordinate() const
297 {
298  return d->xCoordinate;
299 }
300 
301 void Teamdrive::BackgroundImageFile::setXCoordinate(const float xCoordinate) const
302 {
303  d->xCoordinate = xCoordinate;
304 }
305 
306 float Teamdrive::BackgroundImageFile::yCoordinate() const
307 {
308  return d->yCoordinate;
309 }
310 
311 void Teamdrive::BackgroundImageFile::setYCoordinate(const float yCoordinate) const
312 {
313  d->yCoordinate = yCoordinate;
314 }
315 
316 float Teamdrive::BackgroundImageFile::width() const
317 {
318  return d->width;
319 }
320 
321 void Teamdrive::BackgroundImageFile::setWidth(const float width) const
322 {
323  d->width = width;
324 }
325 
326 ///// DriveTeamdrive
327 
328 class Q_DECL_HIDDEN Teamdrive::Private
329 {
330  public:
331  Private() = default;
332  Private(const Private& other) = default;
333 
334  QString id;
335  QString name;
336  QString themeId;
337  QString colorRgb;
338  BackgroundImageFilePtr backgroundImageFile;
339  QString backgroundImageLink;
340  CapabilitiesPtr capabilities;
341  QDateTime createdDate;
342  RestrictionsPtr restrictions;
343 
344  static TeamdrivePtr fromJSON(const QVariantMap &map);
345 };
346 
347 TeamdrivePtr Teamdrive::Private::fromJSON(const QVariantMap &map)
348 {
349  if (!map.contains(Teamdrive::Fields::Kind) ||
350  map[Teamdrive::Fields::Kind].toString() != ApiKind)
351  {
352  return TeamdrivePtr();
353  }
354 
355  auto teamdrive = TeamdrivePtr::create();
356  if (map.contains(Teamdrive::Fields::Id)) {
357  teamdrive->d->id = map[Teamdrive::Fields::Id].toString();
358  }
359  if (map.contains(Teamdrive::Fields::Name)) {
360  teamdrive->d->name = map[Teamdrive::Fields::Name].toString();
361  }
362  if (map.contains(Teamdrive::Fields::ThemeId)) {
363  teamdrive->d->themeId = map[Teamdrive::Fields::ThemeId].toString();
364  }
365  if (map.contains(Teamdrive::Fields::ColorRgb)) {
366  teamdrive->d->colorRgb = map[Teamdrive::Fields::ColorRgb].toString();
367  }
368  if (map.contains(Teamdrive::Fields::BackgroundImageLink)) {
369  teamdrive->d->backgroundImageLink = map[Teamdrive::Fields::BackgroundImageLink].toString();
370  }
371  if (map.contains(Teamdrive::Fields::CreatedDate)) {
372  teamdrive->d->createdDate = QDateTime::fromString(map[Teamdrive::Fields::CreatedDate].toString(), Qt::ISODate);
373  }
374 
375  if (map.contains(Teamdrive::Fields::BackgroundImageFile)) {
376  const QVariantMap backgroundImageFileMap = map[Teamdrive::Fields::BackgroundImageFile].toMap();
377  auto backgroundImageFile = BackgroundImageFilePtr::create();
378  backgroundImageFile->d->id = backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::Id].toString();
379  backgroundImageFile->d->xCoordinate = backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::XCoordinate].toReal();
380  backgroundImageFile->d->yCoordinate = backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::YCoordinate].toReal();
381  backgroundImageFile->d->width = backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::Width].toReal();
382  teamdrive->d->backgroundImageFile = backgroundImageFile;
383  }
384 
385  if (map.contains(Teamdrive::Fields::Capabilities)) {
386  const QVariantMap capabilitiesMap = map[Teamdrive::Fields::Capabilities].toMap();
387  auto capabilities = CapabilitiesPtr::create();
388  capabilities->d->canAddChildren = capabilitiesMap[Teamdrive::Capabilities::Fields::CanAddChildren].toBool();
389  capabilities->d->canChangeCopyRequiresWriterPermissionRestriction = capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction].toBool();
390  capabilities->d->canChangeDomainUsersOnlyRestriction = capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction].toBool();
391  capabilities->d->canChangeTeamDriveBackground = capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeTeamDriveBackground].toBool();
392  capabilities->d->canChangeTeamMembersOnlyRestriction = capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeTeamMembersOnlyRestriction].toBool();
393  capabilities->d->canComment = capabilitiesMap[Teamdrive::Capabilities::Fields::CanComment].toBool();
394  capabilities->d->canCopy = capabilitiesMap[Teamdrive::Capabilities::Fields::CanCopy].toBool();
395  capabilities->d->canDeleteChildren = capabilitiesMap[Teamdrive::Capabilities::Fields::CanDeleteChildren].toBool();
396  capabilities->d->canDeleteTeamDrive = capabilitiesMap[Teamdrive::Capabilities::Fields::CanDeleteTeamDrive].toBool();
397  capabilities->d->canDownload = capabilitiesMap[Teamdrive::Capabilities::Fields::CanDownload].toBool();
398  capabilities->d->canEdit = capabilitiesMap[Teamdrive::Capabilities::Fields::CanEdit].toBool();
399  capabilities->d->canListChildren = capabilitiesMap[Teamdrive::Capabilities::Fields::CanListChildren].toBool();
400  capabilities->d->canManageMembers = capabilitiesMap[Teamdrive::Capabilities::Fields::CanManageMembers].toBool();
401  capabilities->d->canReadRevisions = capabilitiesMap[Teamdrive::Capabilities::Fields::CanReadRevisions].toBool();
402  capabilities->d->canRename = capabilitiesMap[Teamdrive::Capabilities::Fields::CanRename].toBool();
403  capabilities->d->canRenameTeamDrive = capabilitiesMap[Teamdrive::Capabilities::Fields::CanRenameTeamDrive].toBool();
404  capabilities->d->canShare = capabilitiesMap[Teamdrive::Capabilities::Fields::CanShare].toBool();
405  capabilities->d->canTrashChildren = capabilitiesMap[Teamdrive::Capabilities::Fields::CanTrashChildren].toBool();
406  teamdrive->d->capabilities = capabilities;
407  }
408 
409  if (map.contains(Teamdrive::Fields::Restrictions)) {
410  const QVariantMap restrictionsMap = map[Teamdrive::Fields::Restrictions].toMap();
411  auto restrictions = RestrictionsPtr::create();
412  restrictions->d->adminManagedRestrictions = restrictionsMap[Teamdrive::Restrictions::Fields::AdminManagedRestrictions].toBool();
413  restrictions->d->copyRequiresWriterPermission = restrictionsMap[Teamdrive::Restrictions::Fields::CopyRequiresWriterPermission].toBool();
414  restrictions->d->domainUsersOnly = restrictionsMap[Teamdrive::Restrictions::Fields::DomainUsersOnly].toBool();
415  restrictions->d->teamMembersOnly = restrictionsMap[Teamdrive::Restrictions::Fields::TeamMembersOnly].toBool();
416  teamdrive->d->restrictions = restrictions;
417  }
418 
419  return teamdrive;
420 }
421 
422 const QString Teamdrive::Restrictions::Fields::AdminManagedRestrictions = QStringLiteral("adminManagedRestrictions");
423 const QString Teamdrive::Restrictions::Fields::CopyRequiresWriterPermission = QStringLiteral("copyRequiresWriterPermission");
424 const QString Teamdrive::Restrictions::Fields::DomainUsersOnly = QStringLiteral("domainUsersOnly");
425 const QString Teamdrive::Restrictions::Fields::TeamMembersOnly = QStringLiteral("teamMembersOnly");
426 
427 const QString Teamdrive::Capabilities::Fields::CanAddChildren = QStringLiteral("canAddChildren");
428 const QString Teamdrive::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction = QStringLiteral("canChangeCopyRequiresWriterPermissionRestriction");
429 const QString Teamdrive::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction = QStringLiteral("canChangeDomainUsersOnlyRestriction");
430 const QString Teamdrive::Capabilities::Fields::CanChangeTeamDriveBackground = QStringLiteral("canChangeTeamDriveBackground");
431 const QString Teamdrive::Capabilities::Fields::CanChangeTeamMembersOnlyRestriction = QStringLiteral("canChangeTeamMembersOnlyRestriction");
432 const QString Teamdrive::Capabilities::Fields::CanComment = QStringLiteral("canComment");
433 const QString Teamdrive::Capabilities::Fields::CanCopy = QStringLiteral("canCopy");
434 const QString Teamdrive::Capabilities::Fields::CanDeleteChildren = QStringLiteral("canDeleteChildren");
435 const QString Teamdrive::Capabilities::Fields::CanDeleteTeamDrive = QStringLiteral("canDeleteTeamDrive");
436 const QString Teamdrive::Capabilities::Fields::CanDownload = QStringLiteral("canDownload");
437 const QString Teamdrive::Capabilities::Fields::CanEdit = QStringLiteral("canEdit");
438 const QString Teamdrive::Capabilities::Fields::CanListChildren = QStringLiteral("canListChildren");
439 const QString Teamdrive::Capabilities::Fields::CanManageMembers = QStringLiteral("canManageMembers");
440 const QString Teamdrive::Capabilities::Fields::CanReadRevisions = QStringLiteral("canReadRevisions");
441 const QString Teamdrive::Capabilities::Fields::CanRename = QStringLiteral("canRename");
442 const QString Teamdrive::Capabilities::Fields::CanRenameTeamDrive = QStringLiteral("canRenameTeamDrive");
443 const QString Teamdrive::Capabilities::Fields::CanShare = QStringLiteral("canShare");
444 const QString Teamdrive::Capabilities::Fields::CanTrashChildren = QStringLiteral("canTrashChildren");
445 
446 const QString Teamdrive::BackgroundImageFile::Fields::Id = QStringLiteral("id");
447 const QString Teamdrive::BackgroundImageFile::Fields::XCoordinate = QStringLiteral("xCoordinate");
448 const QString Teamdrive::BackgroundImageFile::Fields::YCoordinate = QStringLiteral("yCoordinate");
449 const QString Teamdrive::BackgroundImageFile::Fields::Width = QStringLiteral("width");
450 
451 const QString Teamdrive::Fields::Items = QStringLiteral("items");
452 const QString Teamdrive::Fields::KindDrive = QStringLiteral("kind");
453 const QString Teamdrive::Fields::PageToken = QStringLiteral("pageToken");
454 const QString Teamdrive::Fields::NextPageToken = QStringLiteral("nextPageToken");
455 const QString Teamdrive::Fields::Id = QStringLiteral("id");
456 const QString Teamdrive::Fields::Kind = QStringLiteral("kind");
457 const QString Teamdrive::Fields::Name = QStringLiteral("name");
458 const QString Teamdrive::Fields::ThemeId = QStringLiteral("themeId");
459 const QString Teamdrive::Fields::ColorRgb = QStringLiteral("colorRgb");
460 const QString Teamdrive::Fields::BackgroundImageFile = QStringLiteral("backgroundImageFile");
461 const QString Teamdrive::Fields::BackgroundImageLink = QStringLiteral("backgroundImageLink");
462 const QString Teamdrive::Fields::Capabilities = QStringLiteral("capabilities");
463 const QString Teamdrive::Fields::CreatedDate = QStringLiteral("createdDate");
464 const QString Teamdrive::Fields::Restrictions = QStringLiteral("restrictions");
465 
466 Teamdrive::Teamdrive():
467  KGAPI2::Object(),
468  d(new Private)
469 {
470 }
471 
472 Teamdrive::Teamdrive(const Teamdrive& other):
473  KGAPI2::Object(other),
474  d(new Private(*(other.d)))
475 {
476 }
477 
478 Teamdrive::~Teamdrive() = default;
479 
480 bool Teamdrive::operator==(const Teamdrive &other) const
481 {
482  if (!Object::operator==(other)) {
483  return false;
484  }
485  GAPI_COMPARE(id);
486  GAPI_COMPARE(name);
487  GAPI_COMPARE(themeId);
488  GAPI_COMPARE(colorRgb);
489  GAPI_COMPARE_SHAREDPTRS(backgroundImageFile);
490  GAPI_COMPARE(backgroundImageLink);
491  GAPI_COMPARE_SHAREDPTRS(capabilities);
492  GAPI_COMPARE(createdDate);
493  GAPI_COMPARE_SHAREDPTRS(restrictions);
494  return true;
495 }
496 
497 QString Teamdrive::id() const
498 {
499  return d->id;
500 }
501 
502 void Teamdrive::setId(const QString &id) const
503 {
504  d->id = id;
505 }
506 
507 QString Teamdrive::name() const
508 {
509  return d->name;
510 }
511 
512 void Teamdrive::setName(const QString &name) const
513 {
514  d->name = name;
515 }
516 
517 QString Teamdrive::themeId() const
518 {
519  return d->themeId;
520 }
521 
522 void Teamdrive::setThemeId(const QString &themeId) const
523 {
524  d->themeId = themeId;
525 }
526 
527 QString Teamdrive::colorRgb() const
528 {
529  return d->colorRgb;
530 }
531 
532 void Teamdrive::setColorRgb(const QString &colorRgb) const
533 {
534  d->colorRgb = colorRgb;
535 }
536 
537 Teamdrive::BackgroundImageFilePtr Teamdrive::backgroundImageFile() const
538 {
539  return d->backgroundImageFile;
540 }
541 
542 void Teamdrive::setBackgroundImageFile(const Teamdrive::BackgroundImageFilePtr &backgroundImageFile) const
543 {
544  d->backgroundImageFile = backgroundImageFile;
545 }
546 
547 QString Teamdrive::backgroundImageLink() const
548 {
549  return d->backgroundImageLink;
550 }
551 
552 Teamdrive::CapabilitiesPtr Teamdrive::capabilities() const
553 {
554  return d->capabilities;
555 }
556 
557 QDateTime Teamdrive::createdDate() const
558 {
559  return d->createdDate;
560 }
561 
562 void Teamdrive::setRestrictions(const Teamdrive::RestrictionsPtr &restrictions) const
563 {
564  d->restrictions = restrictions;
565 }
566 
567 Teamdrive::RestrictionsPtr Teamdrive::restrictions() const
568 {
569  return d->restrictions;
570 }
571 
572 TeamdrivePtr Teamdrive::fromJSON(const QByteArray &jsonData)
573 {
574  QJsonDocument document = QJsonDocument::fromJson(jsonData);
575  if (document.isNull()) {
576  return TeamdrivePtr();
577  }
578 
579  const QVariant data = document.toVariant();
580  return Private::fromJSON(data.toMap());
581 }
582 
583 TeamdrivesList Teamdrive::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData)
584 {
585  QJsonDocument document = QJsonDocument::fromJson(jsonData);
586  if (document.isNull()) {
587  return TeamdrivesList();
588  }
589 
590  const QVariant data = document.toVariant();
591  const QVariantMap map = data.toMap();
592  if (!map.contains(Teamdrive::Fields::Kind) ||
593  map[Teamdrive::Fields::Kind].toString() != ApiKindList) {
594  return TeamdrivesList();
595  }
596 
597  if (map.contains(Teamdrive::Fields::NextPageToken)) {
598  feedData.nextPageUrl = DriveService::fetchTeamdrivesUrl();
599  QUrlQuery query(feedData.nextPageUrl);
600  query.addQueryItem(Teamdrive::Fields::PageToken, map.value(Teamdrive::Fields::NextPageToken).toString());
601  feedData.nextPageUrl.setQuery(query);
602  }
603 
604  TeamdrivesList list;
605  const QVariantList items = map[Teamdrive::Fields::Items].toList();
606  for (const QVariant & item : items) {
607  const TeamdrivePtr teamdrive = Private::fromJSON(item.toMap());
608 
609  if (!teamdrive.isNull()) {
610  list << teamdrive;
611  }
612  }
613 
614  return list;
615 }
616 
617 QByteArray Teamdrive::toJSON(const TeamdrivePtr &teamdrive)
618 {
619  QVariantMap teamDriveMap;
620  teamDriveMap[Teamdrive::Fields::Kind] = ApiKind;
621  if (!teamdrive->id().isEmpty()) {
622  teamDriveMap[Teamdrive::Fields::Id] = teamdrive->id();
623  }
624  if (!teamdrive->name().isEmpty()) {
625  teamDriveMap[Teamdrive::Fields::Name] = teamdrive->name();
626  }
627  if (!teamdrive->themeId().isEmpty()) {
628  teamDriveMap[Teamdrive::Fields::ThemeId] = teamdrive->themeId();
629  }
630  if (!teamdrive->colorRgb().isEmpty()) {
631  teamDriveMap[Teamdrive::Fields::ColorRgb] = teamdrive->colorRgb();
632  }
633  if (!teamdrive->backgroundImageLink().isEmpty()) {
634  teamDriveMap[Teamdrive::Fields::BackgroundImageLink] = teamdrive->backgroundImageLink();
635  }
636  if (teamdrive->createdDate().isValid()) {
637  teamDriveMap[Teamdrive::Fields::CreatedDate] = teamdrive->createdDate();
638  }
639 
640  if (teamdrive->restrictions()) {
641  QVariantMap restrictionsMap;
642  restrictionsMap[Teamdrive::Restrictions::Fields::AdminManagedRestrictions] = teamdrive->restrictions()->adminManagedRestrictions();
643  restrictionsMap[Teamdrive::Restrictions::Fields::CopyRequiresWriterPermission] = teamdrive->restrictions()->copyRequiresWriterPermission();
644  restrictionsMap[Teamdrive::Restrictions::Fields::DomainUsersOnly] = teamdrive->restrictions()->domainUsersOnly();
645  restrictionsMap[Teamdrive::Restrictions::Fields::TeamMembersOnly] = teamdrive->restrictions()->teamMembersOnly();
646  teamDriveMap[Teamdrive::Fields::Restrictions] = restrictionsMap;
647  }
648 
649  if (teamdrive->backgroundImageFile()) {
650  QVariantMap backgroundImageFileMap;
651  backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::Id] = teamdrive->backgroundImageFile()->id();
652  backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::XCoordinate] = teamdrive->backgroundImageFile()->xCoordinate();
653  backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::YCoordinate] = teamdrive->backgroundImageFile()->yCoordinate();
654  backgroundImageFileMap[Teamdrive::BackgroundImageFile::Fields::Width] = teamdrive->backgroundImageFile()->width();
655  teamDriveMap[Teamdrive::Fields::BackgroundImageFile] = backgroundImageFileMap;
656  }
657 
658  if (teamdrive->capabilities()) {
659  QVariantMap capabilitiesMap;
660  capabilitiesMap[Teamdrive::Capabilities::Fields::CanAddChildren] = teamdrive->capabilities()->canAddChildren();
661  capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction] = teamdrive->capabilities()->canChangeCopyRequiresWriterPermissionRestriction();
662  capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction] = teamdrive->capabilities()->canChangeDomainUsersOnlyRestriction();
663  capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeTeamDriveBackground] = teamdrive->capabilities()->canChangeTeamDriveBackground();
664  capabilitiesMap[Teamdrive::Capabilities::Fields::CanChangeTeamMembersOnlyRestriction] = teamdrive->capabilities()->canChangeTeamMembersOnlyRestriction();
665  capabilitiesMap[Teamdrive::Capabilities::Fields::CanComment] = teamdrive->capabilities()->canComment();
666  capabilitiesMap[Teamdrive::Capabilities::Fields::CanCopy] = teamdrive->capabilities()->canCopy();
667  capabilitiesMap[Teamdrive::Capabilities::Fields::CanDeleteChildren] = teamdrive->capabilities()->canDeleteChildren();
668  capabilitiesMap[Teamdrive::Capabilities::Fields::CanDeleteTeamDrive] = teamdrive->capabilities()->canDeleteTeamDrive();
669  capabilitiesMap[Teamdrive::Capabilities::Fields::CanDownload] = teamdrive->capabilities()->canDownload();
670  capabilitiesMap[Teamdrive::Capabilities::Fields::CanEdit] = teamdrive->capabilities()->canEdit();
671  capabilitiesMap[Teamdrive::Capabilities::Fields::CanListChildren] = teamdrive->capabilities()->canListChildren();
672  capabilitiesMap[Teamdrive::Capabilities::Fields::CanManageMembers] = teamdrive->capabilities()->canManageMembers();
673  capabilitiesMap[Teamdrive::Capabilities::Fields::CanReadRevisions] = teamdrive->capabilities()->canReadRevisions();
674  capabilitiesMap[Teamdrive::Capabilities::Fields::CanRename] = teamdrive->capabilities()->canRename();
675  capabilitiesMap[Teamdrive::Capabilities::Fields::CanRenameTeamDrive] = teamdrive->capabilities()->canRenameTeamDrive();
676  capabilitiesMap[Teamdrive::Capabilities::Fields::CanShare] = teamdrive->capabilities()->canShare();
677  capabilitiesMap[Teamdrive::Capabilities::Fields::CanTrashChildren] = teamdrive->capabilities()->canTrashChildren();
678  teamDriveMap[Teamdrive::Fields::Capabilities] = capabilitiesMap;
679  }
680 
681  QJsonDocument document = QJsonDocument::fromVariant(teamDriveMap);
682  return document.toJson(QJsonDocument::Compact);
683 }
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QByteArray toJson() const const
Base class for all objects.
Definition: object.h:30
DriveTeamdrive::Restrictions holds the structure used for restrictions property.
Definition: teamdrive.h:41
QUrl nextPageUrl
Link to next page of feed.
Definition: types.h:37
QJsonDocument fromVariant(const QVariant &variant)
Structure to store additional information about a feed.
Definition: types.h:23
bool isNull() const const
DriveTeamdrive::Capabilities holds the structure used for capabilities property.
Definition: teamdrive.h:134
void addQueryItem(const QString &key, const QString &value)
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:15
Teamdrive contains a representation of a Team Drive.
Definition: teamdrive.h:32
QVariant toVariant() const const
QDateTime fromString(const QString &string, Qt::DateFormat format)
QMap< QString, QVariant > toMap() const const
void setQuery(const QString &query, QUrl::ParsingMode mode)
DriveTeamdrive::BackgroundImageFile holds the structure used for backgroundImageFile property...
Definition: teamdrive.h:286
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jul 29 2021 23:11:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.