diff --git a/src/drive/file.cpp b/src/drive/file.cpp index 42bb44f..d38cabe 100644 --- a/src/drive/file.cpp +++ b/src/drive/file.cpp @@ -1,1265 +1,1274 @@ /* Copyright 2012 Andrius da Costa Ribas Copyright 2013 Daniel Vrátil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "file.h" #include "file_p.h" #include "permission_p.h" #include "parentreference_p.h" #include "user.h" #include "utils_p.h" #include using namespace KGAPI2; using namespace KGAPI2::Drive; ///// DriveFile::Labels class Q_DECL_HIDDEN File::Labels::Private { public: Private(); Private(const Private &other); bool starred; bool hidden; bool trashed; bool restricted; bool viewed; }; File::Labels::Private::Private(): starred(false), hidden(false), trashed(false), restricted(false), viewed(false) { } File::Labels::Private::Private(const Private &other): starred(other.starred), hidden(other.hidden), trashed(other.trashed), restricted(other.restricted), viewed(other.viewed) { } File::Labels::Labels(): d(new Private) { } File::Labels::Labels(const Labels& other): d(new Private(*(other.d))) { } File::Labels::~Labels() { delete d; } bool File::Labels::operator==(const Labels &other) const { GAPI_COMPARE(starred) GAPI_COMPARE(hidden) GAPI_COMPARE(trashed) GAPI_COMPARE(restricted) GAPI_COMPARE(viewed) return true; } bool File::Labels::starred() const { return d->starred; } void File::Labels::setStarred(bool starred) { d->starred = starred; } bool File::Labels::hidden() const { return d->hidden; } void File::Labels::setHidden(bool hidden) { d->hidden = hidden; } bool File::Labels::trashed() const { return d->trashed; } void File::Labels::setTrashed(bool trashed) { d->trashed = trashed; } bool File::Labels::restricted() const { return d->restricted; } void File::Labels::setRestricted(bool restricted) { d->restricted = restricted; } bool File::Labels::viewed() const { return d->viewed; } void File::Labels::setViewed(bool viewed) { d->viewed = viewed; } ///// DriveFile::ImageMediaMetadata class Q_DECL_HIDDEN File::IndexableText::Private { public: Private(); Private(const Private &other); QString text; }; File::IndexableText::Private::Private() { } File::IndexableText::Private::Private(const Private &other): text(other.text) { } File::IndexableText::IndexableText(): d(new Private) { } File::IndexableText::IndexableText(const IndexableText& other): d(new Private(*(other.d))) { } File::IndexableText::~IndexableText() { delete d; } bool File::IndexableText::operator==(const IndexableText &other) const { GAPI_COMPARE(text) return true; } QString File::IndexableText::text() const { return d->text; } void File::IndexableText::setText(const QString &text) { d->text = text; } ///// DriveFile::ImageMediaMetadata::Location class Q_DECL_HIDDEN File::ImageMediaMetadata::Location::Private { public: Private(); Private(const Private &other); qreal latitude; qreal longitude; qreal altitude; }; File::ImageMediaMetadata::Location::Private::Private(): latitude(-1), longitude(-1), altitude(0) { } File::ImageMediaMetadata::Location::Private::Private(const Private &other): latitude(other.latitude), longitude(other.longitude), altitude(other.altitude) { } File::ImageMediaMetadata::Location::Location(): d(new Private) { } File::ImageMediaMetadata::Location::Location(const Location& other): d(new Private(*(other.d))) { } File::ImageMediaMetadata::Location::~Location() { delete d; } bool File::ImageMediaMetadata::Location::operator==(const Location &other) const { GAPI_COMPARE(latitude) GAPI_COMPARE(longitude) GAPI_COMPARE(altitude) return true; } qreal File::ImageMediaMetadata::Location::latitude() const { return d->latitude; } qreal File::ImageMediaMetadata::Location::longitude() const { return d->longitude; } qreal File::ImageMediaMetadata::Location::altitude() const { return d->altitude; } ///// DriveFile::ImageMediaMetadata class Q_DECL_HIDDEN File::ImageMediaMetadata::Private { public: Private(); Private(const Private &other); int width; int height; int rotation; LocationPtr location; QString date; QString cameraMake; QString cameraModel; float exposureTime; float aperture; bool flashUsed; float focalLength; int isoSpeed; QString meteringMode; QString sensor; QString exposureMode; QString colorSpace; QString whiteBalance; float exposureBias; float maxApertureValue; int subjectDistance; QString lens; }; File::ImageMediaMetadata::Private::Private(): width(-1), height(-1), rotation(-1), exposureTime(-1), aperture(-1), flashUsed(false), focalLength(-1), isoSpeed(-1), exposureBias(-1), maxApertureValue(-1), subjectDistance(-1) { } File::ImageMediaMetadata::Private::Private(const Private &other): width(other.width), height(other.height), rotation(other.rotation), location(other.location), date(other.date), cameraMake(other.cameraMake), cameraModel(other.cameraModel), exposureTime(other.exposureTime), aperture(other.aperture), flashUsed(other.flashUsed), focalLength(other.focalLength), isoSpeed(other.isoSpeed), meteringMode(other.meteringMode), sensor(other.sensor), exposureMode(other.exposureMode), colorSpace(other.colorSpace), whiteBalance(other.whiteBalance), exposureBias(other.exposureBias), maxApertureValue(other.maxApertureValue), subjectDistance(other.subjectDistance), lens(other.lens) { } File::ImageMediaMetadata::ImageMediaMetadata(const QVariantMap &map): d(new Private) { d->width = map[QStringLiteral("width")].toInt(); d->height = map[QStringLiteral("height")].toInt(); d->rotation = map[QStringLiteral("rotation")].toInt(); d->date = map[QStringLiteral("date")].toString(); d->cameraMake = map[QStringLiteral("cameraMake")].toString(); d->cameraModel = map[QStringLiteral("cameraModel")].toString(); d->exposureTime = map[QStringLiteral("exposureTime")].toFloat(); d->aperture = map[QStringLiteral("aperture")].toFloat(); d->flashUsed = map[QStringLiteral("flashUsed")].toBool(); d->focalLength = map[QStringLiteral("focalLength")].toFloat(); d->isoSpeed = map[QStringLiteral("isoSpeed")].toInt(); d->meteringMode = map[QStringLiteral("meteringMode")].toString(); d->sensor = map[QStringLiteral("sensor")].toString(); d->exposureMode = map[QStringLiteral("exposureMode")].toString(); d->colorSpace = map[QStringLiteral("colorSpace")].toString(); d->whiteBalance = map[QStringLiteral("whiteBalance")].toString(); d->exposureBias = map[QStringLiteral("exposureBias")].toFloat(); d->maxApertureValue = map[QStringLiteral("maxApertureValue")].toFloat(); d->subjectDistance = map[QStringLiteral("subjectDistance")].toFloat(); d->lens = map[QStringLiteral("lens")].toString(); const QVariantMap locationData = map[QStringLiteral("location")].toMap(); File::ImageMediaMetadata::LocationPtr location(new File::ImageMediaMetadata::Location); location->d->latitude = locationData[QStringLiteral("latitude")].toReal(); location->d->longitude = locationData[QStringLiteral("longitude")].toReal(); location->d->altitude = locationData[QStringLiteral("altitude")].toReal(); } File::ImageMediaMetadata::ImageMediaMetadata(const ImageMediaMetadata& other): d(new Private(*(other.d))) { } File::ImageMediaMetadata::~ImageMediaMetadata() { delete d; } bool File::ImageMediaMetadata::operator==(const ImageMediaMetadata &other) const { GAPI_COMPARE(width) GAPI_COMPARE(height) GAPI_COMPARE(rotation) GAPI_COMPARE_SHAREDPTRS(location) GAPI_COMPARE(date) GAPI_COMPARE(cameraMake) GAPI_COMPARE(cameraModel) GAPI_COMPARE(exposureTime) GAPI_COMPARE(aperture) GAPI_COMPARE(flashUsed) GAPI_COMPARE(focalLength) GAPI_COMPARE(isoSpeed) GAPI_COMPARE(meteringMode) GAPI_COMPARE(sensor) GAPI_COMPARE(exposureMode) GAPI_COMPARE(colorSpace) GAPI_COMPARE(whiteBalance) GAPI_COMPARE(exposureBias) GAPI_COMPARE(maxApertureValue) GAPI_COMPARE(subjectDistance) GAPI_COMPARE(lens) return true; } int File::ImageMediaMetadata::width() const { return d->width; } int File::ImageMediaMetadata::height() const { return d->height; } int File::ImageMediaMetadata::rotation() const { return d->rotation; } File::ImageMediaMetadata::LocationPtr File::ImageMediaMetadata::location() const { return d->location; } QString File::ImageMediaMetadata::date() const { return d->date; } QString File::ImageMediaMetadata::cameraMake() const { return d->cameraMake; } QString File::ImageMediaMetadata::cameraModel() const { return d->cameraModel; } float File::ImageMediaMetadata::exposureTime() const { return d->exposureTime; } float File::ImageMediaMetadata::aperture() const { return d->aperture; } bool File::ImageMediaMetadata::flashUsed() const { return d->flashUsed; } float File::ImageMediaMetadata::focalLength() const { return d->focalLength; } int File::ImageMediaMetadata::isoSpeed() const { return d->isoSpeed; } QString File::ImageMediaMetadata::meteringMode() const { return d->meteringMode; } QString File::ImageMediaMetadata::sensor() const { return d->sensor; } QString File::ImageMediaMetadata::exposureMode() const { return d->exposureMode; } QString File::ImageMediaMetadata::colorSpace() const { return d->colorSpace; } QString File::ImageMediaMetadata::whiteBalance() const { return d->whiteBalance; } float File::ImageMediaMetadata::exposureBias() const { return d->exposureBias; } float File::ImageMediaMetadata::maxApertureValue() const { return d->maxApertureValue; } int File::ImageMediaMetadata::subjectDistance() const { return d->subjectDistance; } QString File::ImageMediaMetadata::lens() const { return d->lens; } ////// DriveFile::Thumbnail class Q_DECL_HIDDEN File::Thumbnail::Private { public: Private(); Private(const Private &other); QImage image; QString mimeType; }; File::Thumbnail::Private::Private() { } File::Thumbnail::Private::Private(const Private &other): image(other.image), mimeType(other.mimeType) { } File::Thumbnail::Thumbnail(const QVariantMap &map): d(new Private) { const QByteArray ba = QByteArray::fromBase64(map[QStringLiteral("image")].toByteArray()); d->image = QImage::fromData(ba); d->mimeType = map[Fields::MimeType].toString(); } File::Thumbnail::Thumbnail(const File::Thumbnail &other): d(new Private(*(other.d))) { } File::Thumbnail::~Thumbnail() { delete d; } bool File::Thumbnail::operator==(const Thumbnail &other) const { GAPI_COMPARE(image) GAPI_COMPARE(mimeType) return true; } QImage File::Thumbnail::image() const { return d->image; } QString File::Thumbnail::mimeType() const { return d->mimeType; } ////// DriveFile File::Private::Private(): fileSize(-1), + version(-1), quotaBytesUsed(-1), editable(false), writersCanShare(false), explicitlyTrashed(false), shared(false) { } File::Private::Private(const Private& other): id(other.id), selfLink(other.selfLink), title(other.title), mimeType(other.mimeType), description(other.description), labels(other.labels), createdDate(other.createdDate), modifiedDate(other.modifiedDate), modifiedByMeDate(other.modifiedByMeDate), downloadUrl(other.downloadUrl), indexableText(other.indexableText), userPermission(other.userPermission), fileExtension(other.fileExtension), md5Checksum(other.md5Checksum), fileSize(other.fileSize), alternateLink(other.alternateLink), embedLink(other.embedLink), + version(other.version), sharedWithMeDate(other.sharedWithMeDate), parents(other.parents), exportLinks(other.exportLinks), originalFileName(other.originalFileName), quotaBytesUsed(other.quotaBytesUsed), ownerNames(other.ownerNames), lastModifyingUserName(other.lastModifyingUserName), editable(other.editable), writersCanShare(other.writersCanShare), thumbnailLink(other.thumbnailLink), lastViewedByMeDate(other.lastViewedByMeDate), webContentLink(other.webContentLink), explicitlyTrashed(other.explicitlyTrashed), imageMediaMetadata(other.imageMediaMetadata), thumbnail(other.thumbnail), webViewLink(other.webViewLink), iconLink(other.iconLink), shared(other.shared), owners(other.owners), lastModifyingUser(other.lastModifyingUser) { } bool File::operator==(const File &other) const { if (!Object::operator==(other)) { return false; } GAPI_COMPARE(id) GAPI_COMPARE(selfLink) GAPI_COMPARE(title) GAPI_COMPARE(mimeType) GAPI_COMPARE(description) GAPI_COMPARE_SHAREDPTRS(labels) GAPI_COMPARE(createdDate) GAPI_COMPARE(modifiedDate) GAPI_COMPARE(modifiedByMeDate) GAPI_COMPARE(downloadUrl) GAPI_COMPARE_SHAREDPTRS(indexableText) GAPI_COMPARE_SHAREDPTRS(userPermission) GAPI_COMPARE(fileExtension) GAPI_COMPARE(md5Checksum) GAPI_COMPARE(fileSize) GAPI_COMPARE(alternateLink) GAPI_COMPARE(embedLink) + GAPI_COMPARE(version) GAPI_COMPARE(sharedWithMeDate) GAPI_COMPARE_CONTAINERS(parents) GAPI_COMPARE(exportLinks) GAPI_COMPARE(originalFileName) GAPI_COMPARE(quotaBytesUsed) GAPI_COMPARE(ownerNames) GAPI_COMPARE(lastModifyingUserName) GAPI_COMPARE(editable) GAPI_COMPARE(writersCanShare) GAPI_COMPARE(thumbnailLink) GAPI_COMPARE(lastViewedByMeDate) GAPI_COMPARE(webContentLink) GAPI_COMPARE(explicitlyTrashed) GAPI_COMPARE_SHAREDPTRS(imageMediaMetadata) GAPI_COMPARE_SHAREDPTRS(thumbnail) GAPI_COMPARE(webViewLink) GAPI_COMPARE(iconLink) GAPI_COMPARE(shared) GAPI_COMPARE_CONTAINERS(owners) GAPI_COMPARE_SHAREDPTRS(lastModifyingUser) return true; } FilePtr File::Private::fromJSON(const QVariantMap &map) { if (!map.contains(File::Fields::Kind) || map[File::Fields::Kind].toString() != QLatin1String("drive#file")) { return FilePtr(); } FilePtr file(new File()); file->setEtag(map[Fields::Etag].toString()); file->d->id = map[Fields::Id].toString(); file->d->selfLink = map[Fields::SelfLink].toUrl(); file->d->title = map[Fields::Title].toString(); file->d->mimeType = map[Fields::MimeType].toString(); file->d->description = map[Fields::Description].toString(); const QVariantMap labelsData = map[Fields::Labels].toMap(); File::LabelsPtr labels(new File::Labels()); labels->d->starred = labelsData[QStringLiteral("starred")].toBool(); labels->d->hidden = labelsData[QStringLiteral("hidden")].toBool(); labels->d->trashed = labelsData[QStringLiteral("trashed")].toBool(); labels->d->restricted = labelsData[QStringLiteral("restricted")].toBool(); labels->d->viewed = labelsData[QStringLiteral("viewed")].toBool(); file->d->labels = labels; // FIXME FIXME FIXME Verify the date format file->d->createdDate = QDateTime::fromString(map[Fields::CreatedDate].toString(), Qt::ISODate); file->d->modifiedDate = QDateTime::fromString(map[Fields::ModifiedDate].toString(), Qt::ISODate); file->d->modifiedByMeDate = QDateTime::fromString(map[Fields::ModifiedByMeDate].toString(), Qt::ISODate); file->d->downloadUrl = map[Fields::DownloadUrl].toUrl(); const QVariantMap indexableTextData = map[Fields::IndexableText].toMap(); File::IndexableTextPtr indexableText(new File::IndexableText()); indexableText->d->text = indexableTextData[QStringLiteral("text")].toString(); file->d->indexableText = indexableText; const QVariantMap userPermissionData = map[Fields::UserPermission].toMap(); file->d->userPermission = Permission::Private::fromJSON(userPermissionData); file->d->fileExtension = map[Fields::FileExtension].toString(); file->d->md5Checksum = map[Fields::Md5Checksum].toString(); file->d->fileSize = map[Fields::FileSize].toLongLong(); file->d->alternateLink = map[Fields::AlternateLink].toUrl(); file->d->embedLink = map[Fields::EmbedLink].toUrl(); + file->d->version = map[Fields::Version].toLongLong(); file->d->sharedWithMeDate = QDateTime::fromString(map[Fields::SharedWithMeDate].toString(), Qt::ISODate); const QVariantList parents = map[Fields::Parents].toList(); for (const QVariant &parent : parents) { file->d->parents << ParentReference::Private::fromJSON(parent.toMap()); } const QVariantMap exportLinksData = map[Fields::ExportLinks].toMap(); QVariantMap::ConstIterator iter = exportLinksData.constBegin(); for ( ; iter != exportLinksData.constEnd(); ++iter) { file->d->exportLinks.insert(iter.key(), iter.value().toUrl()); } file->d->originalFileName = map[QStringLiteral("originalFileName")].toString(); file->d->quotaBytesUsed = map[QStringLiteral("quotaBytesUsed")].toLongLong(); file->d->ownerNames = map[Fields::OwnerNames].toStringList(); file->d->lastModifyingUserName = map[QStringLiteral("lastModifyingUserName")].toString(); file->d->editable = map[Fields::Editable].toBool(); file->d->writersCanShare = map[Fields::WritersCanShare].toBool(); file->d->thumbnailLink = map[Fields::ThumbnailLink].toUrl(); file->d->lastViewedByMeDate = QDateTime::fromString(map[Fields::LastViewedByMeDate].toString(), Qt::ISODate); file->d->webContentLink = map[Fields::WebContentLink].toUrl(); file->d->explicitlyTrashed = map[Fields::ExplicitlyTrashed].toBool(); const QVariantMap imageMetaData = map[Fields::ImageMediaMetadata].toMap(); file->d->imageMediaMetadata = File::ImageMediaMetadataPtr(new File::ImageMediaMetadata(imageMetaData)); const QVariantMap thumbnailData = map[Fields::Thumbnail].toMap(); File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData)); file->d->thumbnail = thumbnail; file->d->webViewLink = map[Fields::WebViewLink].toUrl(); file->d->iconLink = map[Fields::IconLink].toUrl(); file->d->shared = map[Fields::Shared].toBool(); const QVariantList ownersList = map[Fields::Owners].toList(); for (const QVariant &owner : ownersList) { file->d->owners << User::fromJSON(owner.toMap()); } const QVariantMap lastModifyingUser = map[Fields::LastModifyingUser].toMap(); file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); return file; } File::File(): KGAPI2::Object(), d(new Private) { } File::File(const File& other): KGAPI2::Object(other), d(new Private(*(other.d))) { } File::~File() { delete d; } QString File::folderMimeType() { return QStringLiteral("application/vnd.google-apps.folder"); } QString File::id() const { return d->id; } QUrl File::selfLink() const { return d->selfLink; } QString File::title() const { return d->title; } void File::setTitle(const QString& title) { d->title = title; } QString File::mimeType() const { return d->mimeType; } void File::setMimeType(const QString& mimeType) { d->mimeType = mimeType; } QString File::description() const { return d->description; } void File::setDescription(const QString& description) { d->description = description; } File::LabelsPtr File::labels() const { return d->labels; } void File::setLabels(const File::LabelsPtr &labels) { d->labels = labels; } QDateTime File::createdDate() const { return d->createdDate; } QDateTime File::modifiedDate() const { return d->modifiedDate; } void File::setModifiedDate(const QDateTime& modifiedDate) { d->modifiedDate = modifiedDate; } QDateTime File::modifiedByMeDate() const { return d->modifiedByMeDate; } QUrl File::downloadUrl() const { return d->downloadUrl; } File::IndexableTextPtr& File::indexableText() { return d->indexableText; } PermissionPtr File::userPermission() const { return d->userPermission; } QString File::fileExtension() const { return d->fileExtension; } QString File::md5Checksum() const { return d->md5Checksum; } qlonglong File::fileSize() const { return d->fileSize; } QUrl File::alternateLink() const { return d->alternateLink; } QUrl File::embedLink() const { return d->embedLink; } +qlonglong File::version() const +{ + return d->version; +} + QDateTime File::sharedWithMeDate() const { return d->sharedWithMeDate; } ParentReferencesList File::parents() const { return d->parents; } void File::setParents(const ParentReferencesList &parents) { d->parents = parents; } QMap< QString, QUrl > File::exportLinks() const { return d->exportLinks; } QString File::originalFileName() const { return d->originalFileName; } qlonglong File::quotaBytesUsed() const { return d->quotaBytesUsed; } QStringList File::ownerNames() const { return d->ownerNames; } QString File::lastModifyingUserName() const { return d->lastModifyingUserName; } bool File::editable() const { return d->editable; } bool File::writersCanShare() const { return d->writersCanShare; } QUrl File::thumbnailLink() const { return d->thumbnailLink; } QDateTime File::lastViewedByMeDate() const { return d->lastViewedByMeDate; } void File::setLastViewedByMeDate(const QDateTime& lastViewedByMeDate) { d->lastViewedByMeDate = lastViewedByMeDate; } QUrl File::webContentLink() const { return d->webContentLink; } bool File::explicitlyTrashed() const { return d->explicitlyTrashed; } File::ImageMediaMetadataPtr File::imageMediaMetadata() const { return d->imageMediaMetadata; } File::ThumbnailPtr File::thumbnail() const { return d->thumbnail; } QUrl File::webViewLink() const { return d->webViewLink; } QUrl File::iconLink() const { return d->iconLink; } bool File::shared() const { return d->shared; } UsersList File::owners() const { return d->owners; } UserPtr File::lastModifyingUser() const { return d->lastModifyingUser; } bool File::isFolder() const { return (d->mimeType == File::folderMimeType()); } const QString File::Fields::Kind = QStringLiteral("kind"); const QString File::Fields::Items = QStringLiteral("items"); const QString File::Fields::NextLink = QStringLiteral("nextLink"); const QString File::Fields::NextPageToken = QStringLiteral("nextPageToken"); const QString File::Fields::SelfLink = QStringLiteral("selfLink"); const QString File::Fields::Etag = QStringLiteral("etag"); const QString File::Fields::Id = QStringLiteral("id"); const QString File::Fields::Title = QStringLiteral("title"); const QString File::Fields::MimeType = QStringLiteral("mimeType"); const QString File::Fields::Description = QStringLiteral("description"); const QString File::Fields::Labels = QStringLiteral("labels"); const QString File::Fields::CreatedDate = QStringLiteral("createdDate"); const QString File::Fields::ModifiedDate = QStringLiteral("modifiedDate"); const QString File::Fields::ModifiedByMeDate = QStringLiteral("modifiedByMeDate"); const QString File::Fields::DownloadUrl = QStringLiteral("downloadUrl"); const QString File::Fields::IndexableText = QStringLiteral("indexableText"); const QString File::Fields::UserPermission = QStringLiteral("userPermission"); const QString File::Fields::FileExtension = QStringLiteral("fileExtension"); const QString File::Fields::Md5Checksum = QStringLiteral("md5Checksum"); const QString File::Fields::FileSize = QStringLiteral("fileSize"); const QString File::Fields::AlternateLink = QStringLiteral("alternateLink"); const QString File::Fields::EmbedLink = QStringLiteral("embedLink"); const QString File::Fields::SharedWithMeDate = QStringLiteral("sharedWithMeDate"); const QString File::Fields::Parents = QStringLiteral("parents"); const QString File::Fields::ExportLinks = QStringLiteral("exportLinks"); const QString File::Fields::OriginalFilename = QStringLiteral("originalFilename"); const QString File::Fields::OwnerNames = QStringLiteral("ownerNames"); const QString File::Fields::LastModifiedByMeDate = QStringLiteral("lastModifiedByMeDate"); const QString File::Fields::Editable = QStringLiteral("editable"); const QString File::Fields::WritersCanShare = QStringLiteral("writersCanShare"); const QString File::Fields::ThumbnailLink = QStringLiteral("thumbnailLink"); const QString File::Fields::LastViewedByMeDate = QStringLiteral("lastViewedByMeDate"); const QString File::Fields::WebContentLink = QStringLiteral("webContentLink"); const QString File::Fields::ExplicitlyTrashed = QStringLiteral("explicitlyTrashed"); const QString File::Fields::ImageMediaMetadata = QStringLiteral("imageMediaMetadata"); const QString File::Fields::Thumbnail = QStringLiteral("thumbnail"); const QString File::Fields::WebViewLink = QStringLiteral("webViewLink"); const QString File::Fields::IconLink = QStringLiteral("iconLink"); const QString File::Fields::Shared = QStringLiteral("shared"); const QString File::Fields::Owners = QStringLiteral("owners"); const QString File::Fields::LastModifyingUser = QStringLiteral("lastModifyingUser"); const QString File::Fields::AppDataContents = QStringLiteral("appDataContents"); const QString File::Fields::OpenWithLinks = QStringLiteral("openWithLinks"); const QString File::Fields::DefaultOpenWithLink = QStringLiteral("defaultOpenWithLink"); const QString File::Fields::HeadRevisionId = QStringLiteral("headRevisionId"); const QString File::Fields::Copyable = QStringLiteral("copyable"); const QString File::Fields::Properties = QStringLiteral("properties"); const QString File::Fields::MarkedViewedByMeDate = QStringLiteral("markedViewedByMeDate"); const QString File::Fields::Version = QStringLiteral("version"); const QString File::Fields::SharingUser = QStringLiteral("sharingUser"); const QString File::Fields::Permissions = QStringLiteral("permissions"); FilePtr File::fromJSON(const QByteArray &jsonData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return FilePtr(); } const QVariant data = document.toVariant(); return Private::fromJSON(data.toMap()); } FilePtr File::fromJSON(const QVariantMap &jsonData) { if (jsonData.isEmpty()) { return FilePtr(); } return Private::fromJSON(jsonData); } FilesList File::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return FilesList(); } const QVariant data = document.toVariant(); const QVariantMap map = data.toMap(); if (!map.contains(File::Fields::Kind) || map[Fields::Kind].toString() != QLatin1String("drive#fileList")) { return FilesList(); } FilesList list; const QVariantList items = map[File::Fields::Items].toList(); for (const QVariant &item : items) { const FilePtr file = Private::fromJSON(item.toMap()); if (!file.isNull()) { list << file; } } if (map.contains(File::Fields::NextLink)) { feedData.nextPageUrl = map[File::Fields::NextLink].toUrl(); } return list; } QByteArray File::toJSON(const FilePtr &file, SerializationOptions options) { QVariantMap map; map[File::Fields::Kind] = QLatin1String("drive#file"); if (!file->description().isEmpty()) { map[Fields::Description] = file->description(); } if (file->indexableText() && !file->indexableText()->text().isEmpty()) { QVariantMap indexableText; indexableText[QStringLiteral("text")] = file->indexableText()->text(); map[Fields::IndexableText] = indexableText; } if (file->labels()) { QVariantMap labels; labels[QStringLiteral("hidden")] = file->labels()->hidden(); labels[QStringLiteral("restricted")] = file->labels()->restricted(); labels[QStringLiteral("starred")] = file->labels()->starred(); labels[QStringLiteral("trashed")] = file->labels()->trashed(); labels[QStringLiteral("viewed")] = file->labels()->viewed(); map[Fields::Labels] = labels; } if (file->lastViewedByMeDate().isValid()) { map[Fields::LastViewedByMeDate] = file->lastViewedByMeDate().toString(Qt::ISODate); } if (!file->mimeType().isEmpty()) { map[Fields::MimeType] = file->mimeType(); } if (file->modifiedDate().isValid()) { map[Fields::ModifiedDate] = file->modifiedDate().toString(Qt::ISODate); } if (file->createdDate().isValid() && !(options & ExcludeCreationDate)) { map[Fields::CreatedDate] = file->createdDate().toString(Qt::ISODate); } if (file->modifiedByMeDate().isValid()) { map[Fields::ModifiedByMeDate] = file->modifiedByMeDate().toString(Qt::ISODate); } if (file->fileSize() > 0) { map[Fields::FileSize] = file->fileSize(); } if (!file->title().isEmpty()) { map[Fields::Title] = file->title(); } QVariantList parents; const auto parentReferences = file->parents(); parents.reserve(parentReferences.size()); for (const ParentReferencePtr &parent : parentReferences) { parents << ParentReference::Private::toJSON(parent); } if (!parents.isEmpty()) { map[Fields::Parents] = parents; } if (!file->etag().isEmpty()) { map[Fields::Etag] = file->etag(); } if (!file->d->id.isEmpty()) { map[Fields::Id] = file->d->id; } if (!file->d->selfLink.isEmpty()) { map[Fields::SelfLink] = file->d->selfLink; } if (!file->d->downloadUrl.isEmpty()) { map[Fields::DownloadUrl] = file->d->downloadUrl; } if (!file->d->fileExtension.isEmpty()) { map[Fields::FileExtension] = file->d->fileExtension; } if (!file->d->md5Checksum.isEmpty()) { map[Fields::Md5Checksum] = file->d->md5Checksum; } if (!file->d->alternateLink.isEmpty()) { map[Fields::AlternateLink] = file->d->alternateLink; } if (!file->d->embedLink.isEmpty()) { map[Fields::EmbedLink] = file->d->embedLink; } if (!file->d->sharedWithMeDate.isNull()) { map[Fields::SharedWithMeDate] = file->d->sharedWithMeDate.toString(Qt::ISODate); } if (!file->d->originalFileName.isEmpty()) { map[QStringLiteral("originalFileName")] = file->d->originalFileName; } if (file->d->quotaBytesUsed > 0) { map[QStringLiteral("quotaBytesUsed")] = file->d->quotaBytesUsed; } if (!file->d->ownerNames.isEmpty()) { map[Fields::OwnerNames] = QVariant(file->d->ownerNames); } if (!file->d->lastModifyingUserName.isEmpty()) { map[QStringLiteral("lastModifyingUserName")] = file->d->lastModifyingUserName; } if (!file->d->editable) { // default is true map[Fields::Editable] = file->d->editable; } if (file->d->writersCanShare) { // default is false map[Fields::WritersCanShare] = file->d->writersCanShare; } if (!file->d->thumbnailLink.isEmpty()) { map[Fields::ThumbnailLink] = file->d->thumbnailLink; } if (!file->d->lastViewedByMeDate.isNull()) { map[Fields::LastViewedByMeDate] = file->d->lastViewedByMeDate.toString(Qt::ISODate); } if (!file->d->webContentLink.isEmpty()) { map[Fields::WebContentLink] = file->d->webContentLink; } if (file->d->explicitlyTrashed) { map[Fields::ExplicitlyTrashed] = file->d->explicitlyTrashed; } if (!file->d->webViewLink.isEmpty()) { map[Fields::WebViewLink] = file->d->webViewLink; } if (!file->d->iconLink.isEmpty()) { map[Fields::IconLink] = file->d->iconLink; } if (file->d->shared) { map[Fields::Shared] = file->d->shared; } #if 0 const QVariantMap userPermissionData = map[QLatin1String("userPermission")].toMap(); file->d->userPermission = Permission::Private::fromJSON(userPermissionData); const QVariantList parents = map[QLatin1String("parents")].toList(); for (const QVariant &parent : parents) { file->d->parents << ParentReference::Private::fromJSON(parent.toMap()); } const QVariantMap exportLinksData = map[QLatin1String("exportLinks")].toMap(); QVariantMap::ConstIterator iter = exportLinksData.constBegin(); for ( ; iter != exportLinksData.constEnd(); ++iter) { file->d->exportLinks.insert(iter.key(), iter.value().toUrl()); } const QVariantMap imageMetaData = map[QLatin1String("imageMediaMetadata")].toMap(); file->d->imageMediaMetadata = File::ImageMediaMetadataPtr(new File::ImageMediaMetadata(imageMetaData)); const QVariantMap thumbnailData = map[QLatin1String("thumbnail")].toMap(); File::ThumbnailPtr thumbnail(new File::Thumbnail(thumbnailData)); file->d->thumbnail = thumbnail; const QVariantList ownersList = map[QLatin1String("owners")].toList(); for (const QVariant &owner : ownersList) { file->d->owners << User::fromJSON(owner.toMap()); } const QVariantMap lastModifyingUser = map[QLatin1String("lastModifyingUser")].toMap(); file->d->lastModifyingUser = User::fromJSON(lastModifyingUser); #endif QJsonDocument document = QJsonDocument::fromVariant(map); return document.toJson(QJsonDocument::Compact); } diff --git a/src/drive/file.h b/src/drive/file.h index 331d692..f1c53b5 100644 --- a/src/drive/file.h +++ b/src/drive/file.h @@ -1,679 +1,684 @@ /* Copyright 2012 Andrius da Costa Ribas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef LIBKGAPI2_DRIVEFILE_H #define LIBKGAPI2_DRIVEFILE_H #include "object.h" #include "types.h" #include "change.h" #include #include #include #include #include #include namespace KGAPI2 { namespace Drive { /** * @brief File contains metadata for a file. * Getters and setters' documentation is based on Google Drive's API v2 reference * @see Files * * @since 2.0 * @author Andrius da Costa Ribas * @author Daniel Vrátil */ class KGAPIDRIVE_EXPORT File: public KGAPI2::Object { private: class Private; public: /** * @brief DriveFile::Labels holds the structure used for labels property. */ class Labels { public: explicit Labels(); explicit Labels(const Labels &other); virtual ~Labels(); bool operator==(const Labels &other) const; bool operator!=(const Labels &other) const { return !operator==(other); } /** * @brief Returns whether this file is starred by the user. */ bool starred() const; /** * @brief Sets whether this file is starred by the user. * * @param starred */ void setStarred(bool starred); /** * @brief Returns whether this file has the 'hidden' label set. * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one. * You can just ignore it. */ #ifndef KGAPIDRIVE_NO_DEPRECATED KGAPIDRIVE_DEPRECATED bool hidden() const; #endif /** * @brief Sets whether this file has the 'hidden' label set. * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one. */ #ifndef KGAPIDRIVE_NO_DEPRECATED KGAPIDRIVE_DEPRECATED void setHidden(bool hidden); #endif /** * @brief Returns whether this file has been trashed. */ bool trashed() const; /** * @brief Sets whether this file has been trashed. * * @param trashed */ void setTrashed(bool trashed); /** * @brief Returns whether viewers are prevented from downloading this file. */ bool restricted() const; /** * @brief Sets whether viewers are prevented from downloading this file. * * @param restricted */ void setRestricted(bool restricted); /** * @brief Returns whether this file has been viewed by this user. */ bool viewed() const; /** * @brief Sets whether this file has been viewed by this user. * * @param viewed */ void setViewed(bool viewed); private: class Private; Private *const d; friend class Private; friend class File::Private; }; typedef QSharedPointer LabelsPtr; typedef QList LabelsList; /** * @brief DriveFile::IndexableText holds the structure used for indexableText property. */ class IndexableText { public: explicit IndexableText(const IndexableText &other); virtual ~IndexableText(); bool operator==(const IndexableText &other) const; bool operator!=(const IndexableText &other) const { return !operator==(other); } /** * @brief Returns the text to be indexed for this file. */ QString text() const; /** * @brief Sets the text to be indexed for this file. * * @param text */ void setText(const QString &text); private: explicit IndexableText(); class Private; Private *const d; friend class Private; friend class File::Private; }; typedef QSharedPointer IndexableTextPtr; /** * @brief DriveFile::ImageMediaMetadata holds the structure used for * imageMediaMetadata property. */ class ImageMediaMetadata { public: /** * @brief DriveFile::ImageMediaMetadata::Location holds the structure used * for imageMediaMetadata.location property. */ class Location { public: explicit Location(const Location &other); virtual ~Location(); bool operator==(const Location &other) const; bool operator!=(const Location &other) const { return !operator==(other); } /** * @brief Returns the latitude stored in the image. */ qreal latitude() const; /** * @brief Returns the longitude stored in the image. */ qreal longitude() const; /** * @brief Returns the altitude stored in the image. */ qreal altitude() const; private: explicit Location(); class Private; Private *const d; friend class Private; friend class ImageMediaMetadata; }; typedef QSharedPointer LocationPtr; explicit ImageMediaMetadata(const ImageMediaMetadata &other); virtual ~ImageMediaMetadata(); bool operator==(const ImageMediaMetadata &other) const; bool operator!=(const ImageMediaMetadata &other) const { return !operator==(other); } /** * @brief Returns the width of the image in pixels. */ int width() const; /** * @brief Returns the height of the image in pixels. */ int height() const; /** * @brief Returns the rotation in clockwise degrees from the image's original orientation. */ int rotation() const; /** * @brief Returns the geographic location information stored in the image. */ LocationPtr location() const; QString date() const; QString cameraMake() const; QString cameraModel() const; float exposureTime() const; float aperture() const; bool flashUsed() const; float focalLength() const; int isoSpeed() const; QString meteringMode() const; QString sensor() const; QString exposureMode() const; QString colorSpace() const; QString whiteBalance() const; float exposureBias() const; float maxApertureValue() const; int subjectDistance() const; QString lens() const; private: explicit ImageMediaMetadata(const QVariantMap &jsonMap); class Private; Private *const d; friend class Private; friend class File::Private; }; typedef QSharedPointer ImageMediaMetadataPtr; class Thumbnail { public: explicit Thumbnail(const Thumbnail &other); virtual ~Thumbnail(); bool operator==(const Thumbnail &other) const; bool operator!=(const Thumbnail &other) const { return !operator==(other); } QImage image() const; QString mimeType() const; private: explicit Thumbnail(const QVariantMap &jsonMap); class Private; Private * const d; friend class Private; friend class File::Private; }; typedef QSharedPointer ThumbnailPtr; /** * @brief JSON serialization options. * @since 5.3.1 */ enum SerializationOption { NoOptions = 0, ///< No option set. ExcludeCreationDate = 1 ///< Exclude 'createdDate' entry. This is necessary when renaming URLs. }; Q_DECLARE_FLAGS(SerializationOptions, SerializationOption) explicit File(); explicit File(const File &other); virtual ~File(); bool operator==(const File &other) const; bool operator!=(const File &other) const { return !operator==(other); } /** * @brief Returns mimetype of folders */ static QString folderMimeType(); /** * @brief Returns the id of the file. */ QString id() const; /** * @brief Returns a link back to this file. */ QUrl selfLink() const; /** * @brief Returns the title of this file. * * Used to identify file or folder name. */ QString title() const; /** * @brief Sets the title of this file. * * Used to identify file or folder name. * * @param title */ void setTitle(const QString &title); /** * @brief Returns the MIME type of the file. */ QString mimeType() const; /** * @brief Sets the MIME type of the file. * * @param mimeType */ void setMimeType(const QString &mimeType); /** * @brief Returns a short description of the file. */ QString description() const; /** * @brief Sets a short description of the file. * * @param description */ void setDescription(const QString &description); /** * @brief Returns a group of labels for the file. */ File::LabelsPtr labels() const; /** * @brief Sets a group of labels for the file. * * @param labels */ void setLabels(const LabelsPtr &labels); /** * @brief Returns the create time for this file. */ QDateTime createdDate() const; /** * @brief Returns the last time this file was modified by anyone. * * This is only mutable on update when the setModifiedDate parameter is set. */ QDateTime modifiedDate() const; /** * @brief Sets the last time this file was modified by anyone. * * This is only mutable on update when the setModifiedDate parameter is set. * * @param modifiedDate */ void setModifiedDate(const QDateTime &modifiedDate); /** * @brief Returns the last time this file was modified by the currently * authenticated user. */ QDateTime modifiedByMeDate() const; /** * @brief Returns a short lived download URL for the file. * * This is only populated for files with content stored in Drive. */ QUrl downloadUrl() const; /** * @brief Returns the indexable text attributes for the file. * * This property can only be written, and is not returned by files.get */ File::IndexableTextPtr& indexableText(); /** * @brief Returns the permissions for the authenticated user on this file. */ PermissionPtr userPermission() const; /** * @brief Returns the file extension used when downloading this file. * * This field is read only. To set the extension, include it on title when creating the file. * This is populated only for files with content stored in Drive. */ QString fileExtension() const; /** * @brief Returns an MD5 checksum for the content of this file. * * This is populated only for files with content stored in Drive. */ QString md5Checksum() const; /** * @brief Returns the size of the file in bytes. * * This is populated only for files with content stored in Drive. */ qlonglong fileSize() const; /** * @brief Returns a link for opening the file in using a relevant * Google editor or viewer. */ QUrl alternateLink() const; /** * @brief Returns a link for embedding the file. */ QUrl embedLink() const; + /** + * @brief Returns the version of the file; + */ + qlonglong version() const; + /** * @brief Returns the time at which this file was shared with the user. */ QDateTime sharedWithMeDate() const; /** * @brief Returns the collection of parent folders which contain this file. * * Setting this field will put the file in all of the provided folders. * On insert, if no folders are provided, the file will be placed in the * default root folder. */ ParentReferencesList parents() const; /** * @brief Sets the collection of parent folders which contain this file. * * Setting this field will put the file in all of the provided folders. * On insert, if no folders are provided, the file will be placed in the * default root folder. * * @param parents */ void setParents(const ParentReferencesList &parents); /** * @brief Returns the links for exporting Google Docs to specific formats. * * This is a map from the export format to URL. */ QMap < QString /* format */, QUrl /* url */ > exportLinks() const; /** * @brief Returns the original filename if the file was uploaded manually, * or the original title if the file was inserted through the API. * * Note that renames of the title will not change the original filename. * This will only be populated on files with content stored in Drive. */ QString originalFileName() const; /** * @brief Returns the number of quota bytes used by this file. */ qlonglong quotaBytesUsed() const; /** * @brief Return the name(s) of the owner(s) of this file. */ QStringList ownerNames() const; /** * @brief Returns the name of the last user to modify this file. * * This will only be populated if a user has edited this file. */ QString lastModifyingUserName() const; /** * @brief Returns whether the file can be edited by the current user. */ bool editable() const; /** * @brief Returns whether writers can share the document with other users. */ bool writersCanShare() const; /** * @brief Returns a link to the file's thumbnail. */ QUrl thumbnailLink() const; /** * @brief Returns the last time this file was viewed by the user. */ QDateTime lastViewedByMeDate() const; /** * @brief Sets the last time this file was viewed by the user. * * @param lastViewedByMeDate */ void setLastViewedByMeDate(const QDateTime &lastViewedByMeDate); /** * @brief Returns a link for downloading the content of the file in a browser * using cookie based authentication. * * In cases where the content is shared publicly, the content can be * downloaded without any credentials. */ QUrl webContentLink() const; /** * @brief Returns whether this file has been explicitly trashed, as opposed * to recursively trashed. * * This will only be populated if the file is trashed. */ bool explicitlyTrashed() const; /** * @brief Returns metadata about image media. * * This will only be present for image types, and its contents will depend * on what can be parsed from the image content. */ File::ImageMediaMetadataPtr imageMediaMetadata() const; /** * @brief Returns thumbnail for the file. */ ThumbnailPtr thumbnail() const; QUrl webViewLink() const; QUrl iconLink() const; bool shared() const; UsersList owners() const; UserPtr lastModifyingUser() const; bool isFolder() const; struct Fields { static const QString Items; static const QString SelfLink; static const QString Etag; static const QString Kind; static const QString NextLink; static const QString NextPageToken; static const QString Id; static const QString Title; static const QString MimeType; static const QString Description; static const QString Labels; static const QString CreatedDate; static const QString ModifiedDate; static const QString ModifiedByMeDate; static const QString DownloadUrl; static const QString IndexableText; static const QString UserPermission; static const QString FileExtension; static const QString Md5Checksum; static const QString FileSize; static const QString AlternateLink; static const QString EmbedLink; static const QString SharedWithMeDate; static const QString Parents; static const QString ExportLinks; static const QString OriginalFilename; static const QString OwnerNames; static const QString LastModifiedByMeDate; static const QString Editable; static const QString WritersCanShare; static const QString ThumbnailLink; static const QString LastViewedByMeDate; static const QString WebContentLink; static const QString ExplicitlyTrashed; static const QString ImageMediaMetadata; static const QString Thumbnail; static const QString WebViewLink; static const QString IconLink; static const QString Shared; static const QString Owners; static const QString LastModifyingUser; static const QString AppDataContents; static const QString OpenWithLinks; static const QString DefaultOpenWithLink; static const QString HeadRevisionId; static const QString Copyable; static const QString Properties; static const QString MarkedViewedByMeDate; static const QString Version; static const QString SharingUser; static const QString Permissions; }; static FilePtr fromJSON(const QByteArray &jsonData); static FilesList fromJSONFeed(const QByteArray &jsonData, FeedData &feedData); static QByteArray toJSON(const FilePtr &file, SerializationOptions options = NoOptions); static FilePtr fromJSON(const QVariantMap &jsonData); private: Private * const d; friend class Private; friend class Change::Private; friend class ParentReference; friend class Permission; }; } /* namespace Drive */ } /* namespace KGAPI2 */ Q_DECLARE_OPERATORS_FOR_FLAGS(KGAPI2::Drive::File::SerializationOptions) #endif // LIBKGAPI2_DRIVEFILE_H diff --git a/src/drive/file_p.h b/src/drive/file_p.h index 38fd177..e5ff7ea 100644 --- a/src/drive/file_p.h +++ b/src/drive/file_p.h @@ -1,86 +1,87 @@ /* Copyright 2012 Andrius da Costa Ribas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef LIBKGAPI2_DRIVEFILE_P_H #define LIBKGAPI2_DRIVEFILE_P_H #include "file.h" #include namespace KGAPI2 { namespace Drive { class Q_DECL_HIDDEN File::Private { public: Private(); Private(const Private &other); QString id; QUrl selfLink; QString title; QString mimeType; QString description; LabelsPtr labels; QDateTime createdDate; QDateTime modifiedDate; QDateTime modifiedByMeDate; QUrl downloadUrl; IndexableTextPtr indexableText; PermissionPtr userPermission; QString fileExtension; QString md5Checksum; qlonglong fileSize; QUrl alternateLink; QUrl embedLink; + qlonglong version; QDateTime sharedWithMeDate; ParentReferencesList parents; QMap exportLinks; QString originalFileName; qlonglong quotaBytesUsed; QList ownerNames; QString lastModifyingUserName; bool editable; bool writersCanShare; QUrl thumbnailLink; QDateTime lastViewedByMeDate; QUrl webContentLink; bool explicitlyTrashed; ImageMediaMetadataPtr imageMediaMetadata; ThumbnailPtr thumbnail; QUrl webViewLink; QUrl iconLink; bool shared; UsersList owners; UserPtr lastModifyingUser; static FilePtr fromJSON(const QVariantMap &map); }; } // namespace Drive } // namespace KGAPI2 #endif // LIBKGAPI2_DRIVEFILE_P_H