| 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_MODEL_H |
| 22 | #define ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H |
| 23 | |
| 24 | #include <LomiriOnlineAccounts/Service> |
| 25 | |
| 26 | #include <QAbstractListModel> |
| 27 | #include <QQmlParserStatus> |
| 28 | #include <QQmlListProperty> |
| 29 | #include <QJSValue> |
| 30 | #include <QString> |
| 31 | #include <QVariant> |
| 32 | |
| 33 | namespace OnlineAccountsModule { |
| 34 | |
| 35 | class Account; |
| 36 | |
| 37 | class AccountModelPrivate; |
| 38 | class AccountModel: public QAbstractListModel, public QQmlParserStatus |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | Q_INTERFACES(QQmlParserStatus) |
| 42 | Q_PROPERTY(int count READ rowCount NOTIFY countChanged) |
| 43 | Q_PROPERTY(bool ready READ isReady NOTIFY isReadyChanged) |
| 44 | Q_PROPERTY(QString applicationId READ applicationId \ |
| 45 | WRITE setApplicationId NOTIFY applicationIdChanged) |
| 46 | Q_PROPERTY(QString serviceId READ serviceId \ |
| 47 | WRITE setServiceId NOTIFY serviceIdChanged) |
| 48 | Q_PROPERTY(QList<QObject*> accountList READ accountList \ |
| 49 | NOTIFY accountListChanged) |
| 50 | Q_PROPERTY(QJSValue serviceList READ serviceList \ |
| 51 | NOTIFY isReadyChanged) |
| 52 | |
| 53 | public: |
| 54 | enum Roles { |
| 55 | DisplayNameRole = Qt::UserRole + 1, |
| 56 | ValidRole, |
| 57 | AccountIdRole, |
| 58 | ServiceIdRole, |
| 59 | AuthenticationMethodRole, |
| 60 | SettingsRole, |
| 61 | AccountRole, |
| 62 | ServiceRole, |
| 63 | }; |
| 64 | |
| 65 | explicit AccountModel(QObject *parent = 0); |
| 66 | ~AccountModel(); |
| 67 | |
| 68 | bool isReady() const; |
| 69 | |
| 70 | void setApplicationId(const QString &applicationId); |
| 71 | QString applicationId() const; |
| 72 | |
| 73 | void setServiceId(const QString &serviceId); |
| 74 | QString serviceId() const; |
| 75 | |
| 76 | QList<QObject*> accountList() const; |
| 77 | |
| 78 | QJSValue serviceList() const; |
| 79 | |
| 80 | Q_INVOKABLE void requestAccess(const QString &service, |
| 81 | const QVariantMap ¶ms); |
| 82 | |
| 83 | Q_INVOKABLE QVariant get(int row, const QString &roleName) const; |
| 84 | |
| 85 | // reimplemented virtual methods |
| 86 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
| 87 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
| 88 | QHash<int, QByteArray> roleNames() const; |
| 89 | |
| 90 | void classBegin() Q_DECL_OVERRIDE; |
| 91 | void componentComplete() Q_DECL_OVERRIDE; |
| 92 | |
| 93 | Q_SIGNALS: |
| 94 | void isReadyChanged(); |
| 95 | void countChanged(); |
| 96 | void applicationIdChanged(); |
| 97 | void serviceIdChanged(); |
| 98 | void accountListChanged(); |
| 99 | void accessReply(const QVariantMap &reply, |
| 100 | const QVariantMap &authenticationData); |
| 101 | |
| 102 | private: |
| 103 | Q_DECLARE_PRIVATE(AccountModel) |
| 104 | AccountModelPrivate *d_ptr; |
| 105 | }; |
| 106 | |
| 107 | } // namespace |
| 108 | |
| 109 | #endif // ONLINE_ACCOUNTS_MODULE_ACCOUNT_MODEL_H |