#include "WifiInterface.h" // Qt #include #include // Project #include "main.h" #include "Logger.h" #include "StorageGlobals.h" using namespace Storage; WifiInterface::WifiInterface(QObject *parent) : QObject(parent) { } void WifiInterface::onInitConnections() { connect(&_scanProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onScanFinished(int, QProcess::ExitStatus))); } /*! * \brief WifiInterface::init * \details Initializes the class by setting the connections * \return true on first initialization, false if it has already been initialized */ bool WifiInterface::doInit() { if (_init) return false; _init = true; onInitConnections(); LOG_EVENT("UI," + tr("%1 Initialized").arg(metaObject()->className())); return true; } /*! * \brief WifiInterface::quit * Called when the application is exiting. */ void WifiInterface::onQuit() { onQuitThread(); // 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 */ void WifiInterface::timerEvent(QTimerEvent *event) { Q_UNUSED(event); } /*! * \brief WifiInterface::doScan * Scans for Wifi Access Points */ void WifiInterface::doScan() { // if scan is already running, return if (_scanRunning) { LOG_DEBUG("Wifi network scan is already running."); return; } // otherwise, start the detached process LOG_DEBUG("Scanning for Wifi Access Points..."); _scanProcess.setWorkingDirectory(Wifi_Scripts_Dir); _scanRunning = true; // TODO: emit scan running to view so scan button is disabled _scanProcess.start(Wifi_Scripts_Scan_For_Networks); } /*! * \brief WifiInterface::onScanFinished * Called when finished scanning for networks (success or error) * \param vPid - pid of the scan for networks process * \param vExitStatus - the status upon exit */ void WifiInterface::onScanFinished(int vPid, QProcess::ExitStatus vExitStatus) { LOG_DEBUG(QString("%1: %2,%3").arg(__FUNCTION__).arg(vPid).arg(vExitStatus)); QString out = _scanProcess.readAllStandardOutput(); QString err = _scanProcess.readAllStandardError(); LOG_DEBUG(out); LOG_DEBUG(err); _scanRunning = false; // TODO: emit scan finished to view so scan button is re-enabled. }