From 95a3e0d5449a6d67c61ecf7a4cbfc8f40445dc7f Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 7 Feb 2014 01:34:43 +0400 Subject: [PATCH] try to get it work --- .gitignore | 2 +- sources/gui/src/mainwindow.cpp | 69 ++++++++++++++++++++---------- sources/gui/src/mainwindow.h | 4 +- sources/gui/src/mainwindow.ui | 15 +++++++ sources/gui/src/netctlinteract.cpp | 16 ++++++- sources/gui/src/netctlinteract.h | 2 +- sources/gui/src/wpasupinteract.cpp | 51 +++++++++++----------- 7 files changed, 106 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index d957b61..5c50d19 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ # Build directory build/ sources/build/ -sources/build/*/ +tmp/ diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 85dc194..201c331 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 "netctlinteract.h" @@ -30,7 +31,6 @@ MainWindow::MainWindow(QWidget *parent) ui(new Ui::MainWindow) { ui->setupUi(this); - ui->tableWidget_main->setSortingEnabled(true); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Ready")); // SettingsWindow *settingsWindow; @@ -66,13 +66,20 @@ MainWindow::~MainWindow() } -bool MainWindow::checkExternalApps() +bool MainWindow::checkExternalApps(QString apps = QString("all")) { + QStringList commandLine; + commandLine.append("which"); + commandLine.append(sudoPath); + if ((apps == QString("netctl")) || (apps == QString("all"))) { + commandLine.append(netctlPath); + } + if ((apps == QString("wpasup")) || (apps == QString("all"))) { + commandLine.append(wpaConfig[0]); + commandLine.append(wpaConfig[1]); + } QProcess command; - command.start(QString("which ") + netctlPath + - QString(" ") + sudoPath + - QString(" ") + wpaConfig[0] + - QString(" ") + wpaConfig[1]); + command.start(commandLine.join(QString(" "))); command.waitForFinished(-1); if (command.exitCode() != 0) return false; @@ -93,6 +100,9 @@ void MainWindow::createActions() 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(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(mainTabRefreshButtons(QTableWidgetItem *, QTableWidgetItem *))); + + // wifi page events + connect(ui->pushButton_wifiRefresh, SIGNAL(clicked(bool)), this, SLOT(updateWifiTab())); } @@ -108,43 +118,56 @@ void MainWindow::updateTabs(const int tab) void MainWindow::updateMainTab() { - if (!checkExternalApps()) + if (!checkExternalApps(QString("netctl"))) return; - QStringList profiles = netctlCommand->getProfileList(); - QStringList descriptions = netctlCommand->getProfileDescriptions(profiles); - QStringList statuses = netctlCommand->getProfileStatuses(profiles); + QList profiles = netctlCommand->getProfileList();; - ui->tableWidget_main->setRowCount(profiles.count()); + ui->tableWidget_main->selectRow(-1); ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder); + ui->tableWidget_main->clear(); + ui->tableWidget_main->setRowCount(profiles.count()); - for (int i=0; itableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i])); - ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(descriptions[i])); - ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(statuses[i])); - } + for (int i=0; itableWidget_main->setItem(i, j, new QTableWidgetItem(profiles[i][j])); ui->tableWidget_main->resizeColumnsToContents(); ui->tableWidget_main->resizeRowsToContents(); ui->tableWidget_main->horizontalHeader()->setStretchLastSection(true); - ui->tableWidget_main->setCurrentCell(0, 0); + update(); } void MainWindow::updateWifiTab() { - if (!checkExternalApps()) + if (!checkExternalApps(QString("wpasup"))) return; QList scanResults = wpaCommand->scanWifi(); + + ui->tableWidget_wifi->selectRow(-1); + ui->tableWidget_wifi->sortByColumn(0, Qt::AscendingOrder); + ui->tableWidget_wifi->clear(); + ui->tableWidget_wifi->setRowCount(scanResults.count()); + + for (int i=0; itableWidget_wifi->setItem(i, j, new QTableWidgetItem(scanResults[i][j])); + + ui->tableWidget_wifi->resizeColumnsToContents(); + ui->tableWidget_wifi->resizeRowsToContents(); + ui->tableWidget_wifi->horizontalHeader()->setStretchLastSection(true); + + update(); } // main tab slots void MainWindow::mainTabEnableProfile() { - if (!checkExternalApps()) + if (!checkExternalApps(QString("netctl"))) return; ui->tableWidget_main->setDisabled(true); @@ -169,7 +192,7 @@ void MainWindow::mainTabEnableProfile() void MainWindow::mainTabRestartProfile() { - if (!checkExternalApps()) + if (!checkExternalApps(QString("netctl"))) return; ui->tableWidget_main->setDisabled(true); @@ -186,7 +209,7 @@ void MainWindow::mainTabRestartProfile() void MainWindow::mainTabStartProfile() { - if (!checkExternalApps()) + if (!checkExternalApps(QString("netctl"))) return; ui->tableWidget_main->setDisabled(true); @@ -212,7 +235,9 @@ void MainWindow::mainTabStartProfile() void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); - if (!checkExternalApps()) + if (current == 0) + return; + if (!checkExternalApps(QString("netctl"))) return; QString profile = ui->tableWidget_main->item(current->row(), 0)->text(); diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index c07059f..34b0407 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -20,8 +20,8 @@ #include #include -#include #include +#include class Netctl; @@ -46,7 +46,7 @@ public: wpaConfDir = 4, wpaConfGroup = 5 }; - bool checkExternalApps(); + bool checkExternalApps(QString apps); private slots: void updateTabs(const int tab); diff --git a/sources/gui/src/mainwindow.ui b/sources/gui/src/mainwindow.ui index e5f897e..2f50ea2 100644 --- a/sources/gui/src/mainwindow.ui +++ b/sources/gui/src/mainwindow.ui @@ -36,6 +36,9 @@ QAbstractItemView::SelectRows + + true + true @@ -46,16 +49,25 @@ Name + + AlignHCenter|AlignVCenter|AlignCenter + Description + + AlignHCenter|AlignVCenter|AlignCenter + Status + + AlignHCenter|AlignVCenter|AlignCenter + @@ -149,6 +161,9 @@ QAbstractItemView::SelectRows + + true + true diff --git a/sources/gui/src/netctlinteract.cpp b/sources/gui/src/netctlinteract.cpp index 2c943a4..7854c1a 100644 --- a/sources/gui/src/netctlinteract.cpp +++ b/sources/gui/src/netctlinteract.cpp @@ -41,9 +41,21 @@ Netctl::~Netctl() // general information -QStringList Netctl::getProfileList() +QList Netctl::getProfileList() { - return profileDirectory->entryList(QDir::Files); + QList fullProfilesInfo; + QStringList profiles = profileDirectory->entryList(QDir::Files); + QStringList descriptions = getProfileDescriptions(profiles); + QStringList statuses = getProfileStatuses(profiles); + + for (int i=0; i getProfileList(); QStringList getProfileDescriptions(QStringList profileList); QStringList getProfileStatuses(QStringList profileList); bool isProfileActive(QString profile); diff --git a/sources/gui/src/wpasupinteract.cpp b/sources/gui/src/wpasupinteract.cpp index 0d3706c..f67debc 100644 --- a/sources/gui/src/wpasupinteract.cpp +++ b/sources/gui/src/wpasupinteract.cpp @@ -31,12 +31,9 @@ WpaSup::WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDirectory(new QDir(ifaceDir)), mainInterface(preferedInterface) { - // remove old files if they exist - if (QFile(wpaConf[2]).exists() || QDir(wpaConf[4]).exists()) { - QProcess command; - command.start(sudoCommand + QString(" /usr/bin/rm -f ") + wpaConf[2] + QString(" ") + wpaConf[4]); - command.waitForFinished(-1); - } + // terminate old loaded profile + if (QFile(wpaConf[2]).exists() || QDir(wpaConf[4]).exists()) + stopWpaSupplicant(); } @@ -52,8 +49,7 @@ QStringList WpaSup::getInterfaceList() QStringList interfaces; if (mainInterface.isEmpty()) { - QStringList allInterfaces; - allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); + QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless")).exists()) @@ -124,29 +120,37 @@ QList WpaSup::scanWifi() return scanResults; SleepThread::sleep(3); - QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n")); + QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"), QString::SkipEmptyParts); + // remove table header rawOutput.removeFirst(); - rawOutput.removeLast(); - for (int i=0; i 4) - for (int j=i+1; j 4) - if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[4] == - rawOutput[j].split(QString(" "), QString::SkipEmptyParts)[4]) - rawOutput.removeAt(j); - + // remove duplicates + QStringList rawList; for (int i=0; i 4) + for (int j=0; j 4) + if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[4] == + rawList[j].split(QString("\t"), QString::SkipEmptyParts)[4]) + exist = true; + if (!exist) + rawList.append(rawOutput[i]); + } + + for (int i=0; i 4) - wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[4]); + if (rawList[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4) + wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[4]); else wifiPoint.append(QString("")); + // profile existance + wifiPoint.append(QString("null")); // point signal - wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[2]); + wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[2]); // point security - QString security = rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[3]; + QString security = rawList[i].split(QString("\t"), QString::SkipEmptyParts)[3]; if (security.indexOf(QString("WPA2"))) security = QString("WPA2"); else if (security.indexOf(QString("WPA"))) @@ -156,9 +160,6 @@ QList WpaSup::scanWifi() else security = QString("none"); wifiPoint.append(security); - // point bssid - wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[0]); - // profile existance scanResults.append(wifiPoint); }