File indexing completed on 2024-05-12 05:22:24
0001 /* 0002 * This file is part of LibKGAPI library 0003 * 0004 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "user.h" 0010 #include "utils_p.h" 0011 0012 using namespace KGAPI2; 0013 using namespace KGAPI2::Drive; 0014 0015 class Q_DECL_HIDDEN User::Private 0016 { 0017 public: 0018 Private(); 0019 Private(const Private &other); 0020 0021 QString displayName; 0022 QUrl pictureUrl; 0023 bool isAuthenticatedUser; 0024 QString permissionId; 0025 }; 0026 0027 User::Private::Private() 0028 : isAuthenticatedUser(false) 0029 { 0030 } 0031 0032 User::Private::Private(const Private &other) 0033 : displayName(other.displayName) 0034 , pictureUrl(other.pictureUrl) 0035 , isAuthenticatedUser(other.isAuthenticatedUser) 0036 , permissionId(other.permissionId) 0037 { 0038 } 0039 0040 User::User() 0041 : d(new Private) 0042 { 0043 } 0044 0045 User::User(const User &other) 0046 : d(new Private(*(other.d))) 0047 { 0048 } 0049 0050 User::~User() 0051 { 0052 delete d; 0053 } 0054 0055 bool User::operator==(const User &other) const 0056 { 0057 GAPI_COMPARE(displayName) 0058 GAPI_COMPARE(pictureUrl) 0059 GAPI_COMPARE(isAuthenticatedUser) 0060 GAPI_COMPARE(permissionId) 0061 return true; 0062 } 0063 0064 QString User::displayName() const 0065 { 0066 return d->displayName; 0067 } 0068 0069 QUrl User::pictureUrl() const 0070 { 0071 return d->pictureUrl; 0072 } 0073 0074 bool User::isAuthenticatedUser() const 0075 { 0076 return d->isAuthenticatedUser; 0077 } 0078 0079 QString User::permissionId() const 0080 { 0081 return d->permissionId; 0082 } 0083 0084 UserPtr User::fromJSON(const QVariantMap &map) 0085 { 0086 if (!map.contains(QLatin1StringView("kind")) || map[QStringLiteral("kind")].toString() != QLatin1StringView("drive#user")) { 0087 return UserPtr(); 0088 } 0089 0090 UserPtr user(new User()); 0091 user->d->displayName = map[QStringLiteral("displayName")].toString(); 0092 const QVariantMap picture = map[QStringLiteral("picture")].toMap(); 0093 user->d->pictureUrl = picture[QStringLiteral("url")].toUrl(); 0094 user->d->isAuthenticatedUser = map[QStringLiteral("isAuthenticatedUser")].toBool(); 0095 user->d->permissionId = map[QStringLiteral("permissionId")].toString(); 0096 0097 return user; 0098 }