aboutsummaryrefslogtreecommitdiff
path: root/src/QMenuModel/qdbusmenumodel.h
blob: e9d24614fa9dfd5ce5765eb5ebe41665a1139465 (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 QDBUSMENUMODEL_H
#define QDBUSMENUMODEL_H

#include "qmenumodel.h"

#include <gio/gio.h>

class QDBusMenuModel : public QMenuModel
{
    Q_OBJECT
    Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged)
    Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged)
    Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged)

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

    QDBusMenuModel(QObject *parent=0);
    ~QDBusMenuModel();

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

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

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

    bool isConnected() const;

public Q_SLOTS:
    void connect();
    void disconnect();


Q_SIGNALS:
    void busTypeChanged(BusType type);
    void busNameChanged(const QString &busNameChanged);
    void objectPathChanged(const QString &objectPath);

    void connected();
    void disconnected();
    void connectionError(const QString &errorMessage);

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

    // workaround to support busType as int
    void setIntBusType(int busType);

    // 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