File indexing completed on 2024-04-21 16:19:52
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0003 0004 #pragma once 0005 0006 #include <QByteArray> 0007 #include <QList> 0008 #include <QMap> 0009 #include <QObject> 0010 #include <QString> 0011 #include <QStringList> 0012 #include <QVariant> 0013 #include <QtDBus> 0014 0015 #include "org.freedesktop.DBus.ObjectManager.h" // needed for typedefs 0016 0017 class DeviceModel : public QAbstractListModel 0018 { 0019 Q_OBJECT 0020 /// Whether kded is available and connected 0021 Q_PROPERTY(bool valid READ valid NOTIFY validChanged) 0022 /// Whether we are waiting for GetManagedObjects (i.e. initial listing) 0023 Q_PROPERTY(bool waiting READ waiting NOTIFY waitingChanged) 0024 public: 0025 enum ItemRole { 0026 ObjectRole = Qt::UserRole + 1, 0027 }; 0028 0029 QVector<QObject *> m_objects; 0030 0031 DeviceModel(QObject *parent = nullptr); 0032 0033 QHash<int, QByteArray> roleNames() const final; 0034 0035 int rowCount(const QModelIndex &parent = QModelIndex()) const final; 0036 0037 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0038 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0039 0040 Q_SCRIPTABLE int role(const QByteArray &roleName) const; 0041 0042 bool valid() const; 0043 bool waiting() const; 0044 0045 signals: 0046 void validChanged(); 0047 void waitingChanged(); 0048 0049 private Q_SLOTS: 0050 void addObject(const QDBusObjectPath &dbusPath, const KDBusObjectManagerInterfacePropertiesMap &interfacePropertyMap); 0051 void removeObject(const QDBusObjectPath &dbusPath); 0052 void reset(); 0053 void reload(); 0054 0055 private: 0056 void initRoleNames(QObject *object); 0057 0058 QHash<int, QByteArray> m_roles; 0059 QHash<int, QByteArray> m_objectPoperties; 0060 QHash<int, int> m_signalIndexToProperties; 0061 0062 OrgFreedesktopDBusObjectManagerInterface *m_iface = nullptr; 0063 QDBusPendingCallWatcher *m_getManagedObjectsWatcher = nullptr; 0064 }; 0065 0066 Q_DECLARE_METATYPE(DeviceModel *)