File indexing completed on 2024-05-12 17:07:20
0001 /* 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractListModel> 0010 0011 #include <memory> 0012 #include <vector> 0013 0014 class QDBusInterface; 0015 class InputDevice; 0016 0017 class DevicesModel : public QAbstractListModel 0018 { 0019 Q_OBJECT 0020 public: 0021 explicit DevicesModel(const QByteArray &kind, QObject *parent = nullptr); 0022 0023 QHash<int, QByteArray> roleNames() const override; 0024 QVariant data(const QModelIndex &index, int role) const override; 0025 int rowCount(const QModelIndex &parent) const override; 0026 Q_SCRIPTABLE InputDevice *deviceAt(int row) const; 0027 0028 void load(); 0029 void save(); 0030 void defaults(); 0031 bool isSaveNeeded() const; 0032 bool isDefaults() const; 0033 0034 private Q_SLOTS: 0035 void onDeviceAdded(const QString &sysName); 0036 void onDeviceRemoved(const QString &sysName); 0037 0038 Q_SIGNALS: 0039 void needsSaveChanged(); 0040 0041 private: 0042 void addDevice(const QString &sysname, bool tellModel); 0043 void resetModel(); 0044 0045 std::vector<std::unique_ptr<InputDevice>> m_devices; 0046 QDBusInterface *m_deviceManager; 0047 QByteArray m_kind; 0048 };