Kgapi

account.h
1 /*
2  SPDX-FileCopyrightText: 2012-2018 Daniel Vrátil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #ifndef LIBKGAPI2_ACCOUNT_H
8 #define LIBKGAPI2_ACCOUNT_H
9 
10 #include <QString>
11 #include <QUrl>
12 #include <QMetaType>
13 #include <QSharedPointer>
14 
15 #include "kgapicore_export.h"
16 #include "types.h"
17 
18 namespace KGAPI2
19 {
20 
21 /**
22  * @headerfile account.h
23  * @brief A Google account
24  *
25  * This class represents a single Google account. The account is uniquely
26  * identified by Account::accountName (which is actually the user's GMail address).
27  *
28  * The class stores an access token, refresh token (to retrieve a new access token
29  * when the old one expires) and list of scopes (APIs that current access token
30  * can be used to access).
31  *
32  * Unlike in previous versions, account management is not handled by LibKGAPI
33  * anymore and it's up to programmer to store the account in a persistent storage.
34  *
35  * To obtain a new account, use AuthJob.
36  *
37  * @author Daniel Vrátil <[email protected]>
38  * @since 0.1
39  */
40 class KGAPICORE_EXPORT Account
41 {
42 
43  public:
44  /**
45  * @brief Constructs an invalid account.
46  */
47  Account();
48 
49  /**
50  * @brief Constructs a new valid account
51  *
52  * @param account Google account name (usually [email protected])
53  * @param accessToken Access token to \p scopes for \p account
54  * @param refreshToken Refresh token
55  * @param scopes List of scopes
56  */
57  explicit Account(const QString &account, const QString &accessToken = QString(),
58  const QString &refreshToken = QString(),
59  const QList< QUrl > &scopes = QList< QUrl >());
60 
61  /**
62  * @brief Copy constructor
63  */
64  Account(const Account &other);
65 
66  /**
67  * @brief Destructor
68  */
69  virtual ~Account();
70 
71 
72  bool operator==(const Account &other) const;
73 
74  /**
75  * @returns Returns unique account identifier
76  */
77  QString accountName() const;
78 
79  /**
80  * Sets account name.
81  *
82  * @param accountName
83  */
84  void setAccountName(const QString &accountName);
85 
86  /**
87  * @return Returns access token.
88  */
89  QString accessToken() const;
90 
91  /**
92  * Sets a new access token.
93  *
94  * @param accessToken
95  */
96  void setAccessToken(const QString &accessToken);
97 
98  /**
99  * @return Returns refresh token.
100  */
101  QString refreshToken() const;
102 
103  /**
104  * Sets a new refresh token for the access token.
105  *
106  * @param refreshToken
107  */
108  void setRefreshToken(const QString &refreshToken);
109 
110  /**
111  * @return Returns list of scopes the account is authenticated against.
112  */
113  QList< QUrl > scopes() const;
114 
115  /**
116  * \brief Sets new scopes.
117  *
118  * @note Note that changing scopes requires makes current tokens invalid.
119  * This means that when this Account is used next time, AuthJob will be
120  * automatically started and user will be prompted with a dialog to grant
121  * access to all scopes.
122  *
123  * @param scopes
124  */
125  void setScopes(const QList< QUrl > &scopes);
126 
127  /**
128  * Adds a single scope to account scopes.
129  *
130  * @param scope
131  * @see Account::setScopes(const QList<QUrl>)
132  */
133  void addScope(const QUrl &scope);
134 
135  /**
136  * Removes scope from the list.
137  *
138  * @param scope
139  * @see Account::setScopes(const QList<QUrl>)
140  */
141  void removeScope(const QUrl &scope);
142 
143  /**
144  * @since 2.0.82
145  * Returns expire date time token
146  */
147  QDateTime expireDateTime() const;
148 
149  /**
150  * @since 2.0.82
151  * set expire date time
152  */
153  void setExpireDateTime(const QDateTime &expire);
154 
155  /**
156  * Returns scope URL for AccountInfo service.
157  */
158  static QUrl accountInfoScopeUrl();
159 
160  /**
161  * Returns scope URL to retrieve AccountInfo with email.
162  */
163  static QUrl accountInfoEmailScopeUrl();
164 
165  /**
166  * Returns scope URL for Google Calendar service.
167  */
168  static QUrl calendarScopeUrl();
169 
170  /**
171  * Returns scope URL for Google Tasks service.
172  */
173  static QUrl tasksScopeUrl();
174 
175  /**
176  * Returns scope URL for Google Contacts service.
177  */
178  static QUrl contactsScopeUrl();
179 
180  /**
181  * Returns scope URL for Google Latitude service.
182  */
183  static QUrl latitudeScopeUrl();
184 
185  /**
186  * Returns scope URL for Google Blogger service.
187  */
188  static QUrl bloggerScopeUrl();
189 
190  /**
191  * Returns scope URL for Gmail service.
192  */
193  static QUrl mailScopeUrl();
194 
195  /**
196  * Returns scope URL for Drive service.
197  */
198  static QUrl driveScopeUrl();
199 private:
200  class Private;
201  Private * const d;
202 
203  /**
204  * @internal
205  * Whether scopes were changed or not.
206  *
207  * AuthJob reads this attribute when Account is passed to it to
208  * determine whether completely new process of authentication is needed,
209  * or whether just refreshing tokens is enough.
210  *
211  * When m_scopesChanged is \p true and AuthJob successffulyperforms full
212  * re-authentication it sets this attribute to \p false and next time it
213  * will just refresh existing tokens until the scopes are changed again.
214  */
215  bool m_scopesChanged; //krazy:exclude=dpointer
216 
217  friend class AuthJob;
218 
219 };
220 
221 } // namespace KGAPI2
222 
223 Q_DECLARE_METATYPE(KGAPI2::AccountPtr)
224 
225 #endif // LIBKGAPI2_ACCOUNT_H
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
A Google account.
Definition: account.h:40
A job to authenticate against Google and fetch tokens.
Definition: authjob.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Mar 3 2021 00:10:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.