mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-09 20:05:53 +00:00
rewrite library to use task
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
# set files
|
||||
file (GLOB SOURCES *.cpp)
|
||||
file (GLOB HEADERS *.h)
|
||||
# set (HEADERS ${HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/task.h)
|
||||
|
||||
# include_path
|
||||
include_directories (${SUBPROJECT_INCLUDE_DIR}
|
||||
|
@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
#include "netctlgui.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -24,34 +24,9 @@
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
|
||||
#include "netctlgui.h"
|
||||
#include "task.h"
|
||||
|
||||
|
||||
struct TaskResult
|
||||
{
|
||||
int exitCode;
|
||||
QByteArray output;
|
||||
};
|
||||
|
||||
|
||||
TaskResult runTask(const QString cmd)
|
||||
{
|
||||
return Task::await<TaskResult>( [ & ]() {
|
||||
QProcess command;
|
||||
command.start(cmd);
|
||||
command.waitForFinished(-1);
|
||||
|
||||
TaskResult r;
|
||||
r.exitCode = command.exitCode();
|
||||
r.output = command.readAllStandardOutput();
|
||||
|
||||
return r;
|
||||
});
|
||||
}
|
||||
#include "taskadds.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -85,10 +60,6 @@ Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> settings)
|
||||
netctlAutoService = settings[QString("NETCTLAUTO_SERVICE")];
|
||||
else
|
||||
netctlAutoService = QString("netctl-auto");
|
||||
if (settings.contains(QString("PROFILE_DIR")))
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
else
|
||||
profileDirectory = new QDir(QString("/etc/netctl/"));
|
||||
if (settings.contains(QString("SUDO_PATH")))
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
else
|
||||
@ -111,212 +82,89 @@ Netctl::~Netctl()
|
||||
delete netctlProfile;
|
||||
if (ifaceDirectory != 0)
|
||||
delete ifaceDirectory;
|
||||
if (profileDirectory != 0)
|
||||
delete profileDirectory;
|
||||
}
|
||||
|
||||
|
||||
// functions
|
||||
/**
|
||||
* @fn getNetctlOutput
|
||||
* @fn cmdCall
|
||||
*/
|
||||
QString Netctl::getNetctlOutput(const bool sudo, const QString commandLine, const QString profile)
|
||||
bool Netctl::cmdCall(const bool sudo, const QString command, const QString commandLine, const QString argument)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Command" << commandLine;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Profile" << profile;
|
||||
if (netctlCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Could not find netctl";
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Command" << command;
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Command line" << commandLine;
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Argument" << argument;
|
||||
if (command == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Could not find command";
|
||||
return false;
|
||||
}
|
||||
if ((sudo) && (sudoCommand == 0)) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Could not find sudo";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString cmd = QString("");
|
||||
if (sudo) cmd = sudoCommand + QString(" ");
|
||||
cmd += command + QString(" ") + commandLine;
|
||||
if (argument != 0) cmd += QString(" ") + argument;
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getCmdOutput
|
||||
*/
|
||||
QString Netctl::getCmdOutput(const bool sudo, const QString command, const QString commandLine, const QString argument)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Command" << command;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Command line" << commandLine;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Argument" << argument;
|
||||
if (command == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Could not find command";
|
||||
return QString();
|
||||
}
|
||||
if ((sudo) && (sudoCommand == 0)) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Could not find sudo";
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Could not find sudo";
|
||||
return QString();
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine +
|
||||
QString(" ") + profile;
|
||||
else
|
||||
commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getNetctlOutput]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
QString cmd = QString("");
|
||||
if (sudo) cmd = sudoCommand + QString(" ");
|
||||
cmd += command + QString(" ") + commandLine;
|
||||
if (argument != 0) cmd += QString(" ") + argument;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
return command.readAllStandardOutput();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn netctlCall
|
||||
*/
|
||||
bool Netctl::netctlCall(const bool sudo, const QString commandLine, const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Command" << commandLine;
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Profile" << profile;
|
||||
if (netctlCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Could not find netctl";
|
||||
return false;
|
||||
}
|
||||
if ((sudo) && (sudoCommand == 0)) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Could not find sudo";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + netctlCommand + QString(" ") + commandLine +
|
||||
QString(" ") + profile;
|
||||
else
|
||||
commandText = netctlCommand + QString(" ") + commandLine + QString(" ") + profile;
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn netctlAutoCall
|
||||
*/
|
||||
bool Netctl::netctlAutoCall(const bool sudo, const QString commandLine, const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Command" << commandLine;
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Profile" << profile;
|
||||
if (netctlAutoCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Could not find netctl-auto";
|
||||
return false;
|
||||
}
|
||||
if ((sudo) && (sudoCommand == 0)) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Could not find sudo";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + netctlAutoCommand + QString(" ") + commandLine;
|
||||
else
|
||||
commandText = netctlAutoCommand + QString(" ") + commandLine;
|
||||
if (profile != 0)
|
||||
commandText = commandText + QString(" ") + profile;
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[netctlAutoCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn systemctlCall
|
||||
*/
|
||||
bool Netctl::systemctlCall(const bool sudo, const QString commandLine)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Command" << commandLine;
|
||||
if (netctlAutoService == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if ((sudo) && (sudoCommand == 0)) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Could not find sudo";
|
||||
return false;
|
||||
}
|
||||
if (systemctlCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Could not find systemctl";
|
||||
return false;
|
||||
}
|
||||
if (getInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString commandText;
|
||||
QString interface = getInterfaceList()[0];
|
||||
if (interface.isEmpty())
|
||||
return false;
|
||||
if (sudo)
|
||||
commandText = sudoCommand + QString(" ") + systemctlCommand + QString(" ") + commandLine +
|
||||
QString(" ") + netctlAutoService + QString("@") + interface + QString(".service");
|
||||
else
|
||||
commandText = systemctlCommand + QString(" ") + commandLine + QString(" ") + netctlAutoService +
|
||||
QString("@") + interface + QString(".service");
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[systemctlCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return process.output;
|
||||
}
|
||||
|
||||
|
||||
// general information
|
||||
/**
|
||||
* @fn getInterfaceList
|
||||
*/
|
||||
QStringList Netctl::getInterfaceList()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getInterfaceList]";
|
||||
if (ifaceDirectory == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getInterfaceList]" << ":" << "Could not find directory";
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList interfaces;
|
||||
if (!mainInterface.isEmpty())
|
||||
interfaces.append(mainInterface);
|
||||
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (int i=0; i<allInterfaces.count(); i++) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getProfileList
|
||||
*/
|
||||
QList<QStringList> Netctl::getProfileList()
|
||||
QList<netctlProfileInfo> Netctl::getProfileList()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileList]";
|
||||
if (profileDirectory == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileList]" << ":" << "Could not find directory";
|
||||
return QList<QStringList>();
|
||||
}
|
||||
|
||||
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]);
|
||||
QList<netctlProfileInfo> fullProfilesInfo;
|
||||
QStringList output = getCmdOutput(false, netctlCommand, QString("list"))
|
||||
.split(QChar('\n'), QString::SkipEmptyParts);
|
||||
for (int i=0; i<output.count(); i++) {
|
||||
netctlProfileInfo profileInfo;
|
||||
profileInfo.name = output[i].mid(2, -1);
|
||||
profileInfo.description = getProfileDescription(profileInfo.name);
|
||||
profileInfo.status = getProfileStatus(profileInfo.name);
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
|
||||
@ -327,26 +175,18 @@ QList<QStringList> Netctl::getProfileList()
|
||||
/**
|
||||
* @fn getProfileListFromNetctlAuto
|
||||
*/
|
||||
QList<QStringList> Netctl::getProfileListFromNetctlAuto()
|
||||
QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileListFromNetctlAuto]";
|
||||
if (netctlAutoCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileListFromNetctlAuto]" << ":" << "Could not find netctl-auto";
|
||||
return QList<QStringList>();
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString commandText = netctlAutoCommand + QString(" list");
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileListFromNetctlAuto]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
QStringList output = QString(command.readAllStandardOutput()).split(QChar('\n'), QString::SkipEmptyParts);
|
||||
QList<QStringList> fullProfilesInfo;
|
||||
QList<netctlProfileInfo> fullProfilesInfo;
|
||||
QStringList output = getCmdOutput(false, netctlAutoCommand, QString("list"))
|
||||
.split(QChar('\n'), QString::SkipEmptyParts);
|
||||
for (int i=0; i<output.count(); i++) {
|
||||
QStringList profileInfo;
|
||||
profileInfo.append(output[i].mid(2, -1));
|
||||
profileInfo.append(getProfileDescription(profileInfo[0]));
|
||||
profileInfo.append(output[i].left(1));
|
||||
netctlProfileInfo profileInfo;
|
||||
profileInfo.name = output[i].mid(2, -1);
|
||||
profileInfo.description = getProfileDescription(profileInfo.name);
|
||||
profileInfo.status = output[i].left(1);
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
|
||||
@ -370,26 +210,6 @@ QString Netctl::getProfileDescription(const QString profile)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getProfileDescriptions
|
||||
*/
|
||||
QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Profile list" << profileList;
|
||||
if (netctlProfile == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Could not find library";
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList descriptions;
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
descriptions.append(netctlProfile->getValueFromProfile(profileList[i], QString("Description")));
|
||||
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getProfileStatus
|
||||
*/
|
||||
@ -412,32 +232,6 @@ QString Netctl::getProfileStatus(const QString profile)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getProfileStatuses
|
||||
*/
|
||||
QStringList Netctl::getProfileStatuses(const QStringList profileList)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileStatuses]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileStatuses]" << ":" << "Profile list" << profileList;
|
||||
|
||||
QStringList statuses;
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
QString status;
|
||||
if (isProfileActive(profileList[i]))
|
||||
status = QString("active");
|
||||
else
|
||||
status = QString("inactive");
|
||||
if (isProfileEnabled(profileList[i]))
|
||||
status = status + QString(" (enabled)");
|
||||
else
|
||||
status = status + QString(" (static)");
|
||||
statuses.append(status);
|
||||
}
|
||||
|
||||
return statuses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn isProfileActive
|
||||
*/
|
||||
@ -447,8 +241,8 @@ bool Netctl::isProfileActive(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[isProfileActive]" << ":" << "Profile" << profile;
|
||||
|
||||
bool status = false;
|
||||
QString cmdOutput = getNetctlOutput(false, QString("status"), profile);
|
||||
if (cmdOutput.contains(QString("Active: active")))
|
||||
QString output = getCmdOutput(false, netctlCommand, QString("status"), profile);
|
||||
if (output.contains(QString("Active: active")))
|
||||
status = true;
|
||||
|
||||
return status;
|
||||
@ -463,7 +257,7 @@ bool Netctl::isProfileEnabled(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[isProfileEnabled]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[isProfileEnabled]" << ":" << "Profile" << profile;
|
||||
|
||||
return netctlCall(false, QString("is-enabled"), profile);
|
||||
return cmdCall(false, netctlCommand, QString("is-enabled"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -476,9 +270,9 @@ bool Netctl::autoIsProfileActive(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileActive]" << ":" << "Profile" << profile;
|
||||
|
||||
bool status = false;
|
||||
QList<QStringList> profiles = getProfileListFromNetctlAuto();
|
||||
QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto();
|
||||
for (int i=0; i<profiles.count(); i++)
|
||||
if ((profiles[i][0] == profile) && (profiles[i][2] == QString("*"))) {
|
||||
if ((profiles[i].name == profile) && (profiles[i].status == QString("*"))) {
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
@ -496,9 +290,9 @@ bool Netctl::autoIsProfileEnabled(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]" << ":" << "Profile" << profile;
|
||||
|
||||
bool status = true;
|
||||
QList<QStringList> profiles = getProfileListFromNetctlAuto();
|
||||
QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto();
|
||||
for (int i=0; i<profiles.count(); i++)
|
||||
if ((profiles[i][0] == profile) && (profiles[i][2] == QString("!"))) {
|
||||
if ((profiles[i].name == profile) && (profiles[i].status == QString("!"))) {
|
||||
status = false;
|
||||
break;
|
||||
}
|
||||
@ -517,24 +311,14 @@ bool Netctl::isNetctlAutoEnabled()
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (systemctlCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Could not find systemctl";
|
||||
return false;
|
||||
}
|
||||
if (getInterfaceList().isEmpty()) {
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString interface = getInterfaceList()[0];
|
||||
QString commandText = systemctlCommand + QString(" is-enabled ") + netctlAutoService + QString("@") +
|
||||
interface + QString(".service");
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Cmd returns" << command.exitCode();
|
||||
QString output = command.readAllStandardOutput().trimmed();
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
QString output = getCmdOutput(false, systemctlCommand, QString("is-enabled"), argument).trimmed();
|
||||
|
||||
if (output == QString("enabled"))
|
||||
return true;
|
||||
@ -553,24 +337,14 @@ bool Netctl::isNetctlAutoRunning()
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (systemctlCommand == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not find systemctl";
|
||||
return false;
|
||||
}
|
||||
if (getInterfaceList().isEmpty()) {
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
QString commandText = systemctlCommand + QString(" is-active ") + netctlAutoService + QString("@") +
|
||||
interface + QString(".service");
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Cmd returns" << command.exitCode();
|
||||
QString output = command.readAllStandardOutput().trimmed();
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
QString output = getCmdOutput(false, systemctlCommand, QString("is-active"), argument).trimmed();
|
||||
|
||||
if (output == QString("active"))
|
||||
return true;
|
||||
@ -579,6 +353,33 @@ bool Netctl::isNetctlAutoRunning()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn getWirelessInterfaceList
|
||||
*/
|
||||
QStringList Netctl::getWirelessInterfaceList()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getWirelessInterfaceList]";
|
||||
if (ifaceDirectory == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getWirelessInterfaceList]" << ":" << "Could not find directory";
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList interfaces;
|
||||
if (!mainInterface.isEmpty())
|
||||
interfaces.append(mainInterface);
|
||||
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for (int i=0; i<allInterfaces.count(); i++) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[getWirelessInterfaceList]" << ":" << "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
|
||||
/**
|
||||
* @fn enableProfile
|
||||
@ -589,9 +390,9 @@ bool Netctl::enableProfile(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[enableProfile]" << ":" << "Profile" << profile;
|
||||
|
||||
if (isProfileEnabled(profile))
|
||||
return netctlCall(true, QString("disable"), profile);
|
||||
return cmdCall(true, netctlCommand, QString("disable"), profile);
|
||||
else
|
||||
return netctlCall(true, QString("enable"), profile);
|
||||
return cmdCall(true, netctlCommand, QString("enable"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -603,7 +404,7 @@ bool Netctl::restartProfile(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[restartProfile]";
|
||||
if (debug) qDebug() << "[Netctl]" << "[restartProfile]" << ":" << "Profile" << profile;
|
||||
|
||||
return netctlCall(true, QString("restart"), profile);
|
||||
return cmdCall(true, netctlCommand, QString("restart"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -616,9 +417,9 @@ bool Netctl::startProfile(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[startProfile]" << ":" << "Profile" << profile;
|
||||
|
||||
if (isProfileActive(profile))
|
||||
return netctlCall(true, QString("stop"), profile);
|
||||
return cmdCall(true, netctlCommand, QString("stop"), profile);
|
||||
else
|
||||
return netctlCall(true, QString("start"), profile);
|
||||
return cmdCall(true, netctlCommand, QString("start"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -629,7 +430,7 @@ bool Netctl::autoDisableAllProfiles()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoDisableAllProfiles]";
|
||||
|
||||
return netctlAutoCall(false, QString("disable-all"));
|
||||
return cmdCall(false, netctlAutoCommand, QString("disable-all"));
|
||||
}
|
||||
|
||||
|
||||
@ -642,9 +443,9 @@ bool Netctl::autoEnableProfile(const QString profile)
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableProfile]" << ":" << "Profile" << profile;
|
||||
|
||||
if (autoIsProfileEnabled(profile))
|
||||
return netctlAutoCall(false, QString("disable"), profile);
|
||||
return cmdCall(false, netctlAutoCommand, QString("disable"), profile);
|
||||
else
|
||||
return netctlAutoCall(false, QString("enable"), profile);
|
||||
return cmdCall(false, netctlAutoCommand, QString("enable"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -655,7 +456,7 @@ bool Netctl::autoEnableAllProfiles()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableAllProfiles]";
|
||||
|
||||
return netctlAutoCall(false, QString("enable-all"));
|
||||
return cmdCall(false, netctlAutoCommand, QString("enable-all"));
|
||||
}
|
||||
|
||||
|
||||
@ -670,7 +471,7 @@ bool Netctl::autoStartProfile(const QString profile)
|
||||
if (autoIsProfileActive(profile))
|
||||
return true;
|
||||
else
|
||||
return netctlAutoCall(false, QString("switch-to"), profile);
|
||||
return cmdCall(false, netctlAutoCommand, QString("switch-to"), profile);
|
||||
}
|
||||
|
||||
|
||||
@ -680,11 +481,22 @@ bool Netctl::autoStartProfile(const QString profile)
|
||||
bool Netctl::autoEnableService()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]";
|
||||
if (netctlAutoService == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoEnabled())
|
||||
return systemctlCall(true, QString("disable"));
|
||||
return cmdCall(true, systemctlCommand, QString("disable"), argument);
|
||||
else
|
||||
return systemctlCall(true, QString("enable"));
|
||||
return cmdCall(true, systemctlCommand, QString("enable"), argument);
|
||||
}
|
||||
|
||||
|
||||
@ -694,9 +506,20 @@ bool Netctl::autoEnableService()
|
||||
bool Netctl::autoRestartService()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]";
|
||||
if (netctlAutoService == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoRunning())
|
||||
return systemctlCall(true, QString("restart"));
|
||||
return cmdCall(true, systemctlCommand, QString("restart"), argument);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
@ -708,9 +531,20 @@ bool Netctl::autoRestartService()
|
||||
bool Netctl::autoStartService()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoStartService]";
|
||||
if (netctlAutoService == 0) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoRunning())
|
||||
return systemctlCall(true, QString("stop"));
|
||||
return cmdCall(true, systemctlCommand, QString("stop"), argument);
|
||||
else
|
||||
return systemctlCall(true, QString("start"));
|
||||
return cmdCall(true, systemctlCommand, QString("start"), argument);
|
||||
}
|
||||
|
@ -26,10 +26,10 @@
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "netctlgui.h"
|
||||
#include "taskadds.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -72,22 +72,21 @@ bool NetctlProfile::copyProfile(const QString oldPath)
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]";
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Path" << oldPath;
|
||||
if (profileDirectory == 0) {
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[profileDirectory]" << ":" << "Could not find directory";
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Could not find directory";
|
||||
return false;
|
||||
}
|
||||
if (sudoCommand == 0) {
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[profileDirectory]" << ":" << "Could not find sudo";
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Could not find sudo";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName();
|
||||
QString commandText = sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath;
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
QString cmd = sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath;
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -220,14 +219,13 @@ bool NetctlProfile::removeProfile(const QString profile)
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString profilePath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName();
|
||||
QString commandText = sudoCommand + QString(" /usr/bin/rm ") + profilePath;
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
QString cmd = sudoCommand + QString(" /usr/bin/rm ") + profilePath;
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
@ -1 +0,0 @@
|
||||
../include/netctlgui/sleepthread.h
|
1
sources/netctlgui/src/taskadds.cpp
Symbolic link
1
sources/netctlgui/src/taskadds.cpp
Symbolic link
@ -0,0 +1 @@
|
||||
../../3rdparty/task/taskadds.cpp
|
1
sources/netctlgui/src/taskadds.h
Symbolic link
1
sources/netctlgui/src/taskadds.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../3rdparty/task/taskadds.h
|
@ -24,9 +24,9 @@
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
|
||||
#include "netctlgui.h"
|
||||
#include "taskadds.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -69,10 +69,6 @@ WpaSup::WpaSup(const bool debugCmd, const QMap<QString, QString> settings)
|
||||
wpaSupPath = settings[QString("WPASUP_PATH")];
|
||||
else
|
||||
wpaSupPath = QString("/usr/bin/wpa_supplicant");
|
||||
|
||||
// terminate old loaded profile
|
||||
if (QFile(pidFile).exists() || QDir(ctrlDir).exists())
|
||||
stopWpaSupplicant();
|
||||
}
|
||||
|
||||
|
||||
@ -108,10 +104,10 @@ QString WpaSup::existentProfile(const QString essid)
|
||||
}
|
||||
|
||||
QString profileFile = QString("");
|
||||
QList<QStringList> profileList = netctlCommand->getProfileList();
|
||||
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i][0], QString("ESSID")))
|
||||
profileFile = profileList[i][0];
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i].name, QString("ESSID")))
|
||||
profileFile = profileList[i].name;
|
||||
|
||||
return profileFile;
|
||||
}
|
||||
@ -134,10 +130,10 @@ bool WpaSup::isProfileActive(const QString essid)
|
||||
}
|
||||
|
||||
QString profileFile;
|
||||
QList<QStringList> profileList = netctlCommand->getProfileList();
|
||||
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i][0], QString("ESSID"))) {
|
||||
profileFile = profileList[i][0];
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i].name, QString("ESSID"))) {
|
||||
profileFile = profileList[i].name;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -162,9 +158,9 @@ bool WpaSup::isProfileExists(const QString essid)
|
||||
}
|
||||
|
||||
bool exists = false;
|
||||
QList<QStringList> profileList = netctlCommand->getProfileList();
|
||||
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profileList.count(); i++)
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i][0], QString("ESSID"))) {
|
||||
if (essid == netctlProfile->getValueFromProfile(profileList[i].name, QString("ESSID"))) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
@ -176,18 +172,18 @@ bool WpaSup::isProfileExists(const QString essid)
|
||||
/**
|
||||
* @fn scanWifi
|
||||
*/
|
||||
QList<QStringList> WpaSup::scanWifi()
|
||||
QList<netctlWifiInfo> WpaSup::scanWifi()
|
||||
{
|
||||
if (debug) qDebug() << "[WpaSup]" << "[scanWifi]";
|
||||
|
||||
QList<QStringList> scanResults;
|
||||
QList<netctlWifiInfo> scanResults;
|
||||
if (!startWpaSupplicant()) {
|
||||
stopWpaSupplicant();
|
||||
return scanResults;
|
||||
}
|
||||
if (!wpaCliCall(QString("scan")))
|
||||
return scanResults;
|
||||
SleepThread::sleep(3);
|
||||
waitForProcess(3);
|
||||
|
||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
|
||||
// remove table header
|
||||
@ -207,26 +203,26 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
}
|
||||
|
||||
for (int i=0; i<rawList.count(); i++) {
|
||||
QStringList wifiPoint;
|
||||
netctlWifiInfo wifiPoint;
|
||||
// point name
|
||||
if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
||||
wifiPoint.append(rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4]);
|
||||
wifiPoint.name = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4];
|
||||
else
|
||||
wifiPoint.append(QString("<hidden>"));
|
||||
wifiPoint.name = QString("<hidden>");
|
||||
// profile status
|
||||
QString status;
|
||||
if (isProfileExists(wifiPoint[0])) {
|
||||
if (isProfileExists(wifiPoint.name)) {
|
||||
status = QString("exists");
|
||||
if (isProfileActive(wifiPoint[0]))
|
||||
if (isProfileActive(wifiPoint.name))
|
||||
status = status + QString(" (active)");
|
||||
else
|
||||
status = status + QString(" (inactive)");
|
||||
}
|
||||
else
|
||||
status = QString("new");
|
||||
wifiPoint.append(status);
|
||||
wifiPoint.status = status;
|
||||
// point signal
|
||||
wifiPoint.append(rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2]);
|
||||
wifiPoint.signal = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2];
|
||||
// point security
|
||||
QString security = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[3];
|
||||
if (security.contains(QString("WPA2")))
|
||||
@ -237,7 +233,7 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
security = QString("WEP");
|
||||
else
|
||||
security = QString("none");
|
||||
wifiPoint.append(security);
|
||||
wifiPoint.security = security;
|
||||
scanResults.append(wifiPoint);
|
||||
}
|
||||
stopWpaSupplicant();
|
||||
@ -280,25 +276,23 @@ bool WpaSup::startWpaSupplicant()
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find library";
|
||||
return false;
|
||||
}
|
||||
if (netctlCommand->getInterfaceList().isEmpty()) {
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find interfaces";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (QFile(pidFile).exists())
|
||||
return true;
|
||||
QProcess command;
|
||||
QString interface = netctlCommand->getInterfaceList()[0];
|
||||
QString commandText = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString cmd = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
||||
QString(" -i ") + interface + QString(" -D ") + wpaDrivers +
|
||||
QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\"");
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << command.exitCode();
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
waitForProcess(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@ -340,20 +334,34 @@ QString WpaSup::getWpaCliOutput(const QString commandLine)
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find library";
|
||||
return QString();
|
||||
}
|
||||
if (netctlCommand->getInterfaceList().isEmpty()) {
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find interfaces";
|
||||
return QString();
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString interface = netctlCommand->getInterfaceList()[0];
|
||||
QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
return command.readAllStandardOutput();
|
||||
return process.output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn waitForProcess
|
||||
*/
|
||||
bool WpaSup::waitForProcess(const int sec)
|
||||
{
|
||||
if (debug) qDebug() << "[WpaSup]" << "[waitForProcess]";
|
||||
if (debug) qDebug() << "[WpaSup]" << "[waitForProcess]" << ":" << "Interval" << sec;
|
||||
|
||||
QString cmd = QString("sleep %1").arg(QString::number(sec));
|
||||
runTask(cmd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -380,22 +388,20 @@ bool WpaSup::wpaCliCall(const QString commandLine)
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find library";
|
||||
return false;
|
||||
}
|
||||
if (netctlCommand->getInterfaceList().isEmpty()) {
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find interfaces";
|
||||
return false;
|
||||
}
|
||||
|
||||
QProcess command;
|
||||
QString interface = netctlCommand->getInterfaceList()[0];
|
||||
QString commandText = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Run cmd" << commandText;
|
||||
command.start(commandText);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Cmd returns" << command.exitCode();
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd);
|
||||
waitForProcess(1);
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
if (command.exitCode() == 0)
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user