/*************************************************************************** * 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 #include #include #include // KF5-KDE4 compability #ifdef BUILD_KDE4 #include #include #else #include #endif /* BUILD_KDE4 */ Netctl::Netctl(QObject *parent, const QVariantList &args) : Plasma::DataEngine(parent, args) { Q_UNUSED(args) // debug QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); QString debugEnv = environment.value(QString("DEBUG"), QString("no")); debug = (debugEnv == QString("yes")); setMinimumPollingInterval(333); readConfiguration(); initSources(); } Netctl::~Netctl() { if (debug) qDebug() << PDEBUG; } QStringList Netctl::sources() const { if (debug) qDebug() << PDEBUG; QStringList sources; sources.append(QString("active")); sources.append(QString("current")); sources.append(QString("extip4")); sources.append(QString("extip6")); sources.append(QString("info")); sources.append(QString("interfaces")); sources.append(QString("intip4")); sources.append(QString("intip6")); sources.append(QString("netctlauto")); sources.append(QString("profiles")); sources.append(QString("status")); return sources; } 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() { if (debug) qDebug() << PDEBUG; QString fileName; #ifdef BUILD_KDE4 fileName = KGlobal::dirs()->findResource("config", "plasma-dataengine-netctl.conf"); #else fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-netctl.conf")); #endif /* BUILD_KDE4 */ if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName; QSettings settings(fileName, QSettings::IniFormat); settings.beginGroup(QString("Netctl commands")); configuration[QString("NETCTLCMD")] = settings.value(QString("NETCTLCMD"), QString("/usr/bin/netctl")).toString(); configuration[QString("NETCTLAUTOCMD")] = settings.value(QString("NETCTLAUTOCMD"), QString("/usr/bin/netctl-auto")).toString(); settings.endGroup(); settings.beginGroup(QString("External IP")); configuration[QString("EXTIP4")] = settings.value(QString("EXTIP4"), QString("false")).toString(); configuration[QString("EXTIP4CMD")] = settings.value(QString("EXTIP4CMD"), QString("curl ip4.telize.com")).toString(); configuration[QString("EXTIP6")] = settings.value(QString("EXTIP6"), QString("false")).toString(); configuration[QString("EXTIP6CMD")] = settings.value(QString("EXTIP6CMD"), QString("curl ip6.telize.com")).toString(); settings.endGroup(); } bool Netctl::sourceRequestEvent(const QString &name) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Source name" << name; return updateSourceEvent(name); } QString Netctl::getExtIp(const QString cmd) { if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; // test network connection if (!isNetworkActive()) return QString("N\\A"); return getCmdOutput(cmd); } QString Netctl::getInfo(const QStringList profiles, const QStringList statuses) { if (debug) qDebug() << PDEBUG; if (profiles.count() != statuses.count()) return QString("N\\A"); QStringList list; for (int i=0; i rawList = QNetworkInterface::allInterfaces(); QStringList interfacesList; for (int i=0; i rawList = QNetworkInterface::allAddresses(); for (int i=0; i