diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index ed8de4c..95ff715 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -40,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent) // temporary block netctlPath = QString("/usr/bin/netctl"); profileDir = QString("/etc/netctl"); - sudoPath = QString("/usr/bin/sudo"); + sudoPath = QString("/usr/bin/kdesu"); wpaConfig.append(QString("/usr/bin/wpa_cli")); wpaConfig.append(QString("/usr/bin/wpa_supplicant")); ifaceDir = QString("/sys/class/net/"); @@ -89,6 +89,15 @@ bool MainWindow::checkExternalApps(QString apps = QString("all")) } +bool MainWindow::checkState(QString state, QString item) +{ + if (item.indexOf(state) > -1) + return true; + else + return false; +} + + // window signals void MainWindow::createActions() { @@ -100,6 +109,7 @@ void MainWindow::createActions() connect(ui->pushButton_mainEnable, SIGNAL(clicked(bool)), this, SLOT(mainTabEnableProfile())); connect(ui->pushButton_mainRestart, SIGNAL(clicked(bool)), this, SLOT(mainTabRestartProfile())); connect(ui->pushButton_mainStart, SIGNAL(clicked(bool)), this, SLOT(mainTabStartProfile())); + connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile())); connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(mainTabRefreshButtons(QTableWidgetItem *, QTableWidgetItem *))); // wifi page events @@ -276,8 +286,8 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt if (!checkExternalApps(QString("netctl"))) return; - QString profile = ui->tableWidget_main->item(current->row(), 0)->text(); - if (netctlCommand->isProfileActive(profile)) { + QString item = ui->tableWidget_main->item(current->row(), 2)->text(); + if (!checkState(QString("inactive"), item)) { ui->pushButton_mainRestart->setEnabled(true); ui->pushButton_mainStart->setText(QApplication::translate("MainWindow", "Stop")); } @@ -285,7 +295,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt ui->pushButton_mainRestart->setDisabled(true); ui->pushButton_mainStart->setText(QApplication::translate("MainWindow", "Start")); } - if (netctlCommand->isProfileEnabled(profile)) + if (checkState(QString("enabled"), item)) ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Disable")); else ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Enable")); @@ -318,11 +328,13 @@ void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt if (!checkExternalApps(QString("wpasup"))) return; - QString network = ui->tableWidget_wifi->item(current->row(), 0)->text(); - if (wpaCommand->isProfileExists(network)) { - if (wpaCommand->isProfileActive(network)) + QString item = ui->tableWidget_wifi->item(current->row(), 3)->text(); + if (checkState(QString("exists"), item)) { + if (!checkState(QString("inactive"), item)) ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Stop")); else ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Start")); } + else + ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Start")); } diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 0af8591..fdaf4c1 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -48,7 +48,6 @@ public: wpaConfDir = 4, wpaConfGroup = 5 }; - bool checkExternalApps(QString apps); private slots: void updateTabs(const int tab); @@ -65,6 +64,8 @@ private slots: private: Ui::MainWindow *ui; + bool checkExternalApps(QString apps); + bool checkState(QString state, QString item); void createActions(); // configuration QString netctlPath; diff --git a/sources/gui/src/wpasupinteract.cpp b/sources/gui/src/wpasupinteract.cpp index df49b10..37e32a4 100644 --- a/sources/gui/src/wpasupinteract.cpp +++ b/sources/gui/src/wpasupinteract.cpp @@ -49,15 +49,13 @@ QStringList WpaSup::getInterfaceList() { QStringList interfaces; - if (mainInterface.isEmpty()) { - QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); - for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + - QDir::separator() + QString("wireless")).exists()) - interfaces.append(allInterfaces[i]); - } - else - interfaces.append(mainInterface); + interfaces.append(mainInterface); + QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + + QDir::separator() + QString("wireless")).exists()) + interfaces.append(allInterfaces[i]); + return interfaces; } @@ -69,7 +67,7 @@ bool WpaSup::wpaCliCall(QString commandLine) QString interface = getInterfaceList()[0]; QProcess command; command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] + - QString(" ") + commandLine); + QString(" -P ") + wpaConf[2] + QString(" ") + commandLine); command.waitForFinished(-1); SleepThread::sleep(1); if (command.exitCode() == 0) @@ -84,7 +82,7 @@ QString WpaSup::getWpaCliOutput(QString commandLine) QString interface = getInterfaceList()[0]; QProcess command; command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] + - QString(" ") + commandLine); + QString(" -P ") + wpaConf[2] + QString(" ") + commandLine); command.waitForFinished(-1); return command.readAllStandardOutput(); }