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