rewrite library to use task

This commit is contained in:
arcan1s 2014-08-05 23:32:12 +04:00
parent 297a18d530
commit 64937105c6
19 changed files with 365 additions and 547 deletions

View File

@ -63,7 +63,6 @@ Additional information
TODO (wish list)
----------------
* refactoring of library (using QtNetwork module instead of some system calls)
* refactoring of GUI according to library changes
* rewrite changelog to more comfortable format

34
sources/3rdparty/task/taskadds.cpp vendored Normal file
View File

@ -0,0 +1,34 @@
/***************************************************************************
* This file is part of netctl-gui *
* *
* netctl-gui 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-gui 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-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "taskadds.h"
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;
});
}

View File

@ -14,54 +14,22 @@
* You should have received a copy of the GNU General Public License *
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
/**
* @file sleepthread.h
* Header of netctlgui library
* @author Evgeniy Alekseev
* @copyright GPLv3
* @bug https://github.com/arcan1s/netctl-gui/issues
*/
#ifndef SLEEPTHREAD_H
#define SLEEPTHREAD_H
#ifndef TASKADDS_H
#define TASKADDS_H
#include <QThread>
#include <QProcess>
#include "task.h"
/**
* @brief The SleepThread class is used for sleep current thread in WpaSup class
*/
class SleepThread : public QThread
struct TaskResult
{
Q_OBJECT
public:
/**
* @brief method which forces the current thread to sleep for usecs microseconds
* @param iSleepTime time in microseconds
*/
static void usleep(long iSleepTime)
{
QThread::usleep(iSleepTime);
}
/**
* @brief method which forces the current thread to sleep for usecs seconds
* @param iSleepTime time in seconds
*/
static void sleep(long iSleepTime)
{
QThread::sleep(iSleepTime);
}
/**
* @brief method which forces the current thread to sleep for usecs milliseconds
* @param iSleepTime time in milliseconds
*/
static void msleep(long iSleepTime)
{
QThread::msleep(iSleepTime);
}
int exitCode;
QByteArray output;
};
TaskResult runTask(const QString cmd);
#endif /* SLEEPTHREAD_H */
#endif /* TASKADDS_H */

View File

@ -15,9 +15,6 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "netctl.h"
#include "task.h"
#include <KGlobal>
#include <KStandardDirs>
#include <Plasma/DataContainer>
@ -28,28 +25,8 @@
#include <QProcessEnvironment>
#include <QTextCodec>
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 "netctl.h"
#include "taskadds.h"
Netctl::Netctl(QObject *parent, const QVariantList &args)

View File

@ -0,0 +1 @@
../3rdparty/task/taskadds.cpp

View File

@ -0,0 +1 @@
../3rdparty/task/taskadds.h

View File

@ -13,7 +13,6 @@ add_custom_target (oxygen-docs ALL COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT
set (MAN_DIR ${CMAKE_CURRENT_BINARY_DIR}/docs/man/man3)
install (FILES ${MAN_DIR}/Netctl.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_Netctl.3)
install (FILES ${MAN_DIR}/NetctlProfile.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_NetctlProfile.3)
install (FILES ${MAN_DIR}/SleepThread.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_SleepThread.3)
install (FILES ${MAN_DIR}/WpaSup.3 DESTINATION share/man/man3 RENAME ${SUBPROJECT}_WpaSup.3)
# html docs
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/html DESTINATION share/doc/${SUBPROJECT})

View File

@ -28,8 +28,6 @@
#include "netctlinteract.h"
#include "netctlprofile.h"
#include "sleepthread.h"
#include "wpasupinteract.h"
#endif /* NETCTLGUI_H */

View File

@ -33,6 +33,23 @@
class NetctlProfile;
/**
* @struct netctlProfileInfo
* @brief netctl profile information structure
* @var netctlProfileInfo::name
* profile name
* @var netctlProfileInfo::description
* profile description
* @var netctlProfileInfo::status
* profile status
*/
typedef struct
{
QString name;
QString description;
QString status;
} netctlProfileInfo;
/**
* @brief The Netctl class interacts with netctl
*/
@ -61,39 +78,22 @@ public:
*/
~Netctl();
// general information
/**
* @brief method which gets interface list from PREFERED_IFACE and IFACE_DIR
* @return interface list. If PREFERED_IFACE is not empty it will be first element
*/
QStringList getInterfaceList();
/**
* @brief method which returns profile informations from netctl
* @return list of profiles. Available information is [NAME, DESCRIPTION, STATUS]:
* NAME is a profile name,
* DESCRIPTION is a profile description (see more details below),
* STATUS is a profile status (see more details below)
* @return list of profiles
*/
QList<QStringList> getProfileList();
QList<netctlProfileInfo> getProfileList();
/**
* @brief method which returns profile informations from netctl-auto
* @return list of profiles. Available information is [NAME, DESCRIPTION, STATUS]:
* NAME is a profile name,
* DESCRIPTION is a profile description (see more details below),
* STATUS is a profile status (see more details below)
* @return list of profiles from netctl-auto
*/
QList<QStringList> getProfileListFromNetctlAuto();
QList<netctlProfileInfo> getProfileListFromNetctlAuto();
/**
* @brief method which gets description from profile
* @param profile profile name
* @return profile description or ""
*/
QString getProfileDescription(const QString profile);
/**
* @brief method which gets descriptions from profile list
* @param profileList profile names
* @return list of profile descriptions (if description is not available returns "")
*/
QStringList getProfileDescriptions(const QStringList profileList);
/**
* @brief method which gets profile status
* @param profile profile name
@ -101,13 +101,6 @@ public:
* "inactive (enabled)", "inactive (static)"
*/
QString getProfileStatus(const QString profile);
/**
* @brief method which gets statuses of profile list
* @param profileList profile names
* @return list of profile statuses. It may be "active (enabled)", "active (static)",
* "inactive (enabled)", "inactive (static)"
*/
QStringList getProfileStatuses(const QStringList profileList);
/**
* @brief method which checks if profile is active
* @param profile profile name
@ -148,6 +141,11 @@ public:
* @return true if netctl-auto is active
*/
bool isNetctlAutoRunning();
/**
* @brief method which gets wireless interface list from PREFERED_IFACE and IFACE_DIR
* @return interface list. If PREFERED_IFACE is not empty it will be first element
*/
QStringList getWirelessInterfaceList();
public slots:
// functions
@ -249,10 +247,6 @@ private:
* @brief netctl-auto service name. Default is "netctl-auto"
*/
QString netctlAutoService;
/**
* @brief directory which contains profiles. Default is "/etc/netctl"
*/
QDir *profileDirectory;
/**
* @brief path to sudo command. Default is "/usr/bin/kdesu"
*/
@ -263,39 +257,26 @@ private:
QString systemctlCommand;
// functions
/**
* @brief method which calls netctl and returns its output
* @brief method which calls command
* @param sudo set true if sudo is needed
* @param commandLine command which will be passed to netctl
* @param profile profile name
* @return netctl output
*/
QString getNetctlOutput(const bool sudo, const QString commandLine, const QString profile = 0);
/**
* @brief method which calls netctl
* @param sudo set true if sudo is needed
* @param commandLine command which will be passed to netctl
* @param profile profile name
* @param command command which will be called
* @param commandLine command which will be passed to command
* @param argument argument which will be passed to commandLine
* @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors
*/
bool netctlCall(const bool sudo, const QString commandLine, const QString profile = 0);
bool cmdCall(const bool sudo, const QString command,
const QString commandLine, const QString argument = 0);
/**
* @brief method which calls netctl-auto
* @brief method which calls command and returns its output
* @param sudo set true if sudo is needed
* @param commandLine command which will be passed to netctl-auto
* @param profile profile name
* @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors
* @param command command which will be called
* @param commandLine command which will be passed to command
* @param argument argument which will be passed to commandLine
* @return command output
*/
bool netctlAutoCall(const bool sudo, const QString commandLine, const QString profile = 0);
/**
* @brief method which calls systemctl associated with netctl-auto
* @param sudo set true if sudo is needed
* @param commandLine command which will be passed to systemctl
* @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors
*/
bool systemctlCall(const bool sudo, const QString commandLine);
QString getCmdOutput(const bool sudo, const QString command,
const QString commandLine, const QString argument = 0);
};

View File

@ -34,6 +34,26 @@
class Netctl;
class NetctlProfile;
/**
* @struct netctlWifiInfo
* @brief WiFi information structure
* @var netctlWifiInfo::name
* ESSID
* @var netctlWifiInfo::security
* may be "WPA2", "WEP", "WEP", "none"
* @var netctlWifiInfo::signal
* Wifi point signal
* @var netctlWifiInfo::status
* netctl status, may be "new", "exist (active)", "exist (inactive)"
*/
typedef struct
{
QString name;
QString security;
QString signal;
QString status;
} netctlWifiInfo;
/**
* @brief The WpaSup class interacts with wpa_supplicant
*/
@ -86,13 +106,9 @@ public slots:
// functions
/**
* @brief method which scans WiFi networks
* @return list of essids. Available information is [NAME, NETCTL_STATUS, SIGNAL, SECUITY]:
* NAME is WiFi point name or "<hidden>",
* NETCTL_STATUS may be "new", "exist (active)", "exist (inactive)",
* SIGNAL is Wifi point signal,
* SECURITY may be "WPA2", "WEP", "WEP", "none"
* @return list of essids
*/
QList<QStringList> scanWifi();
QList<netctlWifiInfo> scanWifi();
/**
* @brief method which calls wpa_supplicant
* @return false if components are not found or command exit code is not equal to 0
@ -154,6 +170,11 @@ private:
* @return wpa_cli output
*/
QString getWpaCliOutput(const QString commandLine);
/**
* @brief method which will be called to sleep thread
* @param sec time interval, seconds
*/
bool waitForProcess(const int sec);
/**
* @brief method which calls wpa_cli
* @param commandLine command which will be passed to wpa_cli

View File

@ -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}

View File

@ -23,7 +23,7 @@
*/
#include <netctlgui/netctlgui.h>
#include "netctlgui.h"
/**

View File

@ -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);
}

View File

@ -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;

View File

@ -1 +0,0 @@
../include/netctlgui/sleepthread.h

View File

@ -0,0 +1 @@
../../3rdparty/task/taskadds.cpp

View File

@ -0,0 +1 @@
../../3rdparty/task/taskadds.h

View File

@ -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;

View File

@ -15,10 +15,6 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "netctl.h"
#include <ui_appearance.h>
#include <ui_widget.h>
#include <KConfigDialog>
#include <KFileDialog>
#include <KGlobal>
@ -32,7 +28,12 @@
#include <QMenu>
#include <QProcessEnvironment>
#include <version.h>
#include "netctl.h"
#include "ui_about.h"
#include "ui_appearance.h"
#include "ui_dataengine.h"
#include "ui_widget.h"
#include "version.h"
IconLabel::IconLabel(Netctl *wid, const bool debugCmd)
@ -68,8 +69,8 @@ Netctl::Netctl(QObject *parent, const QVariantList &args)
else
debug = false;
this->setBackgroundHints(DefaultBackground);
this->setHasConfigurationInterface(true);
setBackgroundHints(DefaultBackground);
setHasConfigurationInterface(true);
connect(this, SIGNAL(activate()), this, SLOT(showGui()));
// text format init
formatLine.append(QString(""));
@ -112,7 +113,7 @@ void Netctl::init()
// generate ui
graphicsWidget = new QWidget();
graphicsWidget->setAttribute(Qt::WA_TranslucentBackground, true);
this->setWidget(graphicsWidget);
setWidget(graphicsWidget);
// layouts
layout = new QHBoxLayout(graphicsWidget);
layout->setContentsMargins(1, 1, 1, 1);
@ -262,7 +263,7 @@ void Netctl::updateIcon()
else
icon = paths[QString("inactive")];
this->setPopupIcon(KIcon(icon));
setPopupIcon(KIcon(icon));
QPixmap iconPixmap;
iconPixmap.load(icon);
iconLabel->setPixmap(iconPixmap);
@ -279,7 +280,7 @@ void Netctl::updateInterface(bool setShown)
else
layout->removeWidget(textLabel);
graphicsWidget->adjustSize();
this->resize(1, 1);
resize(1, 1);
}
@ -580,7 +581,7 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da
info[QString("status")] = QString("(") + value + QString(")");
}
this->update();
update();
}