Index: sources/device/DeviceController.cpp =================================================================== diff -u -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -30,7 +30,6 @@ #include "CloudSyncController.h" #include "ApplicationController.h" #include "FileHandler.h" -#include "DeviceModels.h" #include "Settings.h" #include "encryption.h" @@ -1362,29 +1361,17 @@ */ void DeviceController::processWifiListResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) { - //DEBUG - qDebug() << " 1 ---------- " << __FUNCTION__ << vExitCode << vStatus << vChannel; - + //DEBUG qDebug() << " 1 ---------- " << __FUNCTION__ << vExitCode << vStatus << vChannel; + static MDeviceWifiListResponse model; if ( vExitCode < 0 ) { switch (vChannel) { - case QProcess::StandardOutput : processWifiListReadyOut(); return; - case QProcess::StandardError : processWifiListReadyErr(); return; + case QProcess::StandardOutput : processWifiListReadyOut(model); break; + case QProcess::StandardError : processWifiListReadyErr(model); break; } } + else { + processWifiListComplete(model, vExitCode, vStatus); + } - MDeviceWifiListResponse model; - model._data.mCompleted = true; - QByteArray deviceInfo; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processWifiList.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); emit didAttributeResponse(model.data()); - - bool ok = ! vStatus; - - // log error and exit - if ( ! ok ) { - LOG_DEBUG(QString("WiFi list scan failed [%1]").arg(vExitCode)); - } - return; } Index: sources/device/DeviceController.h =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceController.h (.../DeviceController.h) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceController.h (.../DeviceController.h) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -31,6 +31,7 @@ class tst_initializations; namespace Device { +using namespace Model; /*! * \brief The TimedProcess class Index: sources/device/DeviceGlobals.h =================================================================== diff -u -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) +++ sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -104,23 +104,31 @@ */ \ void process##vATTRIBUTEFLC##Response(int vExitCode, QProcess::ExitStatus vStatus, \ QProcess::ProcessChannel vChannel ); \ - void process##vATTRIBUTEFLC##ReadyOut(); \ - void process##vATTRIBUTEFLC##ReadyErr(); \ + void process##vATTRIBUTEFLC##ReadyOut( M##Device##vATTRIBUTEFLC##Response &); \ + void process##vATTRIBUTEFLC##ReadyErr( M##Device##vATTRIBUTEFLC##Response &); \ + void process##vATTRIBUTEFLC##Complete( M##Device##vATTRIBUTEFLC##Response &, \ + int vExitCode, QProcess::ExitStatus vStatus); \ #define DEVICE_DEV_DECLARATION( vATTRIBUTEFLC ) \ - 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::process##vATTRIBUTEFLC##ReadyOut(M##Device##vATTRIBUTEFLC##Response &vModel) { \ + vModel._data.mCompleted = false; \ + vModel._data.mAccepted = false; \ + vModel._data.mMessage = _process##vATTRIBUTEFLC.readAllStandardOutput(); \ } \ - void DeviceController::process##vATTRIBUTEFLC##ReadyErr() { \ - M##Device##vATTRIBUTEFLC##Response model; \ - model._data.mAccepted = false; \ - model._data.mMessage = QString("Err:") + _process##vATTRIBUTEFLC.readAllStandardError(); \ - emit didAttributeResponse(model.data()); \ - } + void DeviceController::process##vATTRIBUTEFLC##ReadyErr(M##Device##vATTRIBUTEFLC##Response &vModel) { \ + vModel._data.mCompleted = false; \ + vModel._data.mAccepted = false; \ + vModel._data.mMessage = "Err:" +_process##vATTRIBUTEFLC.readAllStandardError(); \ + } \ + void DeviceController::process##vATTRIBUTEFLC##Complete(M##Device##vATTRIBUTEFLC##Response &vModel, \ + int vExitCode, QProcess::ExitStatus vStatus) { \ + vModel._data.mCompleted = true; \ + vModel._data.mAccepted = false; \ + if (vStatus) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; /* CrashExit */ \ + vModel.fromByteArray( vModel._data.mMessage.toLatin1(), &vExitCode ); \ + } \ + #define DEVICE_DEV_INIT_CONNECTIONS( vATTRIBUTEFLC ) \ /* App -> Dev //TODO: Add the error LOG connection */ \ connect(&_ApplicationController , SIGNAL(didAttributeRequest(const Device##vATTRIBUTEFLC##RequestData &)), \ Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r0932b2beee9cc169291cbf69161f902f805237b1 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 0932b2beee9cc169291cbf69161f902f805237b1) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -261,12 +261,12 @@ */ bool MDeviceWifiListResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) { - //DEBUG - qDebug() << __FUNCTION__ << vByteArray; + //DEBUG qDebug() << __FUNCTION__ << vByteArray; // initialize data - int error = 0; - _data.mAccepted = false; + int error = 0; + _data.mCompleted = true; + _data.mAccepted = false; // check if the vExitCode passed and it has a value other than zero if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_WifiList_Error; error = *vExitCode; } @@ -278,7 +278,7 @@ // Now everything is good to extract the data _data.mAccepted = true; _data.mWifiList = vByteArray; - _data.mMessage = QObject::tr("The Wifi list scan Complete."); goto lOut ; // normal return + _data.mMessage = QObject::tr("The Wifi list scan complete."); goto lOut ; // normal return lError: _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error) + "\n" + vByteArray; 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; -} Index: sources/device/DeviceView.h =================================================================== diff -u -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/device/DeviceView.h (.../DeviceView.h) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -38,6 +38,52 @@ 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 ; + // ----- 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 ); + void dataClear ( ); + +private: TRIGGER ( bool , response , true) PROPERTY ( bool , accepted , 0) @@ -62,52 +108,16 @@ 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 , - }; - - 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); private: - QVariantList parseWifiListResult(const QString &vResult); + void parseWifiListResult(const QString &vResult); 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 Index: sources/gui/qml/pages/settings/SettingsWiFi.qml =================================================================== diff -u -r574c7c5fb48b1fcb72337f5fb4c0119a20288815 -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/gui/qml/pages/settings/SettingsWiFi.qml (.../SettingsWiFi.qml) (revision 574c7c5fb48b1fcb72337f5fb4c0119a20288815) +++ sources/gui/qml/pages/settings/SettingsWiFi.qml (.../SettingsWiFi.qml) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -43,6 +43,7 @@ readonly property int rightMargin : 50 readonly property int topMargin : topMarginContent - 40 // moved up to top of the keyboard + readonly property bool isValid : _ipAddress .textInput.acceptableInput && _gateway .textInput.acceptableInput @@ -69,7 +70,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" //TODO: Wifi + textInput.text : "ipAddress" //TODO: Wifi label.text : qsTr("IP Address") textInput.width : entryWidth label.width : labelWidth @@ -82,7 +83,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" //TODO: Wifi + textInput.text : "gateway" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("Gateway") @@ -95,7 +96,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" //TODO: Wifi + textInput.text : "subnetMask" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("Subnet Mask") @@ -107,7 +108,7 @@ } TextEntry { id : _dns - textInput.text : "vNetwork.dns" //TODO: Wifi + textInput.text : "dns" //TODO: Wifi textInput.width : entryWidth label.width : labelWidth label.text : qsTr("DNS") @@ -136,7 +137,7 @@ font.pixelSize : Fonts.fontPixelTextRectExtra color : Colors.textMain horizontalAlignment : TextInput.Alignleft - text : "vNetwork.ssid" //TODO: Wifi + text : "" width : entryWidth } } @@ -170,9 +171,13 @@ 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 bool isConnected : wifiConnected + onIsConnectedChanged: { + if ( isConnected ) { + _ssidText.text = wifiSsid + } + } - clip : true text.text : wifiSsid text.elide : Text.ElideLeft @@ -184,7 +189,8 @@ text.anchors.horizontalCenter : undefined text.horizontalAlignment : Text.AlignLeft text.leftPadding : 5 - border.width : 1 + border.width : 1 + borderColor : wifiConnected ? Colors.borderButtonSelected : Colors.borderButton Text { id : _securityLevel anchors { @@ -204,15 +210,15 @@ bottom : parent.bottom } font.pixelSize : Fonts.fontPixelDialogText - text : _delegate.isCurrrentNetwork ? qsTr("Connected") : "" + text : wifiConnected ? qsTr("Connected") : "" color : _delegate.networkDelegateTextColor } onClicked : { - if( isNetworkSupported ) { - _userConfirmation.isPassword = ! _delegate.isCurrrentNetwork - _userConfirmation.ssid = ssid - _userConfirmation.macAddress = macAddress + if( wifiSupported ) { + _userConfirmation.isPassword = ! wifiConnected + _userConfirmation.ssid = wifiSsid + _userConfirmation.macAddress = wifiMacAddress push( _userConfirmation ) _userConfirmation.setFocus() } @@ -225,7 +231,7 @@ property string macAddress : "" property string separator : "\n\n" readonly property string spaceSeparator : " " - // notificationText : vNetwork.status + notificationText : vDevice.status message : qsTr("Do you want to disconnect from `%1`?").arg(ssid) title : isPassword ? qsTr("Join") + separator + ssid + spaceSeparator + qsTr("Password") : qsTr("Disconnect") + separator + ssid onConfirmClicked : { Index: sources/wifi/WifiInterface.cpp =================================================================== diff -u -r2e97d4783dc34f6953c3602e607900bca26443ff -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 2e97d4783dc34f6953c3602e607900bca26443ff) +++ sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -224,7 +224,7 @@ * Scans for WiFi Access Points */ void WifiInterface::doScan() -{ +{ if (_scanRunning) { LOG_DEBUG("WiFi network scan is already running."); return; @@ -256,7 +256,7 @@ LOG_DEBUG(QString("stderr: %1").arg(err)); _scanRunning = false; emit didScanStatusChanged(_scanRunning); - parseWifiScanResult(out); + parseWifiScan(out); LOG_DEBUG("WiFi Scan Finished"); } @@ -283,151 +283,6 @@ } /*! - * \brief Network::parseWifiScanResult - * \details Extract desired information from the WiFi scan output. Sorts by signal stength - * \param vResult - (QString) output collected from QProcess execution - * \return List of the Found SSIDs in a model. - */ -QList WifiInterface::parseWifiScanResult(const QString &vResult) -{ - enum SSIDInfo_Enum { - eSSID , - eBSSID , - eFREQ , - eRATE , - eSIGNAL , - eSECURITY , - eWPA_FLAGS , - eRSN_FLAGS , - eIN_USE , - }; - enum ValueUnit_Enum { - eValue , - eUnit , - eCount , - }; - - struct SSIDInfo { - QString mSSID ; - QString mBSSID ; - QString mFREQ_Max ; - QString mRATE_Max ; - quint16 mSIGNAL_Max ; - QString mSECURITY ; - QString mFLAGS ; // eWPA_FLAGS, eRSN_FLAGS are exclusive - bool mIN_USE = false ; - bool mSupported = true ; - QString toString() { - QStringList fields = QStringList() - << mSSID - << mBSSID - << mFREQ_Max - << mRATE_Max - << QString::number(mSIGNAL_Max) - << mSECURITY - << mFLAGS - << (mSupported ? "T" : "") - << (mIN_USE ? "T" : ""); - return fields.join(','); - } - }; - - QString mResult = vResult; - - SSIDInfo data; - QHash mSSIDInfoList; - - // 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; - // 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(','); - 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(); - - 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 ( data.mSIGNAL_Max < value ) { data.mSIGNAL_Max = value; } break; - case eIN_USE : data.mIN_USE = field.contains("*"); 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(); - } - // clean up / reset - data.mFREQ_Max = ""; - data.mRATE_Max = ""; - data.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; - if ( field.isEmpty() ) { - data.mSupported = false; - } else { - data.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("ccmp") ) { mWPA_FLAGS += " AES" ; } - if ( ! mWPA_FLAGS.isEmpty() ) { data.mFLAGS = mWPA_FLAGS.trimmed(); } - break; - - case eRSN_FLAGS : - if ( field.contains("tkip") ) { mRSN_FLAGS += " TKIP" ; data.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(); } - break; - } - } - } - return {}; -} - - - -/*! * \brief Network::parseWifiScan * Extract desired information from the WiFi scan output. Sorts by signal stength * Index: sources/wifi/WifiInterface.h =================================================================== diff -u -r2e97d4783dc34f6953c3602e607900bca26443ff -rdb52d097addadd2eef6102340778be143ee81df4 --- sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 2e97d4783dc34f6953c3602e607900bca26443ff) +++ sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision db52d097addadd2eef6102340778be143ee81df4) @@ -90,7 +90,6 @@ bool checkScript(QString &vScript, const QString &vShellScript); QString getTextBetweenDelimiters(const QString &vText, const QString &vLeftDelim, const QString &vRightDelim); QList parseWifiScan(const QString &vOutput); - QList parseWifiScanResult(const QString &vResult); QString parseIP(const QString &vOutput); QString parseBroadcast(const QString &vOutput); QString parseSubnetMask(const QString &vOutput);