2019-10-27 17:08:51 +00:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMANDSMODEL_H
|
|
|
|
#define COMMANDSMODEL_H
|
|
|
|
|
|
|
|
#include "core/kdeconnectpluginconfig.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include "kdeconnectinterfaces_export.h"
|
|
|
|
#include <QAbstractListModel>
|
2019-10-27 17:08:51 +00:00
|
|
|
|
|
|
|
struct CommandEntry {
|
|
|
|
QString key;
|
|
|
|
QString name;
|
|
|
|
QString command;
|
|
|
|
};
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class KDECONNECTINTERFACES_EXPORT CommandsModel : public QAbstractListModel
|
2019-10-27 17:08:51 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
|
|
|
|
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
enum ModelRoles { KeyRole, NameRole, CommandRole };
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit CommandsModel(QObject *parent = nullptr);
|
2019-10-27 17:08:51 +00:00
|
|
|
~CommandsModel() override;
|
|
|
|
|
|
|
|
QString deviceId() const;
|
2022-09-10 22:23:52 +01:00
|
|
|
void setDeviceId(const QString &deviceId);
|
2019-10-27 17:08:51 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2019-10-27 17:08:51 +00:00
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
Q_SCRIPTABLE void removeCommand(int index);
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE void addCommand(const QString &name, const QString &command);
|
2019-10-27 17:08:51 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void refreshCommandList();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2022-09-10 22:23:52 +01:00
|
|
|
void deviceIdChanged(const QString &value);
|
2019-10-27 17:08:51 +00:00
|
|
|
void rowsChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void saveCommands();
|
|
|
|
|
|
|
|
QVector<CommandEntry> m_commandList;
|
|
|
|
QString m_deviceId;
|
|
|
|
KdeConnectPluginConfig m_config;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DEVICESMODEL_H
|