mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
try to get it work
This commit is contained in:
parent
d9571b76cf
commit
95a3e0d544
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,5 +18,5 @@
|
||||
# Build directory
|
||||
build/
|
||||
sources/build/
|
||||
sources/build/*/
|
||||
tmp/
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QProcess>
|
||||
|
||||
#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<QStringList> 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; i<profiles.count(); i++) {
|
||||
ui->tableWidget_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; i<profiles.count(); i++)
|
||||
for (int j=0; j<3; j++)
|
||||
ui->tableWidget_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<QStringList> 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; i<scanResults.count(); i++)
|
||||
for (int j=0; j<4; j++)
|
||||
ui->tableWidget_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();
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QItemSelection>
|
||||
#include <QMainWindow>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QMainWindow>
|
||||
|
||||
|
||||
class Netctl;
|
||||
@ -46,7 +46,7 @@ public:
|
||||
wpaConfDir = 4,
|
||||
wpaConfGroup = 5
|
||||
};
|
||||
bool checkExternalApps();
|
||||
bool checkExternalApps(QString apps);
|
||||
|
||||
private slots:
|
||||
void updateTabs(const int tab);
|
||||
|
@ -36,6 +36,9 @@
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
@ -46,16 +49,25 @@
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
@ -149,6 +161,9 @@
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
|
@ -41,9 +41,21 @@ Netctl::~Netctl()
|
||||
|
||||
|
||||
// general information
|
||||
QStringList Netctl::getProfileList()
|
||||
QList<QStringList> Netctl::getProfileList()
|
||||
{
|
||||
return profileDirectory->entryList(QDir::Files);
|
||||
QList<QStringList> fullProfilesInfo;
|
||||
QStringList profiles = profileDirectory->entryList(QDir::Files);
|
||||
QStringList descriptions = getProfileDescriptions(profiles);
|
||||
QStringList statuses = getProfileStatuses(profiles);
|
||||
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
QStringList profileInfo;
|
||||
profileInfo.append(profiles[i]);
|
||||
profileInfo.append(descriptions[i]);
|
||||
profileInfo.append(statuses[i]);
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
return fullProfilesInfo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
Netctl(MainWindow *wid, QString netctlPath, QString profileDir, QString sudoPath);
|
||||
~Netctl();
|
||||
// general information
|
||||
QStringList getProfileList();
|
||||
QList<QStringList> getProfileList();
|
||||
QStringList getProfileDescriptions(QStringList profileList);
|
||||
QStringList getProfileStatuses(QStringList profileList);
|
||||
bool isProfileActive(QString profile);
|
||||
|
@ -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; i<allInterfaces.count(); i++)
|
||||
if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] +
|
||||
QDir::separator() + QString("wireless")).exists())
|
||||
@ -124,29 +120,37 @@ QList<QStringList> 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<rawOutput.count()-1; i++)
|
||||
if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts).count() > 4)
|
||||
for (int j=i+1; j<rawOutput.count(); j++)
|
||||
if (rawOutput[j].split(QString(" "), QString::SkipEmptyParts).count() > 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<rawOutput.count(); i++) {
|
||||
bool exist = false;
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
for (int j=0; j<rawList.count(); j++)
|
||||
if (rawList[j].split(QString("\t"), QString::SkipEmptyParts).count() > 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<rawList.count(); i++) {
|
||||
QStringList wifiPoint;
|
||||
|
||||
// point name
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts).count() > 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("<hidden>"));
|
||||
// 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<QStringList> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user