Kgapi

file.h
1/*
2 SPDX-FileCopyrightText: 2012 Andrius da Costa Ribas <andriusmao@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include "change.h"
10#include "object.h"
11#include "types.h"
12
13#include <QImage>
14#include <QString>
15#include <QStringList>
16#include <QUrl>
17#include <QVariantMap>
18
19#include <QDateTime>
20
21namespace KGAPI2
22{
23
24namespace Drive
25{
26
27/**
28 * @brief File contains metadata for a file.
29 * Getters and setters' documentation is based on Google Drive's API v2 reference
30 * @see <a href="https://developers.google.com/drive/v2/reference/files">Files</a>
31 *
32 * @since 2.0
33 * @author Andrius da Costa Ribas <andriusmao@gmail.com>
34 * @author Daniel Vrátil <dvratil@redhat.com>
35 */
36class KGAPIDRIVE_EXPORT File : public KGAPI2::Object
37{
38private:
39 class Private;
40
41public:
42 /**
43 * @brief DriveFile::Labels holds the structure used for labels property.
44 */
45 class Labels
46 {
47 public:
48 explicit Labels();
49 explicit Labels(const Labels &other);
50 virtual ~Labels();
51 bool operator==(const Labels &other) const;
52 bool operator!=(const Labels &other) const
53 {
54 return !operator==(other);
55 }
56
57 /**
58 * @brief Returns whether this file is starred by the user.
59 */
60 [[nodiscard]] bool starred() const;
61
62 /**
63 * @brief Sets whether this file is starred by the user.
64 *
65 * @param starred
66 */
67 void setStarred(bool starred);
68
69 /**
70 * @brief Returns whether this file has the 'hidden' label set.
71 * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one.
72 * You can just ignore it.
73 */
74#ifndef KGAPIDRIVE_NO_DEPRECATED
75 KGAPIDRIVE_DEPRECATED bool hidden() const;
76#endif
77
78 /**
79 * @brief Sets whether this file has the 'hidden' label set.
80 * @deprecated The 'hidden' label has been deprecated in the v2 api and removed in the v3 one.
81 */
82#ifndef KGAPIDRIVE_NO_DEPRECATED
83 KGAPIDRIVE_DEPRECATED void setHidden(bool hidden);
84#endif
85
86 /**
87 * @brief Returns whether this file has been trashed.
88 */
89 bool trashed() const;
90
91 /**
92 * @brief Sets whether this file has been trashed.
93 *
94 * @param trashed
95 */
96 void setTrashed(bool trashed);
97
98 /**
99 * @brief Returns whether viewers are prevented from downloading this file.
100 */
101 bool restricted() const;
102
103 /**
104 * @brief Sets whether viewers are prevented from downloading this file.
105 *
106 * @param restricted
107 */
108 void setRestricted(bool restricted);
109
110 /**
111 * @brief Returns whether this file has been viewed by this user.
112 */
113 [[nodiscard]] bool viewed() const;
114
115 /**
116 * @brief Sets whether this file has been viewed by this user.
117 *
118 * @param viewed
119 */
120 void setViewed(bool viewed);
121
122 private:
123 class Private;
124 Private *const d;
125 friend class Private;
126 friend class File::Private;
127 };
128
131
132 /**
133 * @brief DriveFile::IndexableText holds the structure used for indexableText property.
134 */
136 {
137 public:
138 explicit IndexableText(const IndexableText &other);
139 virtual ~IndexableText();
140 bool operator==(const IndexableText &other) const;
141 bool operator!=(const IndexableText &other) const
142 {
143 return !operator==(other);
144 }
145
146 /**
147 * @brief Returns the text to be indexed for this file.
148 */
149 [[nodiscard]] QString text() const;
150
151 /**
152 * @brief Sets the text to be indexed for this file.
153 *
154 * @param text
155 */
156 void setText(const QString &text);
157
158 private:
159 explicit IndexableText();
160
161 class Private;
162 Private *const d;
163 friend class Private;
164 friend class File::Private;
165 };
166
168
169 /**
170 * @brief DriveFile::ImageMediaMetadata holds the structure used for
171 * imageMediaMetadata property.
172 */
174 {
175 public:
176 /**
177 * @brief DriveFile::ImageMediaMetadata::Location holds the structure used
178 * for imageMediaMetadata.location property.
179 */
181 {
182 public:
183 explicit Location(const Location &other);
184 virtual ~Location();
185 bool operator==(const Location &other) const;
186 bool operator!=(const Location &other) const
187 {
188 return !operator==(other);
189 }
190
191 /**
192 * @brief Returns the latitude stored in the image.
193 */
194 [[nodiscard]] qreal latitude() const;
195
196 /**
197 * @brief Returns the longitude stored in the image.
198 */
199 [[nodiscard]] qreal longitude() const;
200
201 /**
202 * @brief Returns the altitude stored in the image.
203 */
204 [[nodiscard]] qreal altitude() const;
205
206 private:
207 explicit Location();
208
209 class Private;
210 Private *const d;
211 friend class Private;
212 friend class ImageMediaMetadata;
213 };
214
216
217 explicit ImageMediaMetadata(const ImageMediaMetadata &other);
218 virtual ~ImageMediaMetadata();
219 bool operator==(const ImageMediaMetadata &other) const;
220 bool operator!=(const ImageMediaMetadata &other) const
221 {
222 return !operator==(other);
223 }
224
225 /**
226 * @brief Returns the width of the image in pixels.
227 */
228 [[nodiscard]] int width() const;
229
230 /**
231 * @brief Returns the height of the image in pixels.
232 */
233 [[nodiscard]] int height() const;
234
235 /**
236 * @brief Returns the rotation in clockwise degrees from the image's original orientation.
237 */
238 [[nodiscard]] int rotation() const;
239
240 /**
241 * @brief Returns the geographic location information stored in the image.
242 */
243 [[nodiscard]] LocationPtr location() const;
244
245 [[nodiscard]] QString date() const;
246
247 [[nodiscard]] QString cameraMake() const;
248
249 [[nodiscard]] QString cameraModel() const;
250
251 [[nodiscard]] float exposureTime() const;
252
253 [[nodiscard]] float aperture() const;
254
255 [[nodiscard]] bool flashUsed() const;
256
257 [[nodiscard]] float focalLength() const;
258
259 [[nodiscard]] int isoSpeed() const;
260
261 [[nodiscard]] QString meteringMode() const;
262
263 [[nodiscard]] QString sensor() const;
264
265 [[nodiscard]] QString exposureMode() const;
266
267 [[nodiscard]] QString colorSpace() const;
268
269 [[nodiscard]] QString whiteBalance() const;
270
271 [[nodiscard]] float exposureBias() const;
272
273 [[nodiscard]] float maxApertureValue() const;
274
275 [[nodiscard]] int subjectDistance() const;
276
277 [[nodiscard]] QString lens() const;
278
279 private:
280 explicit ImageMediaMetadata(const QVariantMap &jsonMap);
281
282 class Private;
283 Private *const d;
284 friend class Private;
285 friend class File::Private;
286 };
287
289
290 class Thumbnail
291 {
292 public:
293 explicit Thumbnail(const Thumbnail &other);
294 virtual ~Thumbnail();
295 bool operator==(const Thumbnail &other) const;
296 bool operator!=(const Thumbnail &other) const
297 {
298 return !operator==(other);
299 }
300
301 [[nodiscard]] QImage image() const;
302
303 [[nodiscard]] QString mimeType() const;
304
305 private:
306 explicit Thumbnail(const QVariantMap &jsonMap);
307
308 class Private;
309 Private *const d;
310 friend class Private;
311 friend class File::Private;
312 };
313
314 using ThumbnailPtr = QSharedPointer<Thumbnail>;
315
316 /**
317 * @brief JSON serialization options.
318 * @since 5.3.1
319 */
321 NoOptions = 0, ///< No option set.
322 ExcludeCreationDate = 1 ///< Exclude 'createdDate' entry. This is necessary when renaming URLs.
323 };
324 Q_DECLARE_FLAGS(SerializationOptions, SerializationOption)
325
326 explicit File();
327 explicit File(const File &other);
328 ~File() override;
329 bool operator==(const File &other) const;
330 bool operator!=(const File &other) const
331 {
332 return !operator==(other);
333 }
334
335 /**
336 * @brief Returns mimetype of folders
337 */
339
340 /**
341 * @brief Returns the id of the file.
342 */
343 [[nodiscard]] QString id() const;
344
345 /**
346 * @brief Returns a link back to this file.
347 */
348 [[nodiscard]] QUrl selfLink() const;
349
350 /**
351 * @brief Returns the title of this file.
352 *
353 * Used to identify file or folder name.
354 */
355 [[nodiscard]] QString title() const;
356
357 /**
358 * @brief Sets the title of this file.
359 *
360 * Used to identify file or folder name.
361 *
362 * @param title
363 */
364 void setTitle(const QString &title);
365
366 /**
367 * @brief Returns the MIME type of the file.
368 */
369 [[nodiscard]] QString mimeType() const;
370
371 /**
372 * @brief Sets the MIME type of the file.
373 *
374 * @param mimeType
375 */
376 void setMimeType(const QString &mimeType);
377
378 /**
379 * @brief Returns a short description of the file.
380 */
381 [[nodiscard]] QString description() const;
382
383 /**
384 * @brief Sets a short description of the file.
385 *
386 * @param description
387 */
388 void setDescription(const QString &description);
389
390 /**
391 * @brief Returns a group of labels for the file.
392 */
394
395 /**
396 * @brief Sets a group of labels for the file.
397 *
398 * @param labels
399 */
400 void setLabels(const LabelsPtr &labels);
401
402 /**
403 * @brief Returns the create time for this file.
404 */
405 [[nodiscard]] QDateTime createdDate() const;
406
407 /**
408 * @brief Returns the last time this file was modified by anyone.
409 *
410 * This is only mutable on update when the setModifiedDate parameter is set.
411 */
412 [[nodiscard]] QDateTime modifiedDate() const;
413
414 /**
415 * @brief Sets the last time this file was modified by anyone.
416 *
417 * This is only mutable on update when the setModifiedDate parameter is set.
418 *
419 * @param modifiedDate
420 */
421 void setModifiedDate(const QDateTime &modifiedDate);
422
423 /**
424 * @brief Returns the last time this file was modified by the currently
425 * authenticated user.
426 */
427 [[nodiscard]] QDateTime modifiedByMeDate() const;
428
429 /**
430 * @brief Returns a short lived download URL for the file.
431 *
432 * This is only populated for files with content stored in Drive.
433 */
434 [[nodiscard]] QUrl downloadUrl() const;
435
436 /**
437 * @brief Returns the indexable text attributes for the file.
438 *
439 * This property can only be written, and is not returned by files.get
440 */
442
443 /**
444 * @brief Returns the permissions for the authenticated user on this file.
445 */
447
448 /**
449 * @brief Returns the file extension used when downloading this file.
450 *
451 * This field is read only. To set the extension, include it on title when creating the file.
452 * This is populated only for files with content stored in Drive.
453 */
454 [[nodiscard]] QString fileExtension() const;
455
456 /**
457 * @brief Returns an MD5 checksum for the content of this file.
458 *
459 * This is populated only for files with content stored in Drive.
460 */
461 [[nodiscard]] QString md5Checksum() const;
462
463 /**
464 * @brief Returns the size of the file in bytes.
465 *
466 * This is populated only for files with content stored in Drive.
467 */
468 [[nodiscard]] qlonglong fileSize() const;
469
470 /**
471 * @brief Returns a link for opening the file in using a relevant
472 * Google editor or viewer.
473 */
474 [[nodiscard]] QUrl alternateLink() const;
475
476 /**
477 * @brief Returns a link for embedding the file.
478 */
479 [[nodiscard]] QUrl embedLink() const;
480
481 /**
482 * @brief Returns the version of the file;
483 */
484 [[nodiscard]] qlonglong version() const;
485
486 /**
487 * @brief Returns the time at which this file was shared with the user.
488 */
489 [[nodiscard]] QDateTime sharedWithMeDate() const;
490
491 /**
492 * @brief Returns the collection of parent folders which contain this file.
493 *
494 * Setting this field will put the file in all of the provided folders.
495 * On insert, if no folders are provided, the file will be placed in the
496 * default root folder.
497 */
499
500 /**
501 * @brief Sets the collection of parent folders which contain this file.
502 *
503 * Setting this field will put the file in all of the provided folders.
504 * On insert, if no folders are provided, the file will be placed in the
505 * default root folder.
506 *
507 * @param parents
508 */
509 void setParents(const ParentReferencesList &parents);
510
511 /**
512 * @brief Returns the links for exporting Google Docs to specific formats.
513 *
514 * This is a map from the export format to URL.
515 */
516 QMap<QString /* format */, QUrl /* url */> exportLinks() const;
517
518 /**
519 * @brief Returns the original filename if the file was uploaded manually,
520 * or the original title if the file was inserted through the API.
521 *
522 * Note that renames of the title will not change the original filename.
523 * This will only be populated on files with content stored in Drive.
524 */
525 [[nodiscard]] QString originalFileName() const;
526
527 /**
528 * @brief Returns the number of quota bytes used by this file.
529 */
530 [[nodiscard]] qlonglong quotaBytesUsed() const;
531
532 /**
533 * @brief Return the name(s) of the owner(s) of this file.
534 */
535 [[nodiscard]] QStringList ownerNames() const;
536
537 /**
538 * @brief Returns the name of the last user to modify this file.
539 *
540 * This will only be populated if a user has edited this file.
541 */
542 [[nodiscard]] QString lastModifyingUserName() const;
543
544 /**
545 * @brief Returns whether the file can be edited by the current user.
546 */
547 [[nodiscard]] bool editable() const;
548
549 /**
550 * @brief Returns whether writers can share the document with other users.
551 */
552 [[nodiscard]] bool writersCanShare() const;
553
554 /**
555 * @brief Returns a link to the file's thumbnail.
556 */
557 [[nodiscard]] QUrl thumbnailLink() const;
558
559 /**
560 * @brief Returns the last time this file was viewed by the user.
561 */
562 [[nodiscard]] QDateTime lastViewedByMeDate() const;
563
564 /**
565 * @brief Sets the last time this file was viewed by the user.
566 *
567 * @param lastViewedByMeDate
568 */
569 void setLastViewedByMeDate(const QDateTime &lastViewedByMeDate);
570
571 /**
572 * @brief Returns a link for downloading the content of the file in a browser
573 * using cookie based authentication.
574 *
575 * In cases where the content is shared publicly, the content can be
576 * downloaded without any credentials.
577 */
578 [[nodiscard]] QUrl webContentLink() const;
579
580 /**
581 * @brief Returns whether this file has been explicitly trashed, as opposed
582 * to recursively trashed.
583 *
584 * This will only be populated if the file is trashed.
585 */
586 [[nodiscard]] bool explicitlyTrashed() const;
587
588 /**
589 * @brief Returns metadata about image media.
590 *
591 * This will only be present for image types, and its contents will depend
592 * on what can be parsed from the image content.
593 */
595
596 /**
597 * @brief Returns thumbnail for the file.
598 */
600
601 [[nodiscard]] QUrl webViewLink() const;
602
603 [[nodiscard]] QUrl iconLink() const;
604
605 [[nodiscard]] bool shared() const;
606
607 [[nodiscard]] UsersList owners() const;
608
609 [[nodiscard]] UserPtr lastModifyingUser() const;
610
611 [[nodiscard]] bool isFolder() const;
612
613 struct Fields {
614 static const QString Items;
615 static const QString SelfLink;
616 static const QString Etag;
617 static const QString Kind;
618 static const QString NextLink;
619 static const QString NextPageToken;
620 static const QString Id;
621 static const QString Title;
622 static const QString MimeType;
623 static const QString Description;
624 static const QString Labels;
625 static const QString CreatedDate;
626 static const QString ModifiedDate;
627 static const QString ModifiedByMeDate;
628 static const QString DownloadUrl;
629 static const QString IndexableText;
630 static const QString UserPermission;
631 static const QString FileExtension;
632 static const QString Md5Checksum;
633 static const QString FileSize;
634 static const QString AlternateLink;
635 static const QString EmbedLink;
636 static const QString SharedWithMeDate;
637 static const QString Parents;
638 static const QString ExportLinks;
639 static const QString OriginalFilename;
640 static const QString OwnerNames;
641 static const QString LastModifiedByMeDate;
642 static const QString Editable;
643 static const QString WritersCanShare;
644 static const QString ThumbnailLink;
645 static const QString LastViewedByMeDate;
646 static const QString WebContentLink;
647 static const QString ExplicitlyTrashed;
648 static const QString ImageMediaMetadata;
649 static const QString Thumbnail;
650 static const QString WebViewLink;
651 static const QString IconLink;
652 static const QString Shared;
653 static const QString Owners;
654 static const QString LastModifyingUser;
655 static const QString AppDataContents;
656 static const QString OpenWithLinks;
657 static const QString DefaultOpenWithLink;
658 static const QString HeadRevisionId;
659 static const QString Copyable;
660 static const QString Properties;
661 static const QString MarkedViewedByMeDate;
662 static const QString Version;
663 static const QString SharingUser;
664 static const QString Permissions;
665 };
666
667 static FilePtr fromJSON(const QByteArray &jsonData);
668 static FilesList fromJSONFeed(const QByteArray &jsonData, FeedData &feedData);
669 static QByteArray toJSON(const FilePtr &file, SerializationOptions options = NoOptions);
670
671 static FilePtr fromJSON(const QVariantMap &jsonData);
672
673private:
674 Private *const d;
675 friend class Private;
676 friend class Change::Private;
677 friend class ParentReference;
678 friend class Permission;
679};
680
681} /* namespace Drive */
682
683} /* namespace KGAPI2 */
684
685Q_DECLARE_OPERATORS_FOR_FLAGS(KGAPI2::Drive::File::SerializationOptions)
DriveFile::ImageMediaMetadata::Location holds the structure used for imageMediaMetadata....
Definition file.h:181
qreal altitude() const
Returns the altitude stored in the image.
qreal longitude() const
Returns the longitude stored in the image.
qreal latitude() const
Returns the latitude stored in the image.
DriveFile::ImageMediaMetadata holds the structure used for imageMediaMetadata property.
Definition file.h:174
LocationPtr location() const
Returns the geographic location information stored in the image.
int width() const
Returns the width of the image in pixels.
int rotation() const
Returns the rotation in clockwise degrees from the image's original orientation.
int height() const
Returns the height of the image in pixels.
DriveFile::IndexableText holds the structure used for indexableText property.
Definition file.h:136
DriveFile::Labels holds the structure used for labels property.
Definition file.h:46
File contains metadata for a file.
Definition file.h:37
qlonglong version() const
Returns the version of the file;.
void setLabels(const LabelsPtr &labels)
Sets a group of labels for the file.
QString fileExtension() const
Returns the file extension used when downloading this file.
qlonglong quotaBytesUsed() const
Returns the number of quota bytes used by this file.
void setLastViewedByMeDate(const QDateTime &lastViewedByMeDate)
Sets the last time this file was viewed by the user.
QString lastModifyingUserName() const
Returns the name of the last user to modify this file.
ParentReferencesList parents() const
Returns the collection of parent folders which contain this file.
QUrl webContentLink() const
Returns a link for downloading the content of the file in a browser using cookie based authentication...
File::LabelsPtr labels() const
Returns a group of labels for the file.
QMap< QString, QUrl > exportLinks() const
Returns the links for exporting Google Docs to specific formats.
QUrl downloadUrl() const
Returns a short lived download URL for the file.
QString mimeType() const
Returns the MIME type of the file.
void setMimeType(const QString &mimeType)
Sets the MIME type of the file.
QUrl thumbnailLink() const
Returns a link to the file's thumbnail.
SerializationOption
JSON serialization options.
Definition file.h:320
void setDescription(const QString &description)
Sets a short description of the file.
File::IndexableTextPtr & indexableText()
Returns the indexable text attributes for the file.
QDateTime modifiedDate() const
Returns the last time this file was modified by anyone.
static QString folderMimeType()
Returns mimetype of folders.
void setTitle(const QString &title)
Sets the title of this file.
void setModifiedDate(const QDateTime &modifiedDate)
Sets the last time this file was modified by anyone.
QString originalFileName() const
Returns the original filename if the file was uploaded manually, or the original title if the file wa...
qlonglong fileSize() const
Returns the size of the file in bytes.
QString id() const
Returns the id of the file.
bool editable() const
Returns whether the file can be edited by the current user.
QString md5Checksum() const
Returns an MD5 checksum for the content of this file.
File::ImageMediaMetadataPtr imageMediaMetadata() const
Returns metadata about image media.
QUrl selfLink() const
Returns a link back to this file.
QDateTime sharedWithMeDate() const
Returns the time at which this file was shared with the user.
QDateTime createdDate() const
Returns the create time for this file.
QString description() const
Returns a short description of the file.
QUrl alternateLink() const
Returns a link for opening the file in using a relevant Google editor or viewer.
QDateTime modifiedByMeDate() const
Returns the last time this file was modified by the currently authenticated user.
QStringList ownerNames() const
Return the name(s) of the owner(s) of this file.
PermissionPtr userPermission() const
Returns the permissions for the authenticated user on this file.
void setParents(const ParentReferencesList &parents)
Sets the collection of parent folders which contain this file.
QUrl embedLink() const
Returns a link for embedding the file.
QDateTime lastViewedByMeDate() const
Returns the last time this file was viewed by the user.
ThumbnailPtr thumbnail() const
Returns thumbnail for the file.
bool explicitlyTrashed() const
Returns whether this file has been explicitly trashed, as opposed to recursively trashed.
QString title() const
Returns the title of this file.
bool writersCanShare() const
Returns whether writers can share the document with other users.
ParentReference contains a reference to a file's parent.
Permission contains a permission for a file.
Definition permission.h:34
Structure to store additional information about a feed.
Definition types.h:24
Base class for all objects.
Definition object.h:31
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.