Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/linuxaccessibility/dbusconnection.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | - | |||||||||||||
41 | - | |||||||||||||
42 | #include "dbusconnection_p.h" | - | ||||||||||||
43 | - | |||||||||||||
44 | #include <QtDBus/QDBusMessage> | - | ||||||||||||
45 | #include <QtDBus/QDBusServiceWatcher> | - | ||||||||||||
46 | #include <qdebug.h> | - | ||||||||||||
47 | - | |||||||||||||
48 | #include <QDBusConnectionInterface> | - | ||||||||||||
49 | #include "bus_interface.h" | - | ||||||||||||
50 | - | |||||||||||||
51 | #include <QtGui/qguiapplication.h> | - | ||||||||||||
52 | #include <qplatformnativeinterface.h> | - | ||||||||||||
53 | - | |||||||||||||
54 | QT_BEGIN_NAMESPACE | - | ||||||||||||
55 | - | |||||||||||||
56 | /* note: do not change these to QStringLiteral; | - | ||||||||||||
57 | we are unloaded before QtDBus is done using the strings. | - | ||||||||||||
58 | */ | - | ||||||||||||
59 | #define A11Y_SERVICE QLatin1String("org.a11y.Bus") | - | ||||||||||||
60 | #define A11Y_PATH QLatin1String("/org/a11y/bus") | - | ||||||||||||
61 | - | |||||||||||||
62 | /*! | - | ||||||||||||
63 | \class DBusConnection | - | ||||||||||||
64 | \internal | - | ||||||||||||
65 | \brief Connects to the accessibility dbus. | - | ||||||||||||
66 | - | |||||||||||||
67 | This is usually a different bus from the session bus. | - | ||||||||||||
68 | */ | - | ||||||||||||
69 | DBusConnection::DBusConnection(QObject *parent) | - | ||||||||||||
70 | : QObject(parent), m_a11yConnection(QString()), m_enabled(false) | - | ||||||||||||
71 | { | - | ||||||||||||
72 | // Start monitoring if "org.a11y.Bus" is registered as DBus service. | - | ||||||||||||
73 | QDBusConnection c = QDBusConnection::sessionBus(); | - | ||||||||||||
74 | dbusWatcher = new QDBusServiceWatcher(A11Y_SERVICE, c, QDBusServiceWatcher::WatchForRegistration, this); | - | ||||||||||||
75 | connect(dbusWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(serviceRegistered())); | - | ||||||||||||
76 | - | |||||||||||||
77 | // If it is registered already, setup a11y right away | - | ||||||||||||
78 | if (c.interface()->isServiceRegistered(A11Y_SERVICE))
| 0-180 | ||||||||||||
79 | serviceRegistered(); executed 180 times by 128 tests: serviceRegistered(); Executed by:
| 180 | ||||||||||||
80 | - | |||||||||||||
81 | // In addition try if there is an xatom exposing the bus address, this allows applications run as root to work | - | ||||||||||||
82 | QString address = getAddressFromXCB(); | - | ||||||||||||
83 | if (!address.isEmpty()) {
| 0-180 | ||||||||||||
84 | m_enabled = true; | - | ||||||||||||
85 | connectA11yBus(address); | - | ||||||||||||
86 | } executed 180 times by 128 tests: end of block Executed by:
| 180 | ||||||||||||
87 | } executed 180 times by 128 tests: end of block Executed by:
| 180 | ||||||||||||
88 | - | |||||||||||||
89 | QString DBusConnection::getAddressFromXCB() | - | ||||||||||||
90 | { | - | ||||||||||||
91 | QGuiApplication *app = qobject_cast<QGuiApplication *>(QCoreApplication::instance()); | - | ||||||||||||
92 | if (!app)
| 0-180 | ||||||||||||
93 | return QString(); never executed: return QString(); | 0 | ||||||||||||
94 | QPlatformNativeInterface *platformNativeInterface = app->platformNativeInterface(); | - | ||||||||||||
95 | QByteArray *addressByteArray = reinterpret_cast<QByteArray*>( | - | ||||||||||||
96 | platformNativeInterface->nativeResourceForIntegration(QByteArrayLiteral("AtspiBus"))); executed 180 times by 128 tests: return ba; Executed by:
| 180 | ||||||||||||
97 | if (addressByteArray) {
| 0-180 | ||||||||||||
98 | QString address = QString::fromLatin1(*addressByteArray); | - | ||||||||||||
99 | delete addressByteArray; | - | ||||||||||||
100 | return address; executed 180 times by 128 tests: return address; Executed by:
| 180 | ||||||||||||
101 | } | - | ||||||||||||
102 | return QString(); never executed: return QString(); | 0 | ||||||||||||
103 | } | - | ||||||||||||
104 | - | |||||||||||||
105 | // We have the a11y registry on the session bus. | - | ||||||||||||
106 | // Subscribe to updates about a11y enabled state. | - | ||||||||||||
107 | // Find out the bus address | - | ||||||||||||
108 | void DBusConnection::serviceRegistered() | - | ||||||||||||
109 | { | - | ||||||||||||
110 | // listen to enabled changes | - | ||||||||||||
111 | QDBusConnection c = QDBusConnection::sessionBus(); | - | ||||||||||||
112 | OrgA11yStatusInterface *a11yStatus = new OrgA11yStatusInterface(A11Y_SERVICE, A11Y_PATH, c, this); | - | ||||||||||||
113 | - | |||||||||||||
114 | //The variable was introduced because on some embedded platforms there are custom accessibility | - | ||||||||||||
115 | //clients which don't set Status.ScreenReaderEnabled to true. The variable is also useful for | - | ||||||||||||
116 | //debugging. | - | ||||||||||||
117 | static const bool a11yAlwaysOn = qEnvironmentVariableIsSet("QT_LINUX_ACCESSIBILITY_ALWAYS_ON"); | - | ||||||||||||
118 | - | |||||||||||||
119 | // a11yStatus->isEnabled() returns always true (since Gnome 3.6) | - | ||||||||||||
120 | bool enabled = a11yAlwaysOn || a11yStatus->screenReaderEnabled();
| 0-180 | ||||||||||||
121 | - | |||||||||||||
122 | if (enabled != m_enabled) {
| 0-180 | ||||||||||||
123 | m_enabled = enabled; | - | ||||||||||||
124 | if (m_a11yConnection.isConnected()) {
| 0 | ||||||||||||
125 | emit enabledChanged(m_enabled); | - | ||||||||||||
126 | } else { never executed: end of block | 0 | ||||||||||||
127 | QDBusConnection c = QDBusConnection::sessionBus(); | - | ||||||||||||
128 | QDBusMessage m = QDBusMessage::createMethodCall(QLatin1String("org.a11y.Bus"), | - | ||||||||||||
129 | QLatin1String("/org/a11y/bus"), | - | ||||||||||||
130 | QLatin1String("org.a11y.Bus"), QLatin1String("GetAddress")); | - | ||||||||||||
131 | c.callWithCallback(m, this, SLOT(connectA11yBus(QString)), SLOT(dbusError(QDBusError))); | - | ||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | // connect(a11yStatus, ); QtDbus doesn't support notifications for property changes yet | - | ||||||||||||
136 | } executed 180 times by 128 tests: end of block Executed by:
| 180 | ||||||||||||
137 | - | |||||||||||||
138 | void DBusConnection::serviceUnregistered() | - | ||||||||||||
139 | { | - | ||||||||||||
140 | emit enabledChanged(false); | - | ||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||
142 | - | |||||||||||||
143 | void DBusConnection::connectA11yBus(const QString &address) | - | ||||||||||||
144 | { | - | ||||||||||||
145 | if (address.isEmpty()) {
| 0-180 | ||||||||||||
146 | qWarning("Could not find Accessibility DBus address."); | - | ||||||||||||
147 | return; never executed: return; | 0 | ||||||||||||
148 | } | - | ||||||||||||
149 | m_a11yConnection = QDBusConnection(QDBusConnection::connectToBus(address, QLatin1String("a11y"))); | - | ||||||||||||
150 | - | |||||||||||||
151 | if (m_enabled)
| 0-180 | ||||||||||||
152 | emit enabledChanged(true); executed 180 times by 128 tests: enabledChanged(true); Executed by:
| 180 | ||||||||||||
153 | } executed 180 times by 128 tests: end of block Executed by:
| 180 | ||||||||||||
154 | - | |||||||||||||
155 | void DBusConnection::dbusError(const QDBusError &error) | - | ||||||||||||
156 | { | - | ||||||||||||
157 | qWarning() << "Accessibility encountered a DBus error:" << error; | - | ||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||
159 | - | |||||||||||||
160 | /*! | - | ||||||||||||
161 | Returns the DBus connection that got established. | - | ||||||||||||
162 | Or an invalid connection if not yet connected. | - | ||||||||||||
163 | */ | - | ||||||||||||
164 | QDBusConnection DBusConnection::connection() const | - | ||||||||||||
165 | { | - | ||||||||||||
166 | return m_a11yConnection; never executed: return m_a11yConnection; | 0 | ||||||||||||
167 | } | - | ||||||||||||
168 | - | |||||||||||||
169 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |