File indexing completed on 2024-04-28 09:49:41

0001 /**
0002  * SPDX-FileCopyrightText: 2020 by Alexander Stippich <a.stippich@gmx.net>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef DEVICES_MODEL_H
0008 #define DEVICES_MODEL_H
0009 
0010 #include <QAbstractListModel>
0011 #include <QDebug>
0012 #include <QList>
0013 #include <QObject>
0014 
0015 #include <memory>
0016 
0017 #include <KSaneCore/Interface>
0018 
0019 class DevicesModelPrivate;
0020 
0021 class DevicesModel : public QAbstractListModel
0022 {
0023     Q_OBJECT
0024 
0025     Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
0026 
0027 public:
0028     enum DevicesModelRoles { NameRole = Qt::UserRole + 1, VendorRole, ModelRole, TypeRole };
0029 
0030     explicit DevicesModel(QObject *parent = nullptr);
0031 
0032     ~DevicesModel();
0033 
0034     QHash<int, QByteArray> roleNames() const override;
0035 
0036     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0037 
0038     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0039 
0040     Q_INVOKABLE QString getSelectedDeviceName() const;
0041 
0042     void updateDevicesList(const QList<KSaneCore::DeviceInformation *> &deviceList);
0043 
0044 public Q_SLOTS:
0045 
0046     void selectDevice(int i);
0047 
0048 Q_SIGNALS:
0049 
0050     void rowCountChanged();
0051 
0052 private:
0053     std::unique_ptr<DevicesModelPrivate> d;
0054 };
0055 
0056 QDebug operator<<(QDebug d, KSaneCore::DeviceInformation *deviceInfo);
0057 
0058 #endif // DEVICES_MODEL_H