mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
improve dataengine permofrmance (fix #39) - TODO: need to be tested
This commit is contained in:
parent
35af460b7b
commit
b7fa17df4e
@ -8,7 +8,7 @@ ProjectRootRelative=./
|
|||||||
|
|
||||||
[CMake][CMake Build Directory 0]
|
[CMake][CMake Build Directory 0]
|
||||||
Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build
|
Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build
|
||||||
Build Type=Debug
|
Build Type=Release
|
||||||
CMake Binary=file:///usr/bin/cmake
|
CMake Binary=file:///usr/bin/cmake
|
||||||
Environment Profile=
|
Environment Profile=
|
||||||
Extra Arguments=
|
Extra Arguments=
|
||||||
|
2
sources/3rdparty/pdebug
vendored
2
sources/3rdparty/pdebug
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 294a590bb966fd79eb2e93a7b02377ca57731cd5
|
Subproject commit 9c63e102b05e11ead690489ca470c8482b6335b1
|
@ -82,6 +82,20 @@ QStringList Netctl::sources() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString Netctl::getCmdOutput(const QString cmd)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
||||||
|
|
||||||
|
TaskResult process = runTask(cmd);
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
|
if (process.exitCode != 0)
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
|
return QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Netctl::readConfiguration()
|
void Netctl::readConfiguration()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -118,35 +132,6 @@ bool Netctl::sourceRequestEvent(const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList Netctl::getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto)
|
|
||||||
{
|
|
||||||
if (debug) qDebug() << PDEBUG;
|
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
|
||||||
|
|
||||||
QString cmd;
|
|
||||||
if (netctlAutoStatus)
|
|
||||||
cmd = cmdNetctlAuto;
|
|
||||||
else
|
|
||||||
cmd = cmdNetctl;
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
|
||||||
TaskResult process = runTask(QString("%1 list").arg(cmd));
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
|
||||||
if (process.exitCode != 0)
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
|
||||||
QStringList currentProfile;
|
|
||||||
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
|
|
||||||
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts);
|
|
||||||
for (int i=0; i<profileList.count(); i++) {
|
|
||||||
if (profileList[i][0] != QChar('*')) continue;
|
|
||||||
currentProfile.append(profileList[i]);
|
|
||||||
}
|
|
||||||
for (int i=0; i<currentProfile.count(); i++)
|
|
||||||
currentProfile[i].remove(0, 2);
|
|
||||||
|
|
||||||
return currentProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString Netctl::getExtIp(const QString cmd)
|
QString Netctl::getExtIp(const QString cmd)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -154,27 +139,22 @@ QString Netctl::getExtIp(const QString cmd)
|
|||||||
|
|
||||||
// test network connection
|
// test network connection
|
||||||
if (!isNetworkActive()) return QString("N\\A");
|
if (!isNetworkActive()) return QString("N\\A");
|
||||||
TaskResult process = runTask(cmd);
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
|
||||||
if (process.exitCode != 0)
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
|
||||||
QString extIp = QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
|
||||||
|
|
||||||
return extIp;
|
return getCmdOutput(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Netctl::getInfo()
|
QString Netctl::getInfo(const QStringList profiles, const QStringList statuses)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (current.split(QChar('|')).count() != status.split(QChar('|')).count()) return QString("N\\A");
|
if (profiles.count() != statuses.count()) return QString("N\\A");
|
||||||
|
|
||||||
QStringList profiles;
|
QStringList list;
|
||||||
for (int i=0; i<current.split(QChar('|')).count(); i++)
|
for (int i=0; i<profiles.count(); i++)
|
||||||
profiles.append(QString("%1 (%2)").arg(current.split(QChar('|'))[i]).arg(status.split(QChar('|'))[i]));
|
list.append(QString("%1 (%2)").arg(profiles[i]).arg(statuses[i]));
|
||||||
if (profiles.isEmpty()) profiles.append(QString("N\\A"));
|
if (list.isEmpty()) list.append(QString("N\\A"));
|
||||||
|
|
||||||
return profiles.join(QString(" | "));
|
return list.join(QString(" | "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,87 +193,56 @@ QString Netctl::getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Netctl::getNetctlAutoStatus(const QString cmdNetctlAuto)
|
|
||||||
{
|
|
||||||
if (debug) qDebug() << PDEBUG;
|
|
||||||
|
|
||||||
TaskResult process = runTask(QString("%1 list").arg(cmdNetctlAuto));
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
|
||||||
if (process.exitCode != 0)
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
|
||||||
QString status;
|
|
||||||
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
|
|
||||||
if (cmdOutput.isEmpty()) {
|
|
||||||
netctlAutoStatus = false;
|
|
||||||
status = QString("false");
|
|
||||||
} else {
|
|
||||||
netctlAutoStatus = true;
|
|
||||||
status = QString("true");
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto)
|
QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
|
||||||
|
|
||||||
QString cmd;
|
netctlAutoStatus = true;
|
||||||
if (netctlAutoStatus)
|
QString output = getCmdOutput(QString("%1 list").arg(cmdNetctlAuto));
|
||||||
cmd = cmdNetctlAuto;
|
if (output.isEmpty()) {
|
||||||
else
|
output = getCmdOutput(QString("%1 list").arg(cmdNetctl));
|
||||||
cmd = cmdNetctl;
|
netctlAutoStatus = false;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
|
}
|
||||||
TaskResult process = runTask(QString("%1 list").arg(cmd));
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
// parse
|
||||||
if (process.exitCode != 0)
|
QStringList currentProfiles;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
QStringList profileList = output.split(QChar('\n'), QString::SkipEmptyParts);
|
||||||
QString cmdOutput = QTextCodec::codecForMib(106)->toUnicode(process.output);
|
for (int i=0; i<profileList.count(); i++) {
|
||||||
QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts);
|
if (profileList[i][0] != QChar('*')) continue;
|
||||||
|
currentProfiles.append(profileList[i]);
|
||||||
|
}
|
||||||
|
// remove first symbols
|
||||||
for (int i=0; i<profileList.count(); i++)
|
for (int i=0; i<profileList.count(); i++)
|
||||||
profileList[i].remove(0, 2);
|
profileList[i].remove(0, 2);
|
||||||
|
for (int i=0; i<currentProfiles.count(); i++)
|
||||||
|
currentProfiles[i].remove(0, 2);
|
||||||
|
|
||||||
|
// return profiles
|
||||||
|
currentProfile = currentProfiles;
|
||||||
|
status = !currentProfiles.isEmpty();
|
||||||
return profileList;
|
return profileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList Netctl::getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto)
|
QStringList Netctl::getProfileStringStatus(const QString cmdNetctl)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
|
||||||
|
|
||||||
QStringList status;
|
QStringList status;
|
||||||
if (netctlAutoStatus)
|
if (netctlAutoStatus) {
|
||||||
status.append(QString("netctl-auto"));
|
status.append(QString("netctl-auto"));
|
||||||
else {
|
return status;
|
||||||
QStringList profiles = getCurrentProfile(cmdNetctl, cmdNetctlAuto);
|
|
||||||
for (int i=0; i<profiles.count(); i++) {
|
|
||||||
TaskResult process = runTask(QString("%1 is-enabled %2").arg(cmdNetctl).arg(profiles[i]));
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
|
||||||
if (process.exitCode != 0)
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
|
||||||
if (process.exitCode == 0)
|
|
||||||
status.append(QString("enabled"));
|
|
||||||
else
|
|
||||||
status.append(QString("static"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
for (int i=0; i<currentProfile.count(); i++) {
|
||||||
}
|
TaskResult process = runTask(QString("%1 is-enabled %2").arg(cmdNetctl).arg(currentProfile[i]));
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
|
if (process.exitCode != 0) {
|
||||||
QString Netctl::getStatus(const QString cmdNetctl, const QString cmdNetctlAuto)
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
{
|
status.append(QString("static"));
|
||||||
if (debug) qDebug() << PDEBUG;
|
} else
|
||||||
getNetctlAutoStatus(cmdNetctlAuto);
|
status.append(QString("enabled"));
|
||||||
|
}
|
||||||
QString status = QString("false");
|
|
||||||
QStringList currentProfile = getCurrentProfile(cmdNetctl, cmdNetctlAuto);
|
|
||||||
if (!currentProfile.isEmpty())
|
|
||||||
status = QString("true");
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -329,13 +278,9 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
|
|
||||||
QString value = QString("N\\A");
|
QString value = QString("N\\A");
|
||||||
if (source == QString("active")) {
|
if (source == QString("active")) {
|
||||||
value = getStatus(configuration[QString("NETCTLCMD")],
|
value = status ? QString("true") : QString("false");
|
||||||
configuration[QString("NETCTLAUTOCMD")]);
|
|
||||||
} else if (source == QString("current")) {
|
} else if (source == QString("current")) {
|
||||||
value = getCurrentProfile(configuration[QString("NETCTLCMD")],
|
value = currentProfile.join(QChar('|'));
|
||||||
configuration[QString("NETCTLAUTOCMD")])
|
|
||||||
.join(QChar('|'));
|
|
||||||
current = value;
|
|
||||||
} else if (source == QString("extip4")) {
|
} else if (source == QString("extip4")) {
|
||||||
if (configuration[QString("EXTIP4")] == QString("true"))
|
if (configuration[QString("EXTIP4")] == QString("true"))
|
||||||
value = getExtIp(configuration[QString("EXTIP4CMD")]);
|
value = getExtIp(configuration[QString("EXTIP4CMD")]);
|
||||||
@ -343,7 +288,7 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
if (configuration[QString("EXTIP6")] == QString("true"))
|
if (configuration[QString("EXTIP6")] == QString("true"))
|
||||||
value = getExtIp(configuration[QString("EXTIP6CMD")]);
|
value = getExtIp(configuration[QString("EXTIP6CMD")]);
|
||||||
} else if (source == QString("info")) {
|
} else if (source == QString("info")) {
|
||||||
value = getInfo();
|
value = getInfo(currentProfile, currentStatus);
|
||||||
} else if (source == QString("interfaces")) {
|
} else if (source == QString("interfaces")) {
|
||||||
value = getInterfaceList().join(QChar(','));
|
value = getInterfaceList().join(QChar(','));
|
||||||
} else if (source == QString("intip4")) {
|
} else if (source == QString("intip4")) {
|
||||||
@ -351,16 +296,13 @@ bool Netctl::updateSourceEvent(const QString &source)
|
|||||||
} else if (source == QString("intip6")) {
|
} else if (source == QString("intip6")) {
|
||||||
value = getIntIp(QAbstractSocket::IPv6Protocol);
|
value = getIntIp(QAbstractSocket::IPv6Protocol);
|
||||||
} else if (source == QString("netctlauto")) {
|
} else if (source == QString("netctlauto")) {
|
||||||
value = getNetctlAutoStatus(configuration[QString("NETCTLAUTOCMD")]);
|
value = netctlAutoStatus ? QString("true") : QString("false");
|
||||||
} else if (source == QString("profiles")) {
|
} else if (source == QString("profiles")) {
|
||||||
value = getProfileList(configuration[QString("NETCTLCMD")],
|
value = getProfileList(configuration[QString("NETCTLCMD")],
|
||||||
configuration[QString("NETCTLAUTOCMD")])
|
configuration[QString("NETCTLAUTOCMD")]).join(QChar(','));
|
||||||
.join(QChar(','));
|
|
||||||
} else if (source == QString("status")) {
|
} else if (source == QString("status")) {
|
||||||
value = getProfileStringStatus(configuration[QString("NETCTLCMD")],
|
currentStatus = getProfileStringStatus(configuration[QString("NETCTLCMD")]);
|
||||||
configuration[QString("NETCTLAUTOCMD")])
|
value = currentStatus.join(QChar('|'));
|
||||||
.join(QChar('|'));
|
|
||||||
status = value;
|
|
||||||
}
|
}
|
||||||
setData(source, QString("value"), value);
|
setData(source, QString("value"), value);
|
||||||
|
|
||||||
|
@ -29,15 +29,12 @@ class Netctl : public Plasma::DataEngine
|
|||||||
public:
|
public:
|
||||||
Netctl(QObject *parent, const QVariantList &args);
|
Netctl(QObject *parent, const QVariantList &args);
|
||||||
~Netctl();
|
~Netctl();
|
||||||
QStringList getCurrentProfile(const QString cmdNetctl, const QString cmdNetctlAuto);
|
|
||||||
QString getExtIp(const QString cmd);
|
QString getExtIp(const QString cmd);
|
||||||
QString getInfo();
|
QString getInfo(const QStringList profiles, const QStringList statuses);
|
||||||
QStringList getInterfaceList();
|
QStringList getInterfaceList();
|
||||||
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
|
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
|
||||||
QString getNetctlAutoStatus(const QString cmdNetctlAuto);
|
|
||||||
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
|
||||||
QStringList getProfileStringStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
QStringList getProfileStringStatus(const QString cmdNetctl);
|
||||||
QString getStatus(const QString cmdNetctl, const QString cmdNetctlAuto);
|
|
||||||
bool isNetworkActive();
|
bool isNetworkActive();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -49,13 +46,14 @@ protected:
|
|||||||
QStringList sources() const;
|
QStringList sources() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool netctlAutoStatus;
|
bool netctlAutoStatus = false;
|
||||||
QString currentProfile;
|
bool status = false;
|
||||||
|
QStringList currentProfile;
|
||||||
|
QStringList currentStatus;
|
||||||
// configuration
|
// configuration
|
||||||
bool debug;
|
bool debug;
|
||||||
QString current = QString("");
|
|
||||||
QString status = QString("");
|
|
||||||
QMap<QString, QString> configuration;
|
QMap<QString, QString> configuration;
|
||||||
|
QString getCmdOutput(const QString cmd);
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user