Unity 8
dashconnection.cpp
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  */
16 
17 #include "dashconnection.h"
18 
19 #include <QDBusInterface>
20 #include <QDBusPendingCall>
21 
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  */
33 class AsyncDBusInterface : public QDBusAbstractInterface
34 {
35  Q_OBJECT
36 public:
37  AsyncDBusInterface(const QString &service, const QString &path,
38  const QString &interface, const QDBusConnection &connection,
39  QObject *parent = 0)
40  : QDBusAbstractInterface(service, path, interface.toLatin1().data(), connection, parent)
41  {}
42  ~AsyncDBusInterface() = default;
43 };
44 
45 
46 DashConnection::DashConnection(const QString &service, const QString &path, const QString &interface, QObject *parent):
47  AbstractDBusServiceMonitor(service, path, interface, SessionBus, parent)
48 {
49 
50 }
51 
52 /* Override the default implementation to create a non-blocking DBus interface (see note above). */
53 QDBusAbstractInterface* DashConnection::createInterface(const QString &service, const QString &path,
54  const QString &interface, const QDBusConnection &connection)
55 {
56  return new AsyncDBusInterface(service, path, interface, connection);
57 }
58 
59 void DashConnection::setCurrentScope(int index, bool animate, bool isSwipe)
60 {
61  if (dbusInterface()) {
62  dbusInterface()->asyncCall(QStringLiteral("SetCurrentScope"), index, animate, isSwipe);
63  }
64 }
65 
66 #include "dashconnection.moc"