| 1 |
/* |
| 2 |
* Copyright (C) 2017~2017 by CSSlayer |
| 3 |
* [email protected] |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
| 7 |
* are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above Copyright |
| 10 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
* |
| 12 |
* 2. Redistributions in binary form must reproduce the above Copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* |
| 16 |
* 3. Neither the name of the authors nor the names of its contributors |
| 17 |
* may be used to endorse or promote products derived from this |
| 18 |
* software without specific prior written permission. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef FCITXWATCHER_H_ |
| 22 |
#define FCITXWATCHER_H_ |
| 23 |
|
| 24 |
#include <QDBusConnection> |
| 25 |
#include <QObject> |
| 26 |
|
| 27 |
class QDBusConnection; |
| 28 |
class QFileSystemWatcher; |
| 29 |
class QDBusServiceWatcher; |
| 30 |
|
| 31 |
// A FcitxQtConnection replacement, to implement compatibility with fcitx 5. |
| 32 |
// Since we have three thing to monitor, the situation becomes much more |
| 33 |
// complexer. |
| 34 |
class FcitxWatcher : public QObject { |
| 35 |
Q_OBJECT |
| 36 |
public: |
| 37 |
explicit FcitxWatcher(QDBusConnection sessionBus, |
| 38 |
QObject *parent = nullptr); |
| 39 |
~FcitxWatcher(); |
| 40 |
void watch(); |
| 41 |
void unwatch(); |
| 42 |
|
| 43 |
bool availability() const; |
| 44 |
|
| 45 |
QDBusConnection connection() const; |
| 46 |
QString service() const; |
| 47 |
|
| 48 |
Q_SIGNALS: |
| 49 |
void availabilityChanged(bool); |
| 50 |
|
| 51 |
private Q_SLOTS: |
| 52 |
void dbusDisconnected(); |
| 53 |
void socketFileChanged(); |
| 54 |
void imChanged(const QString &service, const QString &oldOwner, |
| 55 |
const QString &newOwner); |
| 56 |
|
| 57 |
private: |
| 58 |
QString address(); |
| 59 |
void watchSocketFile(); |
| 60 |
void unwatchSocketFile(); |
| 61 |
void createConnection(); |
| 62 |
void cleanUpConnection(); |
| 63 |
void setAvailability(bool availability); |
| 64 |
void updateAvailability(); |
| 65 |
|
| 66 |
QFileSystemWatcher *m_fsWatcher; |
| 67 |
QDBusServiceWatcher *m_serviceWatcher; |
| 68 |
QDBusConnection *m_connection; |
| 69 |
QDBusConnection m_sessionBus; |
| 70 |
QString m_socketFile; |
| 71 |
QString m_serviceName; |
| 72 |
bool m_availability = false; |
| 73 |
bool m_mainPresent = false; |
| 74 |
bool m_portalPresent = false; |
| 75 |
bool m_watched = false; |
| 76 |
}; |
| 77 |
|
| 78 |
#endif // FCITXWATCHER_H_ |