mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
almost working wifi module
This commit is contained in:
parent
95a3e0d544
commit
65086a9aa3
@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
// SettingsWindow *settingsWindow;
|
||||
// settingsWindow = new SettingsWindow(this);
|
||||
// delete settingsWindow;
|
||||
|
||||
// temporary block
|
||||
netctlPath = QString("/usr/bin/netctl");
|
||||
profileDir = QString("/etc/netctl");
|
||||
@ -54,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
wpaCommand = new WpaSup(this, wpaConfig, sudoPath, ifaceDir, preferedInterface);
|
||||
|
||||
createActions();
|
||||
updateMainTab();
|
||||
updateTabs(ui->tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
|
||||
@ -103,6 +104,7 @@ void MainWindow::createActions()
|
||||
|
||||
// wifi page events
|
||||
connect(ui->pushButton_wifiRefresh, SIGNAL(clicked(bool)), this, SLOT(updateWifiTab()));
|
||||
connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), this, SLOT(wifiTabRefreshButtons(QTableWidgetItem *, QTableWidgetItem *)));
|
||||
}
|
||||
|
||||
|
||||
@ -121,20 +123,35 @@ void MainWindow::updateMainTab()
|
||||
if (!checkExternalApps(QString("netctl")))
|
||||
return;
|
||||
|
||||
ui->tableWidget_main->setDisabled(true);
|
||||
QList<QStringList> profiles = netctlCommand->getProfileList();;
|
||||
|
||||
ui->tableWidget_main->setSortingEnabled(false);
|
||||
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++)
|
||||
for (int j=0; j<3; j++)
|
||||
ui->tableWidget_main->setItem(i, j, new QTableWidgetItem(profiles[i][j]));
|
||||
// create header
|
||||
ui->tableWidget_main->setHorizontalHeaderLabels(QString("Name Description Status").split(QString(" ")));
|
||||
// create items
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
// name
|
||||
ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i][0]));
|
||||
ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
// description
|
||||
ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(profiles[i][1]));
|
||||
ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
// status
|
||||
ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(profiles[i][2]));
|
||||
ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
ui->tableWidget_main->resizeColumnsToContents();
|
||||
ui->tableWidget_main->setSortingEnabled(true);
|
||||
ui->tableWidget_main->resizeRowsToContents();
|
||||
ui->tableWidget_main->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
||||
ui->tableWidget_main->setEnabled(true);
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated"));
|
||||
|
||||
update();
|
||||
}
|
||||
@ -142,23 +159,42 @@ void MainWindow::updateMainTab()
|
||||
|
||||
void MainWindow::updateWifiTab()
|
||||
{
|
||||
wifiTabSetEnabled(checkExternalApps(QString("wpasup")));
|
||||
if (!checkExternalApps(QString("wpasup")))
|
||||
return;
|
||||
|
||||
QList<QStringList> scanResults = wpaCommand->scanWifi();
|
||||
|
||||
ui->tableWidget_wifi->setDisabled(true);
|
||||
ui->tableWidget_wifi->setSortingEnabled(false);
|
||||
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]));
|
||||
// create header
|
||||
ui->tableWidget_wifi->setHorizontalHeaderLabels(QString("Name Status Signal Security").split(QString(" ")));
|
||||
// create items
|
||||
for (int i=0; i<scanResults.count(); i++) {
|
||||
// name
|
||||
ui->tableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i][0]));
|
||||
ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
// status
|
||||
ui->tableWidget_wifi->setItem(i, 1, new QTableWidgetItem(scanResults[i][1]));
|
||||
ui->tableWidget_wifi->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
// signal
|
||||
ui->tableWidget_wifi->setItem(i, 2, new QTableWidgetItem(scanResults[i][2]));
|
||||
ui->tableWidget_wifi->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
// security
|
||||
ui->tableWidget_wifi->setItem(i, 3, new QTableWidgetItem(scanResults[i][3]));
|
||||
ui->tableWidget_wifi->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
ui->tableWidget_wifi->resizeColumnsToContents();
|
||||
ui->tableWidget_wifi->setSortingEnabled(true);
|
||||
ui->tableWidget_wifi->resizeRowsToContents();
|
||||
ui->tableWidget_wifi->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
|
||||
ui->tableWidget_wifi->setEnabled(true);
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated"));
|
||||
|
||||
update();
|
||||
}
|
||||
@ -254,3 +290,39 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt
|
||||
else
|
||||
ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Enable"));
|
||||
}
|
||||
|
||||
|
||||
// wifi tab slots
|
||||
void MainWindow::wifiTabSetEnabled(bool state)
|
||||
{
|
||||
if (state) {
|
||||
ui->tableWidget_wifi->show();
|
||||
ui->pushButton_wifiRefresh->setEnabled(true);
|
||||
ui->pushButton_wifiStart->setEnabled(true);
|
||||
ui->label_wifi->hide();
|
||||
}
|
||||
else {
|
||||
ui->tableWidget_wifi->hide();
|
||||
ui->pushButton_wifiRefresh->setDisabled(true);
|
||||
ui->pushButton_wifiStart->setDisabled(true);
|
||||
ui->label_wifi->show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous)
|
||||
{
|
||||
Q_UNUSED(previous);
|
||||
if (current == 0)
|
||||
return;
|
||||
if (!checkExternalApps(QString("wpasup")))
|
||||
return;
|
||||
|
||||
QString network = ui->tableWidget_wifi->item(current->row(), 0)->text();
|
||||
if (wpaCommand->isProfileExists(network)) {
|
||||
if (wpaCommand->isProfileActive(network))
|
||||
ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Stop"));
|
||||
else
|
||||
ui->pushButton_wifiStart->setText(QApplication::translate("MainWindow", "Start"));
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
Netctl *netctlCommand;
|
||||
WpaSup *wpaCommand;
|
||||
enum wpaConfigIndex {
|
||||
wpaCliPath = 0,
|
||||
wpaSupplicantPath = 1,
|
||||
@ -57,10 +59,11 @@ private slots:
|
||||
void mainTabRestartProfile();
|
||||
void mainTabStartProfile();
|
||||
void mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||
// wifi tab slots
|
||||
void wifiTabSetEnabled(bool state);
|
||||
void wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||
|
||||
private:
|
||||
Netctl *netctlCommand;
|
||||
WpaSup *wpaCommand;
|
||||
Ui::MainWindow *ui;
|
||||
void createActions();
|
||||
// configuration
|
||||
|
@ -146,7 +146,10 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_wifi">
|
||||
<property name="text">
|
||||
<string>Please install 'wpa_supplicant' before using</string>
|
||||
<string>Please install 'wpa_supplicant' before using it</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -94,11 +94,11 @@ QStringList Netctl::getProfileStatuses(QStringList profileList)
|
||||
QStringList statuses;
|
||||
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QString status = QString("");
|
||||
QString status;
|
||||
if (isProfileActive(profileList[i]))
|
||||
status = status + QString("active");
|
||||
status = QString("active");
|
||||
else
|
||||
status = status + QString("inactive");
|
||||
status = QString("inactive");
|
||||
if (isProfileEnabled(profileList[i]))
|
||||
status = status + QString(" (enabled)");
|
||||
else
|
||||
@ -110,6 +110,33 @@ QStringList Netctl::getProfileStatuses(QStringList profileList)
|
||||
}
|
||||
|
||||
|
||||
QString Netctl::getSsidFromProfile(QString profile)
|
||||
{
|
||||
QString ssidName = QString("");
|
||||
QFile profileFile(profileDirectory->absolutePath() + QDir::separator() + profile);
|
||||
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.split(QString("="), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID"))
|
||||
ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0];
|
||||
}
|
||||
}
|
||||
|
||||
profileFile.close();
|
||||
|
||||
ssidName.remove(QChar('\''));
|
||||
ssidName.remove(QChar('"'));
|
||||
return ssidName;
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::isProfileActive(QString profile)
|
||||
{
|
||||
bool status = false;
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
QList<QStringList> getProfileList();
|
||||
QStringList getProfileDescriptions(QStringList profileList);
|
||||
QStringList getProfileStatuses(QStringList profileList);
|
||||
QString getSsidFromProfile(QString profile);
|
||||
bool isProfileActive(QString profile);
|
||||
bool isProfileEnabled(QString profile);
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QProcess>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "netctlinteract.h"
|
||||
#include "sleepthread.h"
|
||||
#include <cstdio>
|
||||
|
||||
@ -89,6 +90,28 @@ QString WpaSup::getWpaCliOutput(QString commandLine)
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileActive(QString profile)
|
||||
{
|
||||
QString profileFile;
|
||||
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 parent->netctlCommand->isProfileActive(profileFile);
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileExists(QString profile)
|
||||
{
|
||||
bool exists = false;
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (profile == parent->netctlCommand->getSsidFromProfile(profileList[i][0]))
|
||||
exists = true;
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::startWpaSupplicant()
|
||||
{
|
||||
if (!QFile(wpaConf[2]).exists()) {
|
||||
@ -145,17 +168,27 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[4]);
|
||||
else
|
||||
wifiPoint.append(QString("<hidden>"));
|
||||
// profile existance
|
||||
wifiPoint.append(QString("null"));
|
||||
// profile status
|
||||
QString status;
|
||||
if (isProfileExists(wifiPoint[0])) {
|
||||
status = QString("exists");
|
||||
if (isProfileActive(wifiPoint[0]))
|
||||
status = status + QString(" (active)");
|
||||
else
|
||||
status = status + QString(" (inactive)");
|
||||
}
|
||||
else
|
||||
status = QString("new");
|
||||
wifiPoint.append(status);
|
||||
// point signal
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[2]);
|
||||
// point security
|
||||
QString security = rawList[i].split(QString("\t"), QString::SkipEmptyParts)[3];
|
||||
if (security.indexOf(QString("WPA2")))
|
||||
if (security.indexOf(QString("WPA2")) > -1)
|
||||
security = QString("WPA2");
|
||||
else if (security.indexOf(QString("WPA")))
|
||||
else if (security.indexOf(QString("WPA")) > -1)
|
||||
security = QString("WPA");
|
||||
else if (security.indexOf(QString("WEP")))
|
||||
else if (security.indexOf(QString("WEP")) > -1)
|
||||
security = QString("WEP");
|
||||
else
|
||||
security = QString("none");
|
||||
|
@ -36,6 +36,8 @@ public:
|
||||
// functions
|
||||
bool wpaCliCall(QString commandLine);
|
||||
QString getWpaCliOutput(QString commandLine);
|
||||
bool isProfileExists(QString profile);
|
||||
bool isProfileActive(QString profile);
|
||||
|
||||
public slots:
|
||||
// functions
|
||||
|
Loading…
Reference in New Issue
Block a user