diff --git a/sources/gui/src/errorwindow.cpp b/sources/gui/src/errorwindow.cpp index 24fc0ea..b73709a 100644 --- a/sources/gui/src/errorwindow.cpp +++ b/sources/gui/src/errorwindow.cpp @@ -18,12 +18,15 @@ #include "errorwindow.h" #include "ui_errorwindow.h" +#include + ErrorWindow::ErrorWindow(QWidget *parent, const int messageNumber) : QMainWindow(parent), ui(new Ui::ErrorWindow) { ui->setupUi(this); + qDebug() << "[ErrorWindow]" << "[ErrorWindow]" << ":" << "Initializate with error code" << messageNumber; setMessage(messageNumber); } diff --git a/sources/gui/src/generalwidget.cpp b/sources/gui/src/generalwidget.cpp index 566a681..9ebd788 100644 --- a/sources/gui/src/generalwidget.cpp +++ b/sources/gui/src/generalwidget.cpp @@ -95,7 +95,7 @@ void GeneralWidget::addBindTo() } -void GeneralWidget::keyPressEvent(const QKeyEvent *pressedKey) +void GeneralWidget::keyPressEvent(QKeyEvent *pressedKey) { if (pressedKey->key() == Qt::Key_Delete) { if (ui->listWidget_bindto->hasFocus() && diff --git a/sources/gui/src/generalwidget.h b/sources/gui/src/generalwidget.h index 800801d..9c6231c 100644 --- a/sources/gui/src/generalwidget.h +++ b/sources/gui/src/generalwidget.h @@ -55,7 +55,7 @@ private: QDir *profileDirectory; Ui::GeneralWidget *ui; void createActions(); - void keyPressEvent(const QKeyEvent *pressedKey); + void keyPressEvent(QKeyEvent *pressedKey); }; diff --git a/sources/gui/src/ipwidget.cpp b/sources/gui/src/ipwidget.cpp index 6f13211..43190fe 100644 --- a/sources/gui/src/ipwidget.cpp +++ b/sources/gui/src/ipwidget.cpp @@ -140,7 +140,7 @@ void IpWidget::createFilter() } -void IpWidget::keyPressEvent(const QKeyEvent *pressedKey) +void IpWidget::keyPressEvent(QKeyEvent *pressedKey) { if (pressedKey->key() == Qt::Key_Delete) { if (ui->listWidget_ipAddress->hasFocus() && diff --git a/sources/gui/src/ipwidget.h b/sources/gui/src/ipwidget.h index 7d7f00a..ca97e76 100644 --- a/sources/gui/src/ipwidget.h +++ b/sources/gui/src/ipwidget.h @@ -63,7 +63,7 @@ private: Ui::IpWidget *ui; void createActions(); void createFilter(); - void keyPressEvent(const QKeyEvent *pressedKey); + void keyPressEvent(QKeyEvent *pressedKey); QString getIp(const QString rawIp); QString getPrefix(const QString rawPrefix); QString getIp6(const QString rawIp); diff --git a/sources/gui/src/main.cpp b/sources/gui/src/main.cpp index 3c480e9..adb1f0b 100644 --- a/sources/gui/src/main.cpp +++ b/sources/gui/src/main.cpp @@ -43,14 +43,14 @@ int main(int argc, char *argv[]) if (configFile.open(QIODevice::ReadOnly)) while (true) { fileStr = QString(configFile.readLine()); - if (configFile.atEnd()) - break; - else if (fileStr[0] != '#') { + if (fileStr[0] != '#') { if (fileStr.contains(QString("LANGUAGE="))) language = fileStr.split(QString("="))[1] .remove(QString(" ")) .trimmed(); } + if (configFile.atEnd()) + break; } configFile.close(); QTranslator translator; @@ -81,9 +81,9 @@ int main(int argc, char *argv[]) return 0; } // default settings - else if ((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 'd') && (argv[i][2] == 'd') && - (argv[i][3] == 'e') && (argv[i][4] == 'f') && (argv[i][5] == 'a') && (argv[i][6] == 'u') && - (argv[i][7] == '8') && (argv[i][2] == 't') && (argv[i][9] == '\0')) { + else if ((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 'd') && (argv[i][3] == 'e') && + (argv[i][4] == 'f') && (argv[i][5] == 'a') && (argv[i][6] == 'u') && (argv[i][7] == 'l') && + (argv[i][8] == 't') && (argv[i][9] == '\0')) { defaultSettings = true; } // tab number diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 5eec321..ada5895 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -18,6 +18,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include #include #include #include @@ -44,6 +45,9 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const int ta : QMainWindow(parent), ui(new Ui::MainWindow) { + qDebug() << "[MainWindow]" << "[MainWindow]" << ":" << QString("defaultSettings") << defaultSettings; + qDebug() << "[MainWindow]" << "[MainWindow]" << ":" << QString("tabNum") << tabNum; + ui->setupUi(this); ui->tabWidget->setCurrentIndex(tabNum-1); @@ -123,6 +127,7 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all")) QProcess command; command.start(commandLine.join(QString(" "))); command.waitForFinished(-1); + qDebug() << "[MainWindow]" << "[checkExternalApps]" << ":" << "Cmd returns" << command.exitCode(); if (command.exitCode() != 0) return false; else @@ -190,6 +195,7 @@ void MainWindow::updateMainTab() return; } + qDebug() << "[MainWindow]" << "[updateMainTab]"; ui->tabWidget->setDisabled(true); QList profiles = netctlCommand->getProfileList();; @@ -227,9 +233,13 @@ void MainWindow::updateMainTab() void MainWindow::updateProfileTab() { + qDebug() << "[MainWindow]" << "[updateProfileTab]"; ui->tabWidget->setDisabled(true); profileTabClear(); ui->tabWidget->setEnabled(true); + ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); + + update(); } @@ -244,6 +254,7 @@ void MainWindow::updateWifiTab() QList scanResults = wpaCommand->scanWifi(); + qDebug() << "[MainWindow]" << "[updateWifiTab]"; ui->tabWidget->setDisabled(true); ui->tableWidget_wifi->setSortingEnabled(false); ui->tableWidget_wifi->selectRow(-1); @@ -291,6 +302,7 @@ void MainWindow::mainTabEnableProfile() if (ui->tableWidget_main->currentItem() == 0) return; + qDebug() << "[MainWindow]" << "[mainTabEnableProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->enableProfile(profile); @@ -320,6 +332,7 @@ void MainWindow::mainTabRestartProfile() if (ui->tableWidget_main->currentItem() == 0) return; + qDebug() << "[MainWindow]" << "[mainTabRestartProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->restartProfile(profile); @@ -341,6 +354,7 @@ void MainWindow::mainTabStartProfile() if (ui->tableWidget_main->currentItem() == 0) return; + qDebug() << "[MainWindow]" << "[mainTabStartProfile]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->startProfile(profile); @@ -375,6 +389,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt return; } + qDebug() << "[MainWindow]" << "[mainTabRefreshButtons]"; ui->pushButton_mainEnable->setEnabled(true); ui->pushButton_mainStart->setEnabled(true); @@ -397,6 +412,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt // profile tab slots void MainWindow::profileTabBrowseProfile() { + qDebug() << "[MainWindow]" << "[profileTabBrowseProfile]"; QString filename = QFileDialog::getSaveFileName( this, QApplication::translate("MainWindow", "Save profile as..."), @@ -409,6 +425,7 @@ void MainWindow::profileTabBrowseProfile() void MainWindow::profileTabChangeState(const QString current) { + qDebug() << "[MainWindow]" << "[profileTabChangeState]"; if (current == QString("ethernet")) { generalWid->setShown(true); ipWid->setShown(true); @@ -523,6 +540,7 @@ void MainWindow::profileTabChangeState(const QString current) void MainWindow::profileTabClear() { + qDebug() << "[MainWindow]" << "[profileTabClear]"; ui->lineEdit_profile->clear(); generalWid->clear(); @@ -669,6 +687,7 @@ void MainWindow::profileTabCreateProfile() } } + qDebug() << "[MainWindow]" << "[profileTabCreateProfile]"; ui->tabWidget->setDisabled(true); // read settings QString profile = ui->lineEdit_profile->text(); @@ -755,6 +774,7 @@ void MainWindow::profileTabCreateProfile() void MainWindow::profileTabLoadProfile() { + qDebug() << "[MainWindow]" << "[profileTabLoadProfile]"; QString profile = ui->lineEdit_profile->text(); QMap settings = netctlProfile->getSettingsFromProfile(profile); @@ -819,6 +839,7 @@ void MainWindow::connectToUnknownEssid(const QString passwd) if (!passwd.isEmpty()) delete passwdWid; + qDebug() << "[MainWindow]" << "[connectToUnknownEssid]"; QMap settings; settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); settings[QString("Interface")] = wpaCommand->getInterfaceList()[0]; @@ -865,6 +886,7 @@ void MainWindow::wifiTabStart() return; } + qDebug() << "[MainWindow]" << "[wifiTabStart]"; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); QString item = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); @@ -921,6 +943,7 @@ void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt return; } + qDebug() << "[MainWindow]" << "[wifiTabRefreshButtons]"; ui->pushButton_wifiStart->setEnabled(true); QString item = ui->tableWidget_wifi->item(current->row(), 1)->text(); if (checkState(QString("exists"), item)) { diff --git a/sources/gui/src/netctlinteract.cpp b/sources/gui/src/netctlinteract.cpp index 53acedf..c47a1ca 100644 --- a/sources/gui/src/netctlinteract.cpp +++ b/sources/gui/src/netctlinteract.cpp @@ -17,6 +17,7 @@ #include "netctlinteract.h" +#include #include #include @@ -38,6 +39,43 @@ Netctl::~Netctl() } +// functions +QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, const QString profile) +{ + QProcess command; + QString commandText; + if (sudo) + commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine + + QString(" ") + profile; + else + commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile; + qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Run cmd" << commandText; + command.start(commandText); + command.waitForFinished(-1); + return command.readAllStandardOutput(); +} + + +bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QString profile) +{ + QProcess command; + QString commandText; + if (sudo) + commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine + + QString(" ") + profile; + else + commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile; + qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Run cmd" << commandText; + command.start(commandText); + command.waitForFinished(-1); + qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Cmd returns" << command.exitCode(); + if (command.exitCode() == 0) + return true; + else + return false; +} + + // general information QList Netctl::getProfileList() { @@ -62,17 +100,19 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList) QStringList descriptions; for (int i=0; iabsolutePath() + QDir::separator() + profileList[i]); + QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profileList[i]; + qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Check" << profileUrl; + QFile profile(profileUrl); QString fileStr; if (profile.open(QIODevice::ReadOnly)) while (true) { fileStr = QString(profile.readLine()); - if (profile.atEnd()) - break; - else if (fileStr[0] != '#') + if (fileStr[0] != '#') if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("Description")) descriptions.append(fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed()); + if (profile.atEnd()) + break; } else descriptions.append(QString("")); @@ -111,20 +151,22 @@ QStringList Netctl::getProfileStatuses(const QStringList profileList) QString Netctl::getSsidFromProfile(const QString profile) { QString ssidName = QString(""); - QFile profileFile(profileDirectory->absolutePath() + QDir::separator() + profile); + QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile; + qDebug() << "[Netctl]" << "[getSsidFromProfile]" << ":" << "Check" << profileUrl; + QFile profileFile(profileUrl); QString fileStr; if (!profileFile.open(QIODevice::ReadOnly)) return ssidName; while (true) { fileStr = QString(profileFile.readLine()); - if (profileFile.atEnd()) - break; - else if (fileStr[0] != '#') { + if (fileStr[0] != '#') { if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID")) ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed(); } + if (profileFile.atEnd()) + break; } profileFile.close(); @@ -138,16 +180,10 @@ QString Netctl::getSsidFromProfile(const QString profile) bool Netctl::isProfileActive(const QString profile) { bool status = false; - QProcess command; - QString cmdOutput = QString(""); - - command.start(netctlCommand + QString(" status ") + profile); - command.waitForFinished(-1); - cmdOutput = command.readAllStandardOutput(); + QString cmdOutput = getNetctlOutput(false, QString("status"), profile); if (!cmdOutput.isEmpty()) if (cmdOutput.indexOf(QString("Active: active")) > -1) status = true; - return status; } @@ -155,12 +191,7 @@ bool Netctl::isProfileActive(const QString profile) bool Netctl::isProfileEnabled(const QString profile) { bool status = false; - QProcess command; - QString cmdOutput = QString(""); - - command.start(netctlCommand + QString(" status ") + profile); - command.waitForFinished(-1); - cmdOutput = command.readAllStandardOutput(); + QString cmdOutput = getNetctlOutput(false, QString("status"), profile); if (!cmdOutput.isEmpty()) { QStringList profileStatus = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); for (int i=0; i -1) status = true; } - return status; } @@ -176,42 +206,23 @@ bool Netctl::isProfileEnabled(const QString profile) // functions bool Netctl::enableProfile(const QString profile) { - QProcess command; if (isProfileEnabled(profile)) - command.start(sudoCommand + QString(" ") + netctlCommand + QString(" disable ") + profile); + return netctlCall(true, QString("disable"), profile); else - command.start(sudoCommand + QString(" ") + netctlCommand + QString(" enable ") + profile); - command.waitForFinished(-1); - if (command.exitCode() == 0) - return true; - else - return false; + return netctlCall(true, QString("enable"), profile); } bool Netctl::restartProfile(const QString profile) { - QProcess command; - if (isProfileActive(profile)) - command.start(sudoCommand + QString(" ") + netctlCommand + QString(" restart ") + profile); - command.waitForFinished(-1); - if (command.exitCode() == 0) - return true; - else - return false; + return netctlCall(true, QString("restart"), profile); } bool Netctl::startProfile(const QString profile) { - QProcess command; if (isProfileActive(profile)) - command.start(sudoCommand + QString(" ") + netctlCommand + QString(" stop ") + profile); + return netctlCall(true, QString("stop"), profile); else - command.start(sudoCommand + QString(" ") + netctlCommand + QString(" start ") + profile); - command.waitForFinished(-1); - if (command.exitCode() == 0) - return true; - else - return false; + return netctlCall(true, QString("start"), profile); } diff --git a/sources/gui/src/netctlinteract.h b/sources/gui/src/netctlinteract.h index 1499775..76879b0 100644 --- a/sources/gui/src/netctlinteract.h +++ b/sources/gui/src/netctlinteract.h @@ -52,6 +52,9 @@ private: QString netctlCommand; QDir *profileDirectory; QString sudoCommand; + // functions + QString getNetctlOutput(const bool sudo, const QString commandLine, const QString profile); + bool netctlCall(const bool sudo, const QString commandLine, const QString profile); }; diff --git a/sources/gui/src/netctlprofile.cpp b/sources/gui/src/netctlprofile.cpp index 5bc0e6a..bc3ada6 100644 --- a/sources/gui/src/netctlprofile.cpp +++ b/sources/gui/src/netctlprofile.cpp @@ -17,6 +17,7 @@ #include "netctlprofile.h" +#include #include #include #include @@ -43,7 +44,9 @@ bool NetctlProfile::copyProfile(const QString oldPath) { QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName(); QProcess command; - command.start(sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath); + QString commandText = sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath; + qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << commandText; + command.start(commandText); command.waitForFinished(-1); if (command.exitCode() == 0) return true; @@ -58,6 +61,7 @@ QString NetctlProfile::createProfile(const QString profile, const QMap NetctlProfile::getSettingsFromProfile(const QString profile) { QMap settings; - QFile profileFile; - QString fileStr; - + QString fileStr, profileUrl; if (profile[0] == QDir::separator()) - profileFile.setFileName(profile); + profileUrl = profile; else - profileFile.setFileName(profileDirectory->absolutePath() + QDir::separator() + profile); + profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile; + QFile profileFile(profileUrl); + qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Read from" << profileUrl; + if (!profileFile.open(QIODevice::ReadOnly)) return settings; while (true) { fileStr = QString(profileFile.readLine()); - if (profileFile.atEnd()) - break; - else if (fileStr[0] != '#') { + if (fileStr[0] != '#') { if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) { if ((fileStr.split(QString("="))[1][0] == QChar('(')) && (fileStr.split(QString("="))[1][fileStr.split(QString("="))[1].size()-2] == QChar(')'))) @@ -124,8 +127,7 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi .trimmed()); while(true) { fileStr = QString(profileFile.readLine()); - if ((profileFile.atEnd()) || - (fileStr[fileStr.size()-2] == QChar(')'))) + if (fileStr[fileStr.size()-2] == QChar(')')) break; if (!fileStr.remove(QString("(")) .remove(QString(")")) @@ -134,6 +136,8 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi parameter.append(fileStr.remove(QString("(")) .remove(QString(")")) .trimmed()); + if (profileFile.atEnd()) + break; } settings[parameterName] = parameter.join(QString("\n")); } @@ -143,6 +147,8 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi } } + if (profileFile.atEnd()) + break; } profileFile.close(); diff --git a/sources/gui/src/passwdwidget.cpp b/sources/gui/src/passwdwidget.cpp index 4d12f4f..43f431d 100644 --- a/sources/gui/src/passwdwidget.cpp +++ b/sources/gui/src/passwdwidget.cpp @@ -42,7 +42,7 @@ PasswdWidget::~PasswdWidget() // ESC press event -void PasswdWidget::keyPressEvent(const QKeyEvent *pressedKey) +void PasswdWidget::keyPressEvent(QKeyEvent *pressedKey) { if (pressedKey->key() == Qt::Key_Escape) cancel(); diff --git a/sources/gui/src/passwdwidget.h b/sources/gui/src/passwdwidget.h index ab71141..fa9ef44 100644 --- a/sources/gui/src/passwdwidget.h +++ b/sources/gui/src/passwdwidget.h @@ -50,7 +50,7 @@ private: QPushButton *cancelButton; QPushButton *okButton; // ESC pressed event - void keyPressEvent(const QKeyEvent *pressedKey); + void keyPressEvent(QKeyEvent *pressedKey); void createActions(); }; diff --git a/sources/gui/src/settingswindow.cpp b/sources/gui/src/settingswindow.cpp index 3166708..d1dbb87 100644 --- a/sources/gui/src/settingswindow.cpp +++ b/sources/gui/src/settingswindow.cpp @@ -18,6 +18,7 @@ #include "settingswindow.h" #include "ui_settingswindow.h" +#include #include #include #include @@ -62,7 +63,7 @@ void SettingsWindow::createActions() // ESC press event -void SettingsWindow::keyPressEvent(const QKeyEvent *pressedKey) +void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) { if (pressedKey->key() == Qt::Key_Escape) close(); @@ -200,9 +201,13 @@ QMap SettingsWindow::readSettings() settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text(); settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text(); settings[QString("SUDO_PATH")] = ui->lineEdit_sudo->text(); - settings[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text(); settings[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text(); settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text(); + settings[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text(); + + for (int i=0; ilineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]); ui->lineEdit_sudo->setText(settings[QString("SUDO_PATH")]); - ui->lineEdit_wpaSupDrivers->setText(settings[QString("WPA_DRIVERS")]); ui->lineEdit_wpaCliPath->setText(settings[QString("WPACLI_PATH")]); ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]); + ui->lineEdit_wpaSupDrivers->setText(settings[QString("WPA_DRIVERS")]); + + for (int i=0; i -1) settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1] .remove(QString(" ")) .trimmed(); } + if (configFile.atEnd()) + break; } configFile.close(); + for (int i=0; i #include #include "mainwindow.h" @@ -50,6 +51,17 @@ WpaSup::~WpaSup() // general information +QString WpaSup::existentProfile(const QString profile) +{ + QString profileFile = QString(""); + QList profileList = parent->netctlCommand->getProfileList(); + for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) + profileFile = profileList[i][0]; + return profileFile; +} + + QStringList WpaSup::getInterfaceList() { QStringList interfaces; @@ -57,43 +69,18 @@ QStringList WpaSup::getInterfaceList() if (!mainInterface.isEmpty()) interfaces.append(mainInterface); QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); - for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless"); if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless")).exists()) interfaces.append(allInterfaces[i]); - + } return interfaces; } -// functions -bool WpaSup::wpaCliCall(const QString commandLine) -{ - QString interface = getInterfaceList()[0]; - QProcess command; - command.start(wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + - QString(" -P ") + pidFile + QString(" ") + commandLine); - command.waitForFinished(-1); - SleepThread::sleep(1); - if (command.exitCode() == 0) - return true; - else - return false; -} - - -QString WpaSup::getWpaCliOutput(const QString commandLine) -{ - QString interface = getInterfaceList()[0]; - QProcess command; - command.start(wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + - QString(" -P ") + pidFile + QString(" ") + commandLine); - command.waitForFinished(-1); - return command.readAllStandardOutput(); -} - - bool WpaSup::isProfileActive(const QString profile) { QString profileFile; @@ -116,44 +103,45 @@ bool WpaSup::isProfileExists(const QString profile) } -QString WpaSup::existentProfile(const QString profile) +// functions +bool WpaSup::wpaCliCall(const QString commandLine) { - QString profileFile = QString(""); - QList profileList = parent->netctlCommand->getProfileList(); - for (int i=0; inetctlCommand->getSsidFromProfile(profileList[i][0])) - profileFile = profileList[i][0]; - return profileFile; + QString interface = getInterfaceList()[0]; + QProcess command; + QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + + QString(" -P ") + pidFile + QString(" ") + commandLine; + qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Run cmd" << commandText; + command.start(commandText); + command.waitForFinished(-1); + SleepThread::sleep(1); + qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Cmd returns" << command.exitCode(); + if (command.exitCode() == 0) + return true; + else + return false; } -bool WpaSup::startWpaSupplicant() +QString WpaSup::getWpaCliOutput(const QString commandLine) { - if (!QFile(pidFile).exists()) { - QString interface = getInterfaceList()[0]; - QProcess command; - command.start(sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile + - QString(" -i ") + interface + QString(" -D ") + wpaDrivers + - QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup); - command.waitForFinished(-1); - SleepThread::sleep(1); - if (command.exitCode() != 0) - return false; - } - return true; -} - - -bool WpaSup::stopWpaSupplicant() -{ - return wpaCliCall(QString("terminate")); + QString interface = getInterfaceList()[0]; + QProcess command; + QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + + QString(" -P ") + pidFile + QString(" ") + commandLine; + qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << commandText; + command.start(commandText); + command.waitForFinished(-1); + return command.readAllStandardOutput(); } QList WpaSup::scanWifi() { QList scanResults; - startWpaSupplicant(); + if (!startWpaSupplicant()) { + stopWpaSupplicant(); + return scanResults; + } if (!wpaCliCall(QString("scan"))) return scanResults; SleepThread::sleep(3); @@ -215,3 +203,29 @@ QList WpaSup::scanWifi() stopWpaSupplicant(); return scanResults; } + + +bool WpaSup::startWpaSupplicant() +{ + if (!QFile(pidFile).exists()) { + QString interface = getInterfaceList()[0]; + QProcess command; + QString commandText = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile + + QString(" -i ") + interface + QString(" -D ") + wpaDrivers + + QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\""); + qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Run cmd" << commandText; + command.start(commandText); + command.waitForFinished(-1); + SleepThread::sleep(1); + qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << command.exitCode(); + if (command.exitCode() != 0) + return false; + } + return true; +} + + +bool WpaSup::stopWpaSupplicant() +{ + return wpaCliCall(QString("terminate")); +} diff --git a/sources/gui/src/wpasupinteract.h b/sources/gui/src/wpasupinteract.h index 3ba4424..6562a16 100644 --- a/sources/gui/src/wpasupinteract.h +++ b/sources/gui/src/wpasupinteract.h @@ -34,19 +34,16 @@ public: const QMap settings = QMap()); ~WpaSup(); // general information - QStringList getInterfaceList(); - // functions - bool wpaCliCall(const QString commandLine); - QString getWpaCliOutput(const QString commandLine); - bool isProfileExists(const QString profile); QString existentProfile(const QString profile); + QStringList getInterfaceList(); bool isProfileActive(const QString profile); + bool isProfileExists(const QString profile); public slots: // functions + QList scanWifi(); bool startWpaSupplicant(); bool stopWpaSupplicant(); - QList scanWifi(); private: MainWindow *parent; @@ -59,6 +56,9 @@ private: QString wpaCliPath; QString wpaDrivers; QString wpaSupPath; + // functions + bool wpaCliCall(const QString commandLine); + QString getWpaCliOutput(const QString commandLine); };