File indexing completed on 2024-05-12 05:22:19
0001 /* 0002 SPDX-FileCopyrightText: 2012 Andrius da Costa Ribas <andriusmao@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "change.h" 0010 #include "object.h" 0011 #include "types.h" 0012 0013 #include <QImage> 0014 #include <QString> 0015 #include <QStringList> 0016 #include <QUrl> 0017 #include <QVariantMap> 0018 0019 #include <QDateTime> 0020 0021 namespace KGAPI2 0022 { 0023 0024 namespace Drive 0025 { 0026 0027 /** 0028 * @brief File contains metadata for a file. 0029 * Getters and setters' documentation is based on Google Drive's API v2 reference 0030 * @see <a href="https://developers.google.com/drive/v2/reference/files">Files</a> 0031 * 0032 * @since 2.0 0033 * @author Andrius da Costa Ribas <andriusmao@gmail.com> 0034 * @author Daniel Vrátil <dvratil@redhat.com> 0035 */ 0036 class KGAPIDRIVE_EXPORT File : public KGAPI2::Object 0037 { 0038 private: 0039 class Private; 0040 0041 public: 0042 /** 0043 * @brief DriveFile::Labels holds the structure used for labels property. 0044 */ 0045 class Labels 0046 { 0047 public: 0048 explicit Labels(); 0049 explicit Labels(const Labels &other); 0050 virtual ~Labels(); 0051 bool operator==(const Labels &other) const; 0052 bool operator!=(const Labels &other) const 0053 { 0054 return !operator==(other); 0055 } 0056 0057 /** 0058 * @brief Returns whether this file is starred by the user. 0059 */ 0060 [[nodiscard]] bool starred() const; 0061 0062 /** 0063 * @brief Sets whether this file is starred by the user. 0064 * 0065 * @param starred 0066 */ 0067 void setStarred(bool starred); 0068 0069 /** 0070 * @brief Returns whether this file has the 'hidden' label set. 0071 * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one. 0072 * You can just ignore it. 0073 */ 0074 #ifndef KGAPIDRIVE_NO_DEPRECATED 0075 KGAPIDRIVE_DEPRECATED bool hidden() const; 0076 #endif 0077 0078 /** 0079 * @brief Sets whether this file has the 'hidden' label set. 0080 * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one. 0081 */ 0082 #ifndef KGAPIDRIVE_NO_DEPRECATED 0083 KGAPIDRIVE_DEPRECATED void setHidden(bool hidden); 0084 #endif 0085 0086 /** 0087 * @brief Returns whether this file has been trashed. 0088 */ 0089 bool trashed() const; 0090 0091 /** 0092 * @brief Sets whether this file has been trashed. 0093 * 0094 * @param trashed 0095 */ 0096 void setTrashed(bool trashed); 0097 0098 /** 0099 * @brief Returns whether viewers are prevented from downloading this file. 0100 */ 0101 bool restricted() const; 0102 0103 /** 0104 * @brief Sets whether viewers are prevented from downloading this file. 0105 * 0106 * @param restricted 0107 */ 0108 void setRestricted(bool restricted); 0109 0110 /** 0111 * @brief Returns whether this file has been viewed by this user. 0112 */ 0113 [[nodiscard]] bool viewed() const; 0114 0115 /** 0116 * @brief Sets whether this file has been viewed by this user. 0117 * 0118 * @param viewed 0119 */ 0120 void setViewed(bool viewed); 0121 0122 private: 0123 class Private; 0124 Private *const d; 0125 friend class Private; 0126 friend class File::Private; 0127 }; 0128 0129 using LabelsPtr = QSharedPointer<Labels>; 0130 using LabelsList = QList<LabelsPtr>; 0131 0132 /** 0133 * @brief DriveFile::IndexableText holds the structure used for indexableText property. 0134 */ 0135 class IndexableText 0136 { 0137 public: 0138 explicit IndexableText(const IndexableText &other); 0139 virtual ~IndexableText(); 0140 bool operator==(const IndexableText &other) const; 0141 bool operator!=(const IndexableText &other) const 0142 { 0143 return !operator==(other); 0144 } 0145 0146 /** 0147 * @brief Returns the text to be indexed for this file. 0148 */ 0149 [[nodiscard]] QString text() const; 0150 0151 /** 0152 * @brief Sets the text to be indexed for this file. 0153 * 0154 * @param text 0155 */ 0156 void setText(const QString &text); 0157 0158 private: 0159 explicit IndexableText(); 0160 0161 class Private; 0162 Private *const d; 0163 friend class Private; 0164 friend class File::Private; 0165 }; 0166 0167 using IndexableTextPtr = QSharedPointer<IndexableText>; 0168 0169 /** 0170 * @brief DriveFile::ImageMediaMetadata holds the structure used for 0171 * imageMediaMetadata property. 0172 */ 0173 class ImageMediaMetadata 0174 { 0175 public: 0176 /** 0177 * @brief DriveFile::ImageMediaMetadata::Location holds the structure used 0178 * for imageMediaMetadata.location property. 0179 */ 0180 class Location 0181 { 0182 public: 0183 explicit Location(const Location &other); 0184 virtual ~Location(); 0185 bool operator==(const Location &other) const; 0186 bool operator!=(const Location &other) const 0187 { 0188 return !operator==(other); 0189 } 0190 0191 /** 0192 * @brief Returns the latitude stored in the image. 0193 */ 0194 [[nodiscard]] qreal latitude() const; 0195 0196 /** 0197 * @brief Returns the longitude stored in the image. 0198 */ 0199 [[nodiscard]] qreal longitude() const; 0200 0201 /** 0202 * @brief Returns the altitude stored in the image. 0203 */ 0204 [[nodiscard]] qreal altitude() const; 0205 0206 private: 0207 explicit Location(); 0208 0209 class Private; 0210 Private *const d; 0211 friend class Private; 0212 friend class ImageMediaMetadata; 0213 }; 0214 0215 using LocationPtr = QSharedPointer<Location>; 0216 0217 explicit ImageMediaMetadata(const ImageMediaMetadata &other); 0218 virtual ~ImageMediaMetadata(); 0219 bool operator==(const ImageMediaMetadata &other) const; 0220 bool operator!=(const ImageMediaMetadata &other) const 0221 { 0222 return !operator==(other); 0223 } 0224 0225 /** 0226 * @brief Returns the width of the image in pixels. 0227 */ 0228 [[nodiscard]] int width() const; 0229 0230 /** 0231 * @brief Returns the height of the image in pixels. 0232 */ 0233 [[nodiscard]] int height() const; 0234 0235 /** 0236 * @brief Returns the rotation in clockwise degrees from the image's original orientation. 0237 */ 0238 [[nodiscard]] int rotation() const; 0239 0240 /** 0241 * @brief Returns the geographic location information stored in the image. 0242 */ 0243 [[nodiscard]] LocationPtr location() const; 0244 0245 [[nodiscard]] QString date() const; 0246 0247 [[nodiscard]] QString cameraMake() const; 0248 0249 [[nodiscard]] QString cameraModel() const; 0250 0251 [[nodiscard]] float exposureTime() const; 0252 0253 [[nodiscard]] float aperture() const; 0254 0255 [[nodiscard]] bool flashUsed() const; 0256 0257 [[nodiscard]] float focalLength() const; 0258 0259 [[nodiscard]] int isoSpeed() const; 0260 0261 [[nodiscard]] QString meteringMode() const; 0262 0263 [[nodiscard]] QString sensor() const; 0264 0265 [[nodiscard]] QString exposureMode() const; 0266 0267 [[nodiscard]] QString colorSpace() const; 0268 0269 [[nodiscard]] QString whiteBalance() const; 0270 0271 [[nodiscard]] float exposureBias() const; 0272 0273 [[nodiscard]] float maxApertureValue() const; 0274 0275 [[nodiscard]] int subjectDistance() const; 0276 0277 [[nodiscard]] QString lens() const; 0278 0279 private: 0280 explicit ImageMediaMetadata(const QVariantMap &jsonMap); 0281 0282 class Private; 0283 Private *const d; 0284 friend class Private; 0285 friend class File::Private; 0286 }; 0287 0288 using ImageMediaMetadataPtr = QSharedPointer<ImageMediaMetadata>; 0289 0290 class Thumbnail 0291 { 0292 public: 0293 explicit Thumbnail(const Thumbnail &other); 0294 virtual ~Thumbnail(); 0295 bool operator==(const Thumbnail &other) const; 0296 bool operator!=(const Thumbnail &other) const 0297 { 0298 return !operator==(other); 0299 } 0300 0301 [[nodiscard]] QImage image() const; 0302 0303 [[nodiscard]] QString mimeType() const; 0304 0305 private: 0306 explicit Thumbnail(const QVariantMap &jsonMap); 0307 0308 class Private; 0309 Private *const d; 0310 friend class Private; 0311 friend class File::Private; 0312 }; 0313 0314 using ThumbnailPtr = QSharedPointer<Thumbnail>; 0315 0316 /** 0317 * @brief JSON serialization options. 0318 * @since 5.3.1 0319 */ 0320 enum SerializationOption { 0321 NoOptions = 0, ///< No option set. 0322 ExcludeCreationDate = 1 ///< Exclude 'createdDate' entry. This is necessary when renaming URLs. 0323 }; 0324 Q_DECLARE_FLAGS(SerializationOptions, SerializationOption) 0325 0326 explicit File(); 0327 explicit File(const File &other); 0328 ~File() override; 0329 bool operator==(const File &other) const; 0330 bool operator!=(const File &other) const 0331 { 0332 return !operator==(other); 0333 } 0334 0335 /** 0336 * @brief Returns mimetype of folders 0337 */ 0338 static QString folderMimeType(); 0339 0340 /** 0341 * @brief Returns the id of the file. 0342 */ 0343 [[nodiscard]] QString id() const; 0344 0345 /** 0346 * @brief Returns a link back to this file. 0347 */ 0348 [[nodiscard]] QUrl selfLink() const; 0349 0350 /** 0351 * @brief Returns the title of this file. 0352 * 0353 * Used to identify file or folder name. 0354 */ 0355 [[nodiscard]] QString title() const; 0356 0357 /** 0358 * @brief Sets the title of this file. 0359 * 0360 * Used to identify file or folder name. 0361 * 0362 * @param title 0363 */ 0364 void setTitle(const QString &title); 0365 0366 /** 0367 * @brief Returns the MIME type of the file. 0368 */ 0369 [[nodiscard]] QString mimeType() const; 0370 0371 /** 0372 * @brief Sets the MIME type of the file. 0373 * 0374 * @param mimeType 0375 */ 0376 void setMimeType(const QString &mimeType); 0377 0378 /** 0379 * @brief Returns a short description of the file. 0380 */ 0381 [[nodiscard]] QString description() const; 0382 0383 /** 0384 * @brief Sets a short description of the file. 0385 * 0386 * @param description 0387 */ 0388 void setDescription(const QString &description); 0389 0390 /** 0391 * @brief Returns a group of labels for the file. 0392 */ 0393 File::LabelsPtr labels() const; 0394 0395 /** 0396 * @brief Sets a group of labels for the file. 0397 * 0398 * @param labels 0399 */ 0400 void setLabels(const LabelsPtr &labels); 0401 0402 /** 0403 * @brief Returns the create time for this file. 0404 */ 0405 [[nodiscard]] QDateTime createdDate() const; 0406 0407 /** 0408 * @brief Returns the last time this file was modified by anyone. 0409 * 0410 * This is only mutable on update when the setModifiedDate parameter is set. 0411 */ 0412 [[nodiscard]] QDateTime modifiedDate() const; 0413 0414 /** 0415 * @brief Sets the last time this file was modified by anyone. 0416 * 0417 * This is only mutable on update when the setModifiedDate parameter is set. 0418 * 0419 * @param modifiedDate 0420 */ 0421 void setModifiedDate(const QDateTime &modifiedDate); 0422 0423 /** 0424 * @brief Returns the last time this file was modified by the currently 0425 * authenticated user. 0426 */ 0427 [[nodiscard]] QDateTime modifiedByMeDate() const; 0428 0429 /** 0430 * @brief Returns a short lived download URL for the file. 0431 * 0432 * This is only populated for files with content stored in Drive. 0433 */ 0434 [[nodiscard]] QUrl downloadUrl() const; 0435 0436 /** 0437 * @brief Returns the indexable text attributes for the file. 0438 * 0439 * This property can only be written, and is not returned by files.get 0440 */ 0441 File::IndexableTextPtr &indexableText(); 0442 0443 /** 0444 * @brief Returns the permissions for the authenticated user on this file. 0445 */ 0446 PermissionPtr userPermission() const; 0447 0448 /** 0449 * @brief Returns the file extension used when downloading this file. 0450 * 0451 * This field is read only. To set the extension, include it on title when creating the file. 0452 * This is populated only for files with content stored in Drive. 0453 */ 0454 [[nodiscard]] QString fileExtension() const; 0455 0456 /** 0457 * @brief Returns an MD5 checksum for the content of this file. 0458 * 0459 * This is populated only for files with content stored in Drive. 0460 */ 0461 [[nodiscard]] QString md5Checksum() const; 0462 0463 /** 0464 * @brief Returns the size of the file in bytes. 0465 * 0466 * This is populated only for files with content stored in Drive. 0467 */ 0468 [[nodiscard]] qlonglong fileSize() const; 0469 0470 /** 0471 * @brief Returns a link for opening the file in using a relevant 0472 * Google editor or viewer. 0473 */ 0474 [[nodiscard]] QUrl alternateLink() const; 0475 0476 /** 0477 * @brief Returns a link for embedding the file. 0478 */ 0479 [[nodiscard]] QUrl embedLink() const; 0480 0481 /** 0482 * @brief Returns the version of the file; 0483 */ 0484 [[nodiscard]] qlonglong version() const; 0485 0486 /** 0487 * @brief Returns the time at which this file was shared with the user. 0488 */ 0489 [[nodiscard]] QDateTime sharedWithMeDate() const; 0490 0491 /** 0492 * @brief Returns the collection of parent folders which contain this file. 0493 * 0494 * Setting this field will put the file in all of the provided folders. 0495 * On insert, if no folders are provided, the file will be placed in the 0496 * default root folder. 0497 */ 0498 ParentReferencesList parents() const; 0499 0500 /** 0501 * @brief Sets the collection of parent folders which contain this file. 0502 * 0503 * Setting this field will put the file in all of the provided folders. 0504 * On insert, if no folders are provided, the file will be placed in the 0505 * default root folder. 0506 * 0507 * @param parents 0508 */ 0509 void setParents(const ParentReferencesList &parents); 0510 0511 /** 0512 * @brief Returns the links for exporting Google Docs to specific formats. 0513 * 0514 * This is a map from the export format to URL. 0515 */ 0516 QMap<QString /* format */, QUrl /* url */> exportLinks() const; 0517 0518 /** 0519 * @brief Returns the original filename if the file was uploaded manually, 0520 * or the original title if the file was inserted through the API. 0521 * 0522 * Note that renames of the title will not change the original filename. 0523 * This will only be populated on files with content stored in Drive. 0524 */ 0525 [[nodiscard]] QString originalFileName() const; 0526 0527 /** 0528 * @brief Returns the number of quota bytes used by this file. 0529 */ 0530 [[nodiscard]] qlonglong quotaBytesUsed() const; 0531 0532 /** 0533 * @brief Return the name(s) of the owner(s) of this file. 0534 */ 0535 [[nodiscard]] QStringList ownerNames() const; 0536 0537 /** 0538 * @brief Returns the name of the last user to modify this file. 0539 * 0540 * This will only be populated if a user has edited this file. 0541 */ 0542 [[nodiscard]] QString lastModifyingUserName() const; 0543 0544 /** 0545 * @brief Returns whether the file can be edited by the current user. 0546 */ 0547 [[nodiscard]] bool editable() const; 0548 0549 /** 0550 * @brief Returns whether writers can share the document with other users. 0551 */ 0552 [[nodiscard]] bool writersCanShare() const; 0553 0554 /** 0555 * @brief Returns a link to the file's thumbnail. 0556 */ 0557 [[nodiscard]] QUrl thumbnailLink() const; 0558 0559 /** 0560 * @brief Returns the last time this file was viewed by the user. 0561 */ 0562 [[nodiscard]] QDateTime lastViewedByMeDate() const; 0563 0564 /** 0565 * @brief Sets the last time this file was viewed by the user. 0566 * 0567 * @param lastViewedByMeDate 0568 */ 0569 void setLastViewedByMeDate(const QDateTime &lastViewedByMeDate); 0570 0571 /** 0572 * @brief Returns a link for downloading the content of the file in a browser 0573 * using cookie based authentication. 0574 * 0575 * In cases where the content is shared publicly, the content can be 0576 * downloaded without any credentials. 0577 */ 0578 [[nodiscard]] QUrl webContentLink() const; 0579 0580 /** 0581 * @brief Returns whether this file has been explicitly trashed, as opposed 0582 * to recursively trashed. 0583 * 0584 * This will only be populated if the file is trashed. 0585 */ 0586 [[nodiscard]] bool explicitlyTrashed() const; 0587 0588 /** 0589 * @brief Returns metadata about image media. 0590 * 0591 * This will only be present for image types, and its contents will depend 0592 * on what can be parsed from the image content. 0593 */ 0594 File::ImageMediaMetadataPtr imageMediaMetadata() const; 0595 0596 /** 0597 * @brief Returns thumbnail for the file. 0598 */ 0599 ThumbnailPtr thumbnail() const; 0600 0601 [[nodiscard]] QUrl webViewLink() const; 0602 0603 [[nodiscard]] QUrl iconLink() const; 0604 0605 [[nodiscard]] bool shared() const; 0606 0607 [[nodiscard]] UsersList owners() const; 0608 0609 [[nodiscard]] UserPtr lastModifyingUser() const; 0610 0611 [[nodiscard]] bool isFolder() const; 0612 0613 struct Fields { 0614 static const QString Items; 0615 static const QString SelfLink; 0616 static const QString Etag; 0617 static const QString Kind; 0618 static const QString NextLink; 0619 static const QString NextPageToken; 0620 static const QString Id; 0621 static const QString Title; 0622 static const QString MimeType; 0623 static const QString Description; 0624 static const QString Labels; 0625 static const QString CreatedDate; 0626 static const QString ModifiedDate; 0627 static const QString ModifiedByMeDate; 0628 static const QString DownloadUrl; 0629 static const QString IndexableText; 0630 static const QString UserPermission; 0631 static const QString FileExtension; 0632 static const QString Md5Checksum; 0633 static const QString FileSize; 0634 static const QString AlternateLink; 0635 static const QString EmbedLink; 0636 static const QString SharedWithMeDate; 0637 static const QString Parents; 0638 static const QString ExportLinks; 0639 static const QString OriginalFilename; 0640 static const QString OwnerNames; 0641 static const QString LastModifiedByMeDate; 0642 static const QString Editable; 0643 static const QString WritersCanShare; 0644 static const QString ThumbnailLink; 0645 static const QString LastViewedByMeDate; 0646 static const QString WebContentLink; 0647 static const QString ExplicitlyTrashed; 0648 static const QString ImageMediaMetadata; 0649 static const QString Thumbnail; 0650 static const QString WebViewLink; 0651 static const QString IconLink; 0652 static const QString Shared; 0653 static const QString Owners; 0654 static const QString LastModifyingUser; 0655 static const QString AppDataContents; 0656 static const QString OpenWithLinks; 0657 static const QString DefaultOpenWithLink; 0658 static const QString HeadRevisionId; 0659 static const QString Copyable; 0660 static const QString Properties; 0661 static const QString MarkedViewedByMeDate; 0662 static const QString Version; 0663 static const QString SharingUser; 0664 static const QString Permissions; 0665 }; 0666 0667 static FilePtr fromJSON(const QByteArray &jsonData); 0668 static FilesList fromJSONFeed(const QByteArray &jsonData, FeedData &feedData); 0669 static QByteArray toJSON(const FilePtr &file, SerializationOptions options = NoOptions); 0670 0671 static FilePtr fromJSON(const QVariantMap &jsonData); 0672 0673 private: 0674 Private *const d; 0675 friend class Private; 0676 friend class Change::Private; 0677 friend class ParentReference; 0678 friend class Permission; 0679 }; 0680 0681 } /* namespace Drive */ 0682 0683 } /* namespace KGAPI2 */ 0684 0685 Q_DECLARE_OPERATORS_FOR_FLAGS(KGAPI2::Drive::File::SerializationOptions)