7#include "parentreference.h"
8#include "parentreference_p.h"
11#include <QJsonDocument>
15using namespace KGAPI2::Drive;
17ParentReference::Private::Private()
22ParentReference::Private::Private(
const Private &other)
24 , selfLink(other.selfLink)
25 , parentLink(other.parentLink)
26 , isRoot(other.isRoot)
30ParentReferencePtr ParentReference::Private::fromJSON(
const QVariantMap &map)
33 return ParentReferencePtr();
37 reference->d->selfLink =
map[QStringLiteral(
"selfLink")].toUrl();
38 reference->d->parentLink =
map[QStringLiteral(
"parentLink")].toUrl();
39 reference->d->isRoot =
map[QStringLiteral(
"isRoot")].toBool();
44QVariantMap ParentReference::Private::toJSON(
const ParentReferencePtr &reference)
47 if (!reference->d->id.isEmpty()) {
48 map[QStringLiteral(
"id")] = reference->id();
50 if (!reference->d->selfLink.isEmpty()) {
51 map[QStringLiteral(
"selfLink")] = reference->d->selfLink;
53 if (!reference->d->parentLink.isEmpty()) {
54 map[QStringLiteral(
"parentLink")] = reference->d->parentLink;
56 if (reference->d->isRoot) {
57 map[QStringLiteral(
"isRoot")] = reference->d->isRoot;
63ParentReference::ParentReference(
const QString &
id)
72 , d(new Private(*(other.d)))
76ParentReference::~ParentReference()
83 if (!Object::operator==(other)) {
105 return d->parentLink;
113ParentReferencePtr ParentReference::fromJSON(
const QByteArray &jsonData)
117 return ParentReferencePtr();
121 return Private::fromJSON(data.
toMap());
124ParentReferencesList ParentReference::fromJSONFeed(
const QByteArray &jsonData)
128 return ParentReferencesList();
131 const QVariant data = document.
toVariant();
132 const QVariantMap
map = data.
toMap();
133 if (!
map.contains(QLatin1StringView(
"kind")) || map[QStringLiteral(
"kind")].
toString() != QLatin1StringView(
"drive#parentList")) {
134 return ParentReferencesList();
137 ParentReferencesList
list;
138 const QVariantList items =
map[QStringLiteral(
"items")].toList();
139 for (
const QVariant &item : items) {
140 const ParentReferencePtr reference = Private::fromJSON(item.toMap());
142 if (!reference.
isNull()) {
150QByteArray ParentReference::toJSON(
const ParentReferencePtr &reference)
152 const QVariantMap
map = Private::toJSON(reference);
ParentReference contains a reference to a file's parent.
QUrl parentLink() const
Returns a link to the parent.
bool isRoot() const
Returns whether or not the parent is the root folder.
QString id() const
Returns the id of the parent.
QUrl selfLink() const
Returns a link back to this reference.
Base class for all objects.
char * toString(const EngineQuery &query)
A job to fetch a single map tile described by a StaticMapUrl.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
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