Kgapi

account.cpp
1/*
2 SPDX-FileCopyrightText: 2012, 2013 Daniel Vrátil <dvratil@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "account.h"
8#include "utils_p.h"
9
10#include <QDateTime>
11
12using namespace KGAPI2;
13
14class Q_DECL_HIDDEN Account::Private
15{
16public:
17 Private();
18 Private(const Private &other);
19
20 QString accName;
21 QString accessToken;
22 QString refreshToken;
23 QDateTime expireDateTime;
24 QList<QUrl> scopes;
25};
26
27Account::Private::Private()
28 : expireDateTime(QDateTime())
29{
30}
31
32Account::Private::Private(const Private &other)
33 : accName(other.accName)
34 , accessToken(other.accessToken)
35 , refreshToken(other.refreshToken)
36 , expireDateTime(other.expireDateTime)
37 , scopes(other.scopes)
38{
39}
40
42 : d(new Private)
43 , m_scopesChanged(false)
44{
45}
46
47Account::Account(const QString &accName, const QString &accessToken, const QString &refreshToken, const QList<QUrl> &scopes)
48 : d(new Private)
49 , m_scopesChanged(false)
50{
51 d->accName = accName;
52 d->accessToken = accessToken;
53 d->refreshToken = refreshToken;
54 d->scopes = scopes;
55}
56
58 : d(new Private(*(other.d)))
59 , m_scopesChanged(other.m_scopesChanged)
60{
61}
62
64{
65 delete d;
66}
67
68bool Account::operator==(const Account &other) const
69{
70 if (d == other.d) {
71 return true;
72 }
73
74 GAPI_COMPARE(accName)
75 GAPI_COMPARE(accessToken)
76 GAPI_COMPARE(refreshToken)
77 GAPI_COMPARE(expireDateTime)
78 GAPI_COMPARE(scopes)
79
80 return true;
81}
82
84{
85 return d->accName;
86}
87
88void Account::setAccountName(const QString &accountName)
89{
90 d->accName = accountName;
91}
92
94{
95 return d->accessToken;
96}
97
98void Account::setAccessToken(const QString &accessToken)
99{
100 d->accessToken = accessToken;
101}
102
104{
105 return d->refreshToken;
106}
107
108void Account::setRefreshToken(const QString &refreshToken)
109{
110 d->refreshToken = refreshToken;
111}
112
114{
115 return d->scopes;
116}
117
119{
120 d->scopes = scopes;
121 m_scopesChanged = true;
122}
123
124void Account::addScope(const QUrl &scope)
125{
126 if (!d->scopes.contains(scope)) {
127 d->scopes.append(scope);
128 m_scopesChanged = true;
129 }
130}
131
132void Account::removeScope(const QUrl &scope)
133{
134 if (d->scopes.contains(scope)) {
135 d->scopes.removeOne(scope);
136 m_scopesChanged = true;
137 }
138}
139
141{
142 return d->expireDateTime;
143}
144
146{
147 d->expireDateTime = expire;
148}
149
151{
152 return QUrl(QStringLiteral("https://www.googleapis.com/auth/userinfo.profile"));
153}
154
156{
157 return QUrl(QStringLiteral("https://www.googleapis.com/auth/userinfo.email"));
158}
159
161{
162 return QUrl(QStringLiteral("https://www.googleapis.com/auth/calendar"));
163}
164
166{
167 return QUrl(QStringLiteral("https://www.googleapis.com/auth/contacts"));
168}
169
171{
172 return QUrl(QStringLiteral("https://www.googleapis.com/auth/latitude.all.best"));
173}
174
176{
177 return QUrl(QStringLiteral("https://www.googleapis.com/auth/tasks"));
178}
179
181{
182 return QUrl(QStringLiteral("https://www.googleapis.com/auth/blogger"));
183}
184
186{
187 return QUrl(QStringLiteral("https://mail.google.com/"));
188}
189
191{
192 return QUrl(QStringLiteral("https://www.googleapis.com/auth/drive"));
193}
A Google account.
Definition account.h:40
QString refreshToken() const
Definition account.cpp:103
static QUrl accountInfoEmailScopeUrl()
Returns scope URL to retrieve AccountInfo with email.
Definition account.cpp:155
static QUrl calendarScopeUrl()
Returns scope URL for Google Calendar service.
Definition account.cpp:160
static QUrl peopleScopeUrl()
Returns scope URL for Google People service.
Definition account.cpp:165
QString accountName() const
Definition account.cpp:83
static QUrl latitudeScopeUrl()
Returns scope URL for Google Latitude service.
Definition account.cpp:170
QString accessToken() const
Definition account.cpp:93
static QUrl mailScopeUrl()
Returns scope URL for Gmail service.
Definition account.cpp:185
void setExpireDateTime(const QDateTime &expire)
Definition account.cpp:145
Account()
Constructs an invalid account.
Definition account.cpp:41
void addScope(const QUrl &scope)
Adds a single scope to account scopes.
Definition account.cpp:124
void setRefreshToken(const QString &refreshToken)
Sets a new refresh token for the access token.
Definition account.cpp:108
void removeScope(const QUrl &scope)
Removes scope from the list.
Definition account.cpp:132
virtual ~Account()
Destructor.
Definition account.cpp:63
static QUrl driveScopeUrl()
Returns scope URL for Drive service.
Definition account.cpp:190
static QUrl bloggerScopeUrl()
Returns scope URL for Google Blogger service.
Definition account.cpp:180
void setScopes(const QList< QUrl > &scopes)
Sets new scopes.
Definition account.cpp:118
void setAccountName(const QString &accountName)
Sets account name.
Definition account.cpp:88
static QUrl accountInfoScopeUrl()
Returns scope URL for AccountInfo service.
Definition account.cpp:150
static QUrl tasksScopeUrl()
Returns scope URL for Google Tasks service.
Definition account.cpp:175
void setAccessToken(const QString &accessToken)
Sets a new access token.
Definition account.cpp:98
QDateTime expireDateTime() const
Definition account.cpp:140
QList< QUrl > scopes() const
Definition account.cpp:113
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
void append(QList< T > &&value)
bool contains(const AT &value) const const
bool removeOne(const AT &t)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.