Index: sources/device/DeviceView.cpp =================================================================== diff -u -r01f614b7ab188f9e0b56f10bb9d3632ad9d0aa99 -ra2a273600d25e863214833ead3324a63fb4759f1 --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 01f614b7ab188f9e0b56f10bb9d3632ad9d0aa99) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision a2a273600d25e863214833ead3324a63fb4759f1) @@ -365,7 +365,6 @@ QStringList fields = lines[row].split(','); // qDebug() << fields.join("-"); -// LOG_DEBUG(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 @@ -433,7 +432,6 @@ data.mWifiSignalLevel = ssid.mSIGNAL_Max; data.mWifiSupported = ssid.mSupported; data.mWifiConnected = ssid.mInUse ; - dataAppend( data, ssid.mInUse, ssid.mSupported); } } @@ -480,6 +478,36 @@ return QString("Wifi %1").arg(vIndex.row()); } +bool View::VDevice::setData(const QModelIndex &vIndex, const QVariant& vValue, int vRole) { + if (! vIndex.isValid() || vIndex.row() >= _dataList.count()) { + return false; + } + + DataModel &dataItem = _dataList[vIndex.row()]; + + switch (vRole) { + case eRole_WifiConnected: { + if (dataItem.mWifiConnected != vValue.toBool()) { + dataItem.mWifiConnected = vValue.toBool(); + } + break; + } + default: + return false; + } + + // explicitly emit a dataChanged signal to notify anybody bound to this property (vRole) +// emit dataChanged(vIndex, vIndex, {vRole}); + emit dataChanged(vIndex, vIndex, QVector(1, vRole)); + return true; +} + +QModelIndex View::VDevice::index(int vRow, int vColumn, const QModelIndex &vParent) const { + return hasIndex(vRow, vColumn, vParent) + ? createIndex(vRow, vColumn) + : QModelIndex(); +} + // ================================================= WifiInfo void VDevice::doInitWifiInfo() { wifiInfoRequest({}); @@ -527,60 +555,61 @@ QString mResult = vResult; QStringList fields = mResult.split(','); - ssid(fields[eSSID].trimmed()); - ipAddress(fields[eIPADDRESS].trimmed()); - subnetMask(fields[eSUBNETMASK].trimmed()); - gateway(fields[eGATEWAY].trimmed()); - QString dnsString = fields[eDNS]; - // Iterate from index 5 to the end to get any extra DNS - for (int i = 5; i < fields.size(); ++i) { - dnsString.append(QStringLiteral(",\n%1").arg(fields.at(i))); + if (! fields[eSSID].trimmed().isEmpty()) { + ssid(fields[eSSID].trimmed()); + ipAddress(fields[eIPADDRESS].trimmed()); + subnetMask(fields[eSUBNETMASK].trimmed()); + gateway(fields[eGATEWAY].trimmed()); + QStringList dnsList = fields.mid(eDNS); + dns(dnsList.join('\n').trimmed()); } - dns(dnsString.trimmed()); + else { + ssid(""); + ipAddress(""); + gateway(""); + subnetMask(""); + dns(""); + } + + updateWifiList(); } -// ================================================= ConnectWifi -void VDevice::doInitConnectWifi() { +void VDevice::updateWifiList() { + for (int row = 0; row < rowCount(); row++) { + setData(index(row,0), _dataList[row].mWifiSSID == ssid(), eRole_WifiConnected); + } +} + +// ================================================= WifiConnect +void VDevice::doInitWifiConnect() { // Nothing for now. } -void VDevice::connectWifiRequest(const bool &) { +void VDevice::wifiConnectRequest(const bool &) { // Nothing for now. } /*! - * \brief Network::doConnectWifi + * \brief Network::doWifiConnect * \details Method to connect/disconnect to desired Wi-Fi with SSID and password * \param vConnect - (bool) determine if user wants to connect or disconnect Wi-Fi * \param vSsid - (QString) SSID to connect or disconnect * \param vPassword - (QString) SSID password */ -void VDevice::doConnectWifi(const bool &vConnect, const QString &vSsid, const QString &vPassword) { - DeviceConnectWifiRequestData data; +void VDevice::doWifiConnect(bool vConnect, const QString &vSsid, const QString &vPassword) { + DeviceWifiConnectRequestData data; data.mConnect = vConnect; data.mSsid = vSsid; data.mPassword = vPassword; - connectWifi(false); emit didAttributeRequest(data); } -void VDevice::onAttributeResponse(const DeviceConnectWifiResponseData &vData) { +void VDevice::onAttributeResponse(const DeviceWifiConnectResponseData &vData) { if ( vData.mCompleted ) { if ( vData.mAccepted ) { - // rescan once connect/disconnect has completed - doInitWifiList(); - connectWifi(true); - status(vData.mConnect ? "WiFi Connected" : "WiFi Disconnected"); - - if ( !vData.mConnect ) { - ssid(""); - ipAddress(""); - gateway(""); - subnetMask(""); - dns(""); - } + wifiInfoRequest({}); } } @@ -591,3 +620,4 @@ // has to be the last one response(true); } +