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