| 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 | #ifndef ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |
| 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |
| 23 | |
| 24 | #include <QJSValue> |
| 25 | #include <QObject> |
| 26 | #include <QString> |
| 27 | #include <QVariantMap> |
| 28 | |
| 29 | class QJSEngine; |
| 30 | |
| 31 | namespace OnlineAccounts { |
| 32 | class Account; |
| 33 | } |
| 34 | |
| 35 | namespace OnlineAccountsModule { |
| 36 | |
| 37 | class AccountPrivate; |
| 38 | class Account: public QObject |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | Q_ENUMS(AuthenticationMethod ErrorCode) |
| 42 | Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) |
| 43 | Q_PROPERTY(QString displayName READ displayName NOTIFY accountChanged) |
| 44 | Q_PROPERTY(int accountId READ accountId CONSTANT) |
| 45 | Q_PROPERTY(QString serviceId READ serviceId CONSTANT) |
| 46 | Q_PROPERTY(QJSValue service READ service CONSTANT) |
| 47 | Q_PROPERTY(AuthenticationMethod authenticationMethod \ |
| 48 | READ authenticationMethod CONSTANT) |
| 49 | Q_PROPERTY(QVariantMap settings READ settings NOTIFY accountChanged) |
| 50 | |
| 51 | public: |
| 52 | enum AuthenticationMethod { |
| 53 | // Make sure these are kept in sync with those from OnlineAccountsQt |
| 54 | AuthenticationMethodUnknown = 0, |
| 55 | AuthenticationMethodOAuth1, |
| 56 | AuthenticationMethodOAuth2, |
| 57 | AuthenticationMethodPassword, |
| 58 | AuthenticationMethodSasl, |
| 59 | }; |
| 60 | |
| 61 | enum ErrorCode { |
| 62 | // Make sure these are kept in sync with those from OnlineAccountsQt |
| 63 | ErrorCodeNoError = 0, |
| 64 | ErrorCodeNoAccount, |
| 65 | ErrorCodeWrongType, |
| 66 | ErrorCodeUserCanceled, |
| 67 | ErrorCodePermissionDenied, |
| 68 | ErrorCodeInteractionRequired, |
| 69 | }; |
| 70 | |
| 71 | explicit Account(OnlineAccounts::Account *account, QJSEngine *engine, |
| 72 | QObject *parent = 0); |
| 73 | ~Account(); |
| 74 | |
| 75 | bool isValid() const; |
| 76 | QString displayName() const; |
| 77 | int accountId() const; |
| 78 | QString serviceId() const; |
| 79 | QJSValue service() const; |
| 80 | AuthenticationMethod authenticationMethod() const; |
| 81 | QVariantMap settings() const; |
| 82 | |
| 83 | OnlineAccounts::Account *internalObject() const; |
| 84 | |
| 85 | Q_INVOKABLE void authenticate(const QVariantMap ¶ms); |
| 86 | |
| 87 | Q_SIGNALS: |
| 88 | void validChanged(); |
| 89 | void accountChanged(); |
| 90 | void authenticationReply(const QVariantMap &authenticationData); |
| 91 | |
| 92 | private: |
| 93 | Q_DECLARE_PRIVATE(Account) |
| 94 | AccountPrivate *d_ptr; |
| 95 | }; |
| 96 | |
| 97 | } // namespace |
| 98 | |
| 99 | Q_DECLARE_METATYPE(OnlineAccountsModule::Account::AuthenticationMethod) |
| 100 | Q_DECLARE_METATYPE(OnlineAccountsModule::Account::ErrorCode) |
| 101 | |
| 102 | #endif // ONLINE_ACCOUNTS_MODULE_ACCOUNT_H |