on vivid help sign in
unity8/plugins/Unity/DashCommunicator/dashconnection.cpp
63 lines 2.6 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "dashconnection.h"
19#include <QDBusInterface>
20#include <QDBusPendingCall>
22/* The default implementation of AbstractDBusServiceMonitor creates a QDBusInterface when the service
23 * appears on the bus.
24 *
25 * On construction QDBusInterface synchronously introspects the service, which will block the GUI
26 * thread of this process if the service is busy. QDBusAbstractInterface does not perform this
27 * introspection, so let's subclass that and avoid the blocking scenario.
28 *
29 * However we lose Qt's wrapping of the DBus service with a MetaObject, with the result that we
30 * cannot easily connect to DBus signals with the usual connect() calls. So this approach only
31 * suited to push communication with the DBus service.
32 */
33class AsyncDBusInterface : public QDBusAbstractInterface
35public:
36 AsyncDBusInterface(const QString &service, const QString &path,
37 const QString &interface, const QDBusConnection &connection,
38 QObject *parent = 0)
39 : QDBusAbstractInterface(service, path, interface.toLatin1().data(), connection, parent)
40 {}
41 ~AsyncDBusInterface() = default;
42};
45DashConnection::DashConnection(const QString &service, const QString &path, const QString &interface, QObject *parent):
46 AbstractDBusServiceMonitor(service, path, interface, SessionBus, parent)
51/* Override the default implementation to create a non-blocking DBus interface (see note above). */
52QDBusAbstractInterface* DashConnection::createInterface(const QString &service, const QString &path,
53 const QString &interface, const QDBusConnection &connection)
55 return new AsyncDBusInterface(service, path, interface, connection);
58void DashConnection::setCurrentScope(int index, bool animate, bool isSwipe)
60 if (dbusInterface()) {
61 dbusInterface()->asyncCall(QStringLiteral("SetCurrentScope"), index, animate, isSwipe);
62 }