Kgapi

revision.cpp
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#include "revision.h"
8#include "user.h"
9#include "utils_p.h"
10
11#include <QJsonDocument>
12
13using namespace KGAPI2;
14using namespace KGAPI2::Drive;
15
16class Q_DECL_HIDDEN Revision::Private
17{
18public:
19 Private();
20 Private(const Private &other);
21
22 QString id;
23 QUrl selfLink;
25 QDateTime modifiedDate;
26 bool pinned;
27 bool published;
28 QUrl publishedLink;
29 bool publishAuto;
30 bool publishedOutsideDomain;
31 QUrl downloadUrl;
32 QMap<QString, QUrl> exportLinks;
33 QString lastModifyingUserName;
34 UserPtr lastModifyingUser;
35 QString originalFilename;
36 QString md5Checksum;
37 qlonglong fileSize;
38
39 static RevisionPtr fromJSON(const QVariantMap &map);
40};
41
42Revision::Private::Private()
43 : pinned(false)
44 , published(false)
45 , publishAuto(false)
46 , publishedOutsideDomain(false)
47 , fileSize(-1)
48{
49}
50
51Revision::Private::Private(const Private &other)
52 : id(other.id)
53 , selfLink(other.selfLink)
54 , mimeType(other.mimeType)
55 , modifiedDate(other.modifiedDate)
56 , pinned(other.pinned)
57 , published(other.published)
58 , publishedLink(other.publishedLink)
59 , publishAuto(other.publishAuto)
60 , publishedOutsideDomain(other.publishedOutsideDomain)
61 , downloadUrl(other.downloadUrl)
62 , exportLinks(other.exportLinks)
63 , lastModifyingUserName(other.lastModifyingUserName)
64 , lastModifyingUser(other.lastModifyingUser)
65 , originalFilename(other.originalFilename)
66 , md5Checksum(other.md5Checksum)
67 , fileSize(other.fileSize)
68{
69}
70
71RevisionPtr Revision::Private::fromJSON(const QVariantMap &map)
72{
73 if (!map.contains(QLatin1StringView("kind")) || map[QStringLiteral("kind")].toString() != QLatin1StringView("drive#revision")) {
74 return RevisionPtr();
75 }
76
77 RevisionPtr revision(new Revision);
78 revision->setEtag(map[QStringLiteral("etag")].toString());
79 revision->d->id = map[QStringLiteral("id")].toString();
80 revision->d->selfLink = map[QStringLiteral("selfLink")].toUrl();
81 revision->d->mimeType = map[QStringLiteral("mimeType")].toString();
82 revision->d->modifiedDate = QDateTime::fromString(map[QStringLiteral("modifiedDate")].toString(), Qt::ISODate);
83 revision->d->pinned = map[QStringLiteral("pinned")].toBool();
84 revision->d->published = map[QStringLiteral("published")].toBool();
85 revision->d->publishedLink = map[QStringLiteral("publishedLink")].toUrl();
86 revision->d->publishAuto = map[QStringLiteral("publishAuto")].toBool();
87 revision->d->publishedOutsideDomain = map[QStringLiteral("publishedOutsideDomain")].toBool();
88 revision->d->downloadUrl = map[QStringLiteral("downloadUrl")].toUrl();
89 revision->d->lastModifyingUserName = map[QStringLiteral("lastModifyingUserName")].toString();
90 revision->d->lastModifyingUser = User::fromJSON(map[QStringLiteral("lastModifyingUser")].toMap());
91 revision->d->originalFilename = map[QStringLiteral("originalFilename")].toString();
92 revision->d->md5Checksum = map[QStringLiteral("md5Checksum")].toString();
93 revision->d->fileSize = map[QStringLiteral("fileSize")].toLongLong();
94
95 const QVariantMap exportLinks = map[QStringLiteral("exportLinks")].toMap();
96 QVariantMap::ConstIterator iter = exportLinks.constBegin();
97 for (; iter != exportLinks.constEnd(); ++iter) {
98 revision->d->exportLinks.insert(iter.key(), iter.value().toUrl());
99 }
100
101 return revision;
102}
103
104Revision::Revision()
105 : KGAPI2::Object()
106 , d(new Private)
107{
108}
109
110Revision::Revision(const Revision &other)
111 : KGAPI2::Object(other)
112 , d(new Private(*(other.d)))
113{
114}
115
116Revision::~Revision()
117{
118 delete d;
119}
120
121bool Revision::operator==(const Revision &other) const
122{
123 if (!Object::operator==(other)) {
124 return false;
125 }
126 GAPI_COMPARE(id)
127 GAPI_COMPARE(selfLink)
128 GAPI_COMPARE(mimeType)
129 GAPI_COMPARE(modifiedDate)
130 GAPI_COMPARE(pinned)
131 GAPI_COMPARE(published)
132 GAPI_COMPARE(publishedLink)
133 GAPI_COMPARE(publishAuto)
134 GAPI_COMPARE(publishedOutsideDomain)
135 GAPI_COMPARE(downloadUrl)
136 GAPI_COMPARE(exportLinks)
137 GAPI_COMPARE(lastModifyingUserName)
138 GAPI_COMPARE_SHAREDPTRS(lastModifyingUser)
139 GAPI_COMPARE(originalFilename)
140 GAPI_COMPARE(md5Checksum)
141 GAPI_COMPARE(fileSize)
142 return true;
143}
144
146{
147 return d->id;
148}
149
151{
152 return d->selfLink;
153}
154
156{
157 return d->mimeType;
158}
159
161{
162 return d->modifiedDate;
163}
164
166{
167 return d->pinned;
168}
169
170void Revision::setPinned(bool pinned)
171{
172 d->pinned = pinned;
173}
174
176{
177 return d->published;
178}
179
180void Revision::setPublished(bool published)
181{
182 d->published = published;
183}
184
186{
187 return d->publishedLink;
188}
189
191{
192 return d->publishAuto;
193}
194
195void Revision::setPublishAuto(bool publishAuto)
196{
197 d->publishAuto = publishAuto;
198}
199
201{
202 return d->publishedOutsideDomain;
203}
204
205void Revision::setPublishedOutsideDomain(bool publishedOutsideDomain)
206{
207 d->publishedOutsideDomain = publishedOutsideDomain;
208}
209
211{
212 return d->downloadUrl;
213}
214
216{
217 return d->exportLinks;
218}
219
221{
222 return d->lastModifyingUserName;
223}
224
226{
227 return d->lastModifyingUser;
228}
229
231{
232 return d->originalFilename;
233}
234
236{
237 return d->md5Checksum;
238}
239
240qlonglong Revision::fileSize() const
241{
242 return d->fileSize;
243}
244
245RevisionPtr Revision::fromJSON(const QByteArray &jsonData)
246{
247 QJsonDocument document = QJsonDocument::fromJson(jsonData);
248 if (document.isNull()) {
249 return RevisionPtr();
250 }
251
252 const QVariant data = document.toVariant();
253 return Private::fromJSON(data.toMap());
254}
255
256RevisionsList Revision::fromJSONFeed(const QByteArray &jsonData)
257{
258 QJsonDocument document = QJsonDocument::fromJson(jsonData);
259 if (document.isNull()) {
260 return RevisionsList();
261 }
262
263 const QVariant data = document.toVariant();
264 const QVariantMap map = data.toMap();
265
266 if (!map.contains(QLatin1StringView("kind")) || map[QStringLiteral("kind")].toString() != QLatin1StringView("drive#revisionList")) {
267 return RevisionsList();
268 }
269
271 const QVariantList items = map[QStringLiteral("items")].toList();
272 for (const QVariant &item : std::as_const(items)) {
273 const RevisionPtr revision = Private::fromJSON(item.toMap());
274
275 if (!revision.isNull()) {
276 list << revision;
277 }
278 }
279
280 return list;
281}
282
283QByteArray Revision::toJSON(const RevisionPtr &revision)
284{
285 QVariantMap map;
286
287 map[QStringLiteral("pinned")] = revision->pinned();
288 map[QStringLiteral("published")] = revision->published();
289 map[QStringLiteral("publishAuto")] = revision->publishAuto();
290 map[QStringLiteral("publishedOutsideDomain")] = revision->publishedOutsideDomain();
291
293 return document.toJson(QJsonDocument::Compact);
294}
Revision contains a revision of a file.
Definition revision.h:35
QUrl downloadUrl() const
Returns a short term download URL for the file.
Definition revision.cpp:210
bool publishAuto() const
Returns whether subsequent revisions will be automatically republished.
Definition revision.cpp:190
bool pinned() const
Returns whether this revision is pinned to prevent automatic purging.
Definition revision.cpp:165
QUrl selfLink() const
Returns a link back to this revision.
Definition revision.cpp:150
QDateTime modifiedDate() const
Returns the last time this revision was modified.
Definition revision.cpp:160
void setPinned(bool pinned)
Sets whether this revision is pinned to prevent automatic purging.
Definition revision.cpp:170
void setPublishedOutsideDomain(bool publishedOutsideDomain)
Sets whether this revision is published outside the domain.
Definition revision.cpp:205
QString originalFilename() const
Returns the original filename when this revision was created.
Definition revision.cpp:230
QMap< QString, QUrl > exportLinks() const
Returns the links for exporting Google Docs to specific formats.
Definition revision.cpp:215
void setPublished(bool published)
Sets whether this revision is published.
Definition revision.cpp:180
QString id() const
Returns the id of the revision.
Definition revision.cpp:145
void setPublishAuto(bool publishAuto)
Sets whether subsequent revisions will be automatically republished.
Definition revision.cpp:195
QString lastModifyingUserName() const
Returns the name of the last user to modify this revision.
Definition revision.cpp:220
bool publishedOutsideDomain() const
Returns whether this revision is published outside the domain.
Definition revision.cpp:200
QString md5Checksum() const
Returns an MD5 checksum for the content of this revision.
Definition revision.cpp:235
QString mimeType() const
Returns the MIME type of the revision.
Definition revision.cpp:155
bool published() const
Returns whether this revision is published.
Definition revision.cpp:175
UserPtr lastModifyingUser() const
Returns object representing the last user to modify this revision.
Definition revision.cpp:225
QUrl publishedLink() const
Returns a link to the published revision.
Definition revision.cpp:185
qlonglong fileSize() const
Returns the size of the revision in bytes.
Definition revision.cpp:240
Base class for all objects.
Definition object.h:31
char * toString(const EngineQuery &query)
const QVariantMap toMap(const MODEL &model)
KCALUTILS_EXPORT QString mimeType()
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonDocument fromVariant(const QVariant &variant)
bool isNull() const const
QByteArray toJson(JsonFormat format) const const
QVariant toVariant() const const
bool isNull() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QMap< QString, QVariant > toMap() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.