Index: denali.pro.user =================================================================== diff -u -r3403122944ec8f31dfd33b387e21204783579f60 -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- denali.pro.user (.../denali.pro.user) (revision 3403122944ec8f31dfd33b387e21204783579f60) +++ denali.pro.user (.../denali.pro.user) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -1,6 +1,6 @@ - + EnvironmentId @@ -1490,7 +1490,7 @@ false true - + /home/denali/Projects/tmp/build/denali-Desktop_Qt_5_12_5_GCC_64bit-Release 1 Index: sources/gui/qml/pages/SettingsHome.qml =================================================================== diff -u -rf35b360054e1e2fa81bf107427fe2d50d78e9e8a -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- sources/gui/qml/pages/SettingsHome.qml (.../SettingsHome.qml) (revision f35b360054e1e2fa81bf107427fe2d50d78e9e8a) +++ sources/gui/qml/pages/SettingsHome.qml (.../SettingsHome.qml) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -126,7 +126,6 @@ push(_wifi); vNetworkModel.doScan() } - } } } Index: sources/view/VNetworkModel.cpp =================================================================== diff -u -r3403122944ec8f31dfd33b387e21204783579f60 -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision 3403122944ec8f31dfd33b387e21204783579f60) +++ sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -135,6 +135,7 @@ */ void VNetworkModel::doAddNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("VNetworkModel::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); if (!_networks.contains(vNetwork)) { LOG_DEBUG(QString("Adding network with SSID: %1.").arg(vNetwork.ssid())); @@ -153,6 +154,7 @@ */ void VNetworkModel::onScanStatusChanged(const bool &vScanning) { + LOG_DEBUG(QString("VNetworkModel::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); if (!vScanning) status(tr("Scan Finished")); @@ -218,6 +220,7 @@ */ void VNetworkModel::onConnectedToNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("VNetworkModel::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); LOG_DEBUG(QString("Connected to %1.").arg(vNetwork.ssid())); ipAddress(vNetwork.mIPSettings.mIPAddress); gateway(vNetwork.mIPSettings.mGateway); @@ -233,6 +236,7 @@ */ void VNetworkModel::onDisconnectedNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("VNetworkModel::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); LOG_DEBUG(QString("Disconnected from %1.").arg(vNetwork.ssid())); status(tr("Disconnected from %1.").arg(vNetwork.ssid())); } @@ -253,5 +257,6 @@ */ void VNetworkModel::onError(const QString &vMessage) { + LOG_DEBUG(QString("VNetworkModel::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); status(vMessage); } Index: sources/wifi/WifiInterface.cpp =================================================================== diff -u -r3403122944ec8f31dfd33b387e21204783579f60 -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 3403122944ec8f31dfd33b387e21204783579f60) +++ sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -23,7 +23,7 @@ _processRequestAutoAssignedIP.setParent(this); } -void WifiInterface::onInitConnections() +void WifiInterface::initConnections() { connect(this, SIGNAL(didError(const QString)), this, SLOT(onLogFailure(const QString))); @@ -124,7 +124,7 @@ if (_init) return false; _init = true; - onInitConnections(); + initConnections(); LOG_EVENT("UI," + tr("%1 Initialized").arg(metaObject()->className())); return true; } @@ -136,24 +136,10 @@ */ void WifiInterface::onQuit() { - onQuitThread(); // verified + quitThread(); // verified } - /*! - * \brief WifiInterface::quitThread - * \details Moves this object to main thread to be handled by QApplicaiton - * It will also be destroyed there. - */ -void WifiInterface::onQuitThread() -{ - if (!_thread) - return; - - moveToThread(qApp->thread()); -} - -/*! * \brief WifiInterface::timerEvent * Built in QObject timer * \param event (QTimerEvent*) - the event timer @@ -169,17 +155,26 @@ */ void WifiInterface::doScan() { - qDebug() << __FUNCTION__ << QThread::currentThread()->objectName(); + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); + if (_scanRunning) { LOG_DEBUG("Wifi network scan is already running."); return; } LOG_DEBUG("Scanning for Wifi Access Points..."); + if (_processScan.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processScan.objectName())); + return; + } _processScan.setWorkingDirectory(Wifi_Scripts_Dir); _scanRunning = true; emit didScanStatusChanged(_scanRunning); _processScan.start(Wifi_Scan_For_Networks); + LOG_DEBUG(QString("WifiInterface::%1 Finished").arg(__FUNCTION__)); } /*! @@ -190,6 +185,7 @@ */ void WifiInterface::onProcessFinishedScan(int vExitCode, QProcess::ExitStatus vExitStatus) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); Q_UNUSED(vExitCode) Q_UNUSED(vExitStatus) QString out = _processScan.readAllStandardOutput(); @@ -198,17 +194,41 @@ LOG_DEBUG(QString("stderr: %1").arg(err)); _scanRunning = false; emit didScanStatusChanged(_scanRunning); - onParseWifiScan(out); + parseWifiScan(out); + LOG_DEBUG(QString("WifiInterface: %1 Finished").arg(__FUNCTION__)); } /*! - * \brief Network::onParseWifiScan + * \brief getTextBetweenDelimiters + * Gets the text between two delimiters + * \param vText - (QString) the text to search + * \param vLeftDelim - (QString) the left delimiter + * \param vRightDelim - (QString) the right delimiter + * \return (QString) the text between the delimiters if found, "" otherwise + */ +QString getTextBetweenDelimiters(const QString &vText, const QString &vLeftDelim, const QString &vRightDelim) +{ + QString result = ""; + QString rightHalf = ""; + QStringList tokenList = vText.split(vLeftDelim); + if (tokenList.length() > 1) + rightHalf = tokenList[1]; + + tokenList = rightHalf.split(vRightDelim); + if (tokenList.length() > 1) + result = tokenList[0]; + return result; +} + +/*! + * \brief Network::parseWifiScan * Extract desired information from the wifi scan output. Sorts by signal stength * * \param vOutput - (QString) output collected from QProcess execution */ -void WifiInterface::onParseWifiScan(const QString &vOutput) +void WifiInterface::parseWifiScan(const QString &vOutput) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); QList networks; QStringList temp = vOutput.split("Cell"); const QString signalLevelSearchTerm = "Signal level="; @@ -221,15 +241,13 @@ { if (line.contains(ssidSearchTerm) && line.contains(macAddressSearchTerm) && line.contains(signalLevelSearchTerm)) { - QString ssid = line.split(ssidSearchTerm)[1].split("\n")[0].replace("\"", "").trimmed(); - if (ssid == "") - continue; - QString macAddress = line.split(macAddressSearchTerm)[1].split("\n")[0].trimmed(); - int signalLevel = line.split(signalLevelSearchTerm)[1].split("dBm")[0].trimmed().toInt(); + QString ssid = getTextBetweenDelimiters(line, ssidSearchTerm, "\n").replace("\"", "").trimmed(); + QString macAddress = getTextBetweenDelimiters(line, macAddressSearchTerm, "\n").trimmed(); + int signalLevel = getTextBetweenDelimiters(line, signalLevelSearchTerm, "dBm").trimmed().toInt(); - bool isCCMP = line.split(groupCipherSearchTerm)[1].split("\n")[0].contains("CCMP"); - bool isEnterprise = line.split(authSuitesSearchTerm)[1].split("\n")[0].contains("802.1x"); - bool isPersonal = line.split(authSuitesSearchTerm)[1].split("\n")[0].contains("PSK"); + bool isCCMP = getTextBetweenDelimiters(line, groupCipherSearchTerm, "\n").contains("CCMP"); + bool isEnterprise = getTextBetweenDelimiters(line, authSuitesSearchTerm, "\n").contains("802.1x"); + bool isPersonal = getTextBetweenDelimiters(line, authSuitesSearchTerm, "\n").contains("PSK"); Network::SECURITY_LEVEL securityLevel = Network::SECURITY_LEVEL::UNSUPPORTED; @@ -243,14 +261,15 @@ emit didAddNetwork(network); } } + LOG_DEBUG(QString("WifiInterface::%1 Finished").arg(__FUNCTION__)); } /*! * \brief WifiInterface::onLogFailure * Ensures any failures reported are logged * \param vMessage (QString) the message detail of the failure */ -void WifiInterface::onLogFailure(const QString &vMessage) +void WifiInterface::onError(const QString &vMessage) { LOG_DEBUG(vMessage); } @@ -263,8 +282,16 @@ */ void WifiInterface::doJoinNetwork(const Network &vNetwork, const QString &vPassword) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); _network = vNetwork; LOG_DEBUG(QString("Joining Network %1").arg(vNetwork.ssid())); + if (_processGenerateWPASupplicant.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processGenerateWPASupplicant.objectName())); + return; + } _processGenerateWPASupplicant.start(Wifi_Generate_WPA_Supplicant, QStringList() << vNetwork.ssid() << vPassword @@ -286,6 +313,13 @@ return; } + if (_processStartWPASupplicant.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processStartWPASupplicant.objectName())); + return; + } _processStartWPASupplicant.start(Wifi_Start_WPA_Supplicant, QStringList() << _iface << _wpaSupplicantConfPath); @@ -305,6 +339,13 @@ emit didError("Could not configure network."); return; } + if (_processRequestAutoAssignedIP.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processRequestAutoAssignedIP.objectName())); + return; + } _processRequestAutoAssignedIP.start(Wifi_Get_Auto_Assigned_IP, QStringList() << _iface); } @@ -332,7 +373,15 @@ */ void WifiInterface::doRequestIPSettings() { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); QString result = ""; + if (_processReadIPSettings.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadIPSettings.objectName())); + return; + } _processReadIPSettings.start(Wifi_Read_IP_Settings, QStringList() << _iface); } @@ -351,6 +400,13 @@ _network.mIPSettings.mIPAddress = parseIP(output); _network.mIPSettings.mBroadcast = parseBroadcast(output); _network.mIPSettings.mSubnetMask = parseSubnetMask(output); + if (_processReadGateway.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadGateway.objectName())); + return; + } _processReadGateway.start(Wifi_Read_Gateway); } @@ -366,6 +422,13 @@ Q_UNUSED(vExitCode); Q_UNUSED(vExitStatus); _network.mIPSettings.mGateway = parseGateway(_processReadGateway.readAllStandardOutput()); + if (_processReadDNS.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processReadDNS.objectName())); + return; + } _processReadDNS.start(Wifi_Read_DNS); } @@ -391,6 +454,7 @@ */ void WifiInterface::doDisconnectNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); LOG_DEBUG(QString("Disconnecting from Network %1").arg(vNetwork.ssid())); QProcess process; process.start(Wifi_Disconnect_Network, Index: sources/wifi/WifiInterface.h =================================================================== diff -u -r3403122944ec8f31dfd33b387e21204783579f60 -r60db0ce19666f04ea58992a7670497d83f9bf7c4 --- sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 3403122944ec8f31dfd33b387e21204783579f60) +++ sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 60db0ce19666f04ea58992a7670497d83f9bf7c4) @@ -51,13 +51,13 @@ bool generateWPASupplicant(const Network &vNetwork, const QString &vPassword); bool startWPASupplicant(); bool requestAutoAssignedIP(int vTries = 4); + void parseWifiScan(const QString &vOutput); QString parseIP(const QString &vOutput); QString parseBroadcast(const QString &vOutput); QString parseSubnetMask(const QString &vOutput); QString parseGateway(const QString &vOutput); QString parseDNS(const QString &vOutput); - void onInitConnections(); - void onQuitThread(); + void initConnections(); void timerEvent(QTimerEvent* event); void initThread(QThread &vThread); void quitThread(); @@ -70,24 +70,21 @@ void doDisconnectNetwork(const Network &vNetwork); void doRequestIPSettings(); -private slots: - void quit(); - signals: void didAddNetwork(const Network); void didDisconnectNetwork(const Network); - void didGetIPSettings(const Network::IPSettings); - void didRequestScan(); + void didRejectRequest(const QString &vFunction, const QString &vReason); + void didBusyChanged(const bool &vBusy); // emitted from separate threads void didScanStatusChanged(const bool); void didConnectToNetwork(const Network); void didError(const QString); private slots: + void quit(); void onQuit(); - void onParseWifiScan(const QString &vOutput); - void onLogFailure(const QString &vMessage); + void onError(const QString &vMessage); void onProcessFinishedScan(int vExitCode, QProcess::ExitStatus vExitStatus); void onProcessFinishedReadIP(int vExitCode, QProcess::ExitStatus vExitStatus); void onProcessFinishedReadGateway(int vExitCode, QProcess::ExitStatus vExitStatus);