#pragma once // Qt #include #include // Project #include "main.h" #include "VView.h" #include "MWifiNetwork.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 , "") PROPERTY(QString, ssid , "") PROPERTY(QString, macAddress , "") 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, SecurityTypesRole, StatusRole, SignalLevelRole, }; void addNetwork (const WifiNetworkData &network); int rowCount (const QModelIndex &parent = QModelIndex()) const; QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; void removeAllRows(); signals: void didScan(); void didJoinNetwork(const WifiNetworkData, const QString); void didDisconnectNetwork(const WifiNetworkData); void didRequestIPSettings(); // set IP addresses void didRequestSetIPAddress(const QString); void didRequestSetGateway(const QString); void didRequestSetSubnetMask(const QString); void didRequestSetDNS(const QString); public slots: void doScan(); bool doCheckIfConnected(const QString &vMacAddress); void doJoinNetwork(const QString &vMacAddress, const QString &vPassword); void doDisconnectNetwork(const QString &vMacAddress); void doRequestIPSettings(); // static IP address assignment void doSetIPAddress(const QString &vIPAddress); void doSetGateway(const QString &vGateway); void doSetSubnetMask(const QString &vSubnetMask); void doSetDNS(const QString &vDNS); protected: QHash roleNames() const; private: void initConnections(); void clearSelectedNetwork(); QList _networks; private slots: void onAddNetwork(const WifiNetworkData &vNetwork); void onScanStatusChanged(const bool &vScanning); void onStatusChanged(const QString &vNewStatus); void onConnectedToNetwork(const WifiNetworkData &vNetwork); void onDisconnectedNetwork(const WifiNetworkData &vNetwork); // static IP address assignment confirmation void onSetIPAddressSuccess(); void onSetGatewaySuccess(); void onSetSubnetMaskSuccess(); void onSetDNSSuccess(); }; }