mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-05 10:05:46 +00:00
intermediate commit
This commit is contained in:
@ -33,6 +33,8 @@ public:
|
||||
~Netctl();
|
||||
// general information
|
||||
QList<QStringList> getProfileList();
|
||||
QList<QStringList> getProfileListFromNetctlAuto();
|
||||
QString getProfileDescription(const QString profile);
|
||||
QStringList getProfileDescriptions(const QStringList profileList);
|
||||
QStringList getProfileStatuses(const QStringList profileList);
|
||||
QString getSsidFromProfile(const QString profile);
|
||||
@ -48,6 +50,7 @@ public slots:
|
||||
private:
|
||||
bool debug;
|
||||
QString netctlCommand;
|
||||
QString netctlAutoCommand;
|
||||
QDir *profileDirectory;
|
||||
QString sudoCommand;
|
||||
// functions
|
||||
|
@ -26,6 +26,7 @@ Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> settings)
|
||||
: debug(debugCmd)
|
||||
{
|
||||
netctlCommand = settings[QString("NETCTL_PATH")];
|
||||
netctlAutoCommand = settings[QString("NETCTLAUTO_PATH")];
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
}
|
||||
@ -104,9 +105,62 @@ QList<QStringList> Netctl::getProfileList()
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
QList<QStringList> Netctl::getProfileListFromNetctlAuto()
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileListFromNetctlAuto]";
|
||||
|
||||
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;
|
||||
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));
|
||||
fullProfilesInfo.append(profileInfo);
|
||||
}
|
||||
|
||||
return fullProfilesInfo;
|
||||
}
|
||||
|
||||
|
||||
QString Netctl::getProfileDescription(const QString profileName)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]";
|
||||
QString description;
|
||||
|
||||
QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profileName;
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Check" << profileUrl;
|
||||
QFile profile(profileUrl);
|
||||
QString fileStr;
|
||||
if (profile.open(QIODevice::ReadOnly))
|
||||
while (true) {
|
||||
fileStr = QString(profile.readLine());
|
||||
if (fileStr[0] != '#')
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts)[0] == QString("Description"))
|
||||
description = fileStr.split(QChar('='), QString::SkipEmptyParts)[1].trimmed();
|
||||
if (profile.atEnd())
|
||||
break;
|
||||
}
|
||||
else
|
||||
description = QString("<unknown>");
|
||||
|
||||
description.remove(QChar('\''));
|
||||
description.remove(QChar('"'));
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
{
|
||||
if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]";
|
||||
QStringList descriptions;
|
||||
|
||||
for (int i=0; i<profileList.count(); i++) {
|
||||
@ -118,9 +172,9 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
while (true) {
|
||||
fileStr = QString(profile.readLine());
|
||||
if (fileStr[0] != '#')
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("Description"))
|
||||
descriptions.append(fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed());
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts)[0] == QString("Description"))
|
||||
descriptions.append(fileStr.split(QChar('='), QString::SkipEmptyParts)[1].trimmed());
|
||||
if (profile.atEnd())
|
||||
break;
|
||||
}
|
||||
@ -175,9 +229,9 @@ QString Netctl::getSsidFromProfile(const QString profile)
|
||||
while (true) {
|
||||
fileStr = QString(profileFile.readLine());
|
||||
if (fileStr[0] != '#') {
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("ESSID"))
|
||||
ssidName = fileStr.split(QString("="), QString::SkipEmptyParts)[1].trimmed();
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2)
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts)[0] == QString("ESSID"))
|
||||
ssidName = fileStr.split(QChar('='), QString::SkipEmptyParts)[1].trimmed();
|
||||
}
|
||||
if (profileFile.atEnd())
|
||||
break;
|
||||
|
@ -139,22 +139,22 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
|
||||
while (true) {
|
||||
fileStr = QString(profileFile.readLine());
|
||||
if (fileStr[0] != '#') {
|
||||
if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) {
|
||||
if ((fileStr.split(QString("="))[1][0] == QChar('(')) &&
|
||||
(fileStr.split(QString("="))[1][fileStr.split(QString("="))[1].size()-2] == QChar(')')))
|
||||
settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1]
|
||||
if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2) {
|
||||
if ((fileStr.split(QChar('='))[1][0] == QChar('(')) &&
|
||||
(fileStr.split(QChar('='))[1][fileStr.split(QChar('='))[1].size()-2] == QChar(')')))
|
||||
settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed();
|
||||
else if (fileStr.split(QString("="))[1][0] == QChar('(')) {
|
||||
QString parameterName = fileStr.split(QString("="))[0];
|
||||
else if (fileStr.split(QChar('='))[1][0] == QChar('(')) {
|
||||
QString parameterName = fileStr.split(QChar('='))[0];
|
||||
QStringList parameter;
|
||||
if (!fileStr.split(QString("="))[1]
|
||||
if (!fileStr.split(QChar('='))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed()
|
||||
.isEmpty())
|
||||
parameter.append(fileStr.split(QString("="))[1]
|
||||
parameter.append(fileStr.split(QChar('='))[1]
|
||||
.remove(QString("("))
|
||||
.remove(QString(")"))
|
||||
.trimmed());
|
||||
@ -175,7 +175,7 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
|
||||
settings[parameterName] = parameter.join(QString("\n"));
|
||||
}
|
||||
else
|
||||
settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1]
|
||||
settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1]
|
||||
.trimmed();
|
||||
}
|
||||
|
||||
|
@ -167,18 +167,18 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
return scanResults;
|
||||
SleepThread::sleep(3);
|
||||
|
||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"), QString::SkipEmptyParts);
|
||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
|
||||
// remove table header
|
||||
rawOutput.removeFirst();
|
||||
// remove duplicates
|
||||
QStringList rawList;
|
||||
for (int i=0; i<rawOutput.count(); i++) {
|
||||
bool exist = false;
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
||||
for (int j=0; j<rawList.count(); j++)
|
||||
if (rawList[j].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[4] ==
|
||||
rawList[j].split(QString("\t"), QString::SkipEmptyParts)[4])
|
||||
if (rawList[j].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
||||
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4] ==
|
||||
rawList[j].split(QChar('\t'), QString::SkipEmptyParts)[4])
|
||||
exist = true;
|
||||
if (!exist)
|
||||
rawList.append(rawOutput[i]);
|
||||
@ -188,8 +188,8 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
QStringList wifiPoint;
|
||||
|
||||
// point name
|
||||
if (rawList[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4)
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[4]);
|
||||
if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
||||
wifiPoint.append(rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4]);
|
||||
else
|
||||
wifiPoint.append(QString("<hidden>"));
|
||||
// profile status
|
||||
@ -205,9 +205,9 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
status = QString("new");
|
||||
wifiPoint.append(status);
|
||||
// point signal
|
||||
wifiPoint.append(rawList[i].split(QString("\t"), QString::SkipEmptyParts)[2]);
|
||||
wifiPoint.append(rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2]);
|
||||
// point security
|
||||
QString security = rawList[i].split(QString("\t"), QString::SkipEmptyParts)[3];
|
||||
QString security = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[3];
|
||||
if (security.contains(QString("WPA2")))
|
||||
security = QString("WPA2");
|
||||
else if (security.contains(QString("WPA")))
|
||||
|
Reference in New Issue
Block a user