mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-08 03:15:54 +00:00
end work on interfaces
This commit is contained in:
@ -27,8 +27,5 @@
|
||||
#define NETCTLGUI_H
|
||||
|
||||
#include "netctlinterface.h"
|
||||
#include "netctlinteract.h"
|
||||
#include "netctlprofile.h"
|
||||
#include "wpasupinteract.h"
|
||||
|
||||
#endif /* NETCTLGUI_H */
|
||||
|
@ -50,6 +50,8 @@ class NetctlProfile;
|
||||
* whether profile is active
|
||||
* @var netctlProfileInfo::enabled
|
||||
* whether profile is enabled
|
||||
* @var netctlProfileInfo::netctlAuto
|
||||
* whether profile is from netctl-auto
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@ -60,6 +62,7 @@ typedef struct
|
||||
QString type;
|
||||
bool active = false;
|
||||
bool enabled = false;
|
||||
bool netctlAuto = false;
|
||||
} netctlProfileInfo;
|
||||
|
||||
/**
|
||||
|
@ -30,10 +30,10 @@
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
#include "netctlinteract.h"
|
||||
#include "netctlprofile.h"
|
||||
#include "wpasupinteract.h"
|
||||
|
||||
class Netctl;
|
||||
class NetctlProfile;
|
||||
class WpaSup;
|
||||
|
||||
/**
|
||||
* @enum InterfaceAnswer
|
||||
@ -51,6 +51,43 @@ enum InterfaceAnswer {
|
||||
Error
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct netctlCurrent
|
||||
* @brief current status structure
|
||||
* @var netctlCurrent::current
|
||||
* current profiles
|
||||
* @var netctlCurrent::enables
|
||||
* are current profiles enabled
|
||||
* @var netctlCurrent::netctlAuto
|
||||
* is netctl-auto active
|
||||
* @var netctlCurrent::profiles
|
||||
* list of profiles
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
QStringList current;
|
||||
QList<bool> enables;
|
||||
QStringList profiles;
|
||||
bool netctlAuto = false;
|
||||
} netctlCurrent;
|
||||
|
||||
/**
|
||||
* @struct netctlInformation
|
||||
* @brief general information structure
|
||||
* @var netctlCurrent::netctlProfiles
|
||||
* list of profiles
|
||||
* @var netctlCurrent::netctlAutoProfiles
|
||||
* list of netctl-auto profiles
|
||||
* @var netctlCurrent::netctlAuto
|
||||
* is netctl-auto active
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
QList<netctlProfileInfo> netctlProfiles;
|
||||
QList<netctlProfileInfo> netctlAutoProfiles;
|
||||
bool netctlAuto = false;
|
||||
} netctlInformation;
|
||||
|
||||
/**
|
||||
* @brief The NetctlInterface class provides complex methods to get access to library
|
||||
*/
|
||||
@ -70,6 +107,7 @@ public:
|
||||
* @brief NetctlInterface class destructor
|
||||
*/
|
||||
~NetctlInterface();
|
||||
// control methods
|
||||
/**
|
||||
* @brief method which enables or disables selected profile and returns its status
|
||||
* @remark netctl-auto only
|
||||
@ -127,6 +165,14 @@ public:
|
||||
* @return InterfaceAnswer::Error if an error occurs
|
||||
*/
|
||||
InterfaceAnswer enableProfile(const QString profile);
|
||||
/**
|
||||
* @brief method which removes selected profile
|
||||
* @remark netctl independ
|
||||
* @param profile profile name
|
||||
* @return InterfaceAnswer::True if profile does not exists anymore
|
||||
* @return InterfaceAnswer::Error if an error occurs
|
||||
*/
|
||||
InterfaceAnswer removeProfile(const QString profile);
|
||||
/**
|
||||
* @brief method which restarts selected profile and returns its status
|
||||
* @remark netctl only
|
||||
@ -161,6 +207,25 @@ public:
|
||||
* @return InterfaceAnswer::Error if an error occurs
|
||||
*/
|
||||
InterfaceAnswer switchToProfile(const QString profile);
|
||||
// information
|
||||
/**
|
||||
* @brief method which returns general information
|
||||
* @remark both netctl and netctl-auto
|
||||
* @return netctlInformation structure
|
||||
*/
|
||||
netctlInformation information();
|
||||
/**
|
||||
* @brief method which reads settings from profile
|
||||
* @param profile profile name
|
||||
* @return settings from profile
|
||||
*/
|
||||
QMap<QString, QString> profileSettings(const QString profile);
|
||||
/**
|
||||
* @brief method which returns current status
|
||||
* @remark both netctl and netctl-auto
|
||||
* @return netctlCurrent structure
|
||||
*/
|
||||
netctlCurrent status();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -203,6 +203,7 @@ QList<netctlProfileInfo> Netctl::getProfileList()
|
||||
profileInfo.essid = profileValues[2];
|
||||
profileInfo.interface = profileValues[3];
|
||||
profileInfo.type = profileValues[0];
|
||||
profileInfo.netctlAuto = false;
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
|
||||
@ -227,12 +228,18 @@ QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
|
||||
profileInfo.enabled = (output[i][0] != QChar('!'));
|
||||
// external
|
||||
QStringList keys;
|
||||
keys.append(QString("Connection"));
|
||||
keys.append(QString("Description"));
|
||||
keys.append(QString("ESSID"));
|
||||
keys.append(QString("Interface"));
|
||||
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
|
||||
keys);
|
||||
profileInfo.description = profileValues[0];
|
||||
profileInfo.description = profileValues[1];
|
||||
profileInfo.essid = profileValues[2];
|
||||
profileInfo.interface = profileValues[3];
|
||||
profileInfo.type = profileValues[0];
|
||||
profileInfo.essid = profileValues[1];
|
||||
profileInfo.netctlAuto = true;
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
#include <netctlgui/netctlinterface.h>
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
|
||||
@ -89,10 +89,11 @@ InterfaceAnswer NetctlInterface::connectToEssid(const QString essid, QMap<QStrin
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
if (wpaCommand->existentProfile(essid).isEmpty())
|
||||
QString profile = wpaCommand->existentProfile(essid);
|
||||
if (profile.isEmpty())
|
||||
return connectToUnknownEssid(essid, settings);
|
||||
else
|
||||
return connectToKnownEssid(essid);
|
||||
return startProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
@ -187,6 +188,24 @@ InterfaceAnswer NetctlInterface::enableProfile(const QString profile)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn removeProfile
|
||||
*/
|
||||
InterfaceAnswer NetctlInterface::removeProfile(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (netctlProfile == nullptr) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
if (netctlProfile->removeProfile(profile))
|
||||
return InterfaceAnswer::True;
|
||||
else
|
||||
return InterfaceAnswer::Error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn restartProfile
|
||||
*/
|
||||
@ -266,3 +285,67 @@ InterfaceAnswer NetctlInterface::switchToProfile(const QString profile)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn information
|
||||
*/
|
||||
netctlInformation NetctlInterface::information()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (netctlCommand == nullptr) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||
return netctlInformation();
|
||||
}
|
||||
|
||||
netctlInformation info;
|
||||
info.netctlAuto = netctlCommand->isNetctlAutoRunning();
|
||||
info.netctlProfiles = netctlCommand->getProfileList();
|
||||
if (info.netctlAuto) info.netctlAutoProfiles = netctlCommand->getProfileListFromNetctlAuto();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn profileSettings
|
||||
*/
|
||||
QMap<QString, QString> NetctlInterface::profileSettings(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (netctlProfile == nullptr) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||
return QMap<QString, QString>();
|
||||
}
|
||||
|
||||
return netctlProfile->getSettingsFromProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn status
|
||||
*/
|
||||
netctlCurrent NetctlInterface::status()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (netctlCommand == nullptr) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||
return netctlCurrent();
|
||||
}
|
||||
|
||||
netctlCurrent current;
|
||||
current.netctlAuto = netctlCommand->isNetctlAutoRunning();
|
||||
QList<netctlProfileInfo> profiles;
|
||||
if (current.netctlAuto)
|
||||
profiles = netctlCommand->getProfileListFromNetctlAuto();
|
||||
else
|
||||
profiles = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
current.profiles.append(profiles[i].name);
|
||||
if (!profiles[i].active) continue;
|
||||
current.current.append(profiles[i].name);
|
||||
current.enables.append(profiles[i].enabled);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
Reference in New Issue
Block a user