Changeset View
Changeset View
Standalone View
Standalone View
src/drive/file.cpp
Show First 20 Lines • Show All 519 Lines • ▼ Show 20 Line(s) | |||||
520 | { | 520 | { | ||
521 | } | 521 | } | ||
522 | 522 | | |||
523 | File::Thumbnail::Thumbnail(const QVariantMap &map): | 523 | File::Thumbnail::Thumbnail(const QVariantMap &map): | ||
524 | d(new Private) | 524 | d(new Private) | ||
525 | { | 525 | { | ||
526 | const QByteArray ba = QByteArray::fromBase64(map[QStringLiteral("image")].toByteArray()); | 526 | const QByteArray ba = QByteArray::fromBase64(map[QStringLiteral("image")].toByteArray()); | ||
527 | d->image = QImage::fromData(ba); | 527 | d->image = QImage::fromData(ba); | ||
528 | d->mimeType = map[QStringLiteral("mimeType")].toString(); | 528 | d->mimeType = map[Fields::MimeType].toString(); | ||
529 | } | 529 | } | ||
530 | 530 | | |||
531 | File::Thumbnail::Thumbnail(const File::Thumbnail &other): | 531 | File::Thumbnail::Thumbnail(const File::Thumbnail &other): | ||
532 | d(new Private(*(other.d))) | 532 | d(new Private(*(other.d))) | ||
533 | { | 533 | { | ||
534 | } | 534 | } | ||
535 | 535 | | |||
536 | File::Thumbnail::~Thumbnail() | 536 | File::Thumbnail::~Thumbnail() | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 612 | { | |||
650 | GAPI_COMPARE(shared) | 650 | GAPI_COMPARE(shared) | ||
651 | GAPI_COMPARE_CONTAINERS(owners) | 651 | GAPI_COMPARE_CONTAINERS(owners) | ||
652 | GAPI_COMPARE_SHAREDPTRS(lastModifyingUser) | 652 | GAPI_COMPARE_SHAREDPTRS(lastModifyingUser) | ||
653 | return true; | 653 | return true; | ||
654 | } | 654 | } | ||
655 | 655 | | |||
656 | FilePtr File::Private::fromJSON(const QVariantMap &map) | 656 | FilePtr File::Private::fromJSON(const QVariantMap &map) | ||
657 | { | 657 | { | ||
658 | if (!map.contains(QStringLiteral("kind")) || | 658 | if (!map.contains(File::Fields::Kind) || | ||
659 | map[QStringLiteral("kind")].toString() != QLatin1String("drive#file")) | 659 | map[File::Fields::Kind].toString() != QLatin1String("drive#file")) | ||
660 | { | 660 | { | ||
661 | return FilePtr(); | 661 | return FilePtr(); | ||
662 | } | 662 | } | ||
663 | 663 | | |||
664 | FilePtr file(new File()); | 664 | FilePtr file(new File()); | ||
665 | file->setEtag(map[QStringLiteral("etag")].toString()); | 665 | file->setEtag(map[Fields::Etag].toString()); | ||
666 | file->d->id = map[QStringLiteral("id")].toString(); | 666 | file->d->id = map[Fields::Id].toString(); | ||
667 | file->d->selfLink = map[QStringLiteral("selfLink")].toUrl(); | 667 | file->d->selfLink = map[Fields::SelfLink].toUrl(); | ||
668 | file->d->title = map[QStringLiteral("title")].toString(); | 668 | file->d->title = map[Fields::Title].toString(); | ||
669 | file->d->mimeType = map[QStringLiteral("mimeType")].toString(); | 669 | file->d->mimeType = map[Fields::MimeType].toString(); | ||
670 | file->d->description = map[QStringLiteral("description")].toString(); | 670 | file->d->description = map[Fields::Description].toString(); | ||
671 | 671 | | |||
672 | const QVariantMap labelsData = map[QStringLiteral("labels")].toMap(); | 672 | const QVariantMap labelsData = map[Fields::Labels].toMap(); | ||
673 | File::LabelsPtr labels(new File::Labels()); | 673 | File::LabelsPtr labels(new File::Labels()); | ||
674 | labels->d->starred = labelsData[QStringLiteral("starred")].toBool(); | 674 | labels->d->starred = labelsData[QStringLiteral("starred")].toBool(); | ||
675 | labels->d->hidden = labelsData[QStringLiteral("hidden")].toBool(); | 675 | labels->d->hidden = labelsData[QStringLiteral("hidden")].toBool(); | ||
676 | labels->d->trashed = labelsData[QStringLiteral("trashed")].toBool(); | 676 | labels->d->trashed = labelsData[QStringLiteral("trashed")].toBool(); | ||
677 | labels->d->restricted = labelsData[QStringLiteral("restricted")].toBool(); | 677 | labels->d->restricted = labelsData[QStringLiteral("restricted")].toBool(); | ||
678 | labels->d->viewed = labelsData[QStringLiteral("viewed")].toBool(); | 678 | labels->d->viewed = labelsData[QStringLiteral("viewed")].toBool(); | ||
679 | file->d->labels = labels; | 679 | file->d->labels = labels; | ||
680 | 680 | | |||
681 | // FIXME FIXME FIXME Verify the date format | 681 | // FIXME FIXME FIXME Verify the date format | ||
682 | file->d->createdDate = QDateTime::fromString(map[QStringLiteral("createdDate")].toString(), Qt::ISODate); | 682 | file->d->createdDate = QDateTime::fromString(map[Fields::CreatedDate].toString(), Qt::ISODate); | ||
683 | file->d->modifiedDate = QDateTime::fromString(map[QStringLiteral("modifiedDate")].toString(), Qt::ISODate); | 683 | file->d->modifiedDate = QDateTime::fromString(map[Fields::ModifiedDate].toString(), Qt::ISODate); | ||
684 | file->d->modifiedByMeDate = QDateTime::fromString(map[QStringLiteral("modifiedByMeDate")].toString(), Qt::ISODate); | 684 | file->d->modifiedByMeDate = QDateTime::fromString(map[Fields::ModifiedByMeDate].toString(), Qt::ISODate); | ||
685 | file->d->downloadUrl = map[QStringLiteral("downloadUrl")].toUrl(); | 685 | file->d->downloadUrl = map[Fields::DownloadUrl].toUrl(); | ||
686 | 686 | | |||
687 | const QVariantMap indexableTextData = map[QStringLiteral("indexableText")].toMap(); | 687 | const QVariantMap indexableTextData = map[Fields::IndexableText].toMap(); | ||
688 | File::IndexableTextPtr indexableText(new File::IndexableText()); | 688 | File::IndexableTextPtr indexableText(new File::IndexableText()); | ||
689 | indexableText->d->text = indexableTextData[QStringLiteral("text")].toString(); | 689 | indexableText->d->text = indexableTextData[QStringLiteral("text")].toString(); | ||
690 | file->d->indexableText = indexableText; | 690 | file->d->indexableText = indexableText; | ||
691 | 691 | | |||
692 | const QVariantMap userPermissionData = map[QStringLiteral("userPermission")].toMap(); | 692 | const QVariantMap userPermissionData = map[Fields::UserPermission].toMap(); | ||
693 | file->d->userPermission = Permission::Private::fromJSON(userPermissionData); | 693 | file->d->userPermission = Permission::Private::fromJSON(userPermissionData); | ||
694 | 694 | | |||
695 | file->d->fileExtension = map[QStringLiteral("fileExtension")].toString(); | 695 | file->d->fileExtension = map[Fields::FileExtension].toString(); | ||
696 | file->d->md5Checksum = map[QStringLiteral("md5Checksum")].toString(); | 696 | file->d->md5Checksum = map[Fields::Md5Checksum].toString(); | ||
697 | file->d->fileSize = map[QStringLiteral("fileSize")].toLongLong(); | 697 | file->d->fileSize = map[Fields::FileSize].toLongLong(); | ||
698 | file->d->alternateLink = map[QStringLiteral("alternateLink")].toUrl(); | 698 | file->d->alternateLink = map[Fields::AlternateLink].toUrl(); | ||
699 | file->d->embedLink = map[QStringLiteral("embedLink")].toUrl(); | 699 | file->d->embedLink = map[Fields::EmbedLink].toUrl(); | ||
700 | file->d->sharedWithMeDate = QDateTime::fromString(map[QStringLiteral("sharedWithMeDate")].toString(), Qt::ISODate); | 700 | file->d->sharedWithMeDate = QDateTime::fromString(map[Fields::SharedWithMeDate].toString(), Qt::ISODate); | ||
701 | 701 | | |||
702 | const QVariantList parents = map[QStringLiteral("parents")].toList(); | 702 | const QVariantList parents = map[Fields::Parents].toList(); | ||
703 | for (const QVariant &parent : parents) | 703 | for (const QVariant &parent : parents) | ||
704 | { | 704 | { | ||
705 | file->d->parents << ParentReference::Private::fromJSON(parent.toMap()); | 705 | file->d->parents << ParentReference::Private::fromJSON(parent.toMap()); | ||
706 | } | 706 | } | ||
707 | 707 | | |||
708 | const QVariantMap exportLinksData = map[QStringLiteral("exportLinks")].toMap(); | 708 | const QVariantMap exportLinksData = map[Fields::ExportLinks].toMap(); | ||
709 | QVariantMap::ConstIterator iter = exportLinksData.constBegin(); | 709 | QVariantMap::ConstIterator iter = exportLinksData.constBegin(); | ||
710 | for ( ; iter != exportLinksData.constEnd(); ++iter) { | 710 | for ( ; iter != exportLinksData.constEnd(); ++iter) { | ||
711 | file->d->exportLinks.insert(iter.key(), iter.value().toUrl()); | 711 | file->d->exportLinks.insert(iter.key(), iter.value().toUrl()); | ||
712 | } | 712 | } | ||
713 | 713 | | |||
714 | file->d->originalFileName = map[QStringLiteral("originalFileName")].toString(); | 714 | file->d->originalFileName = map[QStringLiteral("originalFileName")].toString(); | ||
715 | file->d->quotaBytesUsed = map[QStringLiteral("quotaBytesUsed")].toLongLong(); | 715 | file->d->quotaBytesUsed = map[QStringLiteral("quotaBytesUsed")].toLongLong(); | ||
716 | file->d->ownerNames = map[QStringLiteral("ownerNames")].toStringList(); | 716 | file->d->ownerNames = map[Fields::OwnerNames].toStringList(); | ||
717 | file->d->lastModifyingUserName = map[QStringLiteral("lastModifyingUserName")].toString(); | 717 | file->d->lastModifyingUserName = map[QStringLiteral("lastModifyingUserName")].toString(); | ||
718 | file->d->editable = map[QStringLiteral("editable")].toBool(); | 718 | file->d->editable = map[Fields::Editable].toBool(); | ||
719 | file->d->writersCanShare = map[QStringLiteral("writersCanShare")].toBool(); | 719 | file->d->writersCanShare = map[Fields::WritersCanShare].toBool(); | ||
720 | file->d->thumbnailLink = map[QStringLiteral("thumbnailLink")].toUrl(); | 720 | file->d->thumbnailLink = map[Fields::ThumbnailLink].toUrl(); | ||
721 | file->d->lastViewedByMeDate = QDateTime::fromString(map[QStringLiteral("lastViewedByMeDate")].toString(), Qt::ISODate); | 721 | file->d->lastViewedByMeDate = QDateTime::fromString(map[Fields::LastViewedByMeDate].toString(), Qt::ISODate); | ||
722 | file->d->webContentLink = map[QStringLiteral("webContentLink")].toUrl(); | 722 | file->d->webContentLink = map[Fields::WebContentLink].toUrl(); | ||
723 | file->d->explicitlyTrashed = map[QStringLiteral("explicitlyTrashed")].toBool(); | 723 | file->d->explicitlyTrashed = map[Fields::ExplicitlyTrashed].toBool(); | ||
724 | 724 | | |||
725 | const QVariantMap imageMetaData = map[QStringLiteral("imageMediaMetadata")].toMap(); | 725 | const QVariantMap imageMetaData = map[Fields::ImageMediaMetadata].toMap(); | ||
726 | file->d->imageMediaMetadata = | 726 | file->d->imageMediaMetadata = | ||
727 | File::ImageMediaMetadataPtr(new File::ImageMediaMetadata(imageMetaData)); | 727 | File::ImageMediaMetadataPtr(new File::ImageMediaMetadata(imageMetaData)); | ||
728 | 728 | | |||
729 | const QVariantMap thumbnailData = map[QStringLiteral("thumbnail")].toMap(); | 729 | const QVariantMap thumbnailData = map[Fields::Thumbnail].toMap(); | ||
730 | File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData)); | 730 | File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData)); | ||
731 | file->d->thumbnail = thumbnail; | 731 | file->d->thumbnail = thumbnail; | ||
732 | 732 | | |||
733 | file->d->webViewLink = map[QStringLiteral("webViewLink")].toUrl(); | 733 | file->d->webViewLink = map[Fields::WebViewLink].toUrl(); | ||
734 | file->d->iconLink = map[QStringLiteral("iconLink")].toUrl(); | 734 | file->d->iconLink = map[Fields::IconLink].toUrl(); | ||
735 | file->d->shared = map[QStringLiteral("shared")].toBool(); | 735 | file->d->shared = map[Fields::Shared].toBool(); | ||
736 | 736 | | |||
737 | const QVariantList ownersList = map[QStringLiteral("owners")].toList(); | 737 | const QVariantList ownersList = map[Fields::Owners].toList(); | ||
738 | for (const QVariant &owner : ownersList) { | 738 | for (const QVariant &owner : ownersList) { | ||
739 | file->d->owners << User::fromJSON(owner.toMap()); | 739 | file->d->owners << User::fromJSON(owner.toMap()); | ||
740 | } | 740 | } | ||
741 | 741 | | |||
742 | const QVariantMap lastModifyingUser = map[QStringLiteral("lastModifyingUser")].toMap(); | 742 | const QVariantMap lastModifyingUser = map[Fields::LastModifyingUser].toMap(); | ||
743 | file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); | 743 | file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); | ||
744 | 744 | | |||
745 | return file; | 745 | return file; | ||
746 | } | 746 | } | ||
747 | 747 | | |||
748 | File::File(): | 748 | File::File(): | ||
749 | KGAPI2::Object(), | 749 | KGAPI2::Object(), | ||
750 | d(new Private) | 750 | d(new Private) | ||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Line(s) | 985 | { | |||
986 | return d->lastModifyingUser; | 986 | return d->lastModifyingUser; | ||
987 | } | 987 | } | ||
988 | 988 | | |||
989 | bool File::isFolder() const | 989 | bool File::isFolder() const | ||
990 | { | 990 | { | ||
991 | return (d->mimeType == File::folderMimeType()); | 991 | return (d->mimeType == File::folderMimeType()); | ||
992 | } | 992 | } | ||
993 | 993 | | |||
994 | const QString File::Fields::Kind = QStringLiteral("kind"); | ||||
995 | const QString File::Fields::Items = QStringLiteral("items"); | ||||
996 | const QString File::Fields::NextLink = QStringLiteral("nextLink"); | ||||
997 | const QString File::Fields::NextPageToken = QStringLiteral("nextPageToken"); | ||||
998 | const QString File::Fields::SelfLink = QStringLiteral("selfLink"); | ||||
999 | const QString File::Fields::Etag = QStringLiteral("etag"); | ||||
1000 | const QString File::Fields::Id = QStringLiteral("id"); | ||||
1001 | const QString File::Fields::Title = QStringLiteral("title"); | ||||
1002 | const QString File::Fields::MimeType = QStringLiteral("mimeType"); | ||||
1003 | const QString File::Fields::Description = QStringLiteral("description"); | ||||
1004 | const QString File::Fields::Labels = QStringLiteral("labels"); | ||||
1005 | const QString File::Fields::CreatedDate = QStringLiteral("createdDate"); | ||||
1006 | const QString File::Fields::ModifiedDate = QStringLiteral("modifiedDate"); | ||||
1007 | const QString File::Fields::ModifiedByMeDate = QStringLiteral("modifiedByMeDate"); | ||||
1008 | const QString File::Fields::DownloadUrl = QStringLiteral("downloadUrl"); | ||||
1009 | const QString File::Fields::IndexableText = QStringLiteral("indexableText"); | ||||
1010 | const QString File::Fields::UserPermission = QStringLiteral("userPermission"); | ||||
1011 | const QString File::Fields::FileExtension = QStringLiteral("fileExtension"); | ||||
1012 | const QString File::Fields::Md5Checksum = QStringLiteral("md5Checksum"); | ||||
1013 | const QString File::Fields::FileSize = QStringLiteral("fileSize"); | ||||
1014 | const QString File::Fields::AlternateLink = QStringLiteral("alternateLink"); | ||||
1015 | const QString File::Fields::EmbedLink = QStringLiteral("embedLink"); | ||||
1016 | const QString File::Fields::SharedWithMeDate = QStringLiteral("sharedWithMeDate"); | ||||
1017 | const QString File::Fields::Parents = QStringLiteral("parents"); | ||||
1018 | const QString File::Fields::ExportLinks = QStringLiteral("exportLinks"); | ||||
1019 | const QString File::Fields::OriginalFilename = QStringLiteral("originalFilename"); | ||||
1020 | const QString File::Fields::OwnerNames = QStringLiteral("ownerNames"); | ||||
1021 | const QString File::Fields::LastModifiedByMeDate = QStringLiteral("lastModifiedByMeDate"); | ||||
1022 | const QString File::Fields::Editable = QStringLiteral("editable"); | ||||
1023 | const QString File::Fields::WritersCanShare = QStringLiteral("writersCanShare"); | ||||
1024 | const QString File::Fields::ThumbnailLink = QStringLiteral("thumbnailLink"); | ||||
1025 | const QString File::Fields::LastViewedByMeDate = QStringLiteral("lastViewedByMeDate"); | ||||
1026 | const QString File::Fields::WebContentLink = QStringLiteral("webContentLink"); | ||||
1027 | const QString File::Fields::ExplicitlyTrashed = QStringLiteral("explicitlyTrashed"); | ||||
1028 | const QString File::Fields::ImageMediaMetadata = QStringLiteral("imageMediaMetadata"); | ||||
1029 | const QString File::Fields::Thumbnail = QStringLiteral("thumbnail"); | ||||
1030 | const QString File::Fields::WebViewLink = QStringLiteral("webViewLink"); | ||||
1031 | const QString File::Fields::IconLink = QStringLiteral("iconLink"); | ||||
1032 | const QString File::Fields::Shared = QStringLiteral("shared"); | ||||
1033 | const QString File::Fields::Owners = QStringLiteral("owners"); | ||||
1034 | const QString File::Fields::LastModifyingUser = QStringLiteral("lastModifyingUser"); | ||||
1035 | const QString File::Fields::AppDataContents = QStringLiteral("appDataContents"); | ||||
1036 | const QString File::Fields::OpenWithLinks = QStringLiteral("openWithLinks"); | ||||
1037 | const QString File::Fields::DefaultOpenWithLink = QStringLiteral("defaultOpenWithLink"); | ||||
1038 | const QString File::Fields::HeadRevisionId = QStringLiteral("headRevisionId"); | ||||
1039 | const QString File::Fields::Copyable = QStringLiteral("copyable"); | ||||
1040 | const QString File::Fields::Properties = QStringLiteral("properties"); | ||||
1041 | const QString File::Fields::MarkedViewedByMeDate = QStringLiteral("markedViewedByMeDate"); | ||||
1042 | const QString File::Fields::Version = QStringLiteral("version"); | ||||
1043 | const QString File::Fields::SharingUser = QStringLiteral("sharingUser"); | ||||
1044 | const QString File::Fields::Permissions = QStringLiteral("permissions"); | ||||
1045 | | ||||
994 | FilePtr File::fromJSON(const QByteArray &jsonData) | 1046 | FilePtr File::fromJSON(const QByteArray &jsonData) | ||
995 | { | 1047 | { | ||
996 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | 1048 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||
997 | if (document.isNull()) { | 1049 | if (document.isNull()) { | ||
998 | return FilePtr(); | 1050 | return FilePtr(); | ||
999 | } | 1051 | } | ||
1000 | const QVariant data = document.toVariant(); | 1052 | const QVariant data = document.toVariant(); | ||
1001 | return Private::fromJSON(data.toMap()); | 1053 | return Private::fromJSON(data.toMap()); | ||
Show All 11 Lines | |||||
1013 | FilesList File::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData) | 1065 | FilesList File::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData) | ||
1014 | { | 1066 | { | ||
1015 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | 1067 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||
1016 | if (document.isNull()) { | 1068 | if (document.isNull()) { | ||
1017 | return FilesList(); | 1069 | return FilesList(); | ||
1018 | } | 1070 | } | ||
1019 | const QVariant data = document.toVariant(); | 1071 | const QVariant data = document.toVariant(); | ||
1020 | const QVariantMap map = data.toMap(); | 1072 | const QVariantMap map = data.toMap(); | ||
1021 | if (!map.contains(QStringLiteral("kind")) || | 1073 | if (!map.contains(File::Fields::Kind) || | ||
1022 | map[QStringLiteral("kind")].toString() != QLatin1String("drive#fileList")) | 1074 | map[Fields::Kind].toString() != QLatin1String("drive#fileList")) | ||
1023 | { | 1075 | { | ||
1024 | return FilesList(); | 1076 | return FilesList(); | ||
1025 | } | 1077 | } | ||
1026 | 1078 | | |||
1027 | FilesList list; | 1079 | FilesList list; | ||
1028 | const QVariantList items = map[QStringLiteral("items")].toList(); | 1080 | const QVariantList items = map[File::Fields::Items].toList(); | ||
1029 | for (const QVariant &item : items) { | 1081 | for (const QVariant &item : items) { | ||
1030 | const FilePtr file = Private::fromJSON(item.toMap()); | 1082 | const FilePtr file = Private::fromJSON(item.toMap()); | ||
1031 | 1083 | | |||
1032 | if (!file.isNull()) { | 1084 | if (!file.isNull()) { | ||
1033 | list << file; | 1085 | list << file; | ||
1034 | } | 1086 | } | ||
1035 | } | 1087 | } | ||
1036 | 1088 | | |||
1037 | if (map.contains(QStringLiteral("nextLink"))) { | 1089 | if (map.contains(File::Fields::NextLink)) { | ||
1038 | feedData.nextPageUrl = map[QStringLiteral("nextLink")].toUrl(); | 1090 | feedData.nextPageUrl = map[File::Fields::NextLink].toUrl(); | ||
1039 | } | 1091 | } | ||
1040 | 1092 | | |||
1041 | return list; | 1093 | return list; | ||
1042 | } | 1094 | } | ||
1043 | 1095 | | |||
1044 | QByteArray File::toJSON(const FilePtr &file, SerializationOptions options) | 1096 | QByteArray File::toJSON(const FilePtr &file, SerializationOptions options) | ||
1045 | { | 1097 | { | ||
1046 | QVariantMap map; | 1098 | QVariantMap map; | ||
1047 | 1099 | | |||
1048 | map[QStringLiteral("kind")] = QLatin1String("drive#file"); | 1100 | map[File::Fields::Kind] = QLatin1String("drive#file"); | ||
1049 | if (!file->description().isEmpty()) { | 1101 | if (!file->description().isEmpty()) { | ||
1050 | map[QStringLiteral("description")] = file->description(); | 1102 | map[Fields::Description] = file->description(); | ||
1051 | } | 1103 | } | ||
1052 | 1104 | | |||
1053 | if (file->indexableText() && !file->indexableText()->text().isEmpty()) { | 1105 | if (file->indexableText() && !file->indexableText()->text().isEmpty()) { | ||
1054 | QVariantMap indexableText; | 1106 | QVariantMap indexableText; | ||
1055 | indexableText[QStringLiteral("text")] = file->indexableText()->text(); | 1107 | indexableText[QStringLiteral("text")] = file->indexableText()->text(); | ||
1056 | map[QStringLiteral("indexableText")] = indexableText; | 1108 | map[Fields::IndexableText] = indexableText; | ||
1057 | } | 1109 | } | ||
1058 | 1110 | | |||
1059 | if (file->labels()) { | 1111 | if (file->labels()) { | ||
1060 | QVariantMap labels; | 1112 | QVariantMap labels; | ||
1061 | labels[QStringLiteral("hidden")] = file->labels()->hidden(); | 1113 | labels[QStringLiteral("hidden")] = file->labels()->hidden(); | ||
1062 | labels[QStringLiteral("restricted")] = file->labels()->restricted(); | 1114 | labels[QStringLiteral("restricted")] = file->labels()->restricted(); | ||
1063 | labels[QStringLiteral("starred")] = file->labels()->starred(); | 1115 | labels[QStringLiteral("starred")] = file->labels()->starred(); | ||
1064 | labels[QStringLiteral("trashed")] = file->labels()->trashed(); | 1116 | labels[QStringLiteral("trashed")] = file->labels()->trashed(); | ||
1065 | labels[QStringLiteral("viewed")] = file->labels()->viewed(); | 1117 | labels[QStringLiteral("viewed")] = file->labels()->viewed(); | ||
1066 | map[QStringLiteral("labels")] = labels; | 1118 | map[Fields::Labels] = labels; | ||
1067 | } | 1119 | } | ||
1068 | 1120 | | |||
1069 | if (file->lastViewedByMeDate().isValid()) { | 1121 | if (file->lastViewedByMeDate().isValid()) { | ||
1070 | map[QStringLiteral("lastViewedByMeDate")] = file->lastViewedByMeDate().toString(Qt::ISODate); | 1122 | map[Fields::LastViewedByMeDate] = file->lastViewedByMeDate().toString(Qt::ISODate); | ||
1071 | } | 1123 | } | ||
1072 | 1124 | | |||
1073 | if (!file->mimeType().isEmpty()) { | 1125 | if (!file->mimeType().isEmpty()) { | ||
1074 | map[QStringLiteral("mimeType")] = file->mimeType(); | 1126 | map[Fields::MimeType] = file->mimeType(); | ||
1075 | } | 1127 | } | ||
1076 | 1128 | | |||
1077 | if (file->modifiedDate().isValid()) { | 1129 | if (file->modifiedDate().isValid()) { | ||
1078 | map[QStringLiteral("modifiedDate")] = file->modifiedDate().toString(Qt::ISODate); | 1130 | map[Fields::ModifiedDate] = file->modifiedDate().toString(Qt::ISODate); | ||
1079 | } | 1131 | } | ||
1080 | if (file->createdDate().isValid() && !(options & ExcludeCreationDate)) { | 1132 | if (file->createdDate().isValid() && !(options & ExcludeCreationDate)) { | ||
1081 | map[QStringLiteral("createdDate")] = file->createdDate().toString(Qt::ISODate); | 1133 | map[Fields::CreatedDate] = file->createdDate().toString(Qt::ISODate); | ||
1082 | } | 1134 | } | ||
1083 | if (file->modifiedByMeDate().isValid()) { | 1135 | if (file->modifiedByMeDate().isValid()) { | ||
1084 | map[QStringLiteral("modifiedByMeDate")] = file->modifiedByMeDate().toString(Qt::ISODate); | 1136 | map[Fields::ModifiedByMeDate] = file->modifiedByMeDate().toString(Qt::ISODate); | ||
1085 | } | 1137 | } | ||
1086 | 1138 | | |||
1087 | if (file->fileSize() > 0) { | 1139 | if (file->fileSize() > 0) { | ||
1088 | map[QStringLiteral("fileSize")] = file->fileSize(); | 1140 | map[Fields::FileSize] = file->fileSize(); | ||
1089 | } | 1141 | } | ||
1090 | 1142 | | |||
1091 | if (!file->title().isEmpty()) { | 1143 | if (!file->title().isEmpty()) { | ||
1092 | map[QStringLiteral("title")] = file->title(); | 1144 | map[Fields::Title] = file->title(); | ||
1093 | } | 1145 | } | ||
1094 | 1146 | | |||
1095 | QVariantList parents; | 1147 | QVariantList parents; | ||
1096 | const auto parentReferences = file->parents(); | 1148 | const auto parentReferences = file->parents(); | ||
1097 | parents.reserve(parentReferences.size()); | 1149 | parents.reserve(parentReferences.size()); | ||
1098 | for (const ParentReferencePtr &parent : parentReferences) { | 1150 | for (const ParentReferencePtr &parent : parentReferences) { | ||
1099 | parents << ParentReference::Private::toJSON(parent); | 1151 | parents << ParentReference::Private::toJSON(parent); | ||
1100 | } | 1152 | } | ||
1101 | if (!parents.isEmpty()) { | 1153 | if (!parents.isEmpty()) { | ||
1102 | map[QStringLiteral("parents")] = parents; | 1154 | map[Fields::Parents] = parents; | ||
1103 | } | 1155 | } | ||
1104 | if (!file->etag().isEmpty()) { | 1156 | if (!file->etag().isEmpty()) { | ||
1105 | map[QStringLiteral("etag")] = file->etag(); | 1157 | map[Fields::Etag] = file->etag(); | ||
1106 | } | 1158 | } | ||
1107 | if (!file->d->id.isEmpty()) { | 1159 | if (!file->d->id.isEmpty()) { | ||
1108 | map[QStringLiteral("id")] = file->d->id; | 1160 | map[Fields::Id] = file->d->id; | ||
1109 | } | 1161 | } | ||
1110 | if (!file->d->selfLink.isEmpty()) { | 1162 | if (!file->d->selfLink.isEmpty()) { | ||
1111 | map[QStringLiteral("selfLink")] = file->d->selfLink; | 1163 | map[Fields::SelfLink] = file->d->selfLink; | ||
1112 | } | 1164 | } | ||
1113 | if (!file->d->downloadUrl.isEmpty()) { | 1165 | if (!file->d->downloadUrl.isEmpty()) { | ||
1114 | map[QStringLiteral("downloadUrl")] = file->d->downloadUrl; | 1166 | map[Fields::DownloadUrl] = file->d->downloadUrl; | ||
1115 | } | 1167 | } | ||
1116 | 1168 | | |||
1117 | if (!file->d->fileExtension.isEmpty()) { | 1169 | if (!file->d->fileExtension.isEmpty()) { | ||
1118 | map[QStringLiteral("fileExtension")] = file->d->fileExtension; | 1170 | map[Fields::FileExtension] = file->d->fileExtension; | ||
1119 | } | 1171 | } | ||
1120 | if (!file->d->md5Checksum.isEmpty()) { | 1172 | if (!file->d->md5Checksum.isEmpty()) { | ||
1121 | map[QStringLiteral("md5Checksum")] = file->d->md5Checksum; | 1173 | map[Fields::Md5Checksum] = file->d->md5Checksum; | ||
1122 | } | 1174 | } | ||
1123 | if (!file->d->alternateLink.isEmpty()) { | 1175 | if (!file->d->alternateLink.isEmpty()) { | ||
1124 | map[QStringLiteral("alternateLink")] = file->d->alternateLink; | 1176 | map[Fields::AlternateLink] = file->d->alternateLink; | ||
1125 | } | 1177 | } | ||
1126 | if (!file->d->embedLink.isEmpty()) { | 1178 | if (!file->d->embedLink.isEmpty()) { | ||
1127 | map[QStringLiteral("embedLink")] = file->d->embedLink; | 1179 | map[Fields::EmbedLink] = file->d->embedLink; | ||
1128 | } | 1180 | } | ||
1129 | if (!file->d->sharedWithMeDate.isNull()) { | 1181 | if (!file->d->sharedWithMeDate.isNull()) { | ||
1130 | map[QStringLiteral("sharedWithMeDate")] = file->d->sharedWithMeDate.toString(Qt::ISODate); | 1182 | map[Fields::SharedWithMeDate] = file->d->sharedWithMeDate.toString(Qt::ISODate); | ||
1131 | } | 1183 | } | ||
1132 | 1184 | | |||
1133 | 1185 | | |||
1134 | if (!file->d->originalFileName.isEmpty()) { | 1186 | if (!file->d->originalFileName.isEmpty()) { | ||
1135 | map[QStringLiteral("originalFileName")] = file->d->originalFileName; | 1187 | map[QStringLiteral("originalFileName")] = file->d->originalFileName; | ||
1136 | } | 1188 | } | ||
1137 | if (file->d->quotaBytesUsed > 0) { | 1189 | if (file->d->quotaBytesUsed > 0) { | ||
1138 | map[QStringLiteral("quotaBytesUsed")] = file->d->quotaBytesUsed; | 1190 | map[QStringLiteral("quotaBytesUsed")] = file->d->quotaBytesUsed; | ||
1139 | } | 1191 | } | ||
1140 | if (!file->d->ownerNames.isEmpty()) { | 1192 | if (!file->d->ownerNames.isEmpty()) { | ||
1141 | map[QStringLiteral("ownerNames")] = QVariant(file->d->ownerNames); | 1193 | map[Fields::OwnerNames] = QVariant(file->d->ownerNames); | ||
1142 | } | 1194 | } | ||
1143 | if (!file->d->lastModifyingUserName.isEmpty()) { | 1195 | if (!file->d->lastModifyingUserName.isEmpty()) { | ||
1144 | map[QStringLiteral("lastModifyingUserName")] = file->d->lastModifyingUserName; | 1196 | map[QStringLiteral("lastModifyingUserName")] = file->d->lastModifyingUserName; | ||
1145 | } | 1197 | } | ||
1146 | if (!file->d->editable) { // default is true | 1198 | if (!file->d->editable) { // default is true | ||
1147 | map[QStringLiteral("editable")] = file->d->editable; | 1199 | map[Fields::Editable] = file->d->editable; | ||
1148 | } | 1200 | } | ||
1149 | if (file->d->writersCanShare) { // default is false | 1201 | if (file->d->writersCanShare) { // default is false | ||
1150 | map[QStringLiteral("writersCanShare")] = file->d->writersCanShare; | 1202 | map[Fields::WritersCanShare] = file->d->writersCanShare; | ||
1151 | } | 1203 | } | ||
1152 | if (!file->d->thumbnailLink.isEmpty()) { | 1204 | if (!file->d->thumbnailLink.isEmpty()) { | ||
1153 | map[QStringLiteral("thumbnailLink")] = file->d->thumbnailLink; | 1205 | map[Fields::ThumbnailLink] = file->d->thumbnailLink; | ||
1154 | } | 1206 | } | ||
1155 | if (!file->d->lastViewedByMeDate.isNull()) { | 1207 | if (!file->d->lastViewedByMeDate.isNull()) { | ||
1156 | map[QStringLiteral("lastViewedByMeDate")] = file->d->lastViewedByMeDate.toString(Qt::ISODate); | 1208 | map[Fields::LastViewedByMeDate] = file->d->lastViewedByMeDate.toString(Qt::ISODate); | ||
1157 | } | 1209 | } | ||
1158 | if (!file->d->webContentLink.isEmpty()) { | 1210 | if (!file->d->webContentLink.isEmpty()) { | ||
1159 | map[QStringLiteral("webContentLink")] = file->d->webContentLink; | 1211 | map[Fields::WebContentLink] = file->d->webContentLink; | ||
1160 | } | 1212 | } | ||
1161 | if (file->d->explicitlyTrashed) { | 1213 | if (file->d->explicitlyTrashed) { | ||
1162 | map[QStringLiteral("explicitlyTrashed")] = file->d->explicitlyTrashed; | 1214 | map[Fields::ExplicitlyTrashed] = file->d->explicitlyTrashed; | ||
1163 | } | 1215 | } | ||
1164 | 1216 | | |||
1165 | if (!file->d->webViewLink.isEmpty()) { | 1217 | if (!file->d->webViewLink.isEmpty()) { | ||
1166 | map[QStringLiteral("webViewLink")] = file->d->webViewLink; | 1218 | map[Fields::WebViewLink] = file->d->webViewLink; | ||
1167 | } | 1219 | } | ||
1168 | if (!file->d->iconLink.isEmpty()) { | 1220 | if (!file->d->iconLink.isEmpty()) { | ||
1169 | map[QStringLiteral("iconLink")] = file->d->iconLink; | 1221 | map[Fields::IconLink] = file->d->iconLink; | ||
1170 | } | 1222 | } | ||
1171 | if (file->d->shared) { | 1223 | if (file->d->shared) { | ||
1172 | map[QStringLiteral("shared")] = file->d->shared; | 1224 | map[Fields::Shared] = file->d->shared; | ||
1173 | } | 1225 | } | ||
1174 | 1226 | | |||
1175 | #if 0 | 1227 | #if 0 | ||
1176 | const QVariantMap userPermissionData = map[QLatin1String("userPermission")].toMap(); | 1228 | const QVariantMap userPermissionData = map[QLatin1String("userPermission")].toMap(); | ||
1177 | file->d->userPermission = Permission::Private::fromJSON(userPermissionData); | 1229 | file->d->userPermission = Permission::Private::fromJSON(userPermissionData); | ||
1178 | 1230 | | |||
1179 | const QVariantList parents = map[QLatin1String("parents")].toList(); | 1231 | const QVariantList parents = map[QLatin1String("parents")].toList(); | ||
1180 | for (const QVariant &parent : parents) | 1232 | for (const QVariant &parent : parents) | ||
Show All 25 Lines | |||||
1206 | const QVariantMap lastModifyingUser = map[QLatin1String("lastModifyingUser")].toMap(); | 1258 | const QVariantMap lastModifyingUser = map[QLatin1String("lastModifyingUser")].toMap(); | ||
1207 | file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); | 1259 | file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); | ||
1208 | 1260 | | |||
1209 | #endif | 1261 | #endif | ||
1210 | 1262 | | |||
1211 | QJsonDocument document = QJsonDocument::fromVariant(map); | 1263 | QJsonDocument document = QJsonDocument::fromVariant(map); | ||
1212 | return document.toJson(QJsonDocument::Compact); | 1264 | return document.toJson(QJsonDocument::Compact); | ||
1213 | } | 1265 | } | ||
1214 | | ||||
1215 | | ||||
1216 | | ||||
1217 | | ||||
1218 | | ||||
1219 | |