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

KDE's Doxygen guidelines are available online.