File: fcitx4watcher.h

package info (click to toggle)
fcitx5-qt 5.1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,340 kB
  • sloc: cpp: 11,697; xml: 243; ansic: 46; makefile: 14; sh: 9
file content (68 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * SPDX-FileCopyrightText: 2011~2023 CSSlayer <wengxt@gmail.com>
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#ifndef FCITXWATCHER_H_
#define FCITXWATCHER_H_

#include <QDBusConnection>
#include <QObject>

class QFileSystemWatcher;
class QDBusServiceWatcher;

namespace fcitx {

// A FcitxQtConnection replacement, to implement compatibility with fcitx 5.
// Since we have three thing to monitor, the situation becomes much more
// complexer.
class Fcitx4Watcher : public QObject {
    Q_OBJECT
public:
    explicit Fcitx4Watcher(QDBusConnection sessionBus,
                           QObject *parent = nullptr);
    ~Fcitx4Watcher();
    void watch();
    void unwatch();

    bool availability() const;

    QDBusConnection connection() const;
    QString service() const;

Q_SIGNALS:
    void availabilityChanged(bool);

private Q_SLOTS:
    void dbusDisconnected();
    void socketFileChanged();
    void imChanged(const QString &service, const QString &oldOwner,
                   const QString &newOwner);

private:
    QString address();
    void watchSocketFile();
    void unwatchSocketFile();
    void createConnection();
    void cleanUpConnection();
    void setAvailability(bool availability);
    void updateAvailability();

    QFileSystemWatcher *fsWatcher_ = nullptr;
    QDBusServiceWatcher *serviceWatcher_ = nullptr;
    QDBusConnection *connection_;
    QDBusConnection sessionBus_;
    QString socketFile_;
    QString serviceName_;
    bool availability_ = false;
    bool mainPresent_ = false;
    bool watched_ = false;
    QString uniqueConnectionName_;
};

} // namespace fcitx

#endif // FCITXWATCHER_H_