Kgapi

accountinfo.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #include "accountinfo.h"
10 #include "utils_p.h"
11 
12 #include <QJsonDocument>
13 
14 #include <QVariantMap>
15 
16 using namespace KGAPI2;
17 
18 
19 class Q_DECL_HIDDEN AccountInfo::Private
20 {
21 public:
22  Private();
23  Private(const Private &other);
24  ~Private();
25 
26  QString id;
27  QString email;
28  QString name;
29  QString givenName;
30  QString familyName;
31 
32  QString birthday;
33  QString gender;
34 
35  QString link;
37  QString timezone;
38 
39  bool verifiedEmail;
40 
41  QString pictureUrl;
42 };
43 
44 AccountInfo::Private::Private():
45  verifiedEmail(false)
46 {
47 }
48 
49 AccountInfo::Private::Private(const Private &other):
50  id(other.id),
51  email(other.email),
52  name(other.name),
53  givenName(other.givenName),
54  familyName(other.familyName),
55  birthday(other.birthday),
56  gender(other.gender),
57  link(other.link),
58  locale(other.locale),
59  timezone(other.timezone),
60  verifiedEmail(other.verifiedEmail),
61  pictureUrl(other.pictureUrl)
62 {
63 }
64 
65 AccountInfo::Private::~Private()
66 {
67 }
68 
70  Object(),
71  d(new Private)
72 {
73 }
74 
76  Object(other),
77  d(new Private(*(other.d)))
78 {
79 }
80 
82 {
83  delete d;
84 }
85 
86 bool AccountInfo::operator==(const AccountInfo &other) const
87 {
88  if (!Object::operator==(other)) {
89  return false;
90  }
91  GAPI_COMPARE(id)
92  GAPI_COMPARE(email)
93  GAPI_COMPARE(name)
94  GAPI_COMPARE(givenName)
95  GAPI_COMPARE(familyName)
96  GAPI_COMPARE(birthday)
97  GAPI_COMPARE(gender)
98  GAPI_COMPARE(link)
99  GAPI_COMPARE(locale)
100  GAPI_COMPARE(timezone)
101  GAPI_COMPARE(verifiedEmail)
102  GAPI_COMPARE(pictureUrl)
103  return true;
104 }
105 
107 {
108  d->id = id;
109 }
110 
112 {
113  return d->id;
114 }
115 
117 {
118  d->email = email;
119 }
120 
122 {
123  return d->email;
124 }
125 
127 {
128  d->name = name;
129 }
130 
132 {
133  return d->name;
134 }
135 
137 {
138  d->givenName = givenName;
139 }
140 
142 {
143  return d->givenName;
144 }
145 
147 {
148  d->familyName = familyName;
149 }
150 
152 {
153  return d->familyName;
154 }
155 
157 {
158  d->birthday = birthday;
159 }
160 
162 {
163  return d->birthday;
164 }
165 
167 {
168  d->gender = gender;
169 }
170 
172 {
173  return d->gender;
174 }
175 
177 {
178  d->link = link;
179 }
180 
182 {
183  return d->link;
184 }
185 
187 {
188  d->locale = locale;
189 }
190 
192 {
193  return d->locale;
194 }
195 
197 {
198  d->timezone = timezone;
199 }
200 
202 {
203  return d->timezone;
204 }
205 
207 {
208  d->verifiedEmail = verifiedEmail;
209 }
210 
212 {
213  return d->verifiedEmail;
214 }
215 
217 {
218  d->pictureUrl = url;
219 }
220 
222 {
223  return d->pictureUrl;
224 }
225 
227 {
228  QJsonDocument document = QJsonDocument::fromJson(jsonData);
229  if (document.isNull()) {
230  return AccountInfoPtr();
231  }
232 
233  QVariantMap data;
234  data = document.toVariant().toMap();
235 
236  AccountInfoPtr accountInfo(new AccountInfo);
237  accountInfo->setId(data.value(QStringLiteral("id")).toString());
238  accountInfo->setEmail(data.value(QStringLiteral("email")).toString());
239  accountInfo->setName(data.value(QStringLiteral("name")).toString());
240  accountInfo->setGivenName(data.value(QStringLiteral("given_name")).toString());
241  accountInfo->setFamilyName(data.value(QStringLiteral("family_name")).toString());
242  accountInfo->setBirthday(data.value(QStringLiteral("birthday")).toString());
243  accountInfo->setGender(data.value(QStringLiteral("gender")).toString());
244  accountInfo->setLink(data.value(QStringLiteral("link")).toString());
245  accountInfo->setLocale(data.value(QStringLiteral("locale")).toString());
246  accountInfo->setTimezone(data.value(QStringLiteral("timezone")).toString());
247  accountInfo->setPhotoUrl(data.value(QStringLiteral("picture")).toString());
248  accountInfo->setVerifiedEmail(data.value(QStringLiteral("verified_email")).toBool());
249 
250  return accountInfo;
251 }
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
void setLocale(const QString &locale)
Sets users locale settings.
QString name(const QVariant &location)
Base class for all objects.
Definition: object.h:31
void setLink(const QString &link)
Sets link to user&#39;s profile.
void setTimezone(const QString &timezone)
Sets user&#39;s timezone name.
void setGender(const QString &gender)
Sets user&#39;s gender.
void setEmail(const QString &email)
Sets account email.
void setVerifiedEmail(bool verified)
Sets whether the email address is verified.
bool isNull() const const
virtual ~AccountInfo()
destructor
Definition: accountinfo.cpp:81
void setName(const QString &name)
Sets user&#39;s real full name.
QString timezone() const
Returns name of user&#39;s timezone.
QString locale() const
Returns user&#39;s preferred locales.
static AccountInfoPtr fromJSON(const QByteArray &jsonData)
Parses raw JSON data into AccountInfo object.
QString gender() const
Returns user&#39;s gender.
bool verifiedEmail() const
Returns whether the email is verified.
QString link() const
Returns link to user&#39;s profile.
void setId(const QString &id)
Sets an account ID.
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
QString email() const
Returns account email address.
QString id() const
Returns account ID.
QString photoUrl() const
Returns URL of user&#39;s photo.
QString familyName() const
Returns user&#39;s surname.
QVariant toVariant() const const
QString givenName() const
Returns user&#39;s given name.
void setPhotoUrl(const QString &url)
Sets URL of user&#39;s photo.
QString name() const
Returns user&#39;s real full name.
QMap< QString, QVariant > toMap() const const
AccountInfo contains information about user&#39;s Google account.
Definition: accountinfo.h:32
KIOCORE_EXPORT CopyJob * link(const QUrl &src, const QUrl &destDir, JobFlags flags=DefaultFlags)
void setBirthday(const QString &birthday)
Sets user&#39;s birthday.
LocaleWrapper locale()
QString birthday() const
Returns user&#39;s birthday.
void setGivenName(const QString &givenName)
Sets user&#39;s given name.
AccountInfo()
Constructor.
Definition: accountinfo.cpp:69
void setFamilyName(const QString &familyName)
Sets user&#39;s family name (surname).
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 23:12:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.