/*************************************************************************** * This file is part of netctl-gui * * * * netctl-gui is free software: you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * * * netctl-gui is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include "netctl.h" #include #include #include #include #include #include #include Netctl::Netctl(QObject *parent, const QVariantList &args) : Plasma::DataEngine(parent, args) { Q_UNUSED(args) setMinimumPollingInterval(333); readConfiguration(); } QStringList Netctl::sources() const { QStringList sources; sources.append(QString("currentProfile")); sources.append(QString("extIp")); sources.append(QString("interfaces")); sources.append(QString("intIp")); sources.append(QString("profiles")); sources.append(QString("statusBool")); sources.append(QString("statusString")); return sources; } void Netctl::readConfiguration() { // default configuration QMap rawConfig; rawConfig[QString("CMD")] = QString("/usr/bin/netctl"); rawConfig[QString("EXTIP")] = QString("false"); rawConfig[QString("EXTIPCMD")] = QString("wget -qO- http://ifconfig.me/ip"); rawConfig[QString("IPCMD")] = QString("/usr/bin/ip"); rawConfig[QString("NETDIR")] = QString("/sys/class/net/"); rawConfig[QString("NETCTLAUTOCMD")] = QString("/usr/bin/netctl-auto"); QString fileName = KGlobal::dirs()->findResource("config", "netctl.conf"); QFile confFile(fileName); if (!confFile.open(QIODevice::ReadOnly)) { configuration = updateConfiguration(rawConfig); return; } QString fileStr; QStringList value; while (true) { fileStr = QString(confFile.readLine()).trimmed(); if (fileStr[0] == QChar('#')) continue; if (fileStr[0] == QChar(';')) continue; if (fileStr.contains(QChar('='))) { value.clear(); for (int i=1; i Netctl::updateConfiguration(const QMap rawConfig) { QMap config; QString key, value; // remove spaces and copy source map for (int i=0; itoUnicode(command.readAllStandardOutput()); QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts); for (int i=0; itoUnicode(command.readAllStandardOutput()); extIp = cmdOutput.trimmed(); return extIp; } QStringList Netctl::getInterfaceList(const QString dir) { QStringList interfaceList; if (QDir(dir).exists()) interfaceList = QDir(dir).entryList(QDir::Dirs | QDir::NoDotAndDotDot); return interfaceList; } QString Netctl::getIntIp(const QString cmd, const QString dir) { QProcess command; QString intIp = QString("127.0.0.1/8"); QStringList interfaceList = getInterfaceList(dir); for (int i=0; itoUnicode(command.readAllStandardOutput()); QStringList deviceInfo = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts); for (int j=0; jtoUnicode(command.readAllStandardOutput()); QStringList profileList = cmdOutput.split(QChar('\n'), QString::SkipEmptyParts); for (int i=0; i