Kgapi

file.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Andrius da Costa Ribas <[email protected]>
3  SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "file.h"
9 #include "file_p.h"
10 #include "permission_p.h"
11 #include "parentreference_p.h"
12 #include "user.h"
13 #include "utils_p.h"
14 
15 #include <QJsonDocument>
16 
17 using namespace KGAPI2;
18 using namespace KGAPI2::Drive;
19 
21 
22 class Q_DECL_HIDDEN File::Labels::Private
23 {
24  public:
25  Private();
26  Private(const Private &other);
27 
28  bool starred;
29  bool hidden;
30  bool trashed;
31  bool restricted;
32  bool viewed;
33 };
34 
35 File::Labels::Private::Private():
36  starred(false),
37  hidden(false),
38  trashed(false),
39  restricted(false),
40  viewed(false)
41 {
42 }
43 
44 File::Labels::Private::Private(const Private &other):
45  starred(other.starred),
46  hidden(other.hidden),
47  trashed(other.trashed),
48  restricted(other.restricted),
49  viewed(other.viewed)
50 {
51 }
52 
53 File::Labels::Labels():
54  d(new Private)
55 {
56 }
57 
58 File::Labels::Labels(const Labels& other):
59  d(new Private(*(other.d)))
60 { }
61 
62 File::Labels::~Labels()
63 {
64  delete d;
65 }
66 
67 bool File::Labels::operator==(const Labels &other) const
68 {
69  GAPI_COMPARE(starred)
70  GAPI_COMPARE(hidden)
71  GAPI_COMPARE(trashed)
72  GAPI_COMPARE(restricted)
73  GAPI_COMPARE(viewed)
74  return true;
75 }
76 
77 bool File::Labels::starred() const
78 {
79  return d->starred;
80 }
81 
82 void File::Labels::setStarred(bool starred)
83 {
84  d->starred = starred;
85 }
86 
87 bool File::Labels::hidden() const
88 {
89  return d->hidden;
90 }
91 
92 void File::Labels::setHidden(bool hidden)
93 {
94  d->hidden = hidden;
95 }
96 
97 bool File::Labels::trashed() const
98 {
99  return d->trashed;
100 }
101 
102 void File::Labels::setTrashed(bool trashed)
103 {
104  d->trashed = trashed;
105 }
106 
107 bool File::Labels::restricted() const
108 {
109  return d->restricted;
110 }
111 
112 void File::Labels::setRestricted(bool restricted)
113 {
114  d->restricted = restricted;
115 }
116 
117 bool File::Labels::viewed() const
118 {
119  return d->viewed;
120 }
121 
122 void File::Labels::setViewed(bool viewed)
123 {
124  d->viewed = viewed;
125 }
126 
128 
129 class Q_DECL_HIDDEN File::IndexableText::Private
130 {
131  public:
132  Private();
133  Private(const Private &other);
134 
135  QString text;
136 };
137 
138 File::IndexableText::Private::Private()
139 {
140 }
141 
142 File::IndexableText::Private::Private(const Private &other):
143  text(other.text)
144 {
145 }
146 
147 File::IndexableText::IndexableText():
148  d(new Private)
149 {
150 }
151 
152 File::IndexableText::IndexableText(const IndexableText& other):
153  d(new Private(*(other.d)))
154 {
155 }
156 
157 File::IndexableText::~IndexableText()
158 {
159  delete d;
160 }
161 
162 bool File::IndexableText::operator==(const IndexableText &other) const
163 {
164  GAPI_COMPARE(text)
165  return true;
166 }
167 
168 QString File::IndexableText::text() const
169 {
170  return d->text;
171 }
172 
173 void File::IndexableText::setText(const QString &text)
174 {
175  d->text = text;
176 }
177 
179 
180 class Q_DECL_HIDDEN File::ImageMediaMetadata::Location::Private
181 {
182  public:
183  Private();
184  Private(const Private &other);
185 
186  qreal latitude;
187  qreal longitude;
188  qreal altitude;
189 };
190 
191 File::ImageMediaMetadata::Location::Private::Private():
192  latitude(-1),
193  longitude(-1),
194  altitude(0)
195 {
196 }
197 
198 File::ImageMediaMetadata::Location::Private::Private(const Private &other):
199  latitude(other.latitude),
200  longitude(other.longitude),
201  altitude(other.altitude)
202 {
203 }
204 
205 File::ImageMediaMetadata::Location::Location():
206  d(new Private)
207 {
208 }
209 
210 File::ImageMediaMetadata::Location::Location(const Location& other):
211  d(new Private(*(other.d)))
212 {
213 }
214 
215 File::ImageMediaMetadata::Location::~Location()
216 {
217  delete d;
218 }
219 
220 bool File::ImageMediaMetadata::Location::operator==(const Location &other) const
221 {
222  GAPI_COMPARE(latitude)
223  GAPI_COMPARE(longitude)
224  GAPI_COMPARE(altitude)
225  return true;
226 }
227 
228 qreal File::ImageMediaMetadata::Location::latitude() const
229 {
230  return d->latitude;
231 }
232 
233 qreal File::ImageMediaMetadata::Location::longitude() const
234 {
235  return d->longitude;
236 }
237 
238 qreal File::ImageMediaMetadata::Location::altitude() const
239 {
240  return d->altitude;
241 }
242 
244 
245 class Q_DECL_HIDDEN File::ImageMediaMetadata::Private
246 {
247  public:
248  Private();
249  Private(const Private &other);
250 
251  int width;
252  int height;
253  int rotation;
254  LocationPtr location;
255  QString date;
256  QString cameraMake;
257  QString cameraModel;
258  float exposureTime;
259  float aperture;
260  bool flashUsed;
261  float focalLength;
262  int isoSpeed;
263  QString meteringMode;
264  QString sensor;
265  QString exposureMode;
266  QString colorSpace;
267  QString whiteBalance;
268  float exposureBias;
269  float maxApertureValue;
270  int subjectDistance;
271  QString lens;
272 };
273 
274 File::ImageMediaMetadata::Private::Private():
275  width(-1),
276  height(-1),
277  rotation(-1),
278  exposureTime(-1),
279  aperture(-1),
280  flashUsed(false),
281  focalLength(-1),
282  isoSpeed(-1),
283  exposureBias(-1),
284  maxApertureValue(-1),
285  subjectDistance(-1)
286 {
287 }
288 
289 File::ImageMediaMetadata::Private::Private(const Private &other):
290  width(other.width),
291  height(other.height),
292  rotation(other.rotation),
293  location(other.location),
294  date(other.date),
295  cameraMake(other.cameraMake),
296  cameraModel(other.cameraModel),
297  exposureTime(other.exposureTime),
298  aperture(other.aperture),
299  flashUsed(other.flashUsed),
300  focalLength(other.focalLength),
301  isoSpeed(other.isoSpeed),
302  meteringMode(other.meteringMode),
303  sensor(other.sensor),
304  exposureMode(other.exposureMode),
305  colorSpace(other.colorSpace),
306  whiteBalance(other.whiteBalance),
307  exposureBias(other.exposureBias),
308  maxApertureValue(other.maxApertureValue),
309  subjectDistance(other.subjectDistance),
310  lens(other.lens)
311 {
312 }
313 
314 File::ImageMediaMetadata::ImageMediaMetadata(const QVariantMap &map):
315  d(new Private)
316 {
317  d->width = map[QStringLiteral("width")].toInt();
318  d->height = map[QStringLiteral("height")].toInt();
319  d->rotation = map[QStringLiteral("rotation")].toInt();
320  d->date = map[QStringLiteral("date")].toString();
321  d->cameraMake = map[QStringLiteral("cameraMake")].toString();
322  d->cameraModel = map[QStringLiteral("cameraModel")].toString();
323  d->exposureTime = map[QStringLiteral("exposureTime")].toFloat();
324  d->aperture = map[QStringLiteral("aperture")].toFloat();
325  d->flashUsed = map[QStringLiteral("flashUsed")].toBool();
326  d->focalLength = map[QStringLiteral("focalLength")].toFloat();
327  d->isoSpeed = map[QStringLiteral("isoSpeed")].toInt();
328  d->meteringMode = map[QStringLiteral("meteringMode")].toString();
329  d->sensor = map[QStringLiteral("sensor")].toString();
330  d->exposureMode = map[QStringLiteral("exposureMode")].toString();
331  d->colorSpace = map[QStringLiteral("colorSpace")].toString();
332  d->whiteBalance = map[QStringLiteral("whiteBalance")].toString();
333  d->exposureBias = map[QStringLiteral("exposureBias")].toFloat();
334  d->maxApertureValue = map[QStringLiteral("maxApertureValue")].toFloat();
335  d->subjectDistance = map[QStringLiteral("subjectDistance")].toFloat();
336  d->lens = map[QStringLiteral("lens")].toString();
337 
338  const QVariantMap locationData = map[QStringLiteral("location")].toMap();
340  location->d->latitude = locationData[QStringLiteral("latitude")].toReal();
341  location->d->longitude = locationData[QStringLiteral("longitude")].toReal();
342  location->d->altitude = locationData[QStringLiteral("altitude")].toReal();
343 }
344 
345 File::ImageMediaMetadata::ImageMediaMetadata(const ImageMediaMetadata& other):
346  d(new Private(*(other.d)))
347 {
348 }
349 
350 File::ImageMediaMetadata::~ImageMediaMetadata()
351 {
352  delete d;
353 }
354 
355 bool File::ImageMediaMetadata::operator==(const ImageMediaMetadata &other) const
356 {
357  GAPI_COMPARE(width)
358  GAPI_COMPARE(height)
359  GAPI_COMPARE(rotation)
360  GAPI_COMPARE_SHAREDPTRS(location)
361  GAPI_COMPARE(date)
362  GAPI_COMPARE(cameraMake)
363  GAPI_COMPARE(cameraModel)
364  GAPI_COMPARE(exposureTime)
365  GAPI_COMPARE(aperture)
366  GAPI_COMPARE(flashUsed)
367  GAPI_COMPARE(focalLength)
368  GAPI_COMPARE(isoSpeed)
369  GAPI_COMPARE(meteringMode)
370  GAPI_COMPARE(sensor)
371  GAPI_COMPARE(exposureMode)
372  GAPI_COMPARE(colorSpace)
373  GAPI_COMPARE(whiteBalance)
374  GAPI_COMPARE(exposureBias)
375  GAPI_COMPARE(maxApertureValue)
376  GAPI_COMPARE(subjectDistance)
377  GAPI_COMPARE(lens)
378  return true;
379 }
380 
381 int File::ImageMediaMetadata::width() const
382 {
383  return d->width;
384 }
385 
386 int File::ImageMediaMetadata::height() const
387 {
388  return d->height;
389 }
390 
391 int File::ImageMediaMetadata::rotation() const
392 {
393  return d->rotation;
394 }
395 
396 File::ImageMediaMetadata::LocationPtr File::ImageMediaMetadata::location() const
397 {
398  return d->location;
399 }
400 
401 QString File::ImageMediaMetadata::date() const
402 {
403  return d->date;
404 }
405 
406 QString File::ImageMediaMetadata::cameraMake() const
407 {
408  return d->cameraMake;
409 }
410 
411 QString File::ImageMediaMetadata::cameraModel() const
412 {
413  return d->cameraModel;
414 }
415 
416 float File::ImageMediaMetadata::exposureTime() const
417 {
418  return d->exposureTime;
419 }
420 
421 float File::ImageMediaMetadata::aperture() const
422 {
423  return d->aperture;
424 }
425 
426 bool File::ImageMediaMetadata::flashUsed() const
427 {
428  return d->flashUsed;
429 }
430 
431 float File::ImageMediaMetadata::focalLength() const
432 {
433  return d->focalLength;
434 }
435 
436 int File::ImageMediaMetadata::isoSpeed() const
437 {
438  return d->isoSpeed;
439 }
440 
441 QString File::ImageMediaMetadata::meteringMode() const
442 {
443  return d->meteringMode;
444 }
445 
446 QString File::ImageMediaMetadata::sensor() const
447 {
448  return d->sensor;
449 }
450 
451 QString File::ImageMediaMetadata::exposureMode() const
452 {
453  return d->exposureMode;
454 }
455 
456 QString File::ImageMediaMetadata::colorSpace() const
457 {
458  return d->colorSpace;
459 }
460 
461 QString File::ImageMediaMetadata::whiteBalance() const
462 {
463  return d->whiteBalance;
464 }
465 
466 float File::ImageMediaMetadata::exposureBias() const
467 {
468  return d->exposureBias;
469 }
470 
471 float File::ImageMediaMetadata::maxApertureValue() const
472 {
473  return d->maxApertureValue;
474 }
475 
476 int File::ImageMediaMetadata::subjectDistance() const
477 {
478  return d->subjectDistance;
479 }
480 
481 QString File::ImageMediaMetadata::lens() const
482 {
483  return d->lens;
484 }
485 
486 
488 
489 class Q_DECL_HIDDEN File::Thumbnail::Private
490 {
491  public:
492  Private();
493  Private(const Private &other);
494 
495  QImage image;
496  QString mimeType;
497 };
498 
499 File::Thumbnail::Private::Private()
500 {
501 }
502 
503 File::Thumbnail::Private::Private(const Private &other):
504  image(other.image),
505  mimeType(other.mimeType)
506 {
507 }
508 
509 File::Thumbnail::Thumbnail(const QVariantMap &map):
510  d(new Private)
511 {
512  const QByteArray ba = QByteArray::fromBase64(map[QStringLiteral("image")].toByteArray());
513  d->image = QImage::fromData(ba);
514  d->mimeType = map[Fields::MimeType].toString();
515 }
516 
517 File::Thumbnail::Thumbnail(const File::Thumbnail &other):
518  d(new Private(*(other.d)))
519 {
520 }
521 
522 File::Thumbnail::~Thumbnail()
523 {
524  delete d;
525 }
526 
527 bool File::Thumbnail::operator==(const Thumbnail &other) const
528 {
529  GAPI_COMPARE(image)
530  GAPI_COMPARE(mimeType)
531  return true;
532 }
533 
534 QImage File::Thumbnail::image() const
535 {
536  return d->image;
537 }
538 
539 QString File::Thumbnail::mimeType() const
540 {
541  return d->mimeType;
542 }
543 
545 
546 File::Private::Private():
547  fileSize(-1),
548  version(-1),
549  quotaBytesUsed(-1),
550  editable(false),
551  writersCanShare(false),
552  explicitlyTrashed(false),
553  shared(false)
554 {
555 }
556 
557 File::Private::Private(const Private& other):
558  id(other.id),
559  selfLink(other.selfLink),
560  title(other.title),
561  mimeType(other.mimeType),
562  description(other.description),
563  labels(other.labels),
564  createdDate(other.createdDate),
565  modifiedDate(other.modifiedDate),
566  modifiedByMeDate(other.modifiedByMeDate),
567  downloadUrl(other.downloadUrl),
568  indexableText(other.indexableText),
569  userPermission(other.userPermission),
570  fileExtension(other.fileExtension),
571  md5Checksum(other.md5Checksum),
572  fileSize(other.fileSize),
573  alternateLink(other.alternateLink),
574  embedLink(other.embedLink),
575  version(other.version),
576  sharedWithMeDate(other.sharedWithMeDate),
577  parents(other.parents),
578  exportLinks(other.exportLinks),
579  originalFileName(other.originalFileName),
580  quotaBytesUsed(other.quotaBytesUsed),
581  ownerNames(other.ownerNames),
582  lastModifyingUserName(other.lastModifyingUserName),
583  editable(other.editable),
584  writersCanShare(other.writersCanShare),
585  thumbnailLink(other.thumbnailLink),
586  lastViewedByMeDate(other.lastViewedByMeDate),
587  webContentLink(other.webContentLink),
588  explicitlyTrashed(other.explicitlyTrashed),
589  imageMediaMetadata(other.imageMediaMetadata),
590  thumbnail(other.thumbnail),
591  webViewLink(other.webViewLink),
592  iconLink(other.iconLink),
593  shared(other.shared),
594  owners(other.owners),
595  lastModifyingUser(other.lastModifyingUser)
596 {
597 }
598 
599 bool File::operator==(const File &other) const
600 {
601  if (!Object::operator==(other)) {
602  return false;
603  }
604  GAPI_COMPARE(id)
605  GAPI_COMPARE(selfLink)
606  GAPI_COMPARE(title)
607  GAPI_COMPARE(mimeType)
608  GAPI_COMPARE(description)
609  GAPI_COMPARE_SHAREDPTRS(labels)
610  GAPI_COMPARE(createdDate)
611  GAPI_COMPARE(modifiedDate)
612  GAPI_COMPARE(modifiedByMeDate)
613  GAPI_COMPARE(downloadUrl)
614  GAPI_COMPARE_SHAREDPTRS(indexableText)
615  GAPI_COMPARE_SHAREDPTRS(userPermission)
616  GAPI_COMPARE(fileExtension)
617  GAPI_COMPARE(md5Checksum)
618  GAPI_COMPARE(fileSize)
619  GAPI_COMPARE(alternateLink)
620  GAPI_COMPARE(embedLink)
621  GAPI_COMPARE(version)
622  GAPI_COMPARE(sharedWithMeDate)
623  GAPI_COMPARE_CONTAINERS(parents)
624  GAPI_COMPARE(exportLinks)
625  GAPI_COMPARE(originalFileName)
626  GAPI_COMPARE(quotaBytesUsed)
627  GAPI_COMPARE(ownerNames)
628  GAPI_COMPARE(lastModifyingUserName)
629  GAPI_COMPARE(editable)
630  GAPI_COMPARE(writersCanShare)
631  GAPI_COMPARE(thumbnailLink)
632  GAPI_COMPARE(lastViewedByMeDate)
633  GAPI_COMPARE(webContentLink)
634  GAPI_COMPARE(explicitlyTrashed)
635  GAPI_COMPARE_SHAREDPTRS(imageMediaMetadata)
636  GAPI_COMPARE_SHAREDPTRS(thumbnail)
637  GAPI_COMPARE(webViewLink)
638  GAPI_COMPARE(iconLink)
639  GAPI_COMPARE(shared)
640  GAPI_COMPARE_CONTAINERS(owners)
641  GAPI_COMPARE_SHAREDPTRS(lastModifyingUser)
642  return true;
643 }
644 
645 FilePtr File::Private::fromJSON(const QVariantMap &map)
646 {
647  if (!map.contains(File::Fields::Kind) ||
648  map[File::Fields::Kind].toString() != QLatin1String("drive#file"))
649  {
650  return FilePtr();
651  }
652 
653  FilePtr file(new File());
654  file->setEtag(map[Fields::Etag].toString());
655  file->d->id = map[Fields::Id].toString();
656  file->d->selfLink = map[Fields::SelfLink].toUrl();
657  file->d->title = map[Fields::Title].toString();
658  file->d->mimeType = map[Fields::MimeType].toString();
659  file->d->description = map[Fields::Description].toString();
660 
661  const QVariantMap labelsData = map[Fields::Labels].toMap();
662  File::LabelsPtr labels(new File::Labels());
663  labels->d->starred = labelsData[QStringLiteral("starred")].toBool();
664  labels->d->hidden = labelsData[QStringLiteral("hidden")].toBool();
665  labels->d->trashed = labelsData[QStringLiteral("trashed")].toBool();
666  labels->d->restricted = labelsData[QStringLiteral("restricted")].toBool();
667  labels->d->viewed = labelsData[QStringLiteral("viewed")].toBool();
668  file->d->labels = labels;
669 
670  // FIXME FIXME FIXME Verify the date format
671  file->d->createdDate = QDateTime::fromString(map[Fields::CreatedDate].toString(), Qt::ISODate);
672  file->d->modifiedDate = QDateTime::fromString(map[Fields::ModifiedDate].toString(), Qt::ISODate);
673  file->d->modifiedByMeDate = QDateTime::fromString(map[Fields::ModifiedByMeDate].toString(), Qt::ISODate);
674  file->d->downloadUrl = map[Fields::DownloadUrl].toUrl();
675 
676  const QVariantMap indexableTextData = map[Fields::IndexableText].toMap();
677  File::IndexableTextPtr indexableText(new File::IndexableText());
678  indexableText->d->text = indexableTextData[QStringLiteral("text")].toString();
679  file->d->indexableText = indexableText;
680 
681  const QVariantMap userPermissionData = map[Fields::UserPermission].toMap();
682  file->d->userPermission = Permission::Private::fromJSON(userPermissionData);
683 
684  file->d->fileExtension = map[Fields::FileExtension].toString();
685  file->d->md5Checksum = map[Fields::Md5Checksum].toString();
686  file->d->fileSize = map[Fields::FileSize].toLongLong();
687  file->d->alternateLink = map[Fields::AlternateLink].toUrl();
688  file->d->embedLink = map[Fields::EmbedLink].toUrl();
689  file->d->version = map[Fields::Version].toLongLong();
690  file->d->sharedWithMeDate = QDateTime::fromString(map[Fields::SharedWithMeDate].toString(), Qt::ISODate);
691 
692  const QVariantList parents = map[Fields::Parents].toList();
693  for (const QVariant &parent : parents)
694  {
695  file->d->parents << ParentReference::Private::fromJSON(parent.toMap());
696  }
697 
698  const QVariantMap exportLinksData = map[Fields::ExportLinks].toMap();
699  QVariantMap::ConstIterator iter = exportLinksData.constBegin();
700  for ( ; iter != exportLinksData.constEnd(); ++iter) {
701  file->d->exportLinks.insert(iter.key(), iter.value().toUrl());
702  }
703 
704  file->d->originalFileName = map[QStringLiteral("originalFileName")].toString();
705  file->d->quotaBytesUsed = map[QStringLiteral("quotaBytesUsed")].toLongLong();
706  file->d->ownerNames = map[Fields::OwnerNames].toStringList();
707  file->d->lastModifyingUserName = map[QStringLiteral("lastModifyingUserName")].toString();
708  file->d->editable = map[Fields::Editable].toBool();
709  file->d->writersCanShare = map[Fields::WritersCanShare].toBool();
710  file->d->thumbnailLink = map[Fields::ThumbnailLink].toUrl();
711  file->d->lastViewedByMeDate = QDateTime::fromString(map[Fields::LastViewedByMeDate].toString(), Qt::ISODate);
712  file->d->webContentLink = map[Fields::WebContentLink].toUrl();
713  file->d->explicitlyTrashed = map[Fields::ExplicitlyTrashed].toBool();
714 
715  const QVariantMap imageMetaData = map[Fields::ImageMediaMetadata].toMap();
716  file->d->imageMediaMetadata =
718 
719  const QVariantMap thumbnailData = map[Fields::Thumbnail].toMap();
720  File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData));
721  file->d->thumbnail = thumbnail;
722 
723  file->d->webViewLink = map[Fields::WebViewLink].toUrl();
724  file->d->iconLink = map[Fields::IconLink].toUrl();
725  file->d->shared = map[Fields::Shared].toBool();
726 
727  const QVariantList ownersList = map[Fields::Owners].toList();
728  for (const QVariant &owner : ownersList) {
729  file->d->owners << User::fromJSON(owner.toMap());
730  }
731 
732  const QVariantMap lastModifyingUser = map[Fields::LastModifyingUser].toMap();
733  file->d->lastModifyingUser = User::fromJSON(lastModifyingUser);
734 
735  return file;
736 }
737 
738 File::File():
739  KGAPI2::Object(),
740  d(new Private)
741 {
742 }
743 
744 File::File(const File& other):
745  KGAPI2::Object(other),
746  d(new Private(*(other.d)))
747 { }
748 
749 File::~File()
750 {
751  delete d;
752 }
753 
754 QString File::folderMimeType()
755 {
756  return QStringLiteral("application/vnd.google-apps.folder");
757 }
758 
759 QString File::id() const
760 {
761  return d->id;
762 }
763 
764 QUrl File::selfLink() const
765 {
766  return d->selfLink;
767 }
768 
769 QString File::title() const
770 {
771  return d->title;
772 }
773 
774 void File::setTitle(const QString& title)
775 {
776  d->title = title;
777 }
778 
779 QString File::mimeType() const
780 {
781  return d->mimeType;
782 }
783 
784 void File::setMimeType(const QString& mimeType)
785 {
786  d->mimeType = mimeType;
787 }
788 
789 QString File::description() const
790 {
791  return d->description;
792 }
793 
794 void File::setDescription(const QString& description)
795 {
796  d->description = description;
797 }
798 
799 File::LabelsPtr File::labels() const
800 {
801  return d->labels;
802 }
803 
804 void File::setLabels(const File::LabelsPtr &labels)
805 {
806  d->labels = labels;
807 }
808 
809 QDateTime File::createdDate() const
810 {
811  return d->createdDate;
812 }
813 
814 QDateTime File::modifiedDate() const
815 {
816  return d->modifiedDate;
817 }
818 
819 void File::setModifiedDate(const QDateTime& modifiedDate)
820 {
821  d->modifiedDate = modifiedDate;
822 }
823 
824 QDateTime File::modifiedByMeDate() const
825 {
826  return d->modifiedByMeDate;
827 }
828 
829 QUrl File::downloadUrl() const
830 {
831  return d->downloadUrl;
832 }
833 
834 File::IndexableTextPtr& File::indexableText()
835 {
836  return d->indexableText;
837 }
838 
839 PermissionPtr File::userPermission() const
840 {
841  return d->userPermission;
842 }
843 
844 QString File::fileExtension() const
845 {
846  return d->fileExtension;
847 }
848 
849 QString File::md5Checksum() const
850 {
851  return d->md5Checksum;
852 }
853 
854 qlonglong File::fileSize() const
855 {
856  return d->fileSize;
857 }
858 
859 QUrl File::alternateLink() const
860 {
861  return d->alternateLink;
862 }
863 
864 QUrl File::embedLink() const
865 {
866  return d->embedLink;
867 }
868 
869 qlonglong File::version() const
870 {
871  return d->version;
872 }
873 
874 QDateTime File::sharedWithMeDate() const
875 {
876  return d->sharedWithMeDate;
877 }
878 
879 ParentReferencesList File::parents() const
880 {
881  return d->parents;
882 }
883 
884 void File::setParents(const ParentReferencesList &parents)
885 {
886  d->parents = parents;
887 }
888 
889 QMap< QString, QUrl > File::exportLinks() const
890 {
891  return d->exportLinks;
892 }
893 
894 QString File::originalFileName() const
895 {
896  return d->originalFileName;
897 }
898 
899 qlonglong File::quotaBytesUsed() const
900 {
901  return d->quotaBytesUsed;
902 }
903 
904 QStringList File::ownerNames() const
905 {
906  return d->ownerNames;
907 }
908 
909 QString File::lastModifyingUserName() const
910 {
911  return d->lastModifyingUserName;
912 }
913 
914 bool File::editable() const
915 {
916  return d->editable;
917 }
918 
919 bool File::writersCanShare() const
920 {
921  return d->writersCanShare;
922 }
923 
924 QUrl File::thumbnailLink() const
925 {
926  return d->thumbnailLink;
927 }
928 
929 QDateTime File::lastViewedByMeDate() const
930 {
931  return d->lastViewedByMeDate;
932 }
933 
934 void File::setLastViewedByMeDate(const QDateTime& lastViewedByMeDate)
935 {
936  d->lastViewedByMeDate = lastViewedByMeDate;
937 }
938 
939 QUrl File::webContentLink() const
940 {
941  return d->webContentLink;
942 }
943 
944 bool File::explicitlyTrashed() const
945 {
946  return d->explicitlyTrashed;
947 }
948 
949 File::ImageMediaMetadataPtr File::imageMediaMetadata() const
950 {
951  return d->imageMediaMetadata;
952 }
953 
954 File::ThumbnailPtr File::thumbnail() const
955 {
956  return d->thumbnail;
957 }
958 
959 QUrl File::webViewLink() const
960 {
961  return d->webViewLink;
962 }
963 
964 QUrl File::iconLink() const
965 {
966  return d->iconLink;
967 }
968 
969 bool File::shared() const
970 {
971  return d->shared;
972 }
973 
974 UsersList File::owners() const
975 {
976  return d->owners;
977 }
978 
979 UserPtr File::lastModifyingUser() const
980 {
981  return d->lastModifyingUser;
982 }
983 
984 bool File::isFolder() const
985 {
986  return (d->mimeType == File::folderMimeType());
987 }
988 
989 const QString File::Fields::Kind = QStringLiteral("kind");
990 const QString File::Fields::Items = QStringLiteral("items");
991 const QString File::Fields::NextLink = QStringLiteral("nextLink");
992 const QString File::Fields::NextPageToken = QStringLiteral("nextPageToken");
993 const QString File::Fields::SelfLink = QStringLiteral("selfLink");
994 const QString File::Fields::Etag = QStringLiteral("etag");
995 const QString File::Fields::Id = QStringLiteral("id");
996 const QString File::Fields::Title = QStringLiteral("title");
997 const QString File::Fields::MimeType = QStringLiteral("mimeType");
998 const QString File::Fields::Description = QStringLiteral("description");
999 const QString File::Fields::Labels = QStringLiteral("labels");
1000 const QString File::Fields::CreatedDate = QStringLiteral("createdDate");
1001 const QString File::Fields::ModifiedDate = QStringLiteral("modifiedDate");
1002 const QString File::Fields::ModifiedByMeDate = QStringLiteral("modifiedByMeDate");
1003 const QString File::Fields::DownloadUrl = QStringLiteral("downloadUrl");
1004 const QString File::Fields::IndexableText = QStringLiteral("indexableText");
1005 const QString File::Fields::UserPermission = QStringLiteral("userPermission");
1006 const QString File::Fields::FileExtension = QStringLiteral("fileExtension");
1007 const QString File::Fields::Md5Checksum = QStringLiteral("md5Checksum");
1008 const QString File::Fields::FileSize = QStringLiteral("fileSize");
1009 const QString File::Fields::AlternateLink = QStringLiteral("alternateLink");
1010 const QString File::Fields::EmbedLink = QStringLiteral("embedLink");
1011 const QString File::Fields::SharedWithMeDate = QStringLiteral("sharedWithMeDate");
1012 const QString File::Fields::Parents = QStringLiteral("parents");
1013 const QString File::Fields::ExportLinks = QStringLiteral("exportLinks");
1014 const QString File::Fields::OriginalFilename = QStringLiteral("originalFilename");
1015 const QString File::Fields::OwnerNames = QStringLiteral("ownerNames");
1016 const QString File::Fields::LastModifiedByMeDate = QStringLiteral("lastModifiedByMeDate");
1017 const QString File::Fields::Editable = QStringLiteral("editable");
1018 const QString File::Fields::WritersCanShare = QStringLiteral("writersCanShare");
1019 const QString File::Fields::ThumbnailLink = QStringLiteral("thumbnailLink");
1020 const QString File::Fields::LastViewedByMeDate = QStringLiteral("lastViewedByMeDate");
1021 const QString File::Fields::WebContentLink = QStringLiteral("webContentLink");
1022 const QString File::Fields::ExplicitlyTrashed = QStringLiteral("explicitlyTrashed");
1023 const QString File::Fields::ImageMediaMetadata = QStringLiteral("imageMediaMetadata");
1024 const QString File::Fields::Thumbnail = QStringLiteral("thumbnail");
1025 const QString File::Fields::WebViewLink = QStringLiteral("webViewLink");
1026 const QString File::Fields::IconLink = QStringLiteral("iconLink");
1027 const QString File::Fields::Shared = QStringLiteral("shared");
1028 const QString File::Fields::Owners = QStringLiteral("owners");
1029 const QString File::Fields::LastModifyingUser = QStringLiteral("lastModifyingUser");
1030 const QString File::Fields::AppDataContents = QStringLiteral("appDataContents");
1031 const QString File::Fields::OpenWithLinks = QStringLiteral("openWithLinks");
1032 const QString File::Fields::DefaultOpenWithLink = QStringLiteral("defaultOpenWithLink");
1033 const QString File::Fields::HeadRevisionId = QStringLiteral("headRevisionId");
1034 const QString File::Fields::Copyable = QStringLiteral("copyable");
1035 const QString File::Fields::Properties = QStringLiteral("properties");
1036 const QString File::Fields::MarkedViewedByMeDate = QStringLiteral("markedViewedByMeDate");
1037 const QString File::Fields::Version = QStringLiteral("version");
1038 const QString File::Fields::SharingUser = QStringLiteral("sharingUser");
1039 const QString File::Fields::Permissions = QStringLiteral("permissions");
1040 
1041 FilePtr File::fromJSON(const QByteArray &jsonData)
1042 {
1043  QJsonDocument document = QJsonDocument::fromJson(jsonData);
1044  if (document.isNull()) {
1045  return FilePtr();
1046  }
1047  const QVariant data = document.toVariant();
1048  return Private::fromJSON(data.toMap());
1049 }
1050 
1051 FilePtr File::fromJSON(const QVariantMap &jsonData)
1052 {
1053  if (jsonData.isEmpty()) {
1054  return FilePtr();
1055  }
1056  return Private::fromJSON(jsonData);
1057 }
1058 
1059 
1060 FilesList File::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData)
1061 {
1062  QJsonDocument document = QJsonDocument::fromJson(jsonData);
1063  if (document.isNull()) {
1064  return FilesList();
1065  }
1066  const QVariant data = document.toVariant();
1067  const QVariantMap map = data.toMap();
1068  if (!map.contains(File::Fields::Kind) ||
1069  map[Fields::Kind].toString() != QLatin1String("drive#fileList"))
1070  {
1071  return FilesList();
1072  }
1073 
1074  FilesList list;
1075  const QVariantList items = map[File::Fields::Items].toList();
1076  for (const QVariant &item : items) {
1077  const FilePtr file = Private::fromJSON(item.toMap());
1078 
1079  if (!file.isNull()) {
1080  list << file;
1081  }
1082  }
1083 
1084  if (map.contains(File::Fields::NextLink)) {
1085  feedData.nextPageUrl = map[File::Fields::NextLink].toUrl();
1086  }
1087 
1088  return list;
1089 }
1090 
1091 QByteArray File::toJSON(const FilePtr &file, SerializationOptions options)
1092 {
1093  QVariantMap map;
1094 
1095  map[File::Fields::Kind] = QLatin1String("drive#file");
1096  if (!file->description().isEmpty()) {
1097  map[Fields::Description] = file->description();
1098  }
1099 
1100  if (file->indexableText() && !file->indexableText()->text().isEmpty()) {
1101  QVariantMap indexableText;
1102  indexableText[QStringLiteral("text")] = file->indexableText()->text();
1103  map[Fields::IndexableText] = indexableText;
1104  }
1105 
1106  if (file->labels()) {
1107  QVariantMap labels;
1108  labels[QStringLiteral("hidden")] = file->labels()->hidden();
1109  labels[QStringLiteral("restricted")] = file->labels()->restricted();
1110  labels[QStringLiteral("starred")] = file->labels()->starred();
1111  labels[QStringLiteral("trashed")] = file->labels()->trashed();
1112  labels[QStringLiteral("viewed")] = file->labels()->viewed();
1113  map[Fields::Labels] = labels;
1114  }
1115 
1116  if (file->lastViewedByMeDate().isValid()) {
1117  map[Fields::LastViewedByMeDate] = file->lastViewedByMeDate().toString(Qt::ISODate);
1118  }
1119 
1120  if (!file->mimeType().isEmpty()) {
1121  map[Fields::MimeType] = file->mimeType();
1122  }
1123 
1124  if (file->modifiedDate().isValid()) {
1125  map[Fields::ModifiedDate] = file->modifiedDate().toString(Qt::ISODate);
1126  }
1127  if (file->createdDate().isValid() && !(options & ExcludeCreationDate)) {
1128  map[Fields::CreatedDate] = file->createdDate().toString(Qt::ISODate);
1129  }
1130  if (file->modifiedByMeDate().isValid()) {
1131  map[Fields::ModifiedByMeDate] = file->modifiedByMeDate().toString(Qt::ISODate);
1132  }
1133 
1134  if (file->fileSize() > 0) {
1135  map[Fields::FileSize] = file->fileSize();
1136  }
1137 
1138  if (!file->title().isEmpty()) {
1139  map[Fields::Title] = file->title();
1140  }
1141 
1142  QVariantList parents;
1143  const auto parentReferences = file->parents();
1144  parents.reserve(parentReferences.size());
1145  for (const ParentReferencePtr &parent : parentReferences) {
1146  parents << ParentReference::Private::toJSON(parent);
1147  }
1148  if (!parents.isEmpty()) {
1149  map[Fields::Parents] = parents;
1150  }
1151  if (!file->etag().isEmpty()) {
1152  map[Fields::Etag] = file->etag();
1153  }
1154  if (!file->d->id.isEmpty()) {
1155  map[Fields::Id] = file->d->id;
1156  }
1157  if (!file->d->selfLink.isEmpty()) {
1158  map[Fields::SelfLink] = file->d->selfLink;
1159  }
1160  if (!file->d->downloadUrl.isEmpty()) {
1161  map[Fields::DownloadUrl] = file->d->downloadUrl;
1162  }
1163 
1164  if (!file->d->fileExtension.isEmpty()) {
1165  map[Fields::FileExtension] = file->d->fileExtension;
1166  }
1167  if (!file->d->md5Checksum.isEmpty()) {
1168  map[Fields::Md5Checksum] = file->d->md5Checksum;
1169  }
1170  if (!file->d->alternateLink.isEmpty()) {
1171  map[Fields::AlternateLink] = file->d->alternateLink;
1172  }
1173  if (!file->d->embedLink.isEmpty()) {
1174  map[Fields::EmbedLink] = file->d->embedLink;
1175  }
1176  if (!file->d->sharedWithMeDate.isNull()) {
1177  map[Fields::SharedWithMeDate] = file->d->sharedWithMeDate.toString(Qt::ISODate);
1178  }
1179 
1180 
1181  if (!file->d->originalFileName.isEmpty()) {
1182  map[QStringLiteral("originalFileName")] = file->d->originalFileName;
1183  }
1184  if (file->d->quotaBytesUsed > 0) {
1185  map[QStringLiteral("quotaBytesUsed")] = file->d->quotaBytesUsed;
1186  }
1187  if (!file->d->ownerNames.isEmpty()) {
1188  map[Fields::OwnerNames] = QVariant(file->d->ownerNames);
1189  }
1190  if (!file->d->lastModifyingUserName.isEmpty()) {
1191  map[QStringLiteral("lastModifyingUserName")] = file->d->lastModifyingUserName;
1192  }
1193  if (!file->d->editable) { // default is true
1194  map[Fields::Editable] = file->d->editable;
1195  }
1196  if (file->d->writersCanShare) { // default is false
1197  map[Fields::WritersCanShare] = file->d->writersCanShare;
1198  }
1199  if (!file->d->thumbnailLink.isEmpty()) {
1200  map[Fields::ThumbnailLink] = file->d->thumbnailLink;
1201  }
1202  if (!file->d->lastViewedByMeDate.isNull()) {
1203  map[Fields::LastViewedByMeDate] = file->d->lastViewedByMeDate.toString(Qt::ISODate);
1204  }
1205  if (!file->d->webContentLink.isEmpty()) {
1206  map[Fields::WebContentLink] = file->d->webContentLink;
1207  }
1208  if (file->d->explicitlyTrashed) {
1209  map[Fields::ExplicitlyTrashed] = file->d->explicitlyTrashed;
1210  }
1211 
1212  if (!file->d->webViewLink.isEmpty()) {
1213  map[Fields::WebViewLink] = file->d->webViewLink;
1214  }
1215  if (!file->d->iconLink.isEmpty()) {
1216  map[Fields::IconLink] = file->d->iconLink;
1217  }
1218  if (file->d->shared) {
1219  map[Fields::Shared] = file->d->shared;
1220  }
1221 
1222 #if 0
1223  const QVariantMap userPermissionData = map[QLatin1String("userPermission")].toMap();
1224  file->d->userPermission = Permission::Private::fromJSON(userPermissionData);
1225 
1226  const QVariantList parents = map[QLatin1String("parents")].toList();
1227  for (const QVariant &parent : parents)
1228  {
1229  file->d->parents << ParentReference::Private::fromJSON(parent.toMap());
1230  }
1231 
1232  const QVariantMap exportLinksData = map[QLatin1String("exportLinks")].toMap();
1233  QVariantMap::ConstIterator iter = exportLinksData.constBegin();
1234  for ( ; iter != exportLinksData.constEnd(); ++iter) {
1235  file->d->exportLinks.insert(iter.key(), iter.value().toUrl());
1236  }
1237 
1238 
1239  const QVariantMap imageMetaData = map[QLatin1String("imageMediaMetadata")].toMap();
1240  file->d->imageMediaMetadata =
1242 
1243  const QVariantMap thumbnailData = map[QLatin1String("thumbnail")].toMap();
1244  File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData));
1245  file->d->thumbnail = thumbnail;
1246 
1247 
1248  const QVariantList ownersList = map[QLatin1String("owners")].toList();
1249  for (const QVariant &owner : ownersList) {
1250  file->d->owners << User::fromJSON(owner.toMap());
1251  }
1252 
1253  const QVariantMap lastModifyingUser = map[QLatin1String("lastModifyingUser")].toMap();
1254  file->d->lastModifyingUser = User::fromJSON(lastModifyingUser);
1255 
1256 #endif
1257 
1258  QJsonDocument document = QJsonDocument::fromVariant(map);
1259  return document.toJson(QJsonDocument::Compact);
1260 }
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QImage fromData(const uchar *data, int size, const char *format)
QByteArray toJson() const const
Base class for all objects.
Definition: object.h:31
QUrl nextPageUrl
Link to next page of feed.
Definition: types.h:38
QJsonDocument fromVariant(const QVariant &variant)
Structure to store additional information about a feed.
Definition: types.h:24
bool isNull() const const
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition: fetchjob.cpp:41
DriveFile::IndexableText holds the structure used for indexableText property.
Definition: file.h:133
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
DriveFile::Labels holds the structure used for labels property.
Definition: file.h:46
QVariant toVariant() const const
QDateTime fromString(const QString &string, Qt::DateFormat format)
QMap< QString, QVariant > toMap() const const
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
DriveFile::ImageMediaMetadata holds the structure used for imageMediaMetadata property.
Definition: file.h:168
bool isNull() const const
QObject * parent() const const
Represents a single record about geographical location provided by Google Latitude service...
Definition: location.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 4 2020 23:08:48 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.