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

@ -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,59 +78,35 @@ 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
* @param profile profile name
* @return profile status. It may be "active (enabled)", "active (static)",
* "inactive (enabled)", "inactive (static)"
* "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
* @return false if profile is inactive
* @return true if profile is active
*/
* @brief method which checks if profile is active
* @param profile profile name
* @return false if profile is inactive
* @return true if profile is active
*/
bool isProfileActive(const QString profile);
/**
* @brief method which checks if profile is enabled
@ -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

@ -1,67 +0,0 @@
/***************************************************************************
* 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/ *
***************************************************************************/
/**
* @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
#include <QThread>
/**
* @brief The SleepThread class is used for sleep current thread in WpaSup class
*/
class SleepThread : public QThread
{
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);
}
};
#endif /* SLEEPTHREAD_H */

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