File indexing completed on 2024-04-21 08:46:30

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef REMOTECOMMANDSMODEL_H
0008 #define REMOTECOMMANDSMODEL_H
0009 
0010 #include <QAbstractListModel>
0011 
0012 #include "dbusinterfaces.h"
0013 
0014 struct Command {
0015     QString key;
0016     QString name;
0017     QString command;
0018 };
0019 
0020 class KDECONNECTINTERFACES_EXPORT RemoteCommandsModel : public QAbstractListModel
0021 {
0022     Q_OBJECT
0023     Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
0024 
0025 public:
0026     enum ModelRoles { KeyRole, NameRole, CommandRole };
0027 
0028     explicit RemoteCommandsModel(QObject *parent = nullptr);
0029     ~RemoteCommandsModel() override;
0030 
0031     QString deviceId() const;
0032     void setDeviceId(const QString &deviceId);
0033 
0034     QVariant data(const QModelIndex &index, int role) const override;
0035     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0036 
0037     QHash<int, QByteArray> roleNames() const override;
0038 
0039 private Q_SLOTS:
0040     void refreshCommandList();
0041     void clearCommands();
0042 
0043 Q_SIGNALS:
0044     void deviceIdChanged(const QString &value);
0045     void rowsChanged();
0046 
0047 private:
0048     RemoteCommandsDbusInterface *m_dbusInterface;
0049     QVector<Command> m_commandList;
0050     QString m_deviceId;
0051 };
0052 
0053 #endif // DEVICESMODEL_H