| 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 | #include "dbus_interface.h" |
| 22 | |
| 23 | #include <QDBusMetaType> |
| 24 | #include <QDebug> |
| 25 | #include <QVariantMap> |
| 26 | #include <climits> |
| 27 | |
| 28 | using namespace OnlineAccounts; |
| 29 | |
| 30 | DBusInterface::DBusInterface(const QString &service, |
| 31 | const QString &path, |
| 32 | const char *interface, |
| 33 | const QDBusConnection &connection, |
| 34 | QObject *parent): |
| 35 | QDBusAbstractInterface(service, path, interface, connection, parent) |
| 36 | { |
| 37 | setTimeout(INT_MAX); |
| 38 | |
| 39 | qDBusRegisterMetaType<AccountInfo>(); |
| 40 | qDBusRegisterMetaType<QList<AccountInfo>>(); |
| 41 | qDBusRegisterMetaType<QList<QVariantMap>>(); |
| 42 | |
| 43 | bool ok = connect("AccountChanged", "s(ua{sv})", |
| 44 | this, SLOT(onAccountChanged(const QString&,const OnlineAccounts::AccountInfo&))); |
| 45 | if (Q_UNLIKELY(!ok)) { |
| 46 | qCritical() << "Connection to AccountChanged signal failed"; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | DBusInterface::~DBusInterface() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | QDBusPendingCall DBusInterface::getAccounts(const QVariantMap &filters) |
| 55 | { |
| 56 | return asyncCall(QStringLiteral("GetAccounts"), filters); |
| 57 | } |
| 58 | |
| 59 | QDBusPendingCall DBusInterface::authenticate(AccountId accountId, |
| 60 | const QString &service, |
| 61 | bool interactive, |
| 62 | bool invalidate, |
| 63 | const QVariantMap ¶meters) |
| 64 | { |
| 65 | return asyncCall(QStringLiteral("Authenticate"), accountId, service, |
| 66 | interactive, invalidate, parameters); |
| 67 | } |
| 68 | |
| 69 | QDBusPendingCall DBusInterface::requestAccess(const QString &service, |
| 70 | const QVariantMap ¶meters) |
| 71 | { |
| 72 | return asyncCall(QStringLiteral("RequestAccess"), service, parameters); |
| 73 | } |
| 74 | |
| 75 | void DBusInterface::onAccountChanged(const QString &service, |
| 76 | const AccountInfo &info) |
| 77 | { |
| 78 | Q_EMIT accountChanged(service, info); |
| 79 | } |
| 80 | |
| 81 | bool DBusInterface::connect(const char *signal, const char *signature, |
| 82 | QObject *receiver, const char *slot) |
| 83 | { |
| 84 | return connection().connect(service(), path(), interface(), |
| 85 | QLatin1String(signal), |
| 86 | QLatin1String(signature), |
| 87 | receiver, slot); |
| 88 | } |