File indexing completed on 2024-06-09 05:16:51

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 "accountinfo.h"
0010 #include "utils_p.h"
0011 
0012 #include <QJsonDocument>
0013 
0014 #include <QVariantMap>
0015 
0016 using namespace KGAPI2;
0017 
0018 class Q_DECL_HIDDEN AccountInfo::Private
0019 {
0020 public:
0021     Private();
0022     Private(const Private &other);
0023     ~Private();
0024 
0025     QString id;
0026     QString email;
0027     QString name;
0028     QString givenName;
0029     QString familyName;
0030 
0031     QString birthday;
0032     QString gender;
0033 
0034     QString link;
0035     QString locale;
0036     QString timezone;
0037 
0038     bool verifiedEmail = false;
0039 
0040     QString pictureUrl;
0041 };
0042 
0043 AccountInfo::Private::Private()
0044 {
0045 }
0046 
0047 AccountInfo::Private::Private(const Private &other)
0048     : id(other.id)
0049     , email(other.email)
0050     , name(other.name)
0051     , givenName(other.givenName)
0052     , familyName(other.familyName)
0053     , birthday(other.birthday)
0054     , gender(other.gender)
0055     , link(other.link)
0056     , locale(other.locale)
0057     , timezone(other.timezone)
0058     , verifiedEmail(other.verifiedEmail)
0059     , pictureUrl(other.pictureUrl)
0060 {
0061 }
0062 
0063 AccountInfo::Private::~Private()
0064 {
0065 }
0066 
0067 AccountInfo::AccountInfo()
0068     : Object()
0069     , d(new Private)
0070 {
0071 }
0072 
0073 AccountInfo::AccountInfo(const AccountInfo &other)
0074     : Object(other)
0075     , d(new Private(*(other.d)))
0076 {
0077 }
0078 
0079 AccountInfo::~AccountInfo()
0080 {
0081     delete d;
0082 }
0083 
0084 bool AccountInfo::operator==(const AccountInfo &other) const
0085 {
0086     if (!Object::operator==(other)) {
0087         return false;
0088     }
0089     GAPI_COMPARE(id)
0090     GAPI_COMPARE(email)
0091     GAPI_COMPARE(name)
0092     GAPI_COMPARE(givenName)
0093     GAPI_COMPARE(familyName)
0094     GAPI_COMPARE(birthday)
0095     GAPI_COMPARE(gender)
0096     GAPI_COMPARE(link)
0097     GAPI_COMPARE(locale)
0098     GAPI_COMPARE(timezone)
0099     GAPI_COMPARE(verifiedEmail)
0100     GAPI_COMPARE(pictureUrl)
0101     return true;
0102 }
0103 
0104 void AccountInfo::setId(const QString &id)
0105 {
0106     d->id = id;
0107 }
0108 
0109 QString AccountInfo::id() const
0110 {
0111     return d->id;
0112 }
0113 
0114 void AccountInfo::setEmail(const QString &email)
0115 {
0116     d->email = email;
0117 }
0118 
0119 QString AccountInfo::email() const
0120 {
0121     return d->email;
0122 }
0123 
0124 void AccountInfo::setName(const QString &name)
0125 {
0126     d->name = name;
0127 }
0128 
0129 QString AccountInfo::name() const
0130 {
0131     return d->name;
0132 }
0133 
0134 void AccountInfo::setGivenName(const QString &givenName)
0135 {
0136     d->givenName = givenName;
0137 }
0138 
0139 QString AccountInfo::givenName() const
0140 {
0141     return d->givenName;
0142 }
0143 
0144 void AccountInfo::setFamilyName(const QString &familyName)
0145 {
0146     d->familyName = familyName;
0147 }
0148 
0149 QString AccountInfo::familyName() const
0150 {
0151     return d->familyName;
0152 }
0153 
0154 void AccountInfo::setBirthday(const QString &birthday)
0155 {
0156     d->birthday = birthday;
0157 }
0158 
0159 QString AccountInfo::birthday() const
0160 {
0161     return d->birthday;
0162 }
0163 
0164 void AccountInfo::setGender(const QString &gender)
0165 {
0166     d->gender = gender;
0167 }
0168 
0169 QString AccountInfo::gender() const
0170 {
0171     return d->gender;
0172 }
0173 
0174 void AccountInfo::setLink(const QString &link)
0175 {
0176     d->link = link;
0177 }
0178 
0179 QString AccountInfo::link() const
0180 {
0181     return d->link;
0182 }
0183 
0184 void AccountInfo::setLocale(const QString &locale)
0185 {
0186     d->locale = locale;
0187 }
0188 
0189 QString AccountInfo::locale() const
0190 {
0191     return d->locale;
0192 }
0193 
0194 void AccountInfo::setTimezone(const QString &timezone)
0195 {
0196     d->timezone = timezone;
0197 }
0198 
0199 QString AccountInfo::timezone() const
0200 {
0201     return d->timezone;
0202 }
0203 
0204 void AccountInfo::setVerifiedEmail(const bool verifiedEmail)
0205 {
0206     d->verifiedEmail = verifiedEmail;
0207 }
0208 
0209 bool AccountInfo::verifiedEmail() const
0210 {
0211     return d->verifiedEmail;
0212 }
0213 
0214 void AccountInfo::setPhotoUrl(const QString &url)
0215 {
0216     d->pictureUrl = url;
0217 }
0218 
0219 QString AccountInfo::photoUrl() const
0220 {
0221     return d->pictureUrl;
0222 }
0223 
0224 AccountInfoPtr AccountInfo::fromJSON(const QByteArray &jsonData)
0225 {
0226     QJsonDocument document = QJsonDocument::fromJson(jsonData);
0227     if (document.isNull()) {
0228         return AccountInfoPtr();
0229     }
0230 
0231     QVariantMap data;
0232     data = document.toVariant().toMap();
0233 
0234     AccountInfoPtr accountInfo(new AccountInfo);
0235     accountInfo->setId(data.value(QStringLiteral("id")).toString());
0236     accountInfo->setEmail(data.value(QStringLiteral("email")).toString());
0237     accountInfo->setName(data.value(QStringLiteral("name")).toString());
0238     accountInfo->setGivenName(data.value(QStringLiteral("given_name")).toString());
0239     accountInfo->setFamilyName(data.value(QStringLiteral("family_name")).toString());
0240     accountInfo->setBirthday(data.value(QStringLiteral("birthday")).toString());
0241     accountInfo->setGender(data.value(QStringLiteral("gender")).toString());
0242     accountInfo->setLink(data.value(QStringLiteral("link")).toString());
0243     accountInfo->setLocale(data.value(QStringLiteral("locale")).toString());
0244     accountInfo->setTimezone(data.value(QStringLiteral("timezone")).toString());
0245     accountInfo->setPhotoUrl(data.value(QStringLiteral("picture")).toString());
0246     accountInfo->setVerifiedEmail(data.value(QStringLiteral("verified_email")).toBool());
0247 
0248     return accountInfo;
0249 }