mirror of
				https://github.com/arcan1s/netctl-gui.git
				synced 2025-10-30 21:23:41 +00:00 
			
		
		
		
	more refactoring
+ added debug output
This commit is contained in:
		| @ -18,12 +18,15 @@ | |||||||
| #include "errorwindow.h" | #include "errorwindow.h" | ||||||
| #include "ui_errorwindow.h" | #include "ui_errorwindow.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
|  |  | ||||||
|  |  | ||||||
| ErrorWindow::ErrorWindow(QWidget *parent, const int messageNumber) | ErrorWindow::ErrorWindow(QWidget *parent, const int messageNumber) | ||||||
|     : QMainWindow(parent), |     : QMainWindow(parent), | ||||||
|       ui(new Ui::ErrorWindow) |       ui(new Ui::ErrorWindow) | ||||||
| { | { | ||||||
|     ui->setupUi(this); |     ui->setupUi(this); | ||||||
|  |     qDebug() << "[ErrorWindow]" << "[ErrorWindow]" << ":" << "Initializate with error code" << messageNumber; | ||||||
|     setMessage(messageNumber); |     setMessage(messageNumber); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -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 (pressedKey->key() == Qt::Key_Delete) { | ||||||
|         if (ui->listWidget_bindto->hasFocus() && |         if (ui->listWidget_bindto->hasFocus() && | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ private: | |||||||
|     QDir *profileDirectory; |     QDir *profileDirectory; | ||||||
|     Ui::GeneralWidget *ui; |     Ui::GeneralWidget *ui; | ||||||
|     void createActions(); |     void createActions(); | ||||||
|     void keyPressEvent(const QKeyEvent *pressedKey); |     void keyPressEvent(QKeyEvent *pressedKey); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -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 (pressedKey->key() == Qt::Key_Delete) { | ||||||
|         if (ui->listWidget_ipAddress->hasFocus() && |         if (ui->listWidget_ipAddress->hasFocus() && | ||||||
|  | |||||||
| @ -63,7 +63,7 @@ private: | |||||||
|     Ui::IpWidget *ui; |     Ui::IpWidget *ui; | ||||||
|     void createActions(); |     void createActions(); | ||||||
|     void createFilter(); |     void createFilter(); | ||||||
|     void keyPressEvent(const QKeyEvent *pressedKey); |     void keyPressEvent(QKeyEvent *pressedKey); | ||||||
|     QString getIp(const QString rawIp); |     QString getIp(const QString rawIp); | ||||||
|     QString getPrefix(const QString rawPrefix); |     QString getPrefix(const QString rawPrefix); | ||||||
|     QString getIp6(const QString rawIp); |     QString getIp6(const QString rawIp); | ||||||
|  | |||||||
| @ -43,14 +43,14 @@ int main(int argc, char *argv[]) | |||||||
|     if (configFile.open(QIODevice::ReadOnly)) |     if (configFile.open(QIODevice::ReadOnly)) | ||||||
|         while (true) { |         while (true) { | ||||||
|             fileStr = QString(configFile.readLine()); |             fileStr = QString(configFile.readLine()); | ||||||
|             if (configFile.atEnd()) |             if (fileStr[0] != '#') { | ||||||
|                 break; |  | ||||||
|             else if (fileStr[0] != '#') { |  | ||||||
|                 if (fileStr.contains(QString("LANGUAGE="))) |                 if (fileStr.contains(QString("LANGUAGE="))) | ||||||
|                     language = fileStr.split(QString("="))[1] |                     language = fileStr.split(QString("="))[1] | ||||||
|                             .remove(QString(" ")) |                             .remove(QString(" ")) | ||||||
|                             .trimmed(); |                             .trimmed(); | ||||||
|             } |             } | ||||||
|  |             if (configFile.atEnd()) | ||||||
|  |                 break; | ||||||
|         } |         } | ||||||
|     configFile.close(); |     configFile.close(); | ||||||
|     QTranslator translator; |     QTranslator translator; | ||||||
| @ -81,9 +81,9 @@ int main(int argc, char *argv[]) | |||||||
|             return 0; |             return 0; | ||||||
|         } |         } | ||||||
|         // default settings |         // default settings | ||||||
|         else if ((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 'd') && (argv[i][2] == 'd') && |         else if ((argv[i][0] == '-') && (argv[i][1] == '-') && (argv[i][2] == 'd') && (argv[i][3] == 'e') && | ||||||
|                  (argv[i][3] == 'e') && (argv[i][4] == 'f') && (argv[i][5] == 'a') && (argv[i][6] == 'u') && |                  (argv[i][4] == 'f') && (argv[i][5] == 'a') && (argv[i][6] == 'u') && (argv[i][7] == 'l') && | ||||||
|                  (argv[i][7] == '8') && (argv[i][2] == 't') && (argv[i][9] == '\0')) { |                  (argv[i][8] == 't') && (argv[i][9] == '\0')) { | ||||||
|             defaultSettings = true; |             defaultSettings = true; | ||||||
|         } |         } | ||||||
|         // tab number |         // tab number | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ | |||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| #include "ui_mainwindow.h" | #include "ui_mainwindow.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
| #include <QFileDialog> | #include <QFileDialog> | ||||||
| #include <QFileInfo> | #include <QFileInfo> | ||||||
| #include <QProcess> | #include <QProcess> | ||||||
| @ -44,6 +45,9 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const int ta | |||||||
|     : QMainWindow(parent), |     : QMainWindow(parent), | ||||||
|       ui(new Ui::MainWindow) |       ui(new Ui::MainWindow) | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[MainWindow]" << ":" << QString("defaultSettings") << defaultSettings; | ||||||
|  |     qDebug() << "[MainWindow]" << "[MainWindow]" << ":" << QString("tabNum") << tabNum; | ||||||
|  |  | ||||||
|     ui->setupUi(this); |     ui->setupUi(this); | ||||||
|     ui->tabWidget->setCurrentIndex(tabNum-1); |     ui->tabWidget->setCurrentIndex(tabNum-1); | ||||||
|  |  | ||||||
| @ -123,6 +127,7 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all")) | |||||||
|     QProcess command; |     QProcess command; | ||||||
|     command.start(commandLine.join(QString(" "))); |     command.start(commandLine.join(QString(" "))); | ||||||
|     command.waitForFinished(-1); |     command.waitForFinished(-1); | ||||||
|  |     qDebug() << "[MainWindow]" << "[checkExternalApps]" << ":" << "Cmd returns" << command.exitCode(); | ||||||
|     if (command.exitCode() != 0) |     if (command.exitCode() != 0) | ||||||
|         return false; |         return false; | ||||||
|     else |     else | ||||||
| @ -190,6 +195,7 @@ void MainWindow::updateMainTab() | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[updateMainTab]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     QList<QStringList> profiles = netctlCommand->getProfileList();; |     QList<QStringList> profiles = netctlCommand->getProfileList();; | ||||||
|  |  | ||||||
| @ -227,9 +233,13 @@ void MainWindow::updateMainTab() | |||||||
|  |  | ||||||
| void MainWindow::updateProfileTab() | void MainWindow::updateProfileTab() | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[updateProfileTab]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     profileTabClear(); |     profileTabClear(); | ||||||
|     ui->tabWidget->setEnabled(true); |     ui->tabWidget->setEnabled(true); | ||||||
|  |     ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); | ||||||
|  |  | ||||||
|  |     update(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -244,6 +254,7 @@ void MainWindow::updateWifiTab() | |||||||
|  |  | ||||||
|     QList<QStringList> scanResults = wpaCommand->scanWifi(); |     QList<QStringList> scanResults = wpaCommand->scanWifi(); | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[updateWifiTab]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     ui->tableWidget_wifi->setSortingEnabled(false); |     ui->tableWidget_wifi->setSortingEnabled(false); | ||||||
|     ui->tableWidget_wifi->selectRow(-1); |     ui->tableWidget_wifi->selectRow(-1); | ||||||
| @ -291,6 +302,7 @@ void MainWindow::mainTabEnableProfile() | |||||||
|     if (ui->tableWidget_main->currentItem() == 0) |     if (ui->tableWidget_main->currentItem() == 0) | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[mainTabEnableProfile]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); |     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); | ||||||
|     netctlCommand->enableProfile(profile); |     netctlCommand->enableProfile(profile); | ||||||
| @ -320,6 +332,7 @@ void MainWindow::mainTabRestartProfile() | |||||||
|     if (ui->tableWidget_main->currentItem() == 0) |     if (ui->tableWidget_main->currentItem() == 0) | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[mainTabRestartProfile]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); |     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); | ||||||
|     netctlCommand->restartProfile(profile); |     netctlCommand->restartProfile(profile); | ||||||
| @ -341,6 +354,7 @@ void MainWindow::mainTabStartProfile() | |||||||
|     if (ui->tableWidget_main->currentItem() == 0) |     if (ui->tableWidget_main->currentItem() == 0) | ||||||
|         return; |         return; | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[mainTabStartProfile]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); |     QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); | ||||||
|     netctlCommand->startProfile(profile); |     netctlCommand->startProfile(profile); | ||||||
| @ -375,6 +389,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[mainTabRefreshButtons]"; | ||||||
|     ui->pushButton_mainEnable->setEnabled(true); |     ui->pushButton_mainEnable->setEnabled(true); | ||||||
|     ui->pushButton_mainStart->setEnabled(true); |     ui->pushButton_mainStart->setEnabled(true); | ||||||
|  |  | ||||||
| @ -397,6 +412,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt | |||||||
| // profile tab slots | // profile tab slots | ||||||
| void MainWindow::profileTabBrowseProfile() | void MainWindow::profileTabBrowseProfile() | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[profileTabBrowseProfile]"; | ||||||
|     QString filename = QFileDialog::getSaveFileName( |     QString filename = QFileDialog::getSaveFileName( | ||||||
|                 this, |                 this, | ||||||
|                 QApplication::translate("MainWindow", "Save profile as..."), |                 QApplication::translate("MainWindow", "Save profile as..."), | ||||||
| @ -409,6 +425,7 @@ void MainWindow::profileTabBrowseProfile() | |||||||
|  |  | ||||||
| void MainWindow::profileTabChangeState(const QString current) | void MainWindow::profileTabChangeState(const QString current) | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[profileTabChangeState]"; | ||||||
|     if (current == QString("ethernet")) { |     if (current == QString("ethernet")) { | ||||||
|         generalWid->setShown(true); |         generalWid->setShown(true); | ||||||
|         ipWid->setShown(true); |         ipWid->setShown(true); | ||||||
| @ -523,6 +540,7 @@ void MainWindow::profileTabChangeState(const QString current) | |||||||
|  |  | ||||||
| void MainWindow::profileTabClear() | void MainWindow::profileTabClear() | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[profileTabClear]"; | ||||||
|     ui->lineEdit_profile->clear(); |     ui->lineEdit_profile->clear(); | ||||||
|  |  | ||||||
|     generalWid->clear(); |     generalWid->clear(); | ||||||
| @ -669,6 +687,7 @@ void MainWindow::profileTabCreateProfile() | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[profileTabCreateProfile]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     // read settings |     // read settings | ||||||
|     QString profile = ui->lineEdit_profile->text(); |     QString profile = ui->lineEdit_profile->text(); | ||||||
| @ -755,6 +774,7 @@ void MainWindow::profileTabCreateProfile() | |||||||
|  |  | ||||||
| void MainWindow::profileTabLoadProfile() | void MainWindow::profileTabLoadProfile() | ||||||
| { | { | ||||||
|  |     qDebug() << "[MainWindow]" << "[profileTabLoadProfile]"; | ||||||
|     QString profile = ui->lineEdit_profile->text(); |     QString profile = ui->lineEdit_profile->text(); | ||||||
|     QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile); |     QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile); | ||||||
|  |  | ||||||
| @ -819,6 +839,7 @@ void MainWindow::connectToUnknownEssid(const QString passwd) | |||||||
|     if (!passwd.isEmpty()) |     if (!passwd.isEmpty()) | ||||||
|         delete passwdWid; |         delete passwdWid; | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[connectToUnknownEssid]"; | ||||||
|     QMap<QString, QString> settings; |     QMap<QString, QString> settings; | ||||||
|     settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); |     settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); | ||||||
|     settings[QString("Interface")] = wpaCommand->getInterfaceList()[0]; |     settings[QString("Interface")] = wpaCommand->getInterfaceList()[0]; | ||||||
| @ -865,6 +886,7 @@ void MainWindow::wifiTabStart() | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[wifiTabStart]"; | ||||||
|     ui->tabWidget->setDisabled(true); |     ui->tabWidget->setDisabled(true); | ||||||
|     QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); |     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(); |     QString item = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); | ||||||
| @ -921,6 +943,7 @@ void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     qDebug() << "[MainWindow]" << "[wifiTabRefreshButtons]"; | ||||||
|     ui->pushButton_wifiStart->setEnabled(true); |     ui->pushButton_wifiStart->setEnabled(true); | ||||||
|     QString item = ui->tableWidget_wifi->item(current->row(), 1)->text(); |     QString item = ui->tableWidget_wifi->item(current->row(), 1)->text(); | ||||||
|     if (checkState(QString("exists"), item)) { |     if (checkState(QString("exists"), item)) { | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ | |||||||
|  |  | ||||||
| #include "netctlinteract.h" | #include "netctlinteract.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QProcess> | #include <QProcess> | ||||||
|  |  | ||||||
| @ -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 | // general information | ||||||
| QList<QStringList> Netctl::getProfileList() | QList<QStringList> Netctl::getProfileList() | ||||||
| { | { | ||||||
| @ -62,17 +100,19 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList) | |||||||
|     QStringList descriptions; |     QStringList descriptions; | ||||||
|  |  | ||||||
|     for (int i=0; i<profileList.count(); i++) { |     for (int i=0; i<profileList.count(); i++) { | ||||||
|         QFile profile(profileDirectory->absolutePath() + QDir::separator() + profileList[i]); |         QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profileList[i]; | ||||||
|  |         qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Check" << profileUrl; | ||||||
|  |         QFile profile(profileUrl); | ||||||
|         QString fileStr; |         QString fileStr; | ||||||
|         if (profile.open(QIODevice::ReadOnly)) |         if (profile.open(QIODevice::ReadOnly)) | ||||||
|             while (true) { |             while (true) { | ||||||
|                 fileStr = QString(profile.readLine()); |                 fileStr = QString(profile.readLine()); | ||||||
|                 if (profile.atEnd()) |                 if (fileStr[0] != '#') | ||||||
|                     break; |  | ||||||
|                 else if (fileStr[0] != '#') |  | ||||||
|                     if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) |                     if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) | ||||||
|                         if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("Description")) |                         if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("Description")) | ||||||
|                             descriptions.append(fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed()); |                             descriptions.append(fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed()); | ||||||
|  |                 if (profile.atEnd()) | ||||||
|  |                     break; | ||||||
|             } |             } | ||||||
|         else |         else | ||||||
|             descriptions.append(QString("<unknown>")); |             descriptions.append(QString("<unknown>")); | ||||||
| @ -111,20 +151,22 @@ QStringList Netctl::getProfileStatuses(const QStringList profileList) | |||||||
| QString Netctl::getSsidFromProfile(const QString profile) | QString Netctl::getSsidFromProfile(const QString profile) | ||||||
| { | { | ||||||
|     QString ssidName = QString(""); |     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; |     QString fileStr; | ||||||
|     if (!profileFile.open(QIODevice::ReadOnly)) |     if (!profileFile.open(QIODevice::ReadOnly)) | ||||||
|         return ssidName; |         return ssidName; | ||||||
|  |  | ||||||
|     while (true) { |     while (true) { | ||||||
|         fileStr = QString(profileFile.readLine()); |         fileStr = QString(profileFile.readLine()); | ||||||
|         if (profileFile.atEnd()) |         if (fileStr[0] != '#') { | ||||||
|             break; |  | ||||||
|         else if (fileStr[0] != '#') { |  | ||||||
|             if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) |             if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) | ||||||
|                 if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID")) |                 if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID")) | ||||||
|                     ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed(); |                     ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed(); | ||||||
|         } |         } | ||||||
|  |         if (profileFile.atEnd()) | ||||||
|  |             break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     profileFile.close(); |     profileFile.close(); | ||||||
| @ -138,16 +180,10 @@ QString Netctl::getSsidFromProfile(const QString profile) | |||||||
| bool Netctl::isProfileActive(const QString profile) | bool Netctl::isProfileActive(const QString profile) | ||||||
| { | { | ||||||
|     bool status = false; |     bool status = false; | ||||||
|     QProcess command; |     QString cmdOutput = getNetctlOutput(false, QString("status"), profile); | ||||||
|     QString cmdOutput = QString(""); |  | ||||||
|  |  | ||||||
|     command.start(netctlCommand + QString(" status ") + profile); |  | ||||||
|     command.waitForFinished(-1); |  | ||||||
|     cmdOutput = command.readAllStandardOutput(); |  | ||||||
|     if (!cmdOutput.isEmpty()) |     if (!cmdOutput.isEmpty()) | ||||||
|         if (cmdOutput.indexOf(QString("Active: active")) > -1) |         if (cmdOutput.indexOf(QString("Active: active")) > -1) | ||||||
|             status = true; |             status = true; | ||||||
|  |  | ||||||
|     return status; |     return status; | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -155,12 +191,7 @@ bool Netctl::isProfileActive(const QString profile) | |||||||
| bool Netctl::isProfileEnabled(const QString profile) | bool Netctl::isProfileEnabled(const QString profile) | ||||||
| { | { | ||||||
|     bool status = false; |     bool status = false; | ||||||
|     QProcess command; |     QString cmdOutput = getNetctlOutput(false, QString("status"), profile); | ||||||
|     QString cmdOutput = QString(""); |  | ||||||
|  |  | ||||||
|     command.start(netctlCommand + QString(" status ") + profile); |  | ||||||
|     command.waitForFinished(-1); |  | ||||||
|     cmdOutput = command.readAllStandardOutput(); |  | ||||||
|     if (!cmdOutput.isEmpty()) { |     if (!cmdOutput.isEmpty()) { | ||||||
|         QStringList profileStatus = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); |         QStringList profileStatus = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); | ||||||
|         for (int i=0; i<profileStatus.count(); i++) |         for (int i=0; i<profileStatus.count(); i++) | ||||||
| @ -168,7 +199,6 @@ bool Netctl::isProfileEnabled(const QString profile) | |||||||
|                 if (profileStatus[i].indexOf(QString("enabled")) > -1) |                 if (profileStatus[i].indexOf(QString("enabled")) > -1) | ||||||
|                     status = true; |                     status = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return status; |     return status; | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -176,42 +206,23 @@ bool Netctl::isProfileEnabled(const QString profile) | |||||||
| // functions | // functions | ||||||
| bool Netctl::enableProfile(const QString profile) | bool Netctl::enableProfile(const QString profile) | ||||||
| { | { | ||||||
|     QProcess command; |  | ||||||
|     if (isProfileEnabled(profile)) |     if (isProfileEnabled(profile)) | ||||||
|         command.start(sudoCommand + QString(" ") + netctlCommand + QString(" disable ") + profile); |         return netctlCall(true, QString("disable"), profile); | ||||||
|     else |     else | ||||||
|         command.start(sudoCommand + QString(" ") + netctlCommand + QString(" enable ") + profile); |         return netctlCall(true, QString("enable"), profile); | ||||||
|     command.waitForFinished(-1); |  | ||||||
|     if (command.exitCode() == 0) |  | ||||||
|         return true; |  | ||||||
|     else |  | ||||||
|         return false; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| bool Netctl::restartProfile(const QString profile) | bool Netctl::restartProfile(const QString profile) | ||||||
| { | { | ||||||
|     QProcess command; |     return netctlCall(true, QString("restart"), profile); | ||||||
|     if (isProfileActive(profile)) |  | ||||||
|         command.start(sudoCommand + QString(" ") + netctlCommand + QString(" restart ") + profile); |  | ||||||
|     command.waitForFinished(-1); |  | ||||||
|     if (command.exitCode() == 0) |  | ||||||
|         return true; |  | ||||||
|     else |  | ||||||
|         return false; |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| bool Netctl::startProfile(const QString profile) | bool Netctl::startProfile(const QString profile) | ||||||
| { | { | ||||||
|     QProcess command; |  | ||||||
|     if (isProfileActive(profile)) |     if (isProfileActive(profile)) | ||||||
|         command.start(sudoCommand + QString(" ") + netctlCommand + QString(" stop ") + profile); |         return netctlCall(true, QString("stop"), profile); | ||||||
|     else |     else | ||||||
|         command.start(sudoCommand + QString(" ") + netctlCommand + QString(" start ") + profile); |         return netctlCall(true, QString("start"), profile); | ||||||
|     command.waitForFinished(-1); |  | ||||||
|     if (command.exitCode() == 0) |  | ||||||
|         return true; |  | ||||||
|     else |  | ||||||
|         return false; |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -52,6 +52,9 @@ private: | |||||||
|     QString netctlCommand; |     QString netctlCommand; | ||||||
|     QDir *profileDirectory; |     QDir *profileDirectory; | ||||||
|     QString sudoCommand; |     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); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ | |||||||
|  |  | ||||||
| #include "netctlprofile.h" | #include "netctlprofile.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QFileInfo> | #include <QFileInfo> | ||||||
| #include <QProcess> | #include <QProcess> | ||||||
| @ -43,7 +44,9 @@ bool NetctlProfile::copyProfile(const QString oldPath) | |||||||
| { | { | ||||||
|     QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName(); |     QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName(); | ||||||
|     QProcess command; |     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); |     command.waitForFinished(-1); | ||||||
|     if (command.exitCode() == 0) |     if (command.exitCode() == 0) | ||||||
|         return true; |         return true; | ||||||
| @ -58,6 +61,7 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString, | |||||||
|     QString profileTempName = QDir::homePath() + QDir::separator() + |     QString profileTempName = QDir::homePath() + QDir::separator() + | ||||||
|             QString(".cache") + QDir::separator() + QFileInfo(profile).fileName(); |             QString(".cache") + QDir::separator() + QFileInfo(profile).fileName(); | ||||||
|     QFile profileFile(profileTempName); |     QFile profileFile(profileTempName); | ||||||
|  |     qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Save to" << profileTempName; | ||||||
|  |  | ||||||
|     if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text)) |     if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text)) | ||||||
|         return profileTempName; |         return profileTempName; | ||||||
| @ -89,20 +93,19 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString, | |||||||
| QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile) | QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile) | ||||||
| { | { | ||||||
|     QMap<QString, QString> settings; |     QMap<QString, QString> settings; | ||||||
|     QFile profileFile; |     QString fileStr, profileUrl; | ||||||
|     QString fileStr; |  | ||||||
|  |  | ||||||
|     if (profile[0] == QDir::separator()) |     if (profile[0] == QDir::separator()) | ||||||
|         profileFile.setFileName(profile); |         profileUrl = profile; | ||||||
|     else |     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)) |     if (!profileFile.open(QIODevice::ReadOnly)) | ||||||
|         return settings; |         return settings; | ||||||
|     while (true) { |     while (true) { | ||||||
|         fileStr = QString(profileFile.readLine()); |         fileStr = QString(profileFile.readLine()); | ||||||
|         if (profileFile.atEnd()) |         if (fileStr[0] != '#') { | ||||||
|             break; |  | ||||||
|         else if (fileStr[0] != '#') { |  | ||||||
|             if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) { |             if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) { | ||||||
|                 if ((fileStr.split(QString("="))[1][0] == QChar('(')) && |                 if ((fileStr.split(QString("="))[1][0] == QChar('(')) && | ||||||
|                         (fileStr.split(QString("="))[1][fileStr.split(QString("="))[1].size()-2] == QChar(')'))) |                         (fileStr.split(QString("="))[1][fileStr.split(QString("="))[1].size()-2] == QChar(')'))) | ||||||
| @ -124,8 +127,7 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi | |||||||
|                                 .trimmed()); |                                 .trimmed()); | ||||||
|                     while(true) { |                     while(true) { | ||||||
|                         fileStr = QString(profileFile.readLine()); |                         fileStr = QString(profileFile.readLine()); | ||||||
|                         if ((profileFile.atEnd()) || |                         if (fileStr[fileStr.size()-2] == QChar(')')) | ||||||
|                                 (fileStr[fileStr.size()-2] == QChar(')'))) |  | ||||||
|                             break; |                             break; | ||||||
|                         if (!fileStr.remove(QString("(")) |                         if (!fileStr.remove(QString("(")) | ||||||
|                                 .remove(QString(")")) |                                 .remove(QString(")")) | ||||||
| @ -134,6 +136,8 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi | |||||||
|                             parameter.append(fileStr.remove(QString("(")) |                             parameter.append(fileStr.remove(QString("(")) | ||||||
|                                     .remove(QString(")")) |                                     .remove(QString(")")) | ||||||
|                                     .trimmed()); |                                     .trimmed()); | ||||||
|  |                         if (profileFile.atEnd()) | ||||||
|  |                             break; | ||||||
|                     } |                     } | ||||||
|                     settings[parameterName] = parameter.join(QString("\n")); |                     settings[parameterName] = parameter.join(QString("\n")); | ||||||
|                 } |                 } | ||||||
| @ -143,6 +147,8 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi | |||||||
|             } |             } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|  |         if (profileFile.atEnd()) | ||||||
|  |             break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     profileFile.close(); |     profileFile.close(); | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ PasswdWidget::~PasswdWidget() | |||||||
|  |  | ||||||
|  |  | ||||||
| // ESC press event | // ESC press event | ||||||
| void PasswdWidget::keyPressEvent(const QKeyEvent *pressedKey) | void PasswdWidget::keyPressEvent(QKeyEvent *pressedKey) | ||||||
| { | { | ||||||
|     if (pressedKey->key() == Qt::Key_Escape) |     if (pressedKey->key() == Qt::Key_Escape) | ||||||
|         cancel(); |         cancel(); | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ private: | |||||||
|     QPushButton *cancelButton; |     QPushButton *cancelButton; | ||||||
|     QPushButton *okButton; |     QPushButton *okButton; | ||||||
|     // ESC pressed event |     // ESC pressed event | ||||||
|     void keyPressEvent(const QKeyEvent *pressedKey); |     void keyPressEvent(QKeyEvent *pressedKey); | ||||||
|     void createActions(); |     void createActions(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ | |||||||
| #include "settingswindow.h" | #include "settingswindow.h" | ||||||
| #include "ui_settingswindow.h" | #include "ui_settingswindow.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QFileDialog> | #include <QFileDialog> | ||||||
| #include <QTextStream> | #include <QTextStream> | ||||||
| @ -62,7 +63,7 @@ void SettingsWindow::createActions() | |||||||
|  |  | ||||||
|  |  | ||||||
| // ESC press event | // ESC press event | ||||||
| void SettingsWindow::keyPressEvent(const QKeyEvent *pressedKey) | void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey) | ||||||
| { | { | ||||||
|     if (pressedKey->key() == Qt::Key_Escape) |     if (pressedKey->key() == Qt::Key_Escape) | ||||||
|         close(); |         close(); | ||||||
| @ -200,9 +201,13 @@ QMap<QString, QString> SettingsWindow::readSettings() | |||||||
|     settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text(); |     settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text(); | ||||||
|     settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text(); |     settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text(); | ||||||
|     settings[QString("SUDO_PATH")] = ui->lineEdit_sudo->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("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text(); | ||||||
|     settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text(); |     settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text(); | ||||||
|  |     settings[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text(); | ||||||
|  |  | ||||||
|  |     for (int i=0; i<settings.keys().count(); i++) | ||||||
|  |         qDebug() << "[SettingsWindow]" << "[readSettings]" << ":" << | ||||||
|  |                     settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; | ||||||
|  |  | ||||||
|     return settings; |     return settings; | ||||||
| } | } | ||||||
| @ -223,9 +228,13 @@ void SettingsWindow::setSettings(const QMap<QString, QString> settings) | |||||||
|     ui->lineEdit_profilePath->setText(settings[QString("PROFILE_DIR")]); |     ui->lineEdit_profilePath->setText(settings[QString("PROFILE_DIR")]); | ||||||
|     ui->lineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]); |     ui->lineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]); | ||||||
|     ui->lineEdit_sudo->setText(settings[QString("SUDO_PATH")]); |     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_wpaCliPath->setText(settings[QString("WPACLI_PATH")]); | ||||||
|     ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]); |     ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]); | ||||||
|  |     ui->lineEdit_wpaSupDrivers->setText(settings[QString("WPA_DRIVERS")]); | ||||||
|  |  | ||||||
|  |     for (int i=0; i<settings.keys().count(); i++) | ||||||
|  |         qDebug() << "[SettingsWindow]" << "[setSettings]" << ":" << | ||||||
|  |                     settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -243,9 +252,13 @@ QMap<QString, QString> SettingsWindow::getDefault() | |||||||
|     settings[QString("PROFILE_DIR")] = QString("/etc/netctl/"); |     settings[QString("PROFILE_DIR")] = QString("/etc/netctl/"); | ||||||
|     settings[QString("RFKILL_DIR")] = QString("/sys/class/rfkill/"); |     settings[QString("RFKILL_DIR")] = QString("/sys/class/rfkill/"); | ||||||
|     settings[QString("SUDO_PATH")] = QString("/usr/bin/kdesu"); |     settings[QString("SUDO_PATH")] = QString("/usr/bin/kdesu"); | ||||||
|     settings[QString("WPA_DRIVERS")] = QString("nl80211,wext"); |  | ||||||
|     settings[QString("WPACLI_PATH")] = QString("/usr/bin/wpa_cli"); |     settings[QString("WPACLI_PATH")] = QString("/usr/bin/wpa_cli"); | ||||||
|     settings[QString("WPASUP_PATH")] = QString("/usr/bin/wpa_supplicant"); |     settings[QString("WPASUP_PATH")] = QString("/usr/bin/wpa_supplicant"); | ||||||
|  |     settings[QString("WPA_DRIVERS")] = QString("nl80211,wext"); | ||||||
|  |  | ||||||
|  |     for (int i=0; i<settings.keys().count(); i++) | ||||||
|  |         qDebug() << "[SettingsWindow]" << "[getDefault]" << ":" << | ||||||
|  |                     settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; | ||||||
|  |  | ||||||
|     return settings; |     return settings; | ||||||
| } | } | ||||||
| @ -261,17 +274,21 @@ QMap<QString, QString> SettingsWindow::getSettings() | |||||||
|         return getDefault(); |         return getDefault(); | ||||||
|     while (true) { |     while (true) { | ||||||
|         fileStr = QString(configFile.readLine()); |         fileStr = QString(configFile.readLine()); | ||||||
|         if (configFile.atEnd()) |         if (fileStr[0] != '#') { | ||||||
|             break; |  | ||||||
|         else if (fileStr[0] != '#') { |  | ||||||
|             if (fileStr.indexOf(QString("=")) > -1) |             if (fileStr.indexOf(QString("=")) > -1) | ||||||
|                 settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1] |                 settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1] | ||||||
|                         .remove(QString(" ")) |                         .remove(QString(" ")) | ||||||
|                         .trimmed(); |                         .trimmed(); | ||||||
|         } |         } | ||||||
|  |         if (configFile.atEnd()) | ||||||
|  |             break; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     configFile.close(); |     configFile.close(); | ||||||
|  |  | ||||||
|  |     for (int i=0; i<settings.keys().count(); i++) | ||||||
|  |         qDebug() << "[SettingsWindow]" << "[getSettings]" << ":" << | ||||||
|  |                     settings.keys()[i] + QString("=") + settings[settings.keys()[i]]; | ||||||
|  |  | ||||||
|     return settings; |     return settings; | ||||||
| } | } | ||||||
|  | |||||||
| @ -61,7 +61,7 @@ private: | |||||||
|     Ui::SettingsWindow *ui; |     Ui::SettingsWindow *ui; | ||||||
|     void createActions(); |     void createActions(); | ||||||
|     // ESC pressed event |     // ESC pressed event | ||||||
|     void keyPressEvent(const QKeyEvent *pressedKey); |     void keyPressEvent(QKeyEvent *pressedKey); | ||||||
|     QMap<QString, QString> readSettings(); |     QMap<QString, QString> readSettings(); | ||||||
|     void setSettings(const QMap<QString, QString> settings); |     void setSettings(const QMap<QString, QString> settings); | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -103,7 +103,7 @@ void WirelessWidget::createActions() | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void WirelessWidget::keyPressEvent(const QKeyEvent *pressedKey) | void WirelessWidget::keyPressEvent(QKeyEvent *pressedKey) | ||||||
| { | { | ||||||
|     if (pressedKey->key() == Qt::Key_Delete) { |     if (pressedKey->key() == Qt::Key_Delete) { | ||||||
|         if (ui->listWidget_wpaConfigSection->hasFocus() && |         if (ui->listWidget_wpaConfigSection->hasFocus() && | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ private: | |||||||
|     QDir *rfkillDirectory; |     QDir *rfkillDirectory; | ||||||
|     Ui::WirelessWidget *ui; |     Ui::WirelessWidget *ui; | ||||||
|     void createActions(); |     void createActions(); | ||||||
|     void keyPressEvent(const QKeyEvent *pressedKey); |     void keyPressEvent(QKeyEvent *pressedKey); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ | |||||||
|  |  | ||||||
| #include "wpasupinteract.h" | #include "wpasupinteract.h" | ||||||
|  |  | ||||||
|  | #include <QDebug> | ||||||
| #include <QProcess> | #include <QProcess> | ||||||
|  |  | ||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| @ -50,6 +51,17 @@ WpaSup::~WpaSup() | |||||||
|  |  | ||||||
|  |  | ||||||
| // general information | // general information | ||||||
|  | QString WpaSup::existentProfile(const QString profile) | ||||||
|  | { | ||||||
|  |     QString profileFile = QString(""); | ||||||
|  |     QList<QStringList> profileList = parent->netctlCommand->getProfileList(); | ||||||
|  |     for (int i=0; i<profileList.count(); i++) | ||||||
|  |         if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0])) | ||||||
|  |             profileFile = profileList[i][0]; | ||||||
|  |     return profileFile; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| QStringList WpaSup::getInterfaceList() | QStringList WpaSup::getInterfaceList() | ||||||
| { | { | ||||||
|     QStringList interfaces; |     QStringList interfaces; | ||||||
| @ -57,43 +69,18 @@ QStringList WpaSup::getInterfaceList() | |||||||
|     if (!mainInterface.isEmpty()) |     if (!mainInterface.isEmpty()) | ||||||
|         interfaces.append(mainInterface); |         interfaces.append(mainInterface); | ||||||
|     QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); |     QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); | ||||||
|     for (int i=0; i<allInterfaces.count(); i++) |     for (int i=0; i<allInterfaces.count(); i++) { | ||||||
|  |         qDebug() << "[WpaSup]" << "[getInterfaceList]" << ":" << "Check directory" | ||||||
|  |                  << ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless"); | ||||||
|         if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + |         if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + | ||||||
|                  QDir::separator() + QString("wireless")).exists()) |                  QDir::separator() + QString("wireless")).exists()) | ||||||
|             interfaces.append(allInterfaces[i]); |             interfaces.append(allInterfaces[i]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return interfaces; |     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) | bool WpaSup::isProfileActive(const QString profile) | ||||||
| { | { | ||||||
|     QString profileFile; |     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<QStringList> profileList = parent->netctlCommand->getProfileList(); |  | ||||||
|     for (int i=0; i<profileList.count(); i++) |  | ||||||
|         if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0])) |  | ||||||
|             profileFile = profileList[i][0]; |  | ||||||
|     return profileFile; |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| bool WpaSup::startWpaSupplicant() |  | ||||||
| { |  | ||||||
|     if (!QFile(pidFile).exists()) { |  | ||||||
|     QString interface = getInterfaceList()[0]; |     QString interface = getInterfaceList()[0]; | ||||||
|     QProcess command; |     QProcess command; | ||||||
|         command.start(sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile + |     QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + | ||||||
|                 QString(" -i ") + interface + QString(" -D ") + wpaDrivers + |             QString(" -P ") + pidFile + QString(" ") + commandLine; | ||||||
|                 QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup); |     qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Run cmd" << commandText; | ||||||
|  |     command.start(commandText); | ||||||
|     command.waitForFinished(-1); |     command.waitForFinished(-1); | ||||||
|     SleepThread::sleep(1); |     SleepThread::sleep(1); | ||||||
|         if (command.exitCode() != 0) |     qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Cmd returns" << command.exitCode(); | ||||||
|             return false; |     if (command.exitCode() == 0) | ||||||
|     } |  | ||||||
|         return true; |         return true; | ||||||
|  |     else | ||||||
|  |         return false; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| bool WpaSup::stopWpaSupplicant() | QString WpaSup::getWpaCliOutput(const QString commandLine) | ||||||
| { | { | ||||||
|     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<QStringList> WpaSup::scanWifi() | QList<QStringList> WpaSup::scanWifi() | ||||||
| { | { | ||||||
|     QList<QStringList> scanResults; |     QList<QStringList> scanResults; | ||||||
|     startWpaSupplicant(); |     if (!startWpaSupplicant()) { | ||||||
|  |         stopWpaSupplicant(); | ||||||
|  |         return scanResults; | ||||||
|  |     } | ||||||
|     if (!wpaCliCall(QString("scan"))) |     if (!wpaCliCall(QString("scan"))) | ||||||
|         return scanResults; |         return scanResults; | ||||||
|     SleepThread::sleep(3); |     SleepThread::sleep(3); | ||||||
| @ -215,3 +203,29 @@ QList<QStringList> WpaSup::scanWifi() | |||||||
|     stopWpaSupplicant(); |     stopWpaSupplicant(); | ||||||
|     return scanResults; |     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")); | ||||||
|  | } | ||||||
|  | |||||||
| @ -34,19 +34,16 @@ public: | |||||||
|                     const QMap<QString, QString> settings = QMap<QString, QString>()); |                     const QMap<QString, QString> settings = QMap<QString, QString>()); | ||||||
|     ~WpaSup(); |     ~WpaSup(); | ||||||
|     // general information |     // 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); |     QString existentProfile(const QString profile); | ||||||
|  |     QStringList getInterfaceList(); | ||||||
|     bool isProfileActive(const QString profile); |     bool isProfileActive(const QString profile); | ||||||
|  |     bool isProfileExists(const QString profile); | ||||||
|  |  | ||||||
| public slots: | public slots: | ||||||
|     // functions |     // functions | ||||||
|  |     QList<QStringList> scanWifi(); | ||||||
|     bool startWpaSupplicant(); |     bool startWpaSupplicant(); | ||||||
|     bool stopWpaSupplicant(); |     bool stopWpaSupplicant(); | ||||||
|     QList<QStringList> scanWifi(); |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     MainWindow *parent; |     MainWindow *parent; | ||||||
| @ -59,6 +56,9 @@ private: | |||||||
|     QString wpaCliPath; |     QString wpaCliPath; | ||||||
|     QString wpaDrivers; |     QString wpaDrivers; | ||||||
|     QString wpaSupPath; |     QString wpaSupPath; | ||||||
|  |     // functions | ||||||
|  |     bool wpaCliCall(const QString commandLine); | ||||||
|  |     QString getWpaCliOutput(const QString commandLine); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user