| 1 | /* |
| 2 | * This file is part of OnlineAccountsModule |
| 3 | * |
| 4 | * Copyright (C) 2015 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "account.h"cxx . . $ `<file>/online-accounts/lib/qml/Lomiri/OnlineAccounts/account.h`/ |
| 22 | #include "authentication_data.h"cxx . . $ `<file>/online-accounts/lib/qml/Lomiri/OnlineAccounts/authentication_data.h`/ |
| 23 | |
| 24 | #include <LomiriOnlineAccounts/Account>cxx . . $ `<file>/online-accounts/lib/qt/LomiriOnlineAccounts/Account`/ |
| 25 | #include <LomiriOnlineAccounts/AuthenticationData>cxx . . $ `<file>/online-accounts/lib/qt/LomiriOnlineAccounts/AuthenticationData`/ |
| 26 | #include <LomiriOnlineAccounts/AuthenticationReply>cxx . . $ `<file>/online-accounts/lib/qt/LomiriOnlineAccounts/AuthenticationReply`/ |
| 27 | #include <LomiriOnlineAccounts/PendingCall>cxx . . $ `<file>/online-accounts/lib/qt/LomiriOnlineAccounts/PendingCall`/ |
| 28 | |
| 29 | #include <QDebug> |
| 30 | #include <QJSEngine> |
| 31 | |
| 32 | using namespace OnlineAccountsModule; |
| 33 | |
| 34 | namespace OnlineAccountsModulecxx . . $ OnlineAccountsModule/ { |
| 35 | |
| 36 | class AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#: public QObjectcxx . . $ QObject# |
| 37 | { |
| 38 | Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`! |
| 39 | Q_DECLARE_PUBLICcxx . . $ `<external>/15045578679651060896/qglobal.h:1172:9`!(Account) |
| 40 | |
| 41 | public: |
| 42 | AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#AccountPrivate(e531fde44deabcf2).(OnlineAccountscxx . . $ OnlineAccounts/::Accountcxx . . $ OnlineAccounts/Account# *account, QJSEnginecxx . . $ QJSEngine# *engine, |
| 43 | Accountcxx . . $ OnlineAccountsModule/Account# *q); |
| 44 | |
| 45 | private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!: |
| 46 | void onAuthenticationFinishedcxx . . $ OnlineAccountsModule/AccountPrivate#onAuthenticationFinished(49f6e7a06ebc5aa8).(); |
| 47 | |
| 48 | private: |
| 49 | OnlineAccountscxx . . $ OnlineAccounts/::Accountcxx . . $ OnlineAccounts/Account# *m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.; |
| 50 | QJSEnginecxx . . $ QJSEngine# *m_enginecxx . . $ OnlineAccountsModule/AccountPrivate#m_engine.; |
| 51 | mutable Accountcxx . . $ OnlineAccountsModule/Account# *q_ptrcxx . . $ OnlineAccountsModule/AccountPrivate#q_ptr.; |
| 52 | }; |
| 53 | |
| 54 | } // namespace |
| 55 | |
| 56 | AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#::AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#AccountPrivate(e531fde44deabcf2).(OnlineAccountscxx . . $ OnlineAccounts/::Accountcxx . . $ OnlineAccounts/Account# *account, |
| 57 | QJSEnginecxx . . $ QJSEngine# *engine, |
| 58 | Accountcxx . . $ OnlineAccountsModule/Account# *q): |
| 59 | m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.(account), |
| 60 | m_enginecxx . . $ OnlineAccountsModule/AccountPrivate#m_engine.(engine), |
| 61 | q_ptrcxx . . $ OnlineAccountsModule/AccountPrivate#q_ptr.(q) |
| 62 | { |
| 63 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(account, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(changed()), |
| 64 | q, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(accountChanged())); |
| 65 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(account, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(disabled()), |
| 66 | q, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(validChanged())); |
| 67 | } |
| 68 | |
| 69 | void AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#::onAuthenticationFinishedcxx . . $ OnlineAccountsModule/AccountPrivate#onAuthenticationFinished(49f6e7a06ebc5aa8).() |
| 70 | { |
| 71 | Q_Qcxx . . $ `<external>/15045578679651060896/qglobal.h:1178:9`!(Account); |
| 72 | |
| 73 | auto watcher = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<OnlineAccountscxx . . $ OnlineAccounts/::PendingCallWatchercxx . . $ OnlineAccounts/PendingCallWatcher#*>(sendercxx . . $ QObject#sender(2dbb680a34285c44).()); |
| 74 | |
| 75 | OnlineAccountscxx . . $ OnlineAccounts/::AuthenticationReplycxx . . $ OnlineAccounts/AuthenticationReply# replycxx . . $ OnlineAccounts/AuthenticationReply#AuthenticationReply(8feb05cfa3fd417d).(*watcher); |
| 76 | QVariantMapcxx . . $ QVariantMap# mapcxx . . $ QMap#QMap(ced63f7c635d850d).; |
| 77 | if (reply.hasErrorcxx . . $ OnlineAccounts/AuthenticationReply#hasError(50ce9a9e25b4a850).()) { |
| 78 | map[cxx . . $ QMap#`operator[]`(bbd415b616967878)."errorCode"cxx . . $ QString#QString(85c52e162fed56f9).] =cxx . . $ QVariant#`operator=`(79a68221451e88b7). replycxx . . $ QVariant#QVariant(d4f767463ce0a6b3)..errorcxx . . $ OnlineAccounts/AuthenticationReply#error(b1aaa45c8f119b6a).().codecxx . . $ OnlineAccounts/Error#code(89328546d36c98d).(); |
| 79 | map[cxx . . $ QMap#`operator[]`(bbd415b616967878)."errorText"cxx . . $ QString#QString(85c52e162fed56f9).] =cxx . . $ QVariant#`operator=`(79a68221451e88b7). replycxx . . $ QVariant#QVariant(3520e46b33348bf6)..errorcxx . . $ OnlineAccounts/AuthenticationReply#error(b1aaa45c8f119b6a).().textcxx . . $ OnlineAccounts/Error#text(6ef7b6c27b00b43d).(); |
| 80 | } else { |
| 81 | map =cxx . . $ QMap#`operator=`(86243d55ea3d6313). replyToMapcxx . . $ replyToMap(259f5df199cf362f).(*watcher); |
| 82 | } |
| 83 | |
| 84 | Q_EMITcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:95:10`! q->authenticationReplycxx . . $ OnlineAccountsModule/Account#authenticationReply(3e95df3e31f2cce8).(map); |
| 85 | } |
| 86 | |
| 87 | /*! |
| 88 | * \qmltype Account |
| 89 | * \inqmlmodule Lomiri.OnlineAccounts 2.0 |
| 90 | * \ingroup Lomiri |
| 91 | * \brief Representation of an online account |
| 92 | * |
| 93 | * The Account object holds the information related to an account and provides |
| 94 | * methods to interact with it. |
| 95 | * It's not possible to create such objects from QML; instead, they are |
| 96 | * returned by the \l AccountModel in the \c account role or in the \l |
| 97 | * {AccountModel::accountList} { \c accountList} property. |
| 98 | * |
| 99 | * Here's an example on how to use the account object in a delegate: |
| 100 | * |
| 101 | * \qml |
| 102 | * import QtQuick 2.0 |
| 103 | * import Lomiri.OnlineAccounts 2.0 |
| 104 | * |
| 105 | * ListView { |
| 106 | * model: AccountModel {} |
| 107 | * delegate: Button { |
| 108 | * text: "Authenticate " + model.displayName |
| 109 | * onClicked: model.account.authenticate({}) |
| 110 | * Connections { |
| 111 | * target: model.account |
| 112 | * onAuthenticationReply: { |
| 113 | * console.log("Access token is " + reply['AccessToken']) |
| 114 | * } |
| 115 | * } |
| 116 | * } |
| 117 | * } |
| 118 | * \endqml |
| 119 | * |
| 120 | * \target errorCode |
| 121 | * \section3 Error codes used in this module |
| 122 | * Some operations, such as the \l Account::authenticate() and the \l |
| 123 | * AccountModel::requestAccess() methods, can fail and return one of these |
| 124 | * error codes: |
| 125 | * \list |
| 126 | * \li \c Account.ErrorCodeNoAccount - The accounts is invalid |
| 127 | * \li \c Account.ErrorCodeUserCanceled - The operation was canceled by the user |
| 128 | * \li \c Account.ErrorCodePermissionDenied - The application has no |
| 129 | * permission to complete the operation |
| 130 | * \endlist |
| 131 | */ |
| 132 | |
| 133 | Accountcxx . . $ OnlineAccountsModule/Account#::Accountcxx . . $ OnlineAccountsModule/Account#Account(401d2a618a30041e).(OnlineAccountscxx . . $ OnlineAccounts/::Accountcxx . . $ OnlineAccounts/Account# *account, QJSEnginecxx . . $ QJSEngine# *engine, |
| 134 | QObjectcxx . . $ QObject# *parent): |
| 135 | QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), |
| 136 | d_ptrcxx . . $ OnlineAccountsModule/Account#d_ptr.(new AccountPrivatecxx . . $ OnlineAccountsModule/AccountPrivate#AccountPrivate(e531fde44deabcf2).(account, engine, this)) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | Accountcxx . . $ OnlineAccountsModule/Account#::~cxx . . $ OnlineAccountsModule/Account#`~Account`(ced63f7c635d850d).Accountcxx . . $ OnlineAccountsModule/Account#() |
| 141 | { |
| 142 | delete d_ptrcxx . . $ OnlineAccountsModule/Account#d_ptr.; |
| 143 | } |
| 144 | |
| 145 | /*! |
| 146 | * \qmlproperty bool Account::valid |
| 147 | * |
| 148 | * Whether the account object is valid; this is usually \c true, because the \c |
| 149 | * AccountModel never gives out invalid accounts. However, it can happen that a |
| 150 | * valid account becomes invalid while the application is using it (if, for |
| 151 | * instance, the user deleted the account or revoked the application's access |
| 152 | * rights to use it). As soon as this property becomes \c false, the |
| 153 | * application should stop using this account. |
| 154 | */ |
| 155 | bool Accountcxx . . $ OnlineAccountsModule/Account#::isValidcxx . . $ OnlineAccountsModule/Account#isValid(50ce9a9e25b4a850).() const |
| 156 | { |
| 157 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 158 | return d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->isValidcxx . . $ OnlineAccounts/Account#isValid(50ce9a9e25b4a850).(); |
| 159 | } |
| 160 | |
| 161 | /*! |
| 162 | * \qmlproperty string Account::displayName |
| 163 | * |
| 164 | * The display name of the account. This is usually the user's login name, but |
| 165 | * applications should not rely on the value of this property. Use it only for |
| 166 | * display purposes. |
| 167 | */ |
| 168 | QStringcxx . . $ QString# Accountcxx . . $ OnlineAccountsModule/Account#::displayNamecxx . . $ OnlineAccountsModule/Account#displayName(6ef7b6c27b00b43d).() const |
| 169 | { |
| 170 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 171 | return d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->displayNamecxx . . $ OnlineAccounts/Account#displayName(6ef7b6c27b00b43d).(); |
| 172 | } |
| 173 | |
| 174 | /*! |
| 175 | * \qmlproperty int Account::accountId |
| 176 | * |
| 177 | * Numeric identifier of the account. This property remains constant during the |
| 178 | * lifetime of the account. Note, however, that if the user deletes the account |
| 179 | * and re-creates it, its ID will be different. |
| 180 | */ |
| 181 | int Accountcxx . . $ OnlineAccountsModule/Account#::accountIdcxx . . $ OnlineAccountsModule/Account#accountId(455f465bc33b4cdf).() const |
| 182 | { |
| 183 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 184 | return d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->idcxx . . $ OnlineAccounts/Account#id(ddd8539a2fcdd4ce).(); |
| 185 | } |
| 186 | |
| 187 | /*! |
| 188 | * \qmlproperty int Account::serviceId |
| 189 | * |
| 190 | * Identifier for the service used with the account. |
| 191 | */ |
| 192 | QStringcxx . . $ QString# Accountcxx . . $ OnlineAccountsModule/Account#::serviceIdcxx . . $ OnlineAccountsModule/Account#serviceId(6ef7b6c27b00b43d).() const |
| 193 | { |
| 194 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 195 | return d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->serviceIdcxx . . $ OnlineAccounts/Account#serviceId(6ef7b6c27b00b43d).(); |
| 196 | } |
| 197 | |
| 198 | /*! |
| 199 | * \qmlproperty int Account::service |
| 200 | * |
| 201 | * Service data associated with this account. This is an object containing the |
| 202 | * following properties: |
| 203 | * \list |
| 204 | * \li \c serviceId - same service ID returned by Account::serviceId |
| 205 | * \li \c displayName - the localized display name for the service |
| 206 | * \li \c iconSource - URL for the icon; can be a "file://" URL to a local |
| 207 | * file, or an icon from the theme if the URL starts with "image://theme/" |
| 208 | * \endlist |
| 209 | */ |
| 210 | QJSValuecxx . . $ QJSValue# Accountcxx . . $ OnlineAccountsModule/Account#::servicecxx . . $ OnlineAccountsModule/Account#service(cedfddd5dbefb84d).() const |
| 211 | { |
| 212 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 213 | #if QT_VERSIONcxx . . $ `<external>/15045578679651060896/qglobal.h:57:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/15045578679651060896/qglobal.h:61:9`!(5, 5, 0) |
| 214 | return d->m_enginecxx . . $ OnlineAccountsModule/AccountPrivate#m_engine.->toScriptValuecxx . . $ QJSEngine#toScriptValue(1062736fde553e42).(d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->servicecxx . . $ OnlineAccounts/Account#service(7ad0f4f8a29cc02d).()); |
| 215 | #else |
| 216 | return d->m_engine->toScriptValue(d->m_account->service().toMap()); |
| 217 | #endif |
| 218 | } |
| 219 | |
| 220 | /*! |
| 221 | * \qmlproperty enumeration Account::authenticationMethod |
| 222 | * |
| 223 | * The authentication method used when authenticating with the account. |
| 224 | * Currently, these authentication methods are supported: |
| 225 | * \list |
| 226 | * \li \c Account.AuthenticationMethodOAuth1 - OAuth 1.0 |
| 227 | * \li \c Account.AuthenticationMethodOAuth2 - OAuth 2.0 |
| 228 | * \li \c Account.AuthenticationMethodSasl - SASL |
| 229 | * \li \c Account.AuthenticationMethodPassword - username/password |
| 230 | * \endlist |
| 231 | */ |
| 232 | Accountcxx . . $ OnlineAccountsModule/Account#::AuthenticationMethodcxx . . $ OnlineAccountsModule/Account#AuthenticationMethod# Accountcxx . . $ OnlineAccountsModule/Account#::authenticationMethodcxx . . $ OnlineAccountsModule/Account#authenticationMethod(5a498decbd4374ed).() const |
| 233 | { |
| 234 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 235 | return AuthenticationMethodcxx . . $ OnlineAccountsModule/Account#AuthenticationMethod#(d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->authenticationMethodcxx . . $ OnlineAccounts/Account#authenticationMethod(5844b1512d846331).()); |
| 236 | } |
| 237 | |
| 238 | /*! |
| 239 | * \qmlproperty jsobject Account::settings |
| 240 | * |
| 241 | * A dictionary of the settings stored into the account. |
| 242 | */ |
| 243 | QVariantMapcxx . . $ QVariantMap# Accountcxx . . $ OnlineAccountsModule/Account#::settingscxx . . $ OnlineAccountsModule/Account#settings(87f780dbe64191c4).() const |
| 244 | { |
| 245 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 246 | QVariantMapcxx . . $ QVariantMap# retcxx . . $ QMap#QMap(ced63f7c635d850d).; |
| 247 | Q_FOREACHcxx . . $ `<external>/15045578679651060896/qglobal.h:1137:9`!(const QString &key, d->m_account->keys()) { |
| 248 | ret.insertcxx . . $ QMap#insert(929a1ed410fe8423).(key, d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->settingcxx . . $ OnlineAccounts/Account#setting(f6a024953685a9e0).(key)); |
| 249 | } |
| 250 | return retcxx . . $ QMap#QMap(28c642871a274d78).; |
| 251 | } |
| 252 | |
| 253 | OnlineAccountscxx . . $ OnlineAccounts/::Accountcxx . . $ OnlineAccounts/Account# *Accountcxx . . $ OnlineAccountsModule/Account#::internalObjectcxx . . $ OnlineAccountsModule/Account#internalObject(2cf67f3f9da842b4).() const |
| 254 | { |
| 255 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const Account); |
| 256 | return d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.; |
| 257 | } |
| 258 | |
| 259 | /*! |
| 260 | * \qmlsignal Account::authenticationReply(jsobject authenticationData) |
| 261 | * |
| 262 | * Emitted when the authentication completes. The \a authenticationData object |
| 263 | * will contain the authentication reply. If the authentication failed, the |
| 264 | * following two keys will be present: |
| 265 | * \list |
| 266 | * \li \c errorCode is an \l {errorCode} {error code} |
| 267 | * \li \c errorText is a textual description of the error, not meant for the |
| 268 | * end-user; it can be used for debugging purposes |
| 269 | * \endlist |
| 270 | */ |
| 271 | |
| 272 | /*! |
| 273 | * \qmlmethod void Account::authenticate(jsobject params) |
| 274 | * |
| 275 | * Perform the authentication on this account. The \a params parameter can be |
| 276 | * used to pass authentication data, such as the ClientId and ClientSecret used |
| 277 | * in the OAuth flow. The list of the supported authentication parameters |
| 278 | * depend on the authentication method being used, and are documented in the |
| 279 | * Online Accounts development Guide in the UBports Developer Portal. |
| 280 | * |
| 281 | * There are, however, two authentication parameters which are available |
| 282 | * regardless of the authentication method being used: |
| 283 | * \list |
| 284 | * \li \c invalidateCachedReply can be set to \c true when the previous |
| 285 | * authentication reply returned an invalid access token. It will ensure |
| 286 | * the creation of a new access token. |
| 287 | * \li \c interactive is \c true by default; if set to \c false, it will ensure |
| 288 | * that no interaction with the user will occur. |
| 289 | * \endlist |
| 290 | * |
| 291 | * Each call to this method will cause the \l authenticationReply signal to be |
| 292 | * emitted at some time later. Note that the authentication might involve |
| 293 | * interactions with the network or with the end-user, so don't expect a reply |
| 294 | * to be emitted immediately. |
| 295 | * |
| 296 | * \sa authenticationReply |
| 297 | */ |
| 298 | void Accountcxx . . $ OnlineAccountsModule/Account#::authenticatecxx . . $ OnlineAccountsModule/Account#authenticate(3e95df3e31f2cce8).(const QVariantMapcxx . . $ QVariantMap# ¶ms) |
| 299 | { |
| 300 | Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(Account); |
| 301 | auto method = d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->authenticationMethodcxx . . $ OnlineAccounts/Account#authenticationMethod(5844b1512d846331).(); |
| 302 | OnlineAccountscxx . . $ OnlineAccounts/::PendingCallcxx . . $ OnlineAccounts/PendingCall# call = |
| 303 | d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.->authenticatecxx . . $ OnlineAccounts/Account#authenticate(e8c79b7e1e87f1df).(authenticationDataFromMapcxx . . $ authenticationDataFromMap(451eacff083bcf72).(params, method)); |
| 304 | OnlineAccountscxx . . $ OnlineAccounts/::PendingCallWatchercxx . . $ OnlineAccounts/PendingCallWatcher# *watcher = |
| 305 | new OnlineAccountscxx . . $ OnlineAccounts/::PendingCallWatchercxx . . $ OnlineAccounts/PendingCallWatcher#(call, d->m_accountcxx . . $ OnlineAccountsModule/AccountPrivate#m_account.); |
| 306 | QObjectcxx . . $ QObject#::connectcxx . . $ QObject#connect(158df1d9a01a3410).(watcher, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(finished()), |
| 307 | d, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(onAuthenticationFinished())); |
| 308 | } |
| 309 | |
| 310 | #include "account.moc"cxx . . $ `<file>/build/online-accounts/lib/qml/Lomiri/OnlineAccounts/LomiriOnlineAccountsQML_autogen/include/account.moc`/ |