~mardy/online-accounts-api/sasl-1519330

« back to all changes in this revision

Viewing changes to src/lib/OnlineAccounts/dbus_interface.cpp

  • Committer: Alberto Mardegan
  • Date: 2015-04-28 17:01:03 UTC
  • mfrom: (5.1.30 qt-api-impl)
  • Revision ID: alberto.mardegan@canonical.com-20150428170103-9hty50555f6e7uz6
Qt client API implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of libOnlineAccounts
 
3
 *
 
4
 * Copyright (C) 2015 Canonical Ltd.
 
5
 *
 
6
 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
 
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 <climits>
 
26
 
 
27
using namespace OnlineAccounts;
 
28
 
 
29
DBusInterface::DBusInterface(const QString &service,
 
30
                             const QString &path,
 
31
                             const char *interface,
 
32
                             const QDBusConnection &connection,
 
33
                             QObject *parent):
 
34
    QDBusAbstractInterface(service, path, interface, connection, parent)
 
35
{
 
36
    setTimeout(INT_MAX);
 
37
 
 
38
    qDBusRegisterMetaType<AccountInfo>();
 
39
    qDBusRegisterMetaType<QList<AccountInfo>>();
 
40
 
 
41
    bool ok = connect("AccountChanged", "s(ua{sv})",
 
42
                      this, SLOT(onAccountChanged(const QString&,const OnlineAccounts::AccountInfo&)));
 
43
    if (Q_UNLIKELY(!ok)) {
 
44
        qCritical() << "Connection to AccountChanged signal failed";
 
45
    }
 
46
}
 
47
 
 
48
DBusInterface::~DBusInterface()
 
49
{
 
50
}
 
51
 
 
52
QDBusPendingCall DBusInterface::getAccounts(const QVariantMap &filters)
 
53
{
 
54
    return asyncCall(QStringLiteral("GetAccounts"), filters);
 
55
}
 
56
 
 
57
QDBusPendingCall DBusInterface::authenticate(AccountId accountId,
 
58
                                             const QString &service,
 
59
                                             bool interactive,
 
60
                                             bool invalidate,
 
61
                                             const QVariantMap &parameters)
 
62
{
 
63
    return asyncCall(QStringLiteral("Authenticate"), accountId, service,
 
64
                     interactive, invalidate, parameters);
 
65
}
 
66
 
 
67
QDBusPendingCall DBusInterface::requestAccess(const QString &service,
 
68
                                              const QVariantMap &parameters)
 
69
{
 
70
    return asyncCall(QStringLiteral("RequestAccess"), service, parameters);
 
71
}
 
72
 
 
73
void DBusInterface::onAccountChanged(const QString &service,
 
74
                                     const AccountInfo &info)
 
75
{
 
76
    Q_EMIT accountChanged(service, info);
 
77
}
 
78
 
 
79
bool DBusInterface::connect(const char *signal, const char *signature,
 
80
                            QObject *receiver, const char *slot)
 
81
{
 
82
    return connection().connect(service(), path(), interface(),
 
83
                                QLatin1String(signal),
 
84
                                QLatin1String(signature),
 
85
                                receiver, slot);
 
86
}