| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the tools applications of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef QDBUSMODEL_H |
| 30 | #define QDBUSMODEL_H |
| 31 | |
| 32 | #include <QtCore/qabstractitemmodel.h> |
| 33 | #include <QtDBus/QDBusConnection> |
| 34 | |
| 35 | struct QDBusItem; |
| 36 | |
| 37 | QT_FORWARD_DECLARE_CLASS(QDomDocument); |
| 38 | QT_FORWARD_DECLARE_CLASS(QDomElement); |
| 39 | QT_FORWARD_DECLARE_CLASS(QDBusObjectPath) |
| 40 | |
| 41 | |
| 42 | class QDBusModel: public QAbstractItemModel |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
| 46 | public: |
| 47 | enum Type { InterfaceItem, PathItem, MethodItem, SignalItem, PropertyItem }; |
| 48 | |
| 49 | QDBusModel(const QString &service, const QDBusConnection &connection); |
| 50 | ~QDBusModel(); |
| 51 | |
| 52 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; |
| 53 | QModelIndex parent(const QModelIndex &child) const; |
| 54 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
| 55 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
| 56 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
| 57 | QVariant (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
| 58 | |
| 59 | Type itemType(const QModelIndex &index) const; |
| 60 | QString dBusPath(const QModelIndex &index) const; |
| 61 | QString dBusInterface(const QModelIndex &index) const; |
| 62 | QString dBusMethodName(const QModelIndex &index) const; |
| 63 | QString dBusTypeSignature(const QModelIndex &index) const; |
| 64 | |
| 65 | void refresh(const QModelIndex &index = QModelIndex()); |
| 66 | |
| 67 | QModelIndex findObject(const QDBusObjectPath &objectPath); |
| 68 | |
| 69 | Q_SIGNALS: |
| 70 | void busError(const QString &text); |
| 71 | |
| 72 | private: |
| 73 | QDomDocument introspect(const QString &path); |
| 74 | void addMethods(QDBusItem *parent, const QDomElement &iface); |
| 75 | void addPath(QDBusItem *parent); |
| 76 | |
| 77 | QString service; |
| 78 | QDBusConnection c; |
| 79 | QDBusItem *root; |
| 80 | }; |
| 81 | |
| 82 | #endif |
| 83 | |
| 84 | |