small commit

This commit is contained in:
arcan1s 2014-02-06 11:06:36 +04:00
parent fc43861ba6
commit 4a2a27176f
8 changed files with 203 additions and 18 deletions

4
sources/gui/show_scripts Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
kate /usr/lib/network/wpa /usr/lib/network/globals /usr/bin/wifi-menu &> /dev/null

View File

@ -37,12 +37,18 @@ MainWindow::MainWindow(QWidget *parent)
// temporary block
netctlPath = QString("/usr/bin/netctl");
profileDir = QString("/etc/netctl");
sudoPath = QString("/usr/bin/kdesu -c");
wpaCliPath = QString("/usr/bin/wpa_cli");
sudoPath = QString("/usr/bin/kdesu");
wpaConfig.append(QString("/usr/bin/wpa_cli"));
wpaConfig.append(QString("/usr/bin/wpa_supplicant"));
ifaceDir = QString("/sys/class/net/");
preferedInterface = QString("wifi0");
// additional settings
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui.pid"));
wpaConfig.append(QString("nl80211,wext"));
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui"));
netctlCommand = new Netctl(this, netctlPath, profileDir, sudoPath);
wpaCliCommand = new WpaSup(this, wpaCliPath, ifaceDir);
wpaCommand = new WpaSup(this, wpaConfig, sudoPath, ifaceDir, preferedInterface);
createActions();
updateMainTab();
@ -51,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
delete netctlCommand;
delete wpaCommand;
delete ui;
}
@ -106,7 +113,9 @@ void MainWindow::updateMainTab()
void MainWindow::updateWifiTab()
{
QList<QStringList> scanResults = wpaCommand->scanWifi();
for (int i=0; i<scanResults.count(); i++)
printf("%s\n", scanResults[i][0].toUtf8().data());
}

View File

@ -38,6 +38,13 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
enum wpaConfigIndex {
wpaCliPath = 0,
wpaSupplicantPath = 1,
wpaPidPath = 2,
wpadSupDrivers = 3,
wpaConfDir = 4
};
private slots:
void updateTabs(const int tab);
@ -51,15 +58,16 @@ private slots:
private:
Netctl *netctlCommand;
WpaSup *wpaCliCommand;
WpaSup *wpaCommand;
Ui::MainWindow *ui;
void createActions();
// configuration
QString netctlPath;
QString profileDir;
QString sudoPath;
QString wpaCliPath;
QStringList wpaConfig;
QString ifaceDir;
QString preferedInterface;
};

View File

@ -66,6 +66,9 @@
<property name="text">
<string>Refresh</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
@ -181,6 +184,9 @@
<property name="text">
<string>Refresh</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>

View File

@ -37,6 +37,8 @@ public:
QStringList getProfileStatuses(QStringList profileList);
bool isProfileActive(QString profile);
bool isProfileEnabled(QString profile);
public slots:
// functions
bool enableProfile(QString profile);
bool restartProfile(QString profile);

View File

@ -0,0 +1,46 @@
/***************************************************************************
* This file is part of netctl-plasmoid *
* *
* netctl-plasmoid is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* netctl-plasmoid is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with netctl-plasmoid. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef SLEEPTHREAD_H
#define SLEEPTHREAD_H
#include <QThread>
// class for sleeping function
class SleepThread : public QThread
{
Q_OBJECT
// private run
void run () {}
public :
static void usleep(long iSleepTime)
{
QThread::usleep(iSleepTime);
}
static void sleep(long iSleepTime)
{
QThread::sleep(iSleepTime);
}
static void msleep(long iSleepTime)
{
QThread::msleep(iSleepTime);
}
};
#endif /* SLEEPTHREAD_H */

View File

@ -17,16 +17,25 @@
#include "wpasupinteract.h"
#include <QProcess>
#include "mainwindow.h"
#include "sleepthread.h"
#include <cstdio>
WpaSup::WpaSup(MainWindow *wid, QString wpaCliPath, QString ifaceDir)
WpaSup::WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDir, QString preferedInterface)
: parent(wid),
wpaCliCommand(wpaCliPath),
ifaceDirectory(new QDir(ifaceDir))
wpaConf(wpaConfig),
sudoCommand(sudoPath),
ifaceDirectory(new QDir(ifaceDir)),
mainInterface(preferedInterface)
{
if (QFile(wpaConf[2]).exists()) {
QProcess command;
command.start(sudoCommand + QString(" /usr/bin/rm -f ") + wpaConf[2]);
command.waitForFinished(-1);
}
}
@ -40,13 +49,103 @@ WpaSup::~WpaSup()
QStringList WpaSup::getInterfaceList()
{
QStringList interfaces;
QStringList allInterfaces;
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())
interfaces.append(allInterfaces[i]);
if (mainInterface.isEmpty()) {
QStringList allInterfaces;
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())
interfaces.append(allInterfaces[i]);
}
else
interfaces.append(mainInterface);
return interfaces;
}
// functions
bool WpaSup::wpaCliCall(QString commandLine)
{
QString interface = getInterfaceList()[0];
QProcess command;
command.start(sudoCommand + QString(" ") + wpaConf[0] + QString(" -i ") + interface +
QString(" -p ") + wpaConf[4] + QString(" ") + commandLine);
command.waitForFinished(-1);
SleepThread::sleep(1);
if (command.exitCode() == 0)
return true;
else
return false;
}
QString WpaSup::getWpaCliOutput(QString commandLine)
{
QString interface = getInterfaceList()[0];
QProcess command;
command.start(sudoCommand + QString(" ") + wpaConf[0] + QString(" -i ") + interface +
QString(" -p ") + wpaConf[4] + QString(" ") + commandLine);
command.waitForFinished(-1);
return command.readAllStandardOutput();
}
bool WpaSup::startWpaSupplicant()
{
if (!QFile(wpaConf[2]).exists()) {
QString interface = getInterfaceList()[0];
QProcess command;
command.start(sudoCommand + QString(" ") + wpaConf[1] + QString(" -B -P ") + wpaConf[2] +
QString(" -i ") + interface + QString(" -D ") + wpaConf[3] + QString(" -C ") + wpaConf[4]);
command.waitForFinished(-1);
SleepThread::sleep(1);
if (command.exitCode() != 0)
return false;
}
return true;
}
bool WpaSup::stopWpaSupplicant()
{
return wpaCliCall(QString("terminate"));
}
QList<QStringList> WpaSup::scanWifi()
{
QList<QStringList> scanResults;
startWpaSupplicant();
if (!wpaCliCall(QString("scan")))
return scanResults;
SleepThread::sleep(3);
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"));
rawOutput.removeFirst();
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);
for (int i=0; i<rawOutput.count(); i++) {
QStringList wifiPoint;
if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts).count() > 4)
wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[4]);
else
wifiPoint.append(QString("<hidden>"));
wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[2]);
wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[1]);
wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[0]);
scanResults.append(wifiPoint);
}
stopWpaSupplicant();
return scanResults;
}

View File

@ -29,15 +29,26 @@ class WpaSup : public QWidget
Q_OBJECT
public:
WpaSup(MainWindow *wid, QString wpaCliPath, QString ifaceDir);
WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDir, QString preferedInterface);
~WpaSup();
// general information
QStringList getInterfaceList();
// functions
bool wpaCliCall(QString commandLine);
QString getWpaCliOutput(QString commandLine);
public slots:
// functions
bool startWpaSupplicant();
bool stopWpaSupplicant();
QList<QStringList> scanWifi();
private:
MainWindow *parent;
QString wpaCliCommand;
QStringList wpaConf;
QString sudoCommand;
QDir *ifaceDirectory;
QString mainInterface;
};