/*************************************************************************** * This file is part of netctl-plasmoid * * * * netctl-plasmoid 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-plasmoid 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-plasmoid. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include "netctl.h" #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; } bool Netctl::readConfiguration() { // default configuration configuration[QString("CMD")] = QString("/usr/bin/netctl"); configuration[QString("EXTIP")] = QString("false"); configuration[QString("EXTIPCMD")] = QString("wget -qO- http://ifconfig.me/ip"); configuration[QString("IPCMD")] = QString("/usr/bin/ip"); configuration[QString("NETDIR")] = QString("/sys/class/net/"); QString fileStr; // FIXME: define configuration file QFile confFile(QString(getenv("HOME")) + QString("/.kde4/share/config/netctl.conf")); bool exists = confFile.open(QIODevice::ReadOnly); if (!exists) { confFile.setFileName("/usr/share/config/netctl.conf"); exists = confFile.open(QIODevice::ReadOnly); if (!exists) return false; } while (true) { fileStr = QString(confFile.readLine()); if (fileStr[0] != '#') { if (fileStr.contains(QString("="))) configuration[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1] .remove(QString(" ")) .trimmed(); } if (confFile.atEnd()) break; } confFile.close(); return true; } bool Netctl::sourceRequestEvent(const QString &name) { return updateSourceEvent(name); } bool Netctl::updateSourceEvent(const QString &source) { QProcess command; QString cmdOutput = QString(""); QString value = QString(""); if (source == QString("currentProfile")) { command.start(configuration[QString("CMD")] + QString(" list")); command.waitForFinished(-1); cmdOutput = command.readAllStandardOutput(); if (!cmdOutput.isEmpty()) { QStringList profileList = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); for (int i=0; i