Index: sources/device/DeviceView.cpp =================================================================== diff -u -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -272,37 +272,30 @@ } void VDevice::wifiListRequest(const QStringList &) { + QString norification = QObject::tr("The Wifi list scan started."); + status( norification ); wifiListEnabled(false); DeviceWifiListRequestData data; emit didAttributeRequest(data); } void VDevice::onAttributeResponse(const DeviceWifiListResponseData &vData) { - /// When calling a script, the last echo which is before the exit, is not where the script is completed. - /// therefore we need to store the last one to use it when the script is sending the data and then exits, - /// which is when we have the mComp;eted as true. - static QString result; - // DEBUG : - qDebug() << " 2 ---------- " << __FUNCTION__ << vData.mMessage << result << vData.mCompleted; + // DEBUG : qDebug() << " 2 ---------- " << __FUNCTION__ << vData.mMessage << result << vData.mCompleted; if ( vData.mCompleted ) { + dataClear(); if ( vData.mAccepted ) { - // wifiList(); - status(""); - wifiListEnabled(true); // TODO - parseWifiListResult(vData.mWifiList/*result*/); - status(vData.mMessage); + wifiListEnabled(true); + parseWifiListResult(vData.mWifiList); } else { - // this has to be called to let Gui to set to old value that device controller provided. - // when not accepted could be a message only to update the screen. - emit wifiListChanged({}); - status(vData.mMessage); + wifiList({}); } + status(vData.mMessage); } accepted(vData.mAccepted); reason (vData.mReason ); - result = vData.mWifiList; + // has to be the last one response(true); } @@ -313,7 +306,7 @@ * \param vResult - (QString) output collected from QProcess execution * \return List of the Found SSIDs in a model. */ -QVariantList View::VDevice::parseWifiListResult(const QString &vResult) +void View::VDevice::parseWifiListResult(const QString &vResult) { enum SSIDInfo_Enum { eSSID , @@ -340,7 +333,7 @@ quint16 mSIGNAL_Max ; QString mSECURITY ; QString mFLAGS ; // eWPA_FLAGS, eRSN_FLAGS are exclusive - bool mIN_USE = false ; + bool mInUse = false ; bool mSupported = true ; QString toString() { QStringList fields = QStringList() @@ -352,18 +345,15 @@ << mSECURITY << mFLAGS << (mSupported ? "T" : "") - << (mIN_USE ? "T" : ""); + << (mInUse ? "T" : ""); return fields.join(','); } }; - QString mResult = vResult; - qDebug() << " ---------- "; - qDebug() << mResult; + QString mResult = vResult; + SSIDInfo ssidInfo; + QHash ssidInfoList; - SSIDInfo data; - QHash mSSIDInfoList; - // the Freq, Rate units QString mSSID; const QString mFREQ_Unit = " MHz"; @@ -390,114 +380,103 @@ 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 ( data.mSIGNAL_Max < value ) { data.mSIGNAL_Max = value; } break; - case eIN_USE : data.mIN_USE = field.contains("*"); break; - default: break; + 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; } } else { // else add the previous one and continue to the next. if ( ! mSSID.trimmed().isEmpty() ) { - data.mSSID = mSSID; - data.mFREQ_Max += QString::number(mFREQ_Value) + mFREQ_Unit; - data.mRATE_Max += QString::number(mRATE_Value) + mRATE_Unit; - mSSIDInfoList[mSSID] = data; - qDebug() << data.toString(); + 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 - data.mFREQ_Max = ""; - data.mRATE_Max = ""; - data.mFLAGS = ""; + ssidInfo.mFREQ_Max = ""; + ssidInfo.mRATE_Max = ""; + ssidInfo.mFLAGS = ""; } } 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 : data.mSIGNAL_Max = QString("%1").arg(field).toInt(); break; - case eIN_USE : data.mIN_USE = field.contains("*"); break; - - case eSECURITY : - data.mSECURITY = field; + 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() ) { - data.mSupported = false; + ssidInfo.mSupported = false; } else { - data.mSupported = field.remove(QRegExp("(WPA[23])")).trimmed().isEmpty(); + ssidInfo.mSupported = field.remove(QRegExp("(WPA[23])")).trimmed().isEmpty(); } break; case eWPA_FLAGS : - if ( field.contains("tkip") ) { mWPA_FLAGS += " TKIP" ; data.mSupported = false; } + if ( field.contains("tkip") ) { mWPA_FLAGS += " TKIP" ; ssidInfo.mSupported = false; } if ( field.contains("ccmp") ) { mWPA_FLAGS += " AES" ; } - if ( ! mWPA_FLAGS.isEmpty() ) { data.mFLAGS = mWPA_FLAGS.trimmed(); } + if ( ! mWPA_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mWPA_FLAGS.trimmed(); } break; case eRSN_FLAGS : - if ( field.contains("tkip") ) { mRSN_FLAGS += " TKIP" ; data.mSupported = false; } + 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() ) { data.mFLAGS = mRSN_FLAGS.trimmed(); } + if ( ! mRSN_FLAGS.isEmpty() ) { ssidInfo.mFLAGS = mRSN_FLAGS.trimmed(); } break; } } - DataModel dataModel; - dataModel.mWifiSSID = mSSID; - qDebug() << mSSID; - addData(dataModel); } - // qDebug() << _wifiList; - return {}; + for (const auto &ssid: qAsConst(ssidInfoList)) { + DataModel data; + data.mWifiMacAddress = ssid.mBSSID; + data.mWifiSSID = ssid.mSSID; + data.mWifiSecurityTypes = ssid.mSECURITY; + data.mWifiSignalLevel = ssid.mSIGNAL_Max; + data.mWifiSupported = ssid.mSupported; + data.mWifiConnected = ssid.mInUse ; + dataAppend( data, ssid.mInUse); + } } -void View::VDevice::addData(const DataModel &vDataModel) { +void View::VDevice::dataAppend(const DataModel &vData, bool vFirst) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); - _dataList << vDataModel; + if ( vFirst ) { _dataList.insert(0, vData); } + else { _dataList.append( vData); } endInsertRows(); } -int View::VDevice::rowCount(const QModelIndex &) const +void View::VDevice::dataClear() { - return _wifiList.count(); + beginRemoveRows(QModelIndex(), 0, rowCount()); + _dataList.clear(); + endRemoveRows(); } QVariant View::VDevice::data(const QModelIndex &vIndex, int vRole) const { - if (vIndex.row() < 0 || vIndex.row() >= _dataList.count()) + if (! vIndex.isValid() || vIndex.row() >= _dataList.count()) return QVariant(); - const DataModel &dataList = _dataList[vIndex.row()]; + 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; + // ----- WiFi + case eRole_WifiMacAddress : return dataList.mWifiMacAddress ; + case eRole_WifiSsid : return dataList.mWifiSSID ; + case eRole_WifiSecurityTypes : return dataList.mWifiSecurityTypes ; + case eRole_WifiSignalLevel : return dataList.mWifiSignalLevel ; + case eRole_WifiSupported : return dataList.mWifiSupported ; + case eRole_WifiConnected : return dataList.mWifiConnected ; + // ----- Bluetooth + case eRole_BLE_UNUSED : return ""; ; } - 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; -}