* edit WiFi and ProfileList calls

* optimization of WifiMenu
* small refactoring
This commit is contained in:
arcan1s
2015-03-07 17:12:33 +03:00
parent 9993fee336
commit 2cf876cf32
26 changed files with 207 additions and 153 deletions

View File

@ -40,6 +40,8 @@ class NetctlProfile;
* profile name
* @var netctlProfileInfo::description
* profile description
* @var netctlProfileInfo::essid
* ESSID if any
* @var netctlProfileInfo::active
* whether profile is active
* @var netctlProfileInfo::enabled
@ -49,6 +51,7 @@ typedef struct
{
QString name;
QString description;
QString essid;
bool active;
bool enabled;
} netctlProfileInfo;

View File

@ -85,6 +85,13 @@ public:
* @return value by key
*/
QString getValueFromProfile(const QString profile, const QString key);
/**
* @brief method which return values from profile by keys
* @param profile profile name
* @param keys required keys
* @return values by keys
*/
QStringList getValuesFromProfile(const QString profile, const QStringList keys);
/**
* @brief method which removes profile
* @param profile profile name

View File

@ -43,6 +43,10 @@ class NetctlProfile;
* may be "WPA2", "WEP", "WEP", "none"
* @var netctlWifiInfo::signal
* Wifi point signal
* @var netctlWifiInfo::macs
* point MAC addresses
* @var netctlWifiInfo::frequencies
* point frequencies
* @var netctlWifiInfo::active
* whether associated profile is active
* @var netctlWifiInfo::exists
@ -50,9 +54,11 @@ class NetctlProfile;
*/
typedef struct
{
QStringList frequencies;
QStringList macs;
QString name;
QString security;
QString signal;
int signal;
bool active;
bool exists;
} netctlWifiInfo;

View File

@ -189,9 +189,16 @@ QList<netctlProfileInfo> Netctl::getProfileList()
for (int i=0; i<output.count(); i++) {
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.description = getProfileDescription(profileInfo.name);
profileInfo.active = (output[i][0] == QChar('*'));
profileInfo.enabled = isProfileEnabled(profileInfo.name);
// external
QStringList keys;
keys.append(QString("Description"));
keys.append(QString("ESSID"));
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
keys);
profileInfo.description = profileValues[0];
profileInfo.essid = profileValues[1];
fullProfilesInfo.append(profileInfo);
}
@ -212,9 +219,16 @@ QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
for (int i=0; i<output.count(); i++) {
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.description = getProfileDescription(profileInfo.name);
profileInfo.active = (output[i][0] == QChar('*'));
profileInfo.enabled = (output[i][0] != QChar('!'));
// external
QStringList keys;
keys.append(QString("Description"));
keys.append(QString("ESSID"));
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
keys);
profileInfo.description = profileValues[0];
profileInfo.essid = profileValues[1];
fullProfilesInfo.append(profileInfo);
}

View File

@ -237,7 +237,7 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
/**
* @fn ValueFromProfile
* @fn getValueFromProfile
*/
QString NetctlProfile::getValueFromProfile(const QString profile, const QString key)
{
@ -251,6 +251,24 @@ QString NetctlProfile::getValueFromProfile(const QString profile, const QString
}
/**
* @fn getValuesFromProfile
*/
QStringList NetctlProfile::getValuesFromProfile(const QString profile, const QStringList keys)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (debug) qDebug() << PDEBUG << ":" << "Keys" << keys;
QMap<QString, QString> settings = getSettingsFromProfile(profile);
QStringList values;
for (int i=0; i<keys.count(); i++)
values.append(settings[keys[i]]);
return values;
}
/**
* @fn removeProfile
*/

View File

@ -264,39 +264,51 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
return scanResults;
}
if (!wpaCliCall(QString("scan"))) return scanResults;
waitForProcess(3);
waitForProcess(1);
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
QStringList rawList = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
// remove table header
rawOutput.removeFirst();
// remove duplicates
QStringList rawList;
rawList.removeFirst();
QStringList names;
for (int i=0; i<rawOutput.count(); i++) {
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 4) {
rawList.append(rawOutput[i]);
continue;
} else if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5) {
if (names.contains(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4])) continue;
names.append(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4]);
rawList.append(rawOutput[i]);
}
}
QList<netctlProfileInfo> profiles = netctlCommand->getProfileList();
for (int i=0; i<rawList.count(); i++) {
netctlWifiInfo wifiPoint;
QStringList line = rawList[i].split(QChar('\t'));
if (line.count() != 5) continue;
QString name = line[4];
if (name.isEmpty()) name = QString("<hidden>");
// append mac and frequency if exists
int index = names.indexOf(name);
if ((name != QString("<hidden>")) && (index > -1)) {
scanResults[index].frequencies.append(line[1]);
scanResults[index].macs.append(line[0]);
if (scanResults[index].signal < line[2].toInt())
scanResults[index].signal = line[2].toInt();
continue;
}
// point name
if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5)
wifiPoint.name = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4];
else
wifiPoint.name = QString("<hidden>");
netctlWifiInfo wifiPoint;
wifiPoint.name = name;
// profile status
wifiPoint.active = isProfileActive(wifiPoint.name);
wifiPoint.exists = isProfileExists(wifiPoint.name);
netctlProfileInfo profile;
profile.name = QString("");
profile.active = false;
for (int j=0; j<profiles.count(); j++) {
if (wifiPoint.name != profiles[j].essid) continue;
profile = profiles[j];
break;
}
wifiPoint.active = profile.active;
wifiPoint.exists = (!profile.name.isEmpty());
// mac
wifiPoint.macs.append(line[0]);
// frequencies
wifiPoint.frequencies.append(line[1]);
// point signal
wifiPoint.signal = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2];
wifiPoint.signal = line[2].toInt();
// point security
QString security = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[3];
QString security = line[3];
if (security.contains(QString("WPA2")))
security = QString("WPA2");
else if (security.contains(QString("WPA")))
@ -306,6 +318,9 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
else
security = QString("none");
wifiPoint.security = security;
// append
names.append(name);
scanResults.append(wifiPoint);
}
stopWpaSupplicant();