File indexing completed on 2024-05-05 04:50:48
0001 /* 0002 * SPDX-FileCopyrightText: 2021 George Florea Bănuș <georgefb899@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef CUSTOMCOMMANDSMODEL_H 0008 #define CUSTOMCOMMANDSMODEL_H 0009 0010 #include <KSharedConfig> 0011 0012 #include <QAbstractListModel> 0013 #include <QSortFilterProxyModel> 0014 #include <QtQml/qqmlregistration.h> 0015 0016 class ActionsModel; 0017 0018 class CustomCommandsModel : public QAbstractListModel 0019 { 0020 Q_OBJECT 0021 QML_NAMED_ELEMENT(CustomCommandsModel) 0022 0023 Q_PROPERTY(ActionsModel *appActionsModel READ appActionsModel WRITE setAppActionsModel NOTIFY appActionsModelChanged) 0024 0025 struct Command { 0026 QString commandId; 0027 QString command; 0028 QString osdMessage; 0029 QString shortcut; 0030 QString type; 0031 bool setOnStartup{true}; 0032 int order{-1}; 0033 }; 0034 0035 public: 0036 explicit CustomCommandsModel(QObject *parent = nullptr); 0037 0038 enum Roles { 0039 CommandIdRole = Qt::UserRole + 1, 0040 CommandRole, 0041 OsdMessageRole, 0042 TypeRole, 0043 ShortcutRole, 0044 SetOnStartupRole, 0045 }; 0046 0047 // Basic functionality: 0048 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0049 0050 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0051 QHash<int, QByteArray> roleNames() const override; 0052 0053 Q_INVOKABLE void init(); 0054 Q_INVOKABLE void moveRows(int oldIndex, int newIndex); 0055 Q_INVOKABLE void saveCustomCommand(const QString &command, const QString &osdMessage, const QString &type); 0056 Q_INVOKABLE void editCustomCommand(int row, const QString &command, const QString &osdMessage, const QString &type); 0057 Q_INVOKABLE void toggleCustomCommand(const QString &groupName, int row, bool setOnStartup); 0058 Q_INVOKABLE void deleteCustomCommand(const QString &groupName, int row); 0059 0060 ActionsModel *appActionsModel(); 0061 void setAppActionsModel(ActionsModel *_appActionsModel); 0062 0063 Q_SIGNALS: 0064 void appActionsModelChanged(); 0065 0066 private: 0067 KSharedConfig::Ptr m_customCommandsConfig; 0068 QList<Command *> m_customCommands; 0069 ActionsModel *m_appActionsModel{nullptr}; 0070 }; 0071 0072 #endif // CUSTOMCOMMANDSMODEL_H