| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef QDBUSMODEL_H |
| 5 | #define QDBUSMODEL_H |
| 6 | |
| 7 | #include <QtCore/qabstractitemmodel.h> |
| 8 | #include <QtDBus/QDBusConnection> |
| 9 | |
| 10 | struct QDBusItem; |
| 11 | |
| 12 | QT_FORWARD_DECLARE_CLASS(QDomDocument); |
| 13 | QT_FORWARD_DECLARE_CLASS(QDomElement); |
| 14 | QT_FORWARD_DECLARE_CLASS(QDBusObjectPath) |
| 15 | |
| 16 | |
| 17 | class QDBusModel: public QAbstractItemModel |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | |
| 21 | public: |
| 22 | enum Type { InterfaceItem, PathItem, MethodItem, SignalItem, PropertyItem }; |
| 23 | |
| 24 | QDBusModel(const QString &service, const QDBusConnection &connection); |
| 25 | ~QDBusModel(); |
| 26 | |
| 27 | |
| 28 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
| 29 | QModelIndex parent(const QModelIndex &child) const override; |
| 30 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 31 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 32 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 33 | QVariant (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 34 | |
| 35 | Type itemType(const QModelIndex &index) const; |
| 36 | QString dBusPath(const QModelIndex &index) const; |
| 37 | QString dBusInterface(const QModelIndex &index) const; |
| 38 | QString dBusMethodName(const QModelIndex &index) const; |
| 39 | QString dBusTypeSignature(const QModelIndex &index) const; |
| 40 | |
| 41 | void refresh(const QModelIndex &index = QModelIndex()); |
| 42 | |
| 43 | QModelIndex findObject(const QDBusObjectPath &objectPath); |
| 44 | |
| 45 | Q_SIGNALS: |
| 46 | void busError(const QString &text); |
| 47 | |
| 48 | private: |
| 49 | QDomDocument introspect(const QString &path); |
| 50 | void addMethods(QDBusItem *parent, const QDomElement &iface); |
| 51 | void addPath(QDBusItem *parent); |
| 52 | |
| 53 | QString service; |
| 54 | QDBusConnection c; |
| 55 | QDBusItem *root; |
| 56 | }; |
| 57 | |
| 58 | #endif |
| 59 | |
| 60 | |