Qt Accessibility Client

dbusconnection.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7
8#include "dbusconnection.h"
9
10#include <QDBusMessage>
11#include <QDBusPendingReply>
12#include <QDebug>
13
14using namespace QAccessibleClient;
15
17 : QObject()
18 , m_connection(QDBusConnection::sessionBus())
19{
20 init();
21}
22
23void DBusConnection::init()
24{
26 if (!c.isConnected()) {
27 qWarning("Could not connect to DBus session bus.");
28 return;
29 }
30
31 QDBusMessage m = QDBusMessage::createMethodCall(QStringLiteral("org.a11y.Bus"),
32 QStringLiteral("/org/a11y/bus"),
33 QStringLiteral("org.a11y.Bus"), QStringLiteral("GetAddress"));
34
35 QDBusPendingCall async = c.asyncCall(m);
36 m_initWatcher = new QDBusPendingCallWatcher(async, this);
37 connect(m_initWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(initFinished()));
38}
39
40void DBusConnection::initFinished()
41{
42 if (!m_initWatcher)
43 return;
44 m_status = ConnectionError;
45 QDBusPendingReply<QString> reply = *m_initWatcher;
46 if (reply.isError() || reply.value().isEmpty()) {
47 qWarning() << "Accessibility DBus not found. Falling back to session bus.";
48 } else {
49 QString busAddress = reply.value();
50 qDebug() << "Got Accessibility DBus address:" << busAddress;
51 QDBusConnection c = QDBusConnection::connectToBus(busAddress, QStringLiteral("a11y"));
52 if (c.isConnected()) {
53 qDebug() << "Connected to Accessibility DBus at address=" << busAddress;
54 m_connection = c;
55 m_status = Connected;
56 } else {
57 qWarning() << "Found Accessibility DBus address=" << busAddress << "but cannot connect. Falling back to session bus.";
58 }
59 }
60 m_initWatcher->deleteLater();
61 m_initWatcher = nullptr;
63}
64
66{
67 return m_initWatcher;
68}
69
71{
72 if (m_initWatcher) {
73 m_initWatcher->waitForFinished();
74 const_cast<DBusConnection*>(this)->initFinished();
75 }
76 return m_connection;
77}
78
79DBusConnection::Status DBusConnection::status() const
80{
81 return m_status;
82}
83
84#include "moc_dbusconnection.cpp"
Connection to the a11y dbus bus.
QDBusConnection connection() const
Returns the accessibility dbus connection.
Status status() const
Returns the state the connection is in.
void connectionFetched()
Emitted when the connection was fetched.
bool isFetchingConnection() const
Returns true if the connection is not ready yet.
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout) const const
QDBusConnection connectToBus(BusType type, const QString &name)
bool isConnected() const const
QDBusConnection sessionBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
bool isError() const const
typename Select< 0 >::Type value() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:55:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.