| 1 | /* |
| 2 | * This file is part of libOnlineAccounts |
| 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_MANAGER_P_H |
| 22 | #define ONLINE_ACCOUNTS_MANAGER_P_H |
| 23 | |
| 24 | #include "manager.h" |
| 25 | |
| 26 | #include <QMap> |
| 27 | #include <QObject> |
| 28 | #include <QPair> |
| 29 | #include <QPointer> |
| 30 | #include "account_info.h" |
| 31 | #include "dbus_interface.h" |
| 32 | |
| 33 | class QDBusPendingCallWatcher; |
| 34 | |
| 35 | namespace OnlineAccounts { |
| 36 | |
| 37 | struct AccountData { |
| 38 | AccountInfo info; |
| 39 | QPointer<Account> account; |
| 40 | |
| 41 | AccountData(const AccountInfo &info): info(info) {} |
| 42 | }; |
| 43 | |
| 44 | class ManagerPrivate: public QObject |
| 45 | { |
| 46 | Q_OBJECT |
| 47 | Q_DECLARE_PUBLIC(Manager) |
| 48 | |
| 49 | public: |
| 50 | inline ManagerPrivate(Manager *q, const QString &applicationId, |
| 51 | const QDBusConnection& bus); |
| 52 | ~ManagerPrivate(); |
| 53 | |
| 54 | PendingCall authenticate(const AccountInfo &info, |
| 55 | const AuthenticationData &authData); |
| 56 | PendingCall requestAccess(const QString &service, |
| 57 | const QVariantMap ¶meters); |
| 58 | |
| 59 | Account *ensureAccount(const AccountInfo &info); |
| 60 | |
| 61 | static Service serviceFromMap(const QVariantMap &map); |
| 62 | Service service(const QString &serviceId) { |
| 63 | return m_services.value(serviceId); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | void retrieveAccounts(); |
| 68 | |
| 69 | private Q_SLOTS: |
| 70 | void onGetAccountsFinished(); |
| 71 | void onAccountChanged(const QString &service, |
| 72 | const OnlineAccounts::AccountInfo &info); |
| 73 | |
| 74 | private: |
| 75 | QString m_applicationId; |
| 76 | DBusInterface m_daemon; |
| 77 | QDBusPendingCallWatcher *m_getAccountsCall; |
| 78 | QMap<QPair<AccountId,QString>,AccountData> m_accounts; |
| 79 | QMap<QString,Service> m_services; |
| 80 | mutable Manager *q_ptr; |
| 81 | }; |
| 82 | |
| 83 | } // namespace |
| 84 | |
| 85 | #endif // ONLINE_ACCOUNTS_MANAGER_P_H |