~ci-train-bot/online-accounts-api/online-accounts-api-ubuntu-xenial-landing-033

« back to all changes in this revision

Viewing changes to src/lib/Ubuntu/OnlineAccounts.2/account.cpp

  • Committer: CI Train Bot
  • Author(s): Alberto Mardegan
  • Date: 2015-09-23 12:41:36 UTC
  • mfrom: (8.4.11 update)
  • Revision ID: ci-train-bot@canonical.com-20150923124136-43tthyu1l6lkqq3l
Docs, fixes, library install

- Docs
- Couple of bugfixes
- Package the daemon as a library

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
        map["errorCode"] = reply.error().code();
71
71
        map["errorText"] = reply.error().text();
72
72
    } else {
73
 
        map = replyToMap(*watcher, m_account->authenticationMethod());
 
73
        map = replyToMap(*watcher);
74
74
    }
75
75
 
76
76
    Q_EMIT q->authenticationReply(map);
77
77
}
78
78
 
 
79
/*!
 
80
 * \qmltype Account
 
81
 * \inqmlmodule Ubuntu.OnlineAccounts 2.0
 
82
 * \ingroup Ubuntu
 
83
 * \brief Representation of an online account
 
84
 *
 
85
 * The Account object holds the information related to an account and provides
 
86
 * methods to interact with it.
 
87
 * It's not possible to create such objects from QML; instead, they are
 
88
 * returned by the \l AccountModel in the \c account role or in the \l
 
89
 * {AccountModel::accountList} { \c accountList} property.
 
90
 *
 
91
 * Here's an example on how to use the account object in a delegate:
 
92
 *
 
93
 * \qml
 
94
 *     import QtQuick 2.0
 
95
 *     import Ubuntu.OnlineAccounts 2.0
 
96
 *
 
97
 *     ListView {
 
98
 *         model: AccountModel {}
 
99
 *         delegate: Button {
 
100
 *             text: "Authenticate " + model.displayName
 
101
 *             onClicked: model.account.authenticate({})
 
102
 *             Connections {
 
103
 *                 target: model.account
 
104
 *                 onAuthenticationReply: {
 
105
 *                     console.log("Access token is " + reply['AccessToken'])
 
106
 *                 }
 
107
 *             }
 
108
 *         }
 
109
 *     }
 
110
 * \endqml
 
111
 *
 
112
 * \target errorCode
 
113
 * \section3 Error codes used in this module
 
114
 * Some operations, such as the \l Account::authenticate() and the \l
 
115
 * AccountModel::requestAccess() methods, can fail and return one of these
 
116
 * error codes:
 
117
 * \list
 
118
 * \li \c Account.ErrorCodeNoAccount - The accounts is invalid
 
119
 * \li \c Account.ErrorCodeUserCanceled - The operation was canceled by the user
 
120
 * \li \c Account.ErrorCodePermissionDenied - The application has no
 
121
 *     permission to complete the operation
 
122
 * \endlist
 
123
 */
 
124
 
79
125
Account::Account(OnlineAccounts::Account *account, QObject *parent):
80
126
    QObject(parent),
81
127
    d_ptr(new AccountPrivate(account, this))
87
133
    delete d_ptr;
88
134
}
89
135
 
 
136
/*!
 
137
 * \qmlproperty bool Account::valid
 
138
 *
 
139
 * Whether the account object is valid; this is usually \c true, because the \c
 
140
 * AccountModel never gives out invalid accounts. However, it can happen that a
 
141
 * valid account becomes invalid while the application is using it (if, for
 
142
 * instance, the user deleted the account or revoked the application's access
 
143
 * rights to use it). As soon as this property becomes \c false, the
 
144
 * application should stop using this account.
 
145
 */
90
146
bool Account::isValid() const
91
147
{
92
148
    Q_D(const Account);
93
149
    return d->m_account->isValid();
94
150
}
95
151
 
 
152
/*!
 
153
 * \qmlproperty string Account::displayName
 
154
 *
 
155
 * The display name of the account. This is usually the user's login name, but
 
156
 * applications should not rely on the value of this property. Use it only for
 
157
 * display purposes.
 
158
 */
96
159
QString Account::displayName() const
97
160
{
98
161
    Q_D(const Account);
99
162
    return d->m_account->displayName();
100
163
}
101
164
 
 
165
/*!
 
166
 * \qmlproperty int Account::accountId
 
167
 *
 
168
 * Numeric identifier of the account. This property remains constant during the
 
169
 * lifetime of the account. Note, however, that if the user deletes the account
 
170
 * and re-creates it, its ID will be different.
 
171
 */
102
172
int Account::accountId() const
103
173
{
104
174
    Q_D(const Account);
105
175
    return d->m_account->id();
106
176
}
107
177
 
 
178
/*!
 
179
 * \qmlproperty int Account::serviceId
 
180
 *
 
181
 * Identifier for the service used with the account.
 
182
 */
108
183
QString Account::serviceId() const
109
184
{
110
185
    Q_D(const Account);
111
186
    return d->m_account->serviceId();
112
187
}
113
188
 
 
189
/*!
 
190
 * \qmlproperty enumeration Account::authenticationMethod
 
191
 *
 
192
 * The authentication method used when authenticating with the account.
 
193
 * Currently, these authentication methods are supported:
 
194
 * \list
 
195
 *   \li \c Account.AuthenticationMethodOAuth1 - OAuth 1.0
 
196
 *   \li \c Account.AuthenticationMethodOAuth2 - OAuth 2.0
 
197
 *   \li \c Account.AuthenticationMethodPassword - username/password
 
198
 * \endlist
 
199
 */
114
200
Account::AuthenticationMethod Account::authenticationMethod() const
115
201
{
116
202
    Q_D(const Account);
117
203
    return AuthenticationMethod(d->m_account->authenticationMethod());
118
204
}
119
205
 
 
206
/*!
 
207
 * \qmlproperty jsobject Account::settings
 
208
 *
 
209
 * A dictionary of the settings stored into the account.
 
210
 */
120
211
QVariantMap Account::settings() const
121
212
{
122
 
    /* FIXME: libOnlineAccountsQt lacks a way to retrieve the list of settings;
123
 
     * until that is available, we cannot do much here */
124
 
    return QVariantMap();
 
213
    Q_D(const Account);
 
214
    QVariantMap ret;
 
215
    Q_FOREACH(const QString &key, d->m_account->keys()) {
 
216
        ret.insert(key, d->m_account->setting(key));
 
217
    }
 
218
    return ret;
125
219
}
126
220
 
127
221
OnlineAccounts::Account *Account::internalObject() const
130
224
    return d->m_account;
131
225
}
132
226
 
 
227
/*!
 
228
 * \qmlsignal Account::authenticationReply(jsobject authenticationData)
 
229
 *
 
230
 * Emitted when the authentication completes. The \a authenticationData object
 
231
 * will contain the authentication reply. If the authentication failed, the
 
232
 * following two keys will be present:
 
233
 * \list
 
234
 * \li \c errorCode is an \l {errorCode} {error code}
 
235
 * \li \c errorText is a textual description of the error, not meant for the
 
236
 *     end-user; it can be used for debugging purposes
 
237
 * \endlist
 
238
 */
 
239
 
 
240
/*!
 
241
 * \qmlmethod void Account::authenticate(jsobject params)
 
242
 *
 
243
 * Perform the authentication on this account. The \a params parameter can be
 
244
 * used to pass authentication data, such as the ClientId and ClientSecret used
 
245
 * in the OAuth flow. The list of the supported authentication parameters
 
246
 * depend on the authentication method being used, and are documented in the
 
247
 * Online Accounts development Guide in the Ubuntu Developer Portal.
 
248
 *
 
249
 * There are, however, two authentication parameters which are available
 
250
 * regardless of the authentication method being used:
 
251
 * \list
 
252
 * \li \c invalidateCachedReply can be set to \c true when the previous
 
253
 *     authentication reply returned an invalid access token. It will ensure
 
254
 *     the creation of a new access token.
 
255
 * \li \c interactive is \c true by default; if set to \c false, it will ensure
 
256
 *     that no interaction with the user will occur.
 
257
 * \endlist
 
258
 *
 
259
 * Each call to this method will cause the \l authenticationReply signal to be
 
260
 * emitted at some time later. Note that the authentication might involve
 
261
 * interactions with the network or with the end-user, so don't expect a reply
 
262
 * to be emitted immediately.
 
263
 *
 
264
 * \sa authenticationReply
 
265
 */
133
266
void Account::authenticate(const QVariantMap &params)
134
267
{
135
268
    Q_D(Account);