| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2011~2023 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef FCITXWATCHER_H_ |
| 9 |
#define FCITXWATCHER_H_ |
| 10 |
|
| 11 |
#include <QDBusConnection> |
| 12 |
#include <QObject> |
| 13 |
|
| 14 |
class QFileSystemWatcher; |
| 15 |
class QDBusServiceWatcher; |
| 16 |
|
| 17 |
namespace fcitx { |
| 18 |
|
| 19 |
// A FcitxQtConnection replacement, to implement compatibility with fcitx 5. |
| 20 |
// Since we have three thing to monitor, the situation becomes much more |
| 21 |
// complexer. |
| 22 |
class Fcitx4Watcher : public QObject { |
| 23 |
Q_OBJECT |
| 24 |
public: |
| 25 |
explicit Fcitx4Watcher(QDBusConnection sessionBus, |
| 26 |
QObject *parent = nullptr); |
| 27 |
~Fcitx4Watcher(); |
| 28 |
void watch(); |
| 29 |
void unwatch(); |
| 30 |
|
| 31 |
bool availability() const; |
| 32 |
|
| 33 |
QDBusConnection connection() const; |
| 34 |
QString service() const; |
| 35 |
|
| 36 |
Q_SIGNALS: |
| 37 |
void availabilityChanged(bool); |
| 38 |
|
| 39 |
private Q_SLOTS: |
| 40 |
void dbusDisconnected(); |
| 41 |
void socketFileChanged(); |
| 42 |
void imChanged(const QString &service, const QString &oldOwner, |
| 43 |
const QString &newOwner); |
| 44 |
|
| 45 |
private: |
| 46 |
QString address(); |
| 47 |
void watchSocketFile(); |
| 48 |
void unwatchSocketFile(); |
| 49 |
void createConnection(); |
| 50 |
void cleanUpConnection(); |
| 51 |
void setAvailability(bool availability); |
| 52 |
void updateAvailability(); |
| 53 |
|
| 54 |
QFileSystemWatcher *fsWatcher_ = nullptr; |
| 55 |
QDBusServiceWatcher *serviceWatcher_ = nullptr; |
| 56 |
QDBusConnection *connection_; |
| 57 |
QDBusConnection sessionBus_; |
| 58 |
QString socketFile_; |
| 59 |
QString serviceName_; |
| 60 |
bool availability_ = false; |
| 61 |
bool mainPresent_ = false; |
| 62 |
bool watched_ = false; |
| 63 |
QString uniqueConnectionName_; |
| 64 |
}; |
| 65 |
|
| 66 |
} // namespace fcitx |
| 67 |
|
| 68 |
#endif // FCITXWATCHER_H_ |