Index: sources/view/VNetworkModel.cpp =================================================================== diff -u -re5a802bc26647388cfea4f1d46ae22570ec2dba3 -rea52cee2614f319804690a9b1d5091bed9676753 --- sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision e5a802bc26647388cfea4f1d46ae22570ec2dba3) +++ sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision ea52cee2614f319804690a9b1d5091bed9676753) @@ -4,6 +4,7 @@ // Project #include "VNetworkModel.h" #include "WifiInterface.h" +#include "Logger.h" using namespace View; @@ -13,19 +14,26 @@ */ void VNetworkModel::initConnections() { - connect(this, SIGNAL(didScan()), + connect(this, SIGNAL(didScan()), &_WifiInterface, SLOT(doScan())); + + connect(&_WifiInterface, SIGNAL(didAddNetwork(const Network)), + this, SLOT(doAddNetwork(const Network))); + + connect(&_WifiInterface, SIGNAL(didScanStatusChanged(const bool)), + this, SLOT(onScanStatusChanged(const bool))); } /*! * \brief VNetworkModel::addNetwork * Adds a network to the network model * \param network (Network) - the network to add to the model */ -void VNetworkModel::addNetwork(const Network &network) +void VNetworkModel::addNetwork(const Network &vNetwork) { + LOG_DEBUG(QString("Adding network with SSID: %1").arg(vNetwork.ssid())); beginInsertRows(QModelIndex(), rowCount(), rowCount()); - _networks << network; + _networks << vNetwork; endInsertRows(); } @@ -71,7 +79,7 @@ QHash VNetworkModel::roleNames() const { QHash roles; roles[SSIDRole] = "ssid"; - roles[SecurityLevelRole] = "security_level"; + roles[SecurityLevelRole] = "securityLevel"; roles[StatusRole] = "status"; return roles; } @@ -83,3 +91,32 @@ void VNetworkModel::doScan() { emit didScan(); } + +/*! + * \brief VNetworkModel::onAddNetwork + * Slot that receives a request to add a new network + * \param vNetwork - (Network) the new network to add + */ +void VNetworkModel::doAddNetwork(const Network &vNetwork) +{ + if (!_networks.contains(vNetwork)) + { + qDebug() << QString("Adding network with SSID: %1.").arg(vNetwork.ssid()); + LOG_DEBUG(QString("Adding network with SSID: %1.").arg(vNetwork.ssid())); + addNetwork(vNetwork); + } + else + { + LOG_DEBUG(QString("Skipping adding network with SSID: %1. It already exists").arg(vNetwork.ssid())); + } +} + +/*! + * \brief VNetworkModel::onScanStatusChanged + * Called when the scan status changes. Updates QML with the current state + * \param vScanning - (bool) true if scanning, false otherwise + */ +void VNetworkModel::onScanStatusChanged(const bool &vScanning) +{ + scanInProgress(vScanning); +}