Index: sources/device/DeviceController.cpp =================================================================== diff -u -rdb52d097addadd2eef6102340778be143ee81df4 -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) @@ -93,7 +93,6 @@ quitThread(); } - /*! * \brief DeviceController::initConnections * \details Initializes the required signal/slot connection between this class and other objects @@ -130,7 +129,6 @@ connect(this, SIGNAL(didEventThreadChange()), this, SLOT( onEventThreadChange())); - } /*! @@ -1329,8 +1327,6 @@ */ void DeviceController::wifiListRequest() { - // _deviceWifiListRequest._data - // ----- check that script exists. QString script; if ( checkError( DeviceError::checkScript(script, Wifi_Scan_For_Networks), _deviceWifiListResponse, script) ) @@ -1345,6 +1341,7 @@ // ----- run the process int timeout_ms = 10000; TimedProcess *timedProcess = new TimedProcess(&_processWifiList, script, timeout_ms, {}); + //DEBUG qDebug() << script << timeout_ms; timedProcess->start(); MDeviceWifiListResponse model; @@ -1364,14 +1361,16 @@ //DEBUG qDebug() << " 1 ---------- " << __FUNCTION__ << vExitCode << vStatus << vChannel; static MDeviceWifiListResponse model; if ( vExitCode < 0 ) { + emit didAttributeResponse(model.data()); switch (vChannel) { case QProcess::StandardOutput : processWifiListReadyOut(model); break; case QProcess::StandardError : processWifiListReadyErr(model); break; } } else { processWifiListComplete(model, vExitCode, vStatus); + emit didAttributeResponse(model.data()); + model._data.clear(); } - - emit didAttributeResponse(model.data()); } + Index: sources/device/DeviceModels.cpp =================================================================== diff -u -rdb52d097addadd2eef6102340778be143ee81df4 -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) @@ -284,7 +284,6 @@ _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; lOut: - _data.mCompleted= true; return _data.mAccepted; } Index: sources/device/DeviceModels.h =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a --- sources/device/DeviceModels.h (.../DeviceModels.h) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceModels.h (.../DeviceModels.h) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) @@ -68,12 +68,14 @@ struct Data { bool mCompleted= false; /*!< Completed The mComplete is used to ensure the script ran and is complete, - since the responses may have been produced to inform the UI only like a progress - and the script is not complete unless we are done with the script. */ + since the responses may have been produced to inform the UI only like a progress + and the script is not complete unless we are done with the script. */ bool mAccepted = false; /*!< Accepted The result of the script execution for the request - it could be sent back multiple times with accepted to false just to inform UI of a intermediary value like progress percentage.*/ + it could be sent back multiple times with accepted to false just to inform UI of a intermediary value like progress percentage.*/ quint32 mReason = 0 ; /*!< Reason if the mAccepted is 0 then this includes why it has been rejected with an ID of the rejection reason. */ QString mMessage = "" ; /*!< Message a message that can always be sent from the script. */ + + void clear() { mCompleted = false; mAccepted = false; mReason = 0; mMessage = ""; } }; MDeviceResponseBase () { } Index: sources/device/DeviceView.cpp =================================================================== diff -u -rdb52d097addadd2eef6102340778be143ee81df4 -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) @@ -272,30 +272,31 @@ } void VDevice::wifiListRequest(const QStringList &) { - QString norification = QObject::tr("The Wifi list scan started."); - status( norification ); + status( "" ); + wifiList({}); + dataClear(); wifiListEnabled(false); - DeviceWifiListRequestData data; - emit didAttributeRequest(data); + DeviceWifiListRequestData data ; + emit didAttributeRequest( data ); } void VDevice::onAttributeResponse(const DeviceWifiListResponseData &vData) { // DEBUG : qDebug() << " 2 ---------- " << __FUNCTION__ << vData.mMessage << result << vData.mCompleted; if ( vData.mCompleted ) { - dataClear(); if ( vData.mAccepted ) { wifiListEnabled(true); parseWifiListResult(vData.mWifiList); } else { wifiList({}); } - status(vData.mMessage); } accepted(vData.mAccepted); reason (vData.mReason ); + status (vData.mMessage ); + // has to be the last one response(true); } @@ -328,8 +329,8 @@ struct SSIDInfo { QString mSSID ; QString mBSSID ; - QString mFREQ_Max ; - QString mRATE_Max ; + quint16 mFREQ_Max ; + quint16 mRATE_Max ; quint16 mSIGNAL_Max ; QString mSECURITY ; QString mFLAGS ; // eWPA_FLAGS, eRSN_FLAGS are exclusive @@ -339,9 +340,9 @@ QStringList fields = QStringList() << mSSID << mBSSID - << mFREQ_Max - << mRATE_Max - << QString::number(mSIGNAL_Max) + << QString::number(mFREQ_Max ) + << QString::number(mRATE_Max ) + << QString::number(mSIGNAL_Max ) << mSECURITY << mFLAGS << (mSupported ? "T" : "") @@ -351,88 +352,82 @@ }; QString mResult = vResult; - SSIDInfo ssidInfo; QHash ssidInfoList; // the Freq, Rate units - QString mSSID; - const QString mFREQ_Unit = " MHz"; - const QString mRATE_Unit = " Mbit/s"; - quint32 mFREQ_Value = 0; - quint32 mRATE_Value = 0; + QString mSSID; +const QString mFREQ_Unit = " MHz"; +const QString mRATE_Unit = " Mbit/s"; // Removing the units once from the result to accelerate parsing. (will be added when done) mResult.remove(mFREQ_Unit); mResult.remove(mRATE_Unit); 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; QString mRSN_FLAGS; - for ( int index = 0; index < fields.count(); index++ ) { // the list has to be sorted and the script is written that way. - QString field = fields[index].trimmed(); + QStringList fields = lines[row].split(','); + qDebug() << fields.join("-"); + // this will never fail since even an empty string in split at least has index 0=eSSID; + mSSID = fields[eSSID].trimmed(); + if ( mSSID.isEmpty() ) continue; //hidden networks, or an incorrect entry - if ( row ) { // if is not first row - if ( mSSID == fields[eSSID] ) { // if is the same SSID just update necessary fields - quint32 value = 0; - switch (index) { - case eFREQ : value = QString("%1").arg(field).toInt(); if ( mFREQ_Value < value ) { mFREQ_Value = value; } break; - case eRATE : value = QString("%1").arg(field).toInt(); if ( mRATE_Value < value ) { mRATE_Value = value; } break; - case eSIGNAL : value = QString("%1").arg(field).toInt(); if ( ssidInfo.mSIGNAL_Max < value ) { ssidInfo.mSIGNAL_Max = value; } break; - case eIN_USE : value = field.contains("*"); ssidInfo.mInUse = value; break; - default: break; - } + if ( ssidInfoList.contains( mSSID ) ) { + for ( int index = 0; index < fields.count(); index++ ) { // the list has to be sorted and the script is written that way. + QString field = fields[index].trimmed(); + quint32 value = 0; + switch (index) { + // NOTE: NOT USED FOR NOW + // Not sure if get the max independently for each row is a correct way. + // since if we connect to one then we are bound to the specification of that Ap, so we cannot have a max freq from one and max rate from another one. + case eFREQ : value = QString("%1").arg(field).toInt(); if ( ssidInfoList[mSSID].mFREQ_Max < value ) { ssidInfoList[mSSID].mFREQ_Max = value; } break; + case eRATE : value = QString("%1").arg(field).toInt(); if ( ssidInfoList[mSSID].mRATE_Max < value ) { ssidInfoList[mSSID].mRATE_Max = value; } break; + case eSIGNAL : value = QString("%1").arg(field).toInt(); if ( ssidInfoList[mSSID].mSIGNAL_Max < value ) { ssidInfoList[mSSID].mSIGNAL_Max = value; } break; + case eIN_USE : value = field.contains("*"); ssidInfoList[mSSID].mInUse = value; break; + default: break; } - else { // else add the previous one and continue to the next. - if ( ! mSSID.trimmed().isEmpty() ) { - ssidInfo.mSSID = mSSID; - ssidInfo.mFREQ_Max += QString::number(mFREQ_Value) + mFREQ_Unit; - ssidInfo.mRATE_Max += QString::number(mRATE_Value) + mRATE_Unit; - ssidInfoList[mSSID] = ssidInfo; - //DEBUG qDebug() << ssidInfo.toString(); - } - // clean up / reset - ssidInfo.mFREQ_Max = ""; - ssidInfo.mRATE_Max = ""; - ssidInfo.mFLAGS = ""; - } } + } + else { + SSIDInfo ssidInfo; + for ( int index = 0; index < fields.count(); index++ ) { // the list has to be sorted and the script is written that way. + QString field = fields[index].trimmed(); + switch (index) { // DO NOT USE default in this switch + case eSSID : mSSID = field; break; + case eBSSID :/* ssidInfo.mBSSID = field; */ break; // every row is different and not used now. + case eFREQ : ssidInfo.mFREQ_Max = QString("%1").arg(field).toInt(); break; + case eRATE : ssidInfo.mRATE_Max = QString("%1").arg(field).toInt(); break; + case eSIGNAL : ssidInfo.mSIGNAL_Max = QString("%1").arg(field).toInt(); break; + case eIN_USE : ssidInfo.mInUse = field.contains("*"); break; + case eSECURITY : ssidInfo.mSECURITY = field; + if ( field.isEmpty() ) { + ssidInfo.mSupported = false; + } else { + ssidInfo.mSupported = field.remove(QRegExp("(WPA[23])")).trimmed().isEmpty(); + } + break; - switch (index) { // DO NOT USE default in this switch - case eSSID : mSSID = field; break; - case eBSSID : /*data.mBSSID = field;*/ break; // not directly used for now - case eFREQ : mFREQ_Value = QString("%1").arg(field).toInt(); break; - case eRATE : mRATE_Value = QString("%1").arg(field).toInt(); break; - case eSIGNAL : ssidInfo.mSIGNAL_Max = QString("%1").arg(field).toInt(); break; - case eIN_USE : ssidInfo.mInUse = field.contains("*"); break; - case eSECURITY : ssidInfo.mSECURITY = field; - if ( field.isEmpty() ) { - ssidInfo.mSupported = false; - } else { - ssidInfo.mSupported = field.remove(QRegExp("(WPA[23])")).trimmed().isEmpty(); - } - break; + case eWPA_FLAGS : + if ( field.contains("tkip") ) { mWPA_FLAGS += " TKIP" ; ssidInfo.mSupported = false; } + if ( field.contains("ccmp") ) { mWPA_FLAGS += " AES" ; } + if ( ! mWPA_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mWPA_FLAGS.trimmed(); } + break; - case eWPA_FLAGS : - if ( field.contains("tkip") ) { mWPA_FLAGS += " TKIP" ; ssidInfo.mSupported = false; } - if ( field.contains("ccmp") ) { mWPA_FLAGS += " AES" ; } - if ( ! mWPA_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mWPA_FLAGS.trimmed(); } - break; - - case eRSN_FLAGS : - if ( field.contains("tkip") ) { mRSN_FLAGS += " TKIP" ; ssidInfo.mSupported = false; } - if ( field.contains("ccmp") ) { mRSN_FLAGS += " AES" ; } - if ( field.contains("sae" ) ) { mRSN_FLAGS += " SAE" ; } - if ( ! mRSN_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mRSN_FLAGS.trimmed(); } - break; + case eRSN_FLAGS : + if ( field.contains("tkip") ) { mRSN_FLAGS += " TKIP" ; ssidInfo.mSupported = false; } + if ( field.contains("ccmp") ) { mRSN_FLAGS += " AES" ; } + if ( field.contains("sae" ) ) { mRSN_FLAGS += " SAE" ; } + if ( ! mRSN_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mRSN_FLAGS.trimmed(); } + break; + } } + ssidInfo .mSSID = mSSID; + ssidInfoList[mSSID] = ssidInfo; } } + _dataList.clear(); for (const auto &ssid: qAsConst(ssidInfoList)) { DataModel data; data.mWifiMacAddress = ssid.mBSSID; @@ -441,26 +436,28 @@ data.mWifiSignalLevel = ssid.mSIGNAL_Max; data.mWifiSupported = ssid.mSupported; data.mWifiConnected = ssid.mInUse ; - dataAppend( data, ssid.mInUse); + + dataAppend( data, ssid.mInUse, ssid.mSupported); } } -void View::VDevice::dataAppend(const DataModel &vData, bool vFirst) { +void View::VDevice::dataAppend(const DataModel &vData, bool vFirst, bool vSecond) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); - if ( vFirst ) { _dataList.insert(0, vData); } - else { _dataList.append( vData); } + if ( vFirst && _dataList.count() >= 0 ) { _dataList.insert(0, vData); goto lOut; } + if ( vSecond && _dataList.count() >= 1 ) { _dataList.insert(1, vData); goto lOut; } + + _dataList.append( vData); +lOut: endInsertRows(); } -void View::VDevice::dataClear() -{ +void View::VDevice::dataClear() { beginRemoveRows(QModelIndex(), 0, rowCount()); _dataList.clear(); endRemoveRows(); } -QVariant View::VDevice::data(const QModelIndex &vIndex, int vRole) const -{ +QVariant View::VDevice::data(const QModelIndex &vIndex, int vRole) const { if (! vIndex.isValid() || vIndex.row() >= _dataList.count()) return QVariant(); Index: sources/device/DeviceView.h =================================================================== diff -u -rdb52d097addadd2eef6102340778be143ee81df4 -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a --- sources/device/DeviceView.h (.../DeviceView.h) (revision db52d097addadd2eef6102340778be143ee81df4) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) @@ -80,33 +80,35 @@ 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 ); + void dataAppend (const DataModel &vData , bool vFirst , bool vSecond); void dataClear ( ); private: + TRIGGER ( bool , response , true) - PROPERTY ( bool , accepted , 0) - TRIGGER ( quint32 , reason , 0) PROPERTY ( QString , status , "") - PROPERTY ( QString , osVersion , "") + 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 ) - PROPERTY ( bool , cryptSetupEnabled , true ) + READONLY ( bool , cryptSetupEnabled , true ) ATTRIBUTE ( Qt::CheckState, rootSSHAccess , Qt::Unchecked , RootSSHAccess ) ATTRIBUTE ( QString , factoryReset , "", FactoryReset ) - PROPERTY ( bool , factoryResetEnabled , true ) + READONLY ( bool , factoryResetEnabled , true ) ATTRIBUTE ( QString , decommission , "", Decommission ) - PROPERTY ( bool , decommissionEnabled , true ) + READONLY ( bool , decommissionEnabled , true ) ATTRIBUTE ( QStringList , wifiList , {}, WifiList ) READONLY ( bool , wifiListEnabled , true )