Index: sources/device/DeviceController.cpp =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -578,7 +578,7 @@ } /*! - * \brief DeviceController::onProcessBrightnessFinished + * \brief DeviceController::processBrightnessResponse * \details Called when the process to set the brightness has finished * \param vExitCode (int) the exit code * \note exit code -> 0 : set Accept [MBase] -> Log -> emit @@ -588,7 +588,7 @@ * 3 - get no error when in onProcessBrightnessExitCode : MDeviceResponse.toString() * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. */ -void DeviceController::onProcessBrightnessExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processBrightnessResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { //DEBUG qDebug() << __FUNCTION__ << vExitCode << vStatus; @@ -647,7 +647,7 @@ } /*! - * \brief DeviceController::onProcessRootSSHAccessExitCode + * \brief DeviceController::processRootSSHAccessResponse * \details Called when the process to set the RootSSHAccess has finished * \param vExitCode (int) the exit code * \note exit code -> 0 : set Accept [MBase] -> Log -> emit @@ -657,7 +657,7 @@ * 3 - get no error when in onProcessRootSSHAccessExitCode : MDeviceResponse.toString() * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. */ -void DeviceController::onProcessRootSSHAccessExitCode(int vExitCode, QProcess::ExitStatus) +void DeviceController::processRootSSHAccessResponse(int vExitCode, QProcess::ExitStatus, QProcess::ProcessChannel /*vChannel*/) { if ( ! checkError(static_cast(vExitCode), _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()) ) { // has no error if (_deviceRootSSHAccessRequest._data.mIsGet) { @@ -733,11 +733,11 @@ } /*! - * \brief DeviceController::onProcessCryptSetupExitCode + * \brief DeviceController::processCryptSetupResponse * \param vExitCode * \param vStatus */ -void DeviceController::onProcessCryptSetupExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processCryptSetupResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { const int ERR_CRYPTSETUP_MOUNT_ISMOUNT=134; // is used in crypt_setup.sh do not modify @@ -807,7 +807,7 @@ timedProcess->start(); } -void DeviceController::onProcessBluetoothPairedResetExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processBluetoothPairedResetResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { // TODO: review the usage and definition of this object _deviceBluetoothPairedResetResponse. do we need it any more? MDeviceBluetoothPairedResetResponse model; @@ -839,7 +839,7 @@ timedProcess->start(); } -void DeviceController::onProcessBluetoothPairedQueryExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processBluetoothPairedQueryResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { // The Exit code in this script is not used. // any other checking is done by UI Software at the moment this script is called. @@ -1160,11 +1160,11 @@ } /*! - * \brief DeviceController::onProcessFactoryResetExitCode + * \brief DeviceController::processFactoryResetResponse * \param vExitCode - the script exit code. * \param vStatus - the script echoed message. */ -void DeviceController::onProcessFactoryResetExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processFactoryResetResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { // The Exit code in this script is not used. // any other checking is done by UI Software at the moment this script is called. @@ -1211,11 +1211,11 @@ } /*! - * \brief DeviceController::onProcessDecommissionExitCode + * \brief DeviceController::processDecommissionResponse * \param vExitCode * \param vStatus */ -void DeviceController::onProcessDecommissionExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processDecommissionResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { // The Exit code in this script is not used. // any other checking is done by UI Software at the moment this script is called. @@ -1273,11 +1273,11 @@ } /*! - * \brief DeviceController::onProcessUSBMountExitCode + * \brief DeviceController::processUSBMountResponse * \param vExitCode * \param vStatus */ -void DeviceController::onProcessUSBMountExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processUSBMountResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) { MDeviceUSBMountResponse model; QByteArray deviceInfo; @@ -1356,15 +1356,22 @@ } /*! - * \brief DeviceController::onProcessUSBMountExitCode + * \brief DeviceController::processUSBMountResponse * \param vExitCode * \param vStatus */ -void DeviceController::onProcessWifiListExitCode(int vExitCode, QProcess::ExitStatus vStatus) +void DeviceController::processWifiListResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) { //DEBUG - qDebug() << __FUNCTION__ << vExitCode << vStatus; + qDebug() << " 1 ---------- " << __FUNCTION__ << vExitCode << vStatus << vChannel; + if ( vExitCode < 0 ) { + switch (vChannel) { + case QProcess::StandardOutput : processWifiListReadyOut(); return; + case QProcess::StandardError : processWifiListReadyErr(); return; + } + } + MDeviceWifiListResponse model; model._data.mCompleted = true; QByteArray deviceInfo; @@ -1377,7 +1384,7 @@ // log error and exit if ( ! ok ) { - LOG_DEBUG(QString("WiFi list scan filed [%1]").arg(vExitCode)); + LOG_DEBUG(QString("WiFi list scan failed [%1]").arg(vExitCode)); } return; } Index: sources/device/DeviceGlobals.h =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -94,26 +94,27 @@ * to start the corresponding process and call the script assigned to it. \ */ \ void onAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &vData); \ + private : \ /*! \ * \brief DeviceController::onProcessExitCode \ * \details The slot which is being called once the started process is returning a value \ * as an exit code, probably from within the called script \ * \param vExitCode - the returned exit code \ * \param vStatus - the status of the process \ */ \ - void onProcess##vATTRIBUTEFLC##ExitCode(int vExitCode, QProcess::ExitStatus vStatus); \ - void onProcess##vATTRIBUTEFLC##ReadyOut(); \ - void onProcess##vATTRIBUTEFLC##ReadyErr(); \ - private : + void process##vATTRIBUTEFLC##Response(int vExitCode, QProcess::ExitStatus vStatus, \ + QProcess::ProcessChannel vChannel ); \ + void process##vATTRIBUTEFLC##ReadyOut(); \ + void process##vATTRIBUTEFLC##ReadyErr(); \ #define DEVICE_DEV_DECLARATION( vATTRIBUTEFLC ) \ - void DeviceController::onProcess##vATTRIBUTEFLC##ReadyOut() { \ + void DeviceController::process##vATTRIBUTEFLC##ReadyOut() { \ M##Device##vATTRIBUTEFLC##Response model; \ model._data.mAccepted = false; \ model._data.mMessage = _process##vATTRIBUTEFLC.readAllStandardOutput(); \ emit didAttributeResponse(model.data()); \ } \ - void DeviceController::onProcess##vATTRIBUTEFLC##ReadyErr() { \ + void DeviceController::process##vATTRIBUTEFLC##ReadyErr() { \ M##Device##vATTRIBUTEFLC##Response model; \ model._data.mAccepted = false; \ model._data.mMessage = QString("Err:") + _process##vATTRIBUTEFLC.readAllStandardError(); \ @@ -124,12 +125,18 @@ /* App -> Dev //TODO: Add the error LOG connection */ \ connect(&_ApplicationController , SIGNAL(didAttributeRequest(const Device##vATTRIBUTEFLC##RequestData &)), \ this , SLOT( onAttributeRequest(const Device##vATTRIBUTEFLC##RequestData &))); \ - connect(&_process##vATTRIBUTEFLC, SIGNAL( finished(int, QProcess::ExitStatus)), \ - this, SLOT(onProcess##vATTRIBUTEFLC##ExitCode(int, QProcess::ExitStatus))); \ - connect(&_process##vATTRIBUTEFLC, SIGNAL( readyReadStandardOutput( )), \ - this, SLOT(onProcess##vATTRIBUTEFLC##ReadyOut( ))); \ - connect(&_process##vATTRIBUTEFLC, SIGNAL( readyReadStandardError ( )), \ - this, SLOT(onProcess##vATTRIBUTEFLC##ReadyErr( ))); \ + connect(&_process##vATTRIBUTEFLC, QOverload::of(&QProcess::finished), \ + this , [=](int vExitCode, QProcess::ExitStatus vStatus) { \ + process##vATTRIBUTEFLC##Response(vExitCode, vStatus , QProcess::StandardOutput ); \ + }); \ + connect(&_process##vATTRIBUTEFLC, &QProcess::readyReadStandardOutput, \ + this , [=]( ) { \ + process##vATTRIBUTEFLC##Response(-1, QProcess::NormalExit, QProcess::StandardOutput ); \ + }); \ + connect(&_process##vATTRIBUTEFLC, &QProcess::readyReadStandardError , \ + this , [=]( ) { \ + process##vATTRIBUTEFLC##Response(-1, QProcess::NormalExit, QProcess::StandardError ); \ + }); \ /* ---------------------------- APP */ #define DEVICE_APP_BRIDGE_DEFINITION( vATTRIBUTEFLC ) \ Index: sources/device/DeviceView.cpp =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -24,7 +24,7 @@ #include "encryption.h" #include "MWifiNetwork.h" -VIEW_DEF_CLASS(VDevice) +VIEW_DEF_CLASS_EX(VDevice, QAbstractListModel) void VDevice::initConnections() { @@ -283,13 +283,13 @@ /// which is when we have the mComp;eted as true. static QString result; // DEBUG : - qDebug() << __FUNCTION__ << vData.mMessage << result << vData.mCompleted; + qDebug() << " 2 ---------- " << __FUNCTION__ << vData.mMessage << result << vData.mCompleted; if ( vData.mCompleted ) { if ( vData.mAccepted ) { - wifiList({ "SSID1" , "SSID2" }); + // wifiList(); status(""); wifiListEnabled(true); // TODO - parseWifiListResult(result); + parseWifiListResult(vData.mWifiList/*result*/); status(vData.mMessage); } else { @@ -313,7 +313,7 @@ * \param vResult - (QString) output collected from QProcess execution * \return List of the Found SSIDs in a model. */ -QVariantList VDevice::parseWifiListResult(const QString &vResult) +QVariantList View::VDevice::parseWifiListResult(const QString &vResult) { enum SSIDInfo_Enum { eSSID , @@ -358,6 +358,8 @@ }; QString mResult = vResult; + qDebug() << " ---------- "; + qDebug() << mResult; SSIDInfo data; QHash mSSIDInfoList; @@ -375,6 +377,7 @@ QStringList lines = mResult.split('\n'); for ( int row = 0; row < lines.count(); row++ ) { QStringList fields = lines[row].split(','); + qDebug() << fields.join("-"); if ( fields[eSSID].trimmed().isEmpty() ) continue; // hidden networks, or an incorrect entry QString mWPA_FLAGS; @@ -446,6 +449,55 @@ break; } } + DataModel dataModel; + dataModel.mWifiSSID = mSSID; + qDebug() << mSSID; + addData(dataModel); } + + // qDebug() << _wifiList; return {}; } + +void View::VDevice::addData(const DataModel &vDataModel) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + _dataList << vDataModel; + endInsertRows(); +} + +int View::VDevice::rowCount(const QModelIndex &) const +{ + return _wifiList.count(); +} + +QVariant View::VDevice::data(const QModelIndex &vIndex, int vRole) const +{ + if (vIndex.row() < 0 || vIndex.row() >= _dataList.count()) + return QVariant(); + + const DataModel &dataList = _dataList[vIndex.row()]; + + switch (vRole) { + case eRole_WifiMacAddress : return dataList.mWifiMacAddress ; break; + case eRole_WifiSsid : return dataList.mWifiSSID ; break; + case eRole_WifiSecurityTypes : return dataList.mWifiSecurityTypes ; break; + case eRole_WifiSignalLevel : return dataList.mWifiSignalLevel ; break; + case eRole_WifiSupported : return dataList.mWifiSupported ; break; + case eRole_WifiConnected : return dataList.mWifiConnected ; break; + default: break; + } + + + return QString("Wifi %1").arg(vIndex.row()); +} + +QHash View::VDevice::roleNames() const { + QHash roles; + roles[eRole_WifiMacAddress ] = "wifiMacAddress" ; + roles[eRole_WifiSsid ] = "wifiSsid" ; + roles[eRole_WifiSecurityTypes ] = "wifiSecurityTypes" ; + roles[eRole_WifiSignalLevel ] = "wifiSignalLevel" ; + roles[eRole_WifiSupported ] = "wifiSupported" ; + roles[eRole_WifiConnected ] = "wifiConnected" ; + return roles; +} Index: sources/device/DeviceView.h =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/device/DeviceView.h (.../DeviceView.h) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -16,6 +16,7 @@ // Qt #include +#include // Project #include "main.h" // Doxygen : do not remove @@ -33,7 +34,8 @@ * \details The device view to interact with the UI. * */ -class VDevice : public QObject { +class VDevice : public QAbstractListModel { + Q_OBJECT TRIGGER ( bool , response , true) @@ -60,15 +62,47 @@ ATTRIBUTE ( QString , decommission , "", Decommission ) PROPERTY ( bool , decommissionEnabled , true ) + ATTRIBUTE ( QStringList , wifiList , {}, WifiList ) READONLY ( bool , wifiListEnabled , true ) + VIEW_DEC_CLASS_EX(VDevice, QAbstractListModel) + enum DataRole { + eRole_DataRole_Start = Qt::UserRole , + eRole_WifiMacAddress , + eRole_WifiSsid , + eRole_WifiSecurityTypes , + eRole_WifiSignalLevel , + eRole_WifiSupported , + eRole_WifiConnected , + eRole_BLE_UNUSED , + }; - VIEW_DEC_CLASS(VDevice) + struct DataModel { + QString mWifiMacAddress ; + QString mWifiSSID ; + QString mWifiSecurityTypes ; + qint16 mWifiSignalLevel ; + bool mWifiSupported = false ; + bool mWifiConnected = false ; + QString mBle_Unused ; + }; + + QList _dataList; + +public: + int rowCount (const QModelIndex &parent = QModelIndex() ) const override; + QVariant data (const QModelIndex &vIndex, int vRole = Qt::DisplayRole ) const override; +private: + void addData (const DataModel &vDataModel); + +protected: + QHash roleNames() const override; + private slots: void onPOSTOSVersionData (const QString &vOSVersion); Index: sources/gui/qml/pages/settings/SettingsWiFi.qml =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/gui/qml/pages/settings/SettingsWiFi.qml (.../SettingsWiFi.qml) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/gui/qml/pages/settings/SettingsWiFi.qml (.../SettingsWiFi.qml) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -69,7 +69,7 @@ TextEntry { id : _ipAddress nextInput : _gateway // helps user to tap on enter to go to the next entry, keyboard visibility is handled by TextEntry. - textInput.text : vNetwork.ipAddress + textInput.text : "vNetwork.ipAddress" //TODO: Wifi label.text : qsTr("IP Address") textInput.width : entryWidth label.width : labelWidth @@ -82,7 +82,7 @@ TextEntry { id : _gateway nextInput : _subnetmask // helps user to tap on enter to go to the next entry, keyboard visibility is handled by TextEntry. - textInput.text : vNetwork.gateway + textInput.text : "vNetwork.gateway" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("Gateway") @@ -95,7 +95,7 @@ TextEntry { id : _subnetmask nextInput : _dns // helps user to tap on enter to go to the next entry, keyboard visibility is handled by TextEntry. - textInput.text : vNetwork.subnetMask + textInput.text : "vNetwork.subnetMask" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("Subnet Mask") @@ -107,7 +107,7 @@ } TextEntry { id : _dns - textInput.text : vNetwork.dns + textInput.text : "vNetwork.dns" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("DNS") @@ -136,7 +136,7 @@ font.pixelSize : Fonts.fontPixelTextRectExtra color : Colors.textMain horizontalAlignment : TextInput.Alignleft - text : vNetwork.ssid + text : "vNetwork.ssid" //TODO: Wifi width : entryWidth } } @@ -157,7 +157,7 @@ anchors.fill: _networkList } ListView { id : _networkList - model : vNetwork + model : vDevice clip : true spacing : 7 y : _root.topMargin @@ -166,15 +166,15 @@ anchors.bottom : _scanButton.bottom anchors.right : _root.right anchors.rightMargin : _root.rightMargin - delegate : TouchRect { id : _delegate + delegate : + TouchRect { id : _delegate + readonly property color networkDelegateTextColor : wifiSupported ? Colors.textMain : Colors.textDisableButton + readonly property string postSecurityTypeLabel : wifiSupported ? "" : " - " + qsTr("Not Supported") + property bool isCurrrentNetwork : vDevice.wifiSupported === wifiSupported - readonly property color networkDelegateTextColor : isNetworkSupported ? Colors.textMain : Colors.textDisableButton - readonly property string postSecurityTypeLabel : isNetworkSupported ? "" : " - " + qsTr("Not Supported") - property bool isCurrrentNetwork : vNetwork.macAddress === macAddress - clip : true - text.text : ssid + text.text : wifiSsid text.elide : Text.ElideLeft text.color : _delegate.networkDelegateTextColor width : _networkList.width - Variables.minVGap @@ -193,7 +193,7 @@ bottom : parent.bottom } font.pixelSize : Fonts.fontPixelDialogText - text : securityTypes + _delegate.postSecurityTypeLabel + text : wifiSecurityTypes + _delegate.postSecurityTypeLabel color : _delegate.networkDelegateTextColor } Index: sources/view/VView.h =================================================================== diff -u -r90e68000c37bc14b0dfd5f18caf425c24cc0b5f4 -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 --- sources/view/VView.h (.../VView.h) (revision 90e68000c37bc14b0dfd5f18caf425c24cc0b5f4) +++ sources/view/VView.h (.../VView.h) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) @@ -50,6 +50,19 @@ */\ explicit vCLASS(QObject *parent = nullptr); \ //--------------------------------------------------------------------------------// +#define VIEW_DEC_CLASS_EX(vCLASS, vPARENT) \ +private: \ + /*! \brief Connection Initializer + \details All the class signal/slot connections are defined here. + */\ + void initConnections(); \ +public: \ + /*! \brief Class Constructor + \details Only calls initConnections to initialize the signal/slot connection(s). + \param parent - The QObject parent pointer which is passed as nullptr and is not set. + */\ + explicit vCLASS(vPARENT *parent = nullptr); \ +//--------------------------------------------------------------------------------// #define VIEW_DEC_SLOT(vDATATYPE) \ private Q_SLOTS: \ /*! \brief Model data received message handler. @@ -71,6 +84,12 @@ initConnections(); \ } \ //--------------------------------------------------------------------------------// +#define VIEW_DEF_CLASS_EX(vCLASS, vPARENT) \ +using namespace View; \ +vCLASS::vCLASS(vPARENT *parent) : vPARENT(parent) { \ + initConnections(); \ +} \ +//--------------------------------------------------------------------------------// #define VIEW_DEF_CONNECTION(vCLASS, vDATATYPE) \ void vCLASS::initConnections() { \ ACTION_RECEIVE_BRIDGE_CONNECTION( \