2013-08-16 05:23:54 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2013-06-27 01:13:16 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2013-06-27 01:13:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DEVICESMODEL_H
|
|
|
|
#define DEVICESMODEL_H
|
|
|
|
|
2013-07-02 14:22:05 +01:00
|
|
|
#include <QAbstractListModel>
|
2013-06-27 01:13:16 +01:00
|
|
|
#include <QList>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QPixmap>
|
2013-06-27 01:13:16 +01:00
|
|
|
|
2019-04-30 18:03:24 +01:00
|
|
|
#include "kdeconnectinterfaces_export.h"
|
2013-08-21 17:25:44 +01:00
|
|
|
|
2015-03-14 01:30:35 +00:00
|
|
|
class QDBusPendingCallWatcher;
|
2014-06-14 14:22:40 +01:00
|
|
|
class DaemonDbusInterface;
|
|
|
|
class DeviceDbusInterface;
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class KDECONNECTINTERFACES_EXPORT DevicesModel : public QAbstractListModel
|
2013-06-27 01:13:16 +01:00
|
|
|
{
|
2013-07-03 02:52:44 +01:00
|
|
|
Q_OBJECT
|
2014-07-01 00:19:14 +01:00
|
|
|
Q_PROPERTY(int displayFilter READ displayFilter WRITE setDisplayFilter)
|
2013-08-22 02:21:08 +01:00
|
|
|
Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged)
|
|
|
|
|
2013-06-27 01:13:16 +01:00
|
|
|
public:
|
|
|
|
enum ModelRoles {
|
2022-09-10 22:23:52 +01:00
|
|
|
NameModelRole = Qt::DisplayRole,
|
|
|
|
IconModelRole = Qt::DecorationRole,
|
2013-08-15 23:25:13 +01:00
|
|
|
StatusModelRole = Qt::InitialSortOrderRole,
|
2022-09-10 22:23:52 +01:00
|
|
|
IdModelRole = Qt::UserRole,
|
2015-06-11 15:47:53 +01:00
|
|
|
IconNameRole,
|
|
|
|
DeviceRole
|
2013-08-15 21:22:11 +01:00
|
|
|
};
|
2022-06-23 05:47:52 +01:00
|
|
|
Q_ENUM(ModelRoles)
|
2016-04-01 14:01:42 +01:00
|
|
|
|
|
|
|
// A device is always paired or reachable or both
|
|
|
|
// You can combine the Paired and Reachable flags
|
2015-06-22 03:42:16 +01:00
|
|
|
enum StatusFilterFlag {
|
2022-09-10 22:23:52 +01:00
|
|
|
NoFilter = 0x00,
|
|
|
|
Paired = 0x01, // show device only if it's paired
|
|
|
|
Reachable = 0x02 // show device only if it's reachable
|
2013-06-27 01:13:16 +01:00
|
|
|
};
|
2015-06-22 03:42:16 +01:00
|
|
|
Q_DECLARE_FLAGS(StatusFilterFlags, StatusFilterFlag)
|
|
|
|
Q_FLAGS(StatusFilterFlags)
|
2016-06-08 17:39:31 +01:00
|
|
|
Q_ENUM(StatusFilterFlag)
|
2013-06-27 01:13:16 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
explicit DevicesModel(QObject *parent = nullptr);
|
2016-06-20 08:05:02 +01:00
|
|
|
~DevicesModel() override;
|
2013-06-27 01:13:16 +01:00
|
|
|
|
2013-08-22 02:21:08 +01:00
|
|
|
void setDisplayFilter(int flags);
|
2014-07-01 00:19:14 +01:00
|
|
|
int displayFilter() const;
|
2013-08-22 02:21:08 +01: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;
|
2013-06-27 01:13:16 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE DeviceDbusInterface *getDevice(int row) const;
|
2016-06-20 08:05:02 +01:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2022-09-10 22:23:52 +01:00
|
|
|
Q_SCRIPTABLE int rowForDevice(const QString &id) const;
|
2013-07-02 00:50:32 +01:00
|
|
|
|
2013-07-04 00:09:49 +01:00
|
|
|
private Q_SLOTS:
|
2022-09-10 22:23:52 +01:00
|
|
|
void deviceAdded(const QString &id);
|
|
|
|
void deviceRemoved(const QString &id);
|
|
|
|
void deviceUpdated(const QString &id, bool isVisible);
|
2013-08-13 22:23:32 +01:00
|
|
|
void refreshDeviceList();
|
2022-09-10 22:23:52 +01:00
|
|
|
void receivedDeviceList(QDBusPendingCallWatcher *watcher);
|
|
|
|
void nameChanged(const QString &newName);
|
2013-07-02 00:50:32 +01:00
|
|
|
|
2013-08-22 02:21:08 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void rowsChanged();
|
|
|
|
|
2013-06-27 01:13:16 +01:00
|
|
|
private:
|
2015-03-14 01:30:35 +00:00
|
|
|
void clearDevices();
|
2022-09-10 22:23:52 +01:00
|
|
|
void appendDevice(DeviceDbusInterface *dev);
|
|
|
|
bool passesFilter(DeviceDbusInterface *dev) const;
|
2015-03-14 01:30:35 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
DaemonDbusInterface *m_dbusInterface;
|
|
|
|
QVector<DeviceDbusInterface *> m_deviceList;
|
2015-06-22 03:42:16 +01:00
|
|
|
StatusFilterFlag m_displayFilter;
|
2013-06-27 01:13:16 +01:00
|
|
|
};
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// Q_DECLARE_OPERATORS_FOR_FLAGS(DevicesModel::StatusFilterFlag)
|
2014-07-01 00:19:14 +01:00
|
|
|
|
2013-06-27 01:13:16 +01:00
|
|
|
#endif // DEVICESMODEL_H
|