File indexing completed on 2023-12-03 08:14:44
0001 /* 0002 SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef DBUSCONNECTION_H 0008 #define DBUSCONNECTION_H 0009 0010 #include <QString> 0011 #include <QObject> 0012 #include <QDBusConnection> 0013 #include <QDBusPendingCallWatcher> 0014 0015 namespace QAccessibleClient { 0016 0017 0018 /** 0019 Connection to the a11y dbus bus. 0020 \internal 0021 */ 0022 class DBusConnection : public QObject 0023 { 0024 Q_OBJECT 0025 public: 0026 /** 0027 \brief Constructor. 0028 0029 When called, means the instance is created, we try instantly 0030 to fetch the \a connection . When done the \a connectionFetched 0031 will be emitted. If \a connection is called before it will 0032 block till the connection was fetched and is ready for use. 0033 */ 0034 DBusConnection(); 0035 0036 /** 0037 \brief Returns true if the \a connection is not ready yet. 0038 0039 The initial fetch of the comnnection happens over dbus and 0040 as such can block for a longer time means may need longer. 0041 To make it possible that users of this class do not block 0042 while that happens it is possible to use this method to 0043 determinate if fetching the connection is currently work 0044 in progress and if so connect with the \a connectionFetched 0045 signal to be called back when the connection is ready. 0046 */ 0047 bool isFetchingConnection() const; 0048 0049 /** 0050 \brief Returns the accessibility dbus connection. 0051 0052 This may either be the session bus or a referenced 0053 accessibility bus. If the connection was not fetched 0054 yet, means \a isFetchingConnection returns true, then 0055 calling this method will block till the connection was 0056 fetched. 0057 */ 0058 QDBusConnection connection() const; 0059 0060 enum Status { 0061 Disconnected, 0062 ConnectionError, 0063 Connected 0064 }; 0065 0066 /** 0067 \brief Returns the state the connection is in. 0068 0069 If Disconnected then we got not asked to connect yet or 0070 connection is in progress but not finished yet (see 0071 signal \a connectionFetched which will be emitted if the 0072 connection is not Disconnected any longer. 0073 If connection failed then the state is set to ConnectionError 0074 otherwise, in the case everything went fine and we are 0075 proper connected with tthe atspi daemon now Connected 0076 is returned. 0077 */ 0078 Status status() const; 0079 0080 Q_SIGNALS: 0081 0082 /** 0083 \brief Emitted when the \a connection was fetched. 0084 0085 This will happen exactly one time during the lifetime 0086 of a DBusConnection instance at the very beginning when 0087 the instance is created. 0088 */ 0089 void connectionFetched(); 0090 0091 private Q_SLOTS: 0092 void initFinished(); 0093 0094 private: 0095 void init(); 0096 0097 QDBusConnection m_connection; 0098 mutable Status m_status; 0099 QDBusPendingCallWatcher *m_initWatcher; 0100 }; 0101 } 0102 0103 #endif // DBUSCONNECTION_H