Changeset View
Changeset View
Standalone View
Standalone View
src/drive/drives.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2019 David Barchiesi <david@barchie.si> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "driveservice.h" | ||||
22 | #include "drives.h" | ||||
23 | #include "utils_p.h" | ||||
24 | | ||||
25 | #include <QVariant> | ||||
26 | #include <QUrlQuery> | ||||
27 | #include <QJsonDocument> | ||||
28 | | ||||
29 | namespace { | ||||
30 | static const QString ApiKind = QStringLiteral("drive#drive"); | ||||
31 | static const QString ApiKindList = QStringLiteral("drive#driveList"); | ||||
32 | } | ||||
33 | | ||||
34 | using namespace KGAPI2; | ||||
35 | using namespace KGAPI2::Drive; | ||||
36 | | ||||
37 | ///// Drives::Restrictions | ||||
38 | | ||||
39 | class Q_DECL_HIDDEN Drives::Restrictions::Private | ||||
40 | { | ||||
41 | public: | ||||
42 | Private() = default; | ||||
43 | Private(const Private &other) = default; | ||||
44 | | ||||
45 | bool adminManagedRestrictions = false; | ||||
46 | bool copyRequiresWriterPermission = false; | ||||
47 | bool domainUsersOnly = false; | ||||
48 | bool driveMembersOnly = false; | ||||
49 | }; | ||||
50 | | ||||
51 | Drives::Restrictions::Restrictions(): | ||||
52 | d(new Private) | ||||
53 | { | ||||
54 | } | ||||
55 | | ||||
56 | Drives::Restrictions::Restrictions(const Drives::Restrictions &other): | ||||
57 | d(new Private(*(other.d))) | ||||
58 | { | ||||
59 | } | ||||
60 | | ||||
61 | Drives::Restrictions::~Restrictions() = default; | ||||
62 | | ||||
63 | bool Drives::Restrictions::operator==(const Drives::Restrictions &other) const | ||||
64 | { | ||||
65 | GAPI_COMPARE(adminManagedRestrictions); | ||||
66 | GAPI_COMPARE(copyRequiresWriterPermission); | ||||
67 | GAPI_COMPARE(domainUsersOnly); | ||||
68 | GAPI_COMPARE(driveMembersOnly); | ||||
69 | return true; | ||||
70 | } | ||||
71 | | ||||
72 | bool Drives::Restrictions::adminManagedRestrictions() const | ||||
73 | { | ||||
74 | return d->adminManagedRestrictions; | ||||
75 | } | ||||
76 | | ||||
77 | void Drives::Restrictions::setAdminManagedRestrictions(bool adminManagedRestrictions) const | ||||
78 | { | ||||
79 | d->adminManagedRestrictions = adminManagedRestrictions; | ||||
80 | } | ||||
81 | | ||||
82 | bool Drives::Restrictions::copyRequiresWriterPermission() const | ||||
83 | { | ||||
84 | return d->copyRequiresWriterPermission; | ||||
85 | } | ||||
86 | | ||||
87 | void Drives::Restrictions::setCopyRequiresWriterPermission(bool copyRequiresWriterPermission) const | ||||
88 | { | ||||
89 | d->copyRequiresWriterPermission = copyRequiresWriterPermission; | ||||
90 | } | ||||
91 | | ||||
92 | bool Drives::Restrictions::domainUsersOnly() const | ||||
93 | { | ||||
94 | return d->domainUsersOnly; | ||||
95 | } | ||||
96 | | ||||
97 | void Drives::Restrictions::setDomainUsersOnly(bool domainUsersOnly) const | ||||
98 | { | ||||
99 | d->domainUsersOnly = domainUsersOnly; | ||||
100 | } | ||||
101 | | ||||
102 | bool Drives::Restrictions::driveMembersOnly() const | ||||
103 | { | ||||
104 | return d->driveMembersOnly; | ||||
105 | } | ||||
106 | | ||||
107 | void Drives::Restrictions::setDriveMembersOnly(bool driveMembersOnly) const | ||||
108 | { | ||||
109 | d->driveMembersOnly = driveMembersOnly; | ||||
110 | } | ||||
111 | | ||||
112 | ///// Drives::Capabilities | ||||
113 | | ||||
114 | class Q_DECL_HIDDEN Drives::Capabilities::Private | ||||
115 | { | ||||
116 | public: | ||||
117 | Private() = default; | ||||
118 | Private(const Private &other) = default; | ||||
119 | | ||||
120 | bool canAddChildren = false; | ||||
121 | bool canChangeCopyRequiresWriterPermissionRestriction = false; | ||||
122 | bool canChangeDomainUsersOnlyRestriction = false; | ||||
123 | bool canChangeDriveBackground = false; | ||||
124 | bool canChangeDriveMembersOnlyRestriction = false; | ||||
125 | bool canComment = false; | ||||
126 | bool canCopy = false; | ||||
127 | bool canDeleteChildren = false; | ||||
128 | bool canDeleteDrive = false; | ||||
129 | bool canDownload = false; | ||||
130 | bool canEdit = false; | ||||
131 | bool canListChildren = false; | ||||
132 | bool canManageMembers = false; | ||||
133 | bool canReadRevisions = false; | ||||
134 | bool canRename = false; | ||||
135 | bool canRenameDrive = false; | ||||
136 | bool canShare = false; | ||||
137 | bool canTrashChildren = false; | ||||
138 | }; | ||||
139 | | ||||
140 | Drives::Capabilities::Capabilities(): | ||||
141 | d(new Private) | ||||
142 | { | ||||
143 | } | ||||
144 | | ||||
145 | Drives::Capabilities::Capabilities(const Drives::Capabilities &other): | ||||
146 | d(new Private(*(other.d))) | ||||
147 | { | ||||
148 | } | ||||
149 | | ||||
150 | Drives::Capabilities::~Capabilities() = default; | ||||
151 | | ||||
152 | bool Drives::Capabilities::operator==(const Drives::Capabilities &other) const | ||||
153 | { | ||||
154 | GAPI_COMPARE(canAddChildren); | ||||
155 | GAPI_COMPARE(canChangeCopyRequiresWriterPermissionRestriction); | ||||
156 | GAPI_COMPARE(canChangeDomainUsersOnlyRestriction); | ||||
157 | GAPI_COMPARE(canChangeDriveBackground); | ||||
158 | GAPI_COMPARE(canChangeDriveMembersOnlyRestriction); | ||||
159 | GAPI_COMPARE(canComment); | ||||
160 | GAPI_COMPARE(canCopy); | ||||
161 | GAPI_COMPARE(canDeleteChildren); | ||||
162 | GAPI_COMPARE(canDeleteDrive); | ||||
163 | GAPI_COMPARE(canDownload); | ||||
164 | GAPI_COMPARE(canEdit); | ||||
165 | GAPI_COMPARE(canListChildren); | ||||
166 | GAPI_COMPARE(canManageMembers); | ||||
167 | GAPI_COMPARE(canReadRevisions); | ||||
168 | GAPI_COMPARE(canRename); | ||||
169 | GAPI_COMPARE(canRenameDrive); | ||||
170 | GAPI_COMPARE(canShare); | ||||
171 | GAPI_COMPARE(canTrashChildren); | ||||
172 | return true; | ||||
173 | } | ||||
174 | | ||||
175 | bool Drives::Capabilities::canAddChildren() const | ||||
176 | { | ||||
177 | return d->canAddChildren; | ||||
178 | } | ||||
179 | | ||||
180 | bool Drives::Capabilities::canChangeCopyRequiresWriterPermissionRestriction() const | ||||
181 | { | ||||
182 | return d->canChangeCopyRequiresWriterPermissionRestriction; | ||||
183 | } | ||||
184 | | ||||
185 | bool Drives::Capabilities::canChangeDomainUsersOnlyRestriction() const | ||||
186 | { | ||||
187 | return d->canChangeDomainUsersOnlyRestriction; | ||||
188 | } | ||||
189 | | ||||
190 | bool Drives::Capabilities::canChangeDriveBackground() const | ||||
191 | { | ||||
192 | return d->canChangeDriveBackground; | ||||
193 | } | ||||
194 | | ||||
195 | bool Drives::Capabilities::canChangeDriveMembersOnlyRestriction() const | ||||
196 | { | ||||
197 | return d->canChangeDriveMembersOnlyRestriction; | ||||
198 | } | ||||
199 | | ||||
200 | bool Drives::Capabilities::canComment() const | ||||
201 | { | ||||
202 | return d->canComment; | ||||
203 | } | ||||
204 | | ||||
205 | bool Drives::Capabilities::canCopy() const | ||||
206 | { | ||||
207 | return d->canCopy; | ||||
208 | } | ||||
209 | | ||||
210 | bool Drives::Capabilities::canDeleteChildren() const | ||||
211 | { | ||||
212 | return d->canDeleteChildren; | ||||
213 | } | ||||
214 | | ||||
215 | bool Drives::Capabilities::canDeleteDrive() const | ||||
216 | { | ||||
217 | return d->canDeleteDrive; | ||||
218 | } | ||||
219 | | ||||
220 | bool Drives::Capabilities::canDownload() const | ||||
221 | { | ||||
222 | return d->canDownload; | ||||
223 | } | ||||
224 | | ||||
225 | bool Drives::Capabilities::canEdit() const | ||||
226 | { | ||||
227 | return d->canEdit; | ||||
228 | } | ||||
229 | | ||||
230 | bool Drives::Capabilities::canListChildren() const | ||||
231 | { | ||||
232 | return d->canListChildren; | ||||
233 | } | ||||
234 | | ||||
235 | bool Drives::Capabilities::canManageMembers() const | ||||
236 | { | ||||
237 | return d->canManageMembers; | ||||
238 | } | ||||
239 | | ||||
240 | bool Drives::Capabilities::canReadRevisions() const | ||||
241 | { | ||||
242 | return d->canReadRevisions; | ||||
243 | } | ||||
244 | | ||||
245 | bool Drives::Capabilities::canRename() const | ||||
246 | { | ||||
247 | return d->canRename; | ||||
248 | } | ||||
249 | | ||||
250 | bool Drives::Capabilities::canRenameDrive() const | ||||
251 | { | ||||
252 | return d->canRenameDrive; | ||||
253 | } | ||||
254 | | ||||
255 | bool Drives::Capabilities::canShare() const | ||||
256 | { | ||||
257 | return d->canShare; | ||||
258 | } | ||||
259 | | ||||
260 | bool Drives::Capabilities::canTrashChildren() const | ||||
261 | { | ||||
262 | return d->canTrashChildren; | ||||
263 | } | ||||
264 | | ||||
265 | ///// Drives::BackgroundImageFile | ||||
266 | | ||||
267 | class Q_DECL_HIDDEN Drives::BackgroundImageFile::Private | ||||
268 | { | ||||
269 | public: | ||||
270 | Private() = default; | ||||
271 | Private(const Private &other) = default; | ||||
272 | | ||||
273 | QString id; | ||||
274 | float xCoordinate = 0.0f; | ||||
275 | float yCoordinate = 0.0f; | ||||
276 | float width = 0.0f; | ||||
277 | }; | ||||
278 | | ||||
279 | Drives::BackgroundImageFile::BackgroundImageFile(): | ||||
280 | d(new Private) | ||||
281 | { | ||||
282 | } | ||||
283 | | ||||
284 | Drives::BackgroundImageFile::BackgroundImageFile(const Drives::BackgroundImageFile &other): | ||||
285 | d(new Private(*(other.d))) | ||||
286 | { | ||||
287 | } | ||||
288 | | ||||
289 | Drives::BackgroundImageFile::~BackgroundImageFile() = default; | ||||
290 | | ||||
291 | bool Drives::BackgroundImageFile::operator==(const Drives::BackgroundImageFile &other) const | ||||
292 | { | ||||
293 | GAPI_COMPARE(id); | ||||
294 | GAPI_COMPARE(xCoordinate); | ||||
295 | GAPI_COMPARE(yCoordinate); | ||||
296 | GAPI_COMPARE(width); | ||||
297 | return true; | ||||
298 | } | ||||
299 | | ||||
300 | QString Drives::BackgroundImageFile::id() const | ||||
301 | { | ||||
302 | return d->id; | ||||
303 | } | ||||
304 | | ||||
305 | void Drives::BackgroundImageFile::setId(const QString &id) const | ||||
306 | { | ||||
307 | d->id = id; | ||||
308 | } | ||||
309 | | ||||
310 | float Drives::BackgroundImageFile::xCoordinate() const | ||||
311 | { | ||||
312 | return d->xCoordinate; | ||||
313 | } | ||||
314 | | ||||
315 | void Drives::BackgroundImageFile::setXCoordinate(const float xCoordinate) const | ||||
316 | { | ||||
317 | d->xCoordinate = xCoordinate; | ||||
318 | } | ||||
319 | | ||||
320 | float Drives::BackgroundImageFile::yCoordinate() const | ||||
321 | { | ||||
322 | return d->yCoordinate; | ||||
323 | } | ||||
324 | | ||||
325 | void Drives::BackgroundImageFile::setYCoordinate(const float yCoordinate) const | ||||
326 | { | ||||
327 | d->yCoordinate = yCoordinate; | ||||
328 | } | ||||
329 | | ||||
330 | float Drives::BackgroundImageFile::width() const | ||||
331 | { | ||||
332 | return d->width; | ||||
333 | } | ||||
334 | | ||||
335 | void Drives::BackgroundImageFile::setWidth(const float width) const | ||||
336 | { | ||||
337 | d->width = width; | ||||
338 | } | ||||
339 | | ||||
340 | ///// Drives | ||||
341 | | ||||
342 | class Q_DECL_HIDDEN Drives::Private | ||||
343 | { | ||||
344 | public: | ||||
345 | Private() = default; | ||||
346 | Private(const Private& other) = default; | ||||
347 | | ||||
348 | QString id; | ||||
349 | QString name; | ||||
350 | QString themeId; | ||||
351 | QString colorRgb; | ||||
352 | BackgroundImageFilePtr backgroundImageFile; | ||||
353 | QString backgroundImageLink; | ||||
354 | CapabilitiesPtr capabilities; | ||||
355 | QDateTime createdDate; | ||||
356 | bool hidden = false; | ||||
357 | RestrictionsPtr restrictions; | ||||
358 | | ||||
359 | static DrivesPtr fromJSON(const QVariantMap &map); | ||||
360 | }; | ||||
361 | | ||||
362 | DrivesPtr Drives::Private::fromJSON(const QVariantMap &map) | ||||
363 | { | ||||
364 | if (!map.contains(Drives::Fields::Kind) || | ||||
365 | map[Drives::Fields::Kind].toString() != ApiKind) | ||||
366 | { | ||||
367 | return DrivesPtr(); | ||||
368 | } | ||||
369 | | ||||
370 | auto drives = DrivesPtr::create(); | ||||
371 | if (map.contains(Drives::Fields::Id)) { | ||||
372 | drives->d->id = map[Drives::Fields::Id].toString(); | ||||
373 | } | ||||
374 | if (map.contains(Drives::Fields::Name)) { | ||||
375 | drives->d->name = map[Drives::Fields::Name].toString(); | ||||
376 | } | ||||
377 | if (map.contains(Drives::Fields::ThemeId)) { | ||||
378 | drives->d->themeId = map[Drives::Fields::ThemeId].toString(); | ||||
379 | } | ||||
380 | if (map.contains(Drives::Fields::ColorRgb)) { | ||||
381 | drives->d->colorRgb = map[Drives::Fields::ColorRgb].toString(); | ||||
382 | } | ||||
383 | if (map.contains(Drives::Fields::BackgroundImageLink)) { | ||||
384 | drives->d->backgroundImageLink = map[Drives::Fields::BackgroundImageLink].toString(); | ||||
385 | } | ||||
386 | if (map.contains(Drives::Fields::CreatedDate)) { | ||||
387 | drives->d->createdDate = QDateTime::fromString(map[Drives::Fields::CreatedDate].toString(), Qt::ISODate); | ||||
388 | } | ||||
389 | if (map.contains(Drives::Fields::Hidden)) { | ||||
390 | drives->d->hidden = map[Drives::Fields::Hidden].toBool(); | ||||
391 | } | ||||
392 | | ||||
393 | if (map.contains(Drives::Fields::BackgroundImageFile)) { | ||||
394 | const QVariantMap backgroundImageFileMap = map[Drives::Fields::BackgroundImageFile].toMap(); | ||||
395 | auto backgroundImageFile = BackgroundImageFilePtr::create(); | ||||
396 | backgroundImageFile->d->id = backgroundImageFileMap[Drives::BackgroundImageFile::Fields::Id].toString(); | ||||
397 | backgroundImageFile->d->xCoordinate = backgroundImageFileMap[Drives::BackgroundImageFile::Fields::XCoordinate].toReal(); | ||||
398 | backgroundImageFile->d->yCoordinate = backgroundImageFileMap[Drives::BackgroundImageFile::Fields::YCoordinate].toReal(); | ||||
399 | backgroundImageFile->d->width = backgroundImageFileMap[Drives::BackgroundImageFile::Fields::Width].toReal(); | ||||
400 | drives->d->backgroundImageFile = backgroundImageFile; | ||||
401 | } | ||||
402 | | ||||
403 | if (map.contains(Drives::Fields::Capabilities)) { | ||||
404 | const QVariantMap capabilitiesMap = map[Drives::Fields::Capabilities].toMap(); | ||||
405 | auto capabilities = CapabilitiesPtr::create(); | ||||
406 | capabilities->d->canAddChildren = capabilitiesMap[Drives::Capabilities::Fields::CanAddChildren].toBool(); | ||||
407 | capabilities->d->canChangeCopyRequiresWriterPermissionRestriction = capabilitiesMap[Drives::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction].toBool(); | ||||
408 | capabilities->d->canChangeDomainUsersOnlyRestriction = capabilitiesMap[Drives::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction].toBool(); | ||||
409 | capabilities->d->canChangeDriveBackground = capabilitiesMap[Drives::Capabilities::Fields::CanChangeDriveBackground].toBool(); | ||||
410 | capabilities->d->canChangeDriveMembersOnlyRestriction = capabilitiesMap[Drives::Capabilities::Fields::CanChangeDriveMembersOnlyRestriction].toBool(); | ||||
411 | capabilities->d->canComment = capabilitiesMap[Drives::Capabilities::Fields::CanComment].toBool(); | ||||
412 | capabilities->d->canCopy = capabilitiesMap[Drives::Capabilities::Fields::CanCopy].toBool(); | ||||
413 | capabilities->d->canDeleteChildren = capabilitiesMap[Drives::Capabilities::Fields::CanDeleteChildren].toBool(); | ||||
414 | capabilities->d->canDeleteDrive = capabilitiesMap[Drives::Capabilities::Fields::CanDeleteDrive].toBool(); | ||||
415 | capabilities->d->canDownload = capabilitiesMap[Drives::Capabilities::Fields::CanDownload].toBool(); | ||||
416 | capabilities->d->canEdit = capabilitiesMap[Drives::Capabilities::Fields::CanEdit].toBool(); | ||||
417 | capabilities->d->canListChildren = capabilitiesMap[Drives::Capabilities::Fields::CanListChildren].toBool(); | ||||
418 | capabilities->d->canManageMembers = capabilitiesMap[Drives::Capabilities::Fields::CanManageMembers].toBool(); | ||||
419 | capabilities->d->canReadRevisions = capabilitiesMap[Drives::Capabilities::Fields::CanReadRevisions].toBool(); | ||||
420 | capabilities->d->canRename = capabilitiesMap[Drives::Capabilities::Fields::CanRename].toBool(); | ||||
421 | capabilities->d->canRenameDrive = capabilitiesMap[Drives::Capabilities::Fields::CanRenameDrive].toBool(); | ||||
422 | capabilities->d->canShare = capabilitiesMap[Drives::Capabilities::Fields::CanShare].toBool(); | ||||
423 | capabilities->d->canTrashChildren = capabilitiesMap[Drives::Capabilities::Fields::CanTrashChildren].toBool(); | ||||
424 | drives->d->capabilities = capabilities; | ||||
425 | } | ||||
426 | | ||||
427 | if (map.contains(Drives::Fields::Restrictions)) { | ||||
428 | const QVariantMap restrictionsMap = map[Drives::Fields::Restrictions].toMap(); | ||||
429 | auto restrictions = RestrictionsPtr::create(); | ||||
430 | restrictions->d->adminManagedRestrictions = restrictionsMap[Drives::Restrictions::Fields::AdminManagedRestrictions].toBool(); | ||||
431 | restrictions->d->copyRequiresWriterPermission = restrictionsMap[Drives::Restrictions::Fields::CopyRequiresWriterPermission].toBool(); | ||||
432 | restrictions->d->domainUsersOnly = restrictionsMap[Drives::Restrictions::Fields::DomainUsersOnly].toBool(); | ||||
433 | restrictions->d->driveMembersOnly = restrictionsMap[Drives::Restrictions::Fields::DriveMembersOnly].toBool(); | ||||
434 | drives->d->restrictions = restrictions; | ||||
435 | } | ||||
436 | | ||||
437 | return drives; | ||||
438 | } | ||||
439 | | ||||
440 | const QString Drives::Restrictions::Fields::AdminManagedRestrictions = QStringLiteral("adminManagedRestrictions"); | ||||
441 | const QString Drives::Restrictions::Fields::CopyRequiresWriterPermission = QStringLiteral("copyRequiresWriterPermission"); | ||||
442 | const QString Drives::Restrictions::Fields::DomainUsersOnly = QStringLiteral("domainUsersOnly"); | ||||
443 | const QString Drives::Restrictions::Fields::DriveMembersOnly = QStringLiteral("driveMembersOnly"); | ||||
444 | | ||||
445 | const QString Drives::Capabilities::Fields::CanAddChildren = QStringLiteral("canAddChildren"); | ||||
446 | const QString Drives::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction = QStringLiteral("canChangeCopyRequiresWriterPermissionRestriction"); | ||||
447 | const QString Drives::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction = QStringLiteral("canChangeDomainUsersOnlyRestriction"); | ||||
448 | const QString Drives::Capabilities::Fields::CanChangeDriveBackground = QStringLiteral("canChangeDriveBackground"); | ||||
449 | const QString Drives::Capabilities::Fields::CanChangeDriveMembersOnlyRestriction = QStringLiteral("canChangeDriveMembersOnlyRestriction"); | ||||
450 | const QString Drives::Capabilities::Fields::CanComment = QStringLiteral("canComment"); | ||||
451 | const QString Drives::Capabilities::Fields::CanCopy = QStringLiteral("canCopy"); | ||||
452 | const QString Drives::Capabilities::Fields::CanDeleteChildren = QStringLiteral("canDeleteChildren"); | ||||
453 | const QString Drives::Capabilities::Fields::CanDeleteDrive = QStringLiteral("canDeleteDrive"); | ||||
454 | const QString Drives::Capabilities::Fields::CanDownload = QStringLiteral("canDownload"); | ||||
455 | const QString Drives::Capabilities::Fields::CanEdit = QStringLiteral("canEdit"); | ||||
456 | const QString Drives::Capabilities::Fields::CanListChildren = QStringLiteral("canListChildren"); | ||||
457 | const QString Drives::Capabilities::Fields::CanManageMembers = QStringLiteral("canManageMembers"); | ||||
458 | const QString Drives::Capabilities::Fields::CanReadRevisions = QStringLiteral("canReadRevisions"); | ||||
459 | const QString Drives::Capabilities::Fields::CanRename = QStringLiteral("canRename"); | ||||
460 | const QString Drives::Capabilities::Fields::CanRenameDrive = QStringLiteral("canRenameDrive"); | ||||
461 | const QString Drives::Capabilities::Fields::CanShare = QStringLiteral("canShare"); | ||||
462 | const QString Drives::Capabilities::Fields::CanTrashChildren = QStringLiteral("canTrashChildren"); | ||||
463 | | ||||
464 | const QString Drives::BackgroundImageFile::Fields::Id = QStringLiteral("id"); | ||||
465 | const QString Drives::BackgroundImageFile::Fields::XCoordinate = QStringLiteral("xCoordinate"); | ||||
466 | const QString Drives::BackgroundImageFile::Fields::YCoordinate = QStringLiteral("yCoordinate"); | ||||
467 | const QString Drives::BackgroundImageFile::Fields::Width = QStringLiteral("width"); | ||||
468 | | ||||
469 | const QString Drives::Fields::Items = QStringLiteral("items"); | ||||
470 | const QString Drives::Fields::KindDrive = QStringLiteral("kind"); | ||||
471 | const QString Drives::Fields::PageToken = QStringLiteral("pageToken"); | ||||
472 | const QString Drives::Fields::NextPageToken = QStringLiteral("nextPageToken"); | ||||
473 | const QString Drives::Fields::Id = QStringLiteral("id"); | ||||
474 | const QString Drives::Fields::Kind = QStringLiteral("kind"); | ||||
475 | const QString Drives::Fields::Name = QStringLiteral("name"); | ||||
476 | const QString Drives::Fields::ThemeId = QStringLiteral("themeId"); | ||||
477 | const QString Drives::Fields::ColorRgb = QStringLiteral("colorRgb"); | ||||
478 | const QString Drives::Fields::BackgroundImageFile = QStringLiteral("backgroundImageFile"); | ||||
479 | const QString Drives::Fields::BackgroundImageLink = QStringLiteral("backgroundImageLink"); | ||||
480 | const QString Drives::Fields::Capabilities = QStringLiteral("capabilities"); | ||||
481 | const QString Drives::Fields::CreatedDate = QStringLiteral("createdDate"); | ||||
482 | const QString Drives::Fields::Hidden = QStringLiteral("hidden"); | ||||
483 | const QString Drives::Fields::Restrictions = QStringLiteral("restrictions"); | ||||
484 | | ||||
485 | Drives::Drives(): | ||||
486 | KGAPI2::Object(), | ||||
487 | d(new Private) | ||||
488 | { | ||||
489 | } | ||||
490 | | ||||
491 | Drives::Drives(const Drives& other): | ||||
492 | KGAPI2::Object(other), | ||||
493 | d(new Private(*(other.d))) | ||||
494 | { | ||||
495 | } | ||||
496 | | ||||
497 | Drives::~Drives() = default; | ||||
498 | | ||||
499 | bool Drives::operator==(const Drives &other) const | ||||
500 | { | ||||
501 | if (!Object::operator==(other)) { | ||||
502 | return false; | ||||
503 | } | ||||
504 | GAPI_COMPARE(id); | ||||
505 | GAPI_COMPARE(name); | ||||
506 | GAPI_COMPARE(themeId); | ||||
507 | GAPI_COMPARE(colorRgb); | ||||
508 | GAPI_COMPARE_SHAREDPTRS(backgroundImageFile); | ||||
509 | GAPI_COMPARE(backgroundImageLink); | ||||
510 | GAPI_COMPARE_SHAREDPTRS(capabilities); | ||||
511 | GAPI_COMPARE(createdDate); | ||||
512 | GAPI_COMPARE(hidden); | ||||
513 | GAPI_COMPARE_SHAREDPTRS(restrictions); | ||||
514 | return true; | ||||
515 | } | ||||
516 | | ||||
517 | QString Drives::id() const | ||||
518 | { | ||||
519 | return d->id; | ||||
520 | } | ||||
521 | | ||||
522 | void Drives::setId(const QString &id) const | ||||
523 | { | ||||
524 | d->id = id; | ||||
525 | } | ||||
526 | | ||||
527 | QString Drives::name() const | ||||
528 | { | ||||
529 | return d->name; | ||||
530 | } | ||||
531 | | ||||
532 | void Drives::setName(const QString &name) const | ||||
533 | { | ||||
534 | d->name = name; | ||||
535 | } | ||||
536 | | ||||
537 | QString Drives::themeId() const | ||||
538 | { | ||||
539 | return d->themeId; | ||||
540 | } | ||||
541 | | ||||
542 | void Drives::setThemeId(const QString &themeId) const | ||||
543 | { | ||||
544 | d->themeId = themeId; | ||||
545 | } | ||||
546 | | ||||
547 | QString Drives::colorRgb() const | ||||
548 | { | ||||
549 | return d->colorRgb; | ||||
550 | } | ||||
551 | | ||||
552 | void Drives::setColorRgb(const QString &colorRgb) const | ||||
553 | { | ||||
554 | d->colorRgb = colorRgb; | ||||
555 | } | ||||
556 | | ||||
557 | Drives::BackgroundImageFilePtr Drives::backgroundImageFile() const | ||||
558 | { | ||||
559 | return d->backgroundImageFile; | ||||
560 | } | ||||
561 | | ||||
562 | void Drives::setBackgroundImageFile(const Drives::BackgroundImageFilePtr &backgroundImageFile) const | ||||
563 | { | ||||
564 | d->backgroundImageFile = backgroundImageFile; | ||||
565 | } | ||||
566 | | ||||
567 | QString Drives::backgroundImageLink() const | ||||
568 | { | ||||
569 | return d->backgroundImageLink; | ||||
570 | } | ||||
571 | | ||||
572 | Drives::CapabilitiesPtr Drives::capabilities() const | ||||
573 | { | ||||
574 | return d->capabilities; | ||||
575 | } | ||||
576 | | ||||
577 | QDateTime Drives::createdDate() const | ||||
578 | { | ||||
579 | return d->createdDate; | ||||
580 | } | ||||
581 | | ||||
582 | bool Drives::hidden() const | ||||
583 | { | ||||
584 | return d->hidden; | ||||
585 | } | ||||
586 | | ||||
587 | void Drives::setRestrictions(const Drives::RestrictionsPtr &restrictions) const | ||||
588 | { | ||||
589 | d->restrictions = restrictions; | ||||
590 | } | ||||
591 | | ||||
592 | Drives::RestrictionsPtr Drives::restrictions() const | ||||
593 | { | ||||
594 | return d->restrictions; | ||||
595 | } | ||||
596 | | ||||
597 | DrivesPtr Drives::fromJSON(const QByteArray &jsonData) | ||||
598 | { | ||||
599 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||||
600 | if (document.isNull()) { | ||||
601 | return DrivesPtr(); | ||||
602 | } | ||||
603 | | ||||
604 | const QVariant data = document.toVariant(); | ||||
605 | return Private::fromJSON(data.toMap()); | ||||
606 | } | ||||
607 | | ||||
608 | DrivesList Drives::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData) | ||||
609 | { | ||||
610 | QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||||
611 | if (document.isNull()) { | ||||
612 | return DrivesList(); | ||||
613 | } | ||||
614 | | ||||
615 | const QVariant data = document.toVariant(); | ||||
616 | const QVariantMap map = data.toMap(); | ||||
617 | if (!map.contains(Drives::Fields::Kind) || | ||||
618 | map[Drives::Fields::Kind].toString() != ApiKindList) { | ||||
619 | return DrivesList(); | ||||
620 | } | ||||
621 | | ||||
622 | if (map.contains(Drives::Fields::NextPageToken)) { | ||||
623 | feedData.nextPageUrl = DriveService::fetchDrivesUrl(); | ||||
624 | QUrlQuery query(feedData.nextPageUrl); | ||||
625 | query.addQueryItem(Drives::Fields::PageToken, map.value(Drives::Fields::NextPageToken).toString()); | ||||
626 | feedData.nextPageUrl.setQuery(query); | ||||
627 | } | ||||
628 | | ||||
629 | DrivesList list; | ||||
630 | const QVariantList items = map[Drives::Fields::Items].toList(); | ||||
631 | for (const QVariant & item : items) { | ||||
632 | const DrivesPtr drives = Private::fromJSON(item.toMap()); | ||||
633 | | ||||
634 | if (!drives.isNull()) { | ||||
635 | list << drives; | ||||
636 | } | ||||
637 | } | ||||
638 | | ||||
639 | return list; | ||||
640 | } | ||||
641 | | ||||
642 | QByteArray Drives::toJSON(const DrivesPtr &drives) | ||||
643 | { | ||||
644 | QVariantMap drivesMap; | ||||
645 | drivesMap[Drives::Fields::Kind] = ApiKind; | ||||
646 | if (!drives->id().isEmpty()) { | ||||
647 | drivesMap[Drives::Fields::Id] = drives->id(); | ||||
648 | } | ||||
649 | if (!drives->name().isEmpty()) { | ||||
650 | drivesMap[Drives::Fields::Name] = drives->name(); | ||||
651 | } | ||||
652 | if (!drives->themeId().isEmpty()) { | ||||
653 | drivesMap[Drives::Fields::ThemeId] = drives->themeId(); | ||||
654 | } | ||||
655 | if (!drives->colorRgb().isEmpty()) { | ||||
656 | drivesMap[Drives::Fields::ColorRgb] = drives->colorRgb(); | ||||
657 | } | ||||
658 | if (!drives->backgroundImageLink().isEmpty()) { | ||||
659 | drivesMap[Drives::Fields::BackgroundImageLink] = drives->backgroundImageLink(); | ||||
660 | } | ||||
661 | if (drives->createdDate().isValid()) { | ||||
662 | drivesMap[Drives::Fields::CreatedDate] = drives->createdDate(); | ||||
663 | } | ||||
664 | drivesMap[Drives::Fields::Hidden] = drives->hidden(); | ||||
665 | | ||||
666 | if (drives->restrictions()) { | ||||
667 | QVariantMap restrictionsMap; | ||||
668 | restrictionsMap[Drives::Restrictions::Fields::AdminManagedRestrictions] = drives->restrictions()->adminManagedRestrictions(); | ||||
669 | restrictionsMap[Drives::Restrictions::Fields::CopyRequiresWriterPermission] = drives->restrictions()->copyRequiresWriterPermission(); | ||||
670 | restrictionsMap[Drives::Restrictions::Fields::DomainUsersOnly] = drives->restrictions()->domainUsersOnly(); | ||||
671 | restrictionsMap[Drives::Restrictions::Fields::DriveMembersOnly] = drives->restrictions()->driveMembersOnly(); | ||||
672 | drivesMap[Drives::Fields::Restrictions] = restrictionsMap; | ||||
673 | } | ||||
674 | | ||||
675 | if (drives->backgroundImageFile()) { | ||||
676 | QVariantMap backgroundImageFileMap; | ||||
677 | backgroundImageFileMap[Drives::BackgroundImageFile::Fields::Id] = drives->backgroundImageFile()->id(); | ||||
678 | backgroundImageFileMap[Drives::BackgroundImageFile::Fields::XCoordinate] = drives->backgroundImageFile()->xCoordinate(); | ||||
679 | backgroundImageFileMap[Drives::BackgroundImageFile::Fields::YCoordinate] = drives->backgroundImageFile()->yCoordinate(); | ||||
680 | backgroundImageFileMap[Drives::BackgroundImageFile::Fields::Width] = drives->backgroundImageFile()->width(); | ||||
681 | drivesMap[Drives::Fields::BackgroundImageFile] = backgroundImageFileMap; | ||||
682 | } | ||||
683 | | ||||
684 | if (drives->capabilities()) { | ||||
685 | QVariantMap capabilitiesMap; | ||||
686 | capabilitiesMap[Drives::Capabilities::Fields::CanAddChildren] = drives->capabilities()->canAddChildren(); | ||||
687 | capabilitiesMap[Drives::Capabilities::Fields::CanChangeCopyRequiresWriterPermissionRestriction] = drives->capabilities()->canChangeCopyRequiresWriterPermissionRestriction(); | ||||
688 | capabilitiesMap[Drives::Capabilities::Fields::CanChangeDomainUsersOnlyRestriction] = drives->capabilities()->canChangeDomainUsersOnlyRestriction(); | ||||
689 | capabilitiesMap[Drives::Capabilities::Fields::CanChangeDriveBackground] = drives->capabilities()->canChangeDriveBackground(); | ||||
690 | capabilitiesMap[Drives::Capabilities::Fields::CanChangeDriveMembersOnlyRestriction] = drives->capabilities()->canChangeDriveMembersOnlyRestriction(); | ||||
691 | capabilitiesMap[Drives::Capabilities::Fields::CanComment] = drives->capabilities()->canComment(); | ||||
692 | capabilitiesMap[Drives::Capabilities::Fields::CanCopy] = drives->capabilities()->canCopy(); | ||||
693 | capabilitiesMap[Drives::Capabilities::Fields::CanDeleteChildren] = drives->capabilities()->canDeleteChildren(); | ||||
694 | capabilitiesMap[Drives::Capabilities::Fields::CanDeleteDrive] = drives->capabilities()->canDeleteDrive(); | ||||
695 | capabilitiesMap[Drives::Capabilities::Fields::CanDownload] = drives->capabilities()->canDownload(); | ||||
696 | capabilitiesMap[Drives::Capabilities::Fields::CanEdit] = drives->capabilities()->canEdit(); | ||||
697 | capabilitiesMap[Drives::Capabilities::Fields::CanListChildren] = drives->capabilities()->canListChildren(); | ||||
698 | capabilitiesMap[Drives::Capabilities::Fields::CanManageMembers] = drives->capabilities()->canManageMembers(); | ||||
699 | capabilitiesMap[Drives::Capabilities::Fields::CanReadRevisions] = drives->capabilities()->canReadRevisions(); | ||||
700 | capabilitiesMap[Drives::Capabilities::Fields::CanRename] = drives->capabilities()->canRename(); | ||||
701 | capabilitiesMap[Drives::Capabilities::Fields::CanRenameDrive] = drives->capabilities()->canRenameDrive(); | ||||
702 | capabilitiesMap[Drives::Capabilities::Fields::CanShare] = drives->capabilities()->canShare(); | ||||
703 | capabilitiesMap[Drives::Capabilities::Fields::CanTrashChildren] = drives->capabilities()->canTrashChildren(); | ||||
704 | drivesMap[Drives::Fields::Capabilities] = capabilitiesMap; | ||||
705 | } | ||||
706 | | ||||
707 | QJsonDocument document = QJsonDocument::fromVariant(drivesMap); | ||||
708 | return document.toJson(QJsonDocument::Compact); | ||||
709 | } |