Kgapi

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

KDE's Doxygen guidelines are available online.