#pragma once // Qt #include #include // Project #include "main.h" #include "VView.h" #include "Network.h" // forward declarations class tst_views; namespace View { /*! * \brief The VNetworkModel class * Interface between QML and the networks * \details Exposes networks to QML and provides an interface to connect and disconnect from those networks. * References: https://doc.qt.io/qt-5.12/qtquick-modelviewsdata-cppmodels.html * */ class VNetworkModel : public QAbstractListModel { Q_OBJECT PROPERTY(bool , scanInProgress, false) PROPERTY(QString, status , "") PROPERTY(QString, ipAddress , "") PROPERTY(QString, gateway , "") PROPERTY(QString, subnetMask , "") PROPERTY(QString, dns , "") public: // Note: VIEW_DEC_CLASS(VNetworkModel) requires QObject as the parent, so it's necessary to define it here // Otherwise a VIEW_DEC_CLASS macro could allow specifying the parent class with QObject as the default VNetworkModel(QAbstractListModel *parent = nullptr) : QAbstractListModel(parent) { initConnections(); } enum NetworkDataRole { MacAddressRole = Qt::UserRole + 1, SSIDRole, SecurityLevelRole, StatusRole, SignalLevelRole, }; void addNetwork (const Network &network); int rowCount (const QModelIndex &parent = QModelIndex()) const; QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; signals: void didScan(); void didJoinNetwork(const Network, const QString); void didDisconnectNetwork(const Network); void didRequestIPSettings(); public slots: void doScan(); void doAddNetwork(const Network &vNetwork); bool doCheckIfConnected(const QString &vMacAddress); void doJoinNetwork(const QString &vMacAddress, const QString &vPassword); void doDisconnectNetwork(const QString &vMacAddress); void doRequestIPSettings(); protected: QHash roleNames() const; private: void initConnections(); QList _networks; private slots: void onScanStatusChanged(const bool &vScanning); void onConnectedToNetwork(const Network &vNetwork); void onDisconnectedNetwork(const Network &vNetwork); void onError(const QString &vMessage); }; }