rewrite tables

This commit is contained in:
arcan1s
2014-08-06 13:12:18 +04:00
parent 0bade9c42f
commit 2aa6b43e61
11 changed files with 297 additions and 201 deletions

View File

@ -41,9 +41,9 @@ class NetctlProfile;
* @var netctlProfileInfo::description
* profile description
* @var netctlProfileInfo::active
* profile status
* whether profile is active
* @var netctlProfileInfo::enabled
* profile status
* whether profile is enabled
*/
typedef struct
{
@ -81,6 +81,16 @@ public:
*/
~Netctl();
// general information
/**
* @brief method which returns active profile name
* @return profile name or ""
*/
QString getActiveProfile();
/**
* @brief method which returns active profile name from netctl-auto
* @return profile name or ""
*/
QString autoGetActiveProfile();
/**
* @brief method which returns profile informations from netctl
* @return list of profiles
@ -174,6 +184,13 @@ public slots:
* @return true if the method was completed without errors
*/
bool startProfile(const QString profile);
/**
* @brief method which starts another profile
* @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
*/
bool switchToProfile(const QString profile);
// netctl-auto
/**
* @brief method which sets all profiles disabled (netctl-auto)

View File

@ -43,15 +43,18 @@ class NetctlProfile;
* may be "WPA2", "WEP", "WEP", "none"
* @var netctlWifiInfo::signal
* Wifi point signal
* @var netctlWifiInfo::status
* netctl status, may be "new", "exist (active)", "exist (inactive)"
* @var netctlWifiInfo::active
* whether associated profile is active
* @var netctlWifiInfo::exists
* whether associated profile exists
*/
typedef struct
{
QString name;
QString security;
QString signal;
QString status;
bool active;
bool exists;
} netctlWifiInfo;
/**

View File

@ -150,6 +150,44 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri
// general information
/**
* @fn getActiveProfile
*/
QString Netctl::getActiveProfile()
{
if (debug) qDebug() << "[Netctl]" << "[getActiveProfile]";
QString profile = QString("");
QList<netctlProfileInfo> fullProfilesInfo = getProfileList();
for (int i=0; i<fullProfilesInfo.count(); i++)
if (fullProfilesInfo[i].active) {
profile = fullProfilesInfo[i].name;
break;
}
return profile;
}
/**
* @fn autoGetActiveProfile
*/
QString Netctl::autoGetActiveProfile()
{
if (debug) qDebug() << "[Netctl]" << "[autoGetActiveProfile]";
QString profile = QString("");
QList<netctlProfileInfo> fullProfilesInfo = getProfileListFromNetctlAuto();
for (int i=0; i<fullProfilesInfo.count(); i++)
if (fullProfilesInfo[i].active) {
profile = fullProfilesInfo[i].name;
break;
}
return profile;
}
/**
* @fn getProfileList
*/
@ -164,7 +202,10 @@ QList<netctlProfileInfo> Netctl::getProfileList()
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.description = getProfileDescription(profileInfo.name);
profileInfo.active = isProfileActive(profileInfo.name);
if (output[i][0] == QChar('*'))
profileInfo.active = true;
else
profileInfo.active = false;
profileInfo.enabled = isProfileEnabled(profileInfo.name);
fullProfilesInfo.append(profileInfo);
}
@ -187,8 +228,12 @@ QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.description = getProfileDescription(profileInfo.name);
profileInfo.active = autoIsProfileActive(profileInfo.name);
profileInfo.enabled = autoIsProfileEnabled(profileInfo.name);
profileInfo.active = false;
profileInfo.enabled = true;
if (output[i][0] == QChar('*'))
profileInfo.active = true;
else if (output[i][0] == QChar('!'))
profileInfo.enabled = false;
fullProfilesInfo.append(profileInfo);
}
@ -320,12 +365,8 @@ bool Netctl::isNetctlAutoEnabled()
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;
else
return false;
return cmdCall(false, systemctlCommand, QString("is-enabled"), argument);
}
@ -346,12 +387,8 @@ bool Netctl::isNetctlAutoRunning()
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;
else
return false;
return cmdCall(false, systemctlCommand, QString("is-active"), argument);
}
@ -425,6 +462,21 @@ bool Netctl::startProfile(const QString profile)
}
/**
* @fn switchToProfile
*/
bool Netctl::switchToProfile(const QString profile)
{
if (debug) qDebug() << "[Netctl]" << "[switchToProfile]";
if (debug) qDebug() << "[Netctl]" << "[switchToProfile]" << ":" << "Profile" << profile;
if (isProfileActive(profile))
return true;
else
return cmdCall(true, netctlCommand, QString("switch-to"), profile);
}
/**
* @fn autoDisableAllProfiles
*/

View File

@ -210,17 +210,8 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
else
wifiPoint.name = QString("<hidden>");
// profile status
QString status;
if (isProfileExists(wifiPoint.name)) {
status = QString("exists");
if (isProfileActive(wifiPoint.name))
status = status + QString(" (active)");
else
status = status + QString(" (inactive)");
}
else
status = QString("new");
wifiPoint.status = status;
wifiPoint.active = isProfileActive(wifiPoint.name);
wifiPoint.exists = isProfileExists(wifiPoint.name);
// point signal
wifiPoint.signal = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2];
// point security