/*! * * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file DeviceView.h * \author (last) Behrouz NematiPour * \date (last) 10-Sep-2023 * \author (original) Behrouz NematiPour * \date (original) 03-Jun-2021 * */ #pragma once // Qt #include #include // Project #include "main.h" // Doxygen : do not remove #include "VView.h" #include "DeviceGlobals.h" #include "DeviceModels.h" // define // namespace namespace View { /*! * \brief The VDevice class * \details The device view to interact with the UI. * */ class VDevice : public QAbstractListModel { Q_OBJECT enum DataRole { eRole_Start = Qt::UserRole , // ----- WiFi eRole_WifiMacAddress , eRole_WifiSsid , eRole_WifiSecurityTypes , eRole_WifiSignalLevel , eRole_WifiSupported , eRole_WifiConnected , // ----- Bluetooth eRole_BLE_UNUSED , }; QHash dataRoles { // ----- WiFi { eRole_WifiMacAddress , "wifiMacAddress" }, { eRole_WifiSsid , "wifiSsid" }, { eRole_WifiSecurityTypes , "wifiSecurityTypes" }, { eRole_WifiSignalLevel , "wifiSignalLevel" }, { eRole_WifiSupported , "wifiSupported" }, { eRole_WifiConnected , "wifiConnected" }, // ----- Bluetooth }; struct DataModel { // ----- WiFi QString mWifiMacAddress ; QString mWifiSSID ; QString mWifiSecurityTypes ; qint16 mWifiSignalLevel ; bool mWifiSupported = false ; bool mWifiConnected = false ; QString mWifiIpAddress ; QString mWifiGateway ; QString mWifiSubnetMask ; QString mWifiDns ; // ----- Bluetooth QString mBle_Unused ; }; typedef QList TDataList; TDataList _dataList; typedef QHash TDataRoles; TDataRoles roleNames ( ) const override { return dataRoles; } int rowCount (const QModelIndex & = QModelIndex() ) const override { return _dataList.count(); } QVariant data (const QModelIndex &vIndex , int vRole = Qt::DisplayRole ) const override ; void dataAppend (const DataModel &vData , bool vFirst , bool vSecond); void dataClear ( ); bool setData (const QModelIndex &vIndex, const QVariant& vValue, int vRole = Qt::EditRole) override; QModelIndex index (int vRow, int vColumn, const QModelIndex &vParent = QModelIndex()) const override; private: TRIGGER ( bool , response , true) PROPERTY ( QString , status , "") READONLY ( bool , accepted , 0) TRIGGER ( quint32 , reason , 0) READONLY ( QString , osVersion , "") ATTRIBUTE ( quint8 , brightness , 0, Brightness ) ATTRIBUTE ( quint8 , bluetoothPairedReset, 0, BluetoothPairedReset ) ATTRIBUTE ( QStringList , bluetoothPairedQuery, {}, BluetoothPairedQuery ) ATTRIBUTE ( QString , cryptSetup , "", CryptSetup ) READONLY ( bool , cryptSetupEnabled , true ) ATTRIBUTE ( Qt::CheckState, rootSSHAccess , Qt::Unchecked , RootSSHAccess ) ATTRIBUTE ( QString , factoryReset , "", FactoryReset ) READONLY ( bool , factoryResetEnabled , true ) ATTRIBUTE ( QString , decommission , "", Decommission ) READONLY ( bool , decommissionEnabled , true ) ATTRIBUTE ( QString , dateTime , "", DateTime ) ATTRIBUTE ( QStringList , wifiList , {}, WifiList ) ATTRIBUTE ( QStringList , wifiInfo , {}, WifiInfo ) ATTRIBUTE ( bool , wifiConnect , false, WifiConnect ) READONLY ( bool , wifiListEnabled , true ) READONLY ( QString , ssid , "" ) READONLY ( QString , ipAddress , "" ) READONLY ( QString , gateway , "" ) READONLY ( QString , subnetMask , "" ) READONLY ( QString , dns , "" ) VIEW_DEC_CLASS_EX(VDevice, QAbstractListModel) public slots: void doWifiConnect(bool vConnect, const QString &vSsid, const QString &vPassword); void doDateTime ( const QString &vYear, const QString &vMonth, const QString &vDay, const QString &vHour, const QString &vMinute, bool vNTP); private slots: void onPOSTOSVersionData (const QString &vOSVersion); void onWiFiIP (const QString &vData, bool vWifiError); private: void parseWifiListResult(const QString &vResult); void parseWifiInfoResult(const QString &vResult); void updateWifiList(); bool isCompleteResponse(Model::MDeviceResponseBase::Data vData) { // Either the script exited successfully or the script failed and the reason is provided // There are situations that the script is using the attribute response to update the UI // but it is not the final/completed response return vData.mAccepted || (!vData.mAccepted && vData.mReason != 0 ); } }; }