aboutsummaryrefslogtreecommitdiff
path: root/src/QMenuModel/qdbusobject.h
blob: 0b17ae1ff6f64f03ac46f12ee4d03eee6d56a6f4 (plain)
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
#ifndef QDBUSOBJECT_H
#define QDBUSOBJECT_H

#include <QObject>

#include <gio/gio.h>

class QDbusObject
{
public:
    enum BusType {
        None = 0,
        SessionBus,
        SystemBus,
        LastBusType
    };

    enum ConnectionStatus {
        Disconnected = 0,
        Connecting,
        Connected
    };

    QDbusObject();
    ~QDbusObject();

    BusType busType() const;
    void setBusType(BusType type);

    QString busName() const;
    void setBusName(const QString &busName);

    QString objectPath() const;
    void setObjectPath(const QString &busName);

    ConnectionStatus status() const;

    void connect();
    void disconnect();

protected:
    virtual void serviceAppear(GDBusConnection *connection) = 0;
    virtual void serviceVanish(GDBusConnection *connection) = 0;

    // notify functions
    virtual void busTypeChanged(BusType type) = 0;
    virtual void busNameChanged(const QString &busNameChanged) = 0;
    virtual void objectPathChanged(const QString &objectPath) = 0;
    virtual void statusChanged(ConnectionStatus status) = 0;

private:
    guint m_watchId;
    BusType m_busType;
    QString m_busName;
    QString m_objectPath;
    ConnectionStatus m_status;

    void setStatus(ConnectionStatus status);

    // glib slots
    static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data);
    static void onServiceFanished(GDBusConnection *connection, const gchar *name, gpointer data);
};

#endif