diff --git a/.gitignore b/.gitignore index 8e254f0..d957b61 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,8 @@ # Source archive *.tar.xz +# Build directory +build/ +sources/build/ +sources/build/*/ + diff --git a/LICENSE b/LICENSE index ef7e7ef..b09a390 100644 --- a/LICENSE +++ b/LICENSE @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} + netctl-plasmoid + Copyright (C) 2014 Evgeniy Alekseev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - {project} Copyright (C) {year} {fullname} + netctl-plasmoid Copyright (C) 2014 Evgeniy Alekseev This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 39b8edb..c239ac0 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -49,3 +49,5 @@ endif () if (BUILD_PLASMOID) add_subdirectory (plasmoid) endif () + +install (FILES netctl-gui.png DESTINATION ls share/pixmaps/netctl-gui.png) diff --git a/sources/dataengine/netctl.conf b/sources/dataengine/netctl.conf new file mode 100644 index 0000000..fb941be --- /dev/null +++ b/sources/dataengine/netctl.conf @@ -0,0 +1,18 @@ +# Configuration file for netctl data engine +# Uncomment needed lines + +## Commands +# command +#CMD=/usr/bin/netctl +# ip command +#IPCMD=/usr/bin/ip + +## Network +# path to list of network devices +#NETDIR=/sys/class/net/ + +## External IP +# external ip check command +#EXTIPCMD=wget -qO- http://ifconfig.me/ip +# 'true' - check external IP +#EXTIP=false diff --git a/sources/dataengine/netctl.cpp b/sources/dataengine/netctl.cpp new file mode 100644 index 0000000..45722e7 --- /dev/null +++ b/sources/dataengine/netctl.cpp @@ -0,0 +1,221 @@ +/*************************************************************************** + * 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 Foobar. If not, see . * + ***************************************************************************/ + +#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 + checkExtIP = QString("false"); + cmd = QString("/usr/bin/netctl"); + extIpCmd = QString("wget -qO- http://ifconfig.me/ip"); + ipCmd = QString("/usr/bin/ip"); + 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 (confFile.atEnd()) + break; + else if (fileStr[0] != '#') { + if (fileStr.split(QString("="), QString::SkipEmptyParts).count() == 2) { + if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("EXTIP")) + checkExtIP = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("CMD")) + cmd = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("EXTIPCMD")) + extIpCmd = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("IPCMD")) + ipCmd = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + else if (fileStr.split(QString("="), QString::SkipEmptyParts)[0] == QString("NETDIR")) + netDir = fileStr.split(QString("="), QString::SkipEmptyParts)[1].split(QString("\n"), QString::SkipEmptyParts)[0]; + } + } + } + + 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(""); + QStringList valueList; + + if (source == QString("currentProfile")) { + command.start(cmd + QString(" list")); + command.waitForFinished(-1); + cmdOutput = command.readAllStandardOutput(); + if (cmdOutput != QString("")) { + QStringList profileList = cmdOutput.split(QString("\n"), QString::SkipEmptyParts); + for (int i=0; i -1) { + value = QString("enabled"); + break; + } + } + setData(source, QString("value"), value); + } + + return true; +} + + +K_EXPORT_PLASMA_DATAENGINE(netctl, Netctl) + +#include "netctl.moc" diff --git a/sources/dataengine/netctl.h b/sources/dataengine/netctl.h new file mode 100644 index 0000000..b176514 --- /dev/null +++ b/sources/dataengine/netctl.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * 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 Foobar. If not, see . * + ***************************************************************************/ + +#ifndef NETCTL_DE_H +#define NETCTL_DE_H + +#include + +class Netctl : public Plasma::DataEngine +{ + Q_OBJECT + +public: + Netctl(QObject *parent, const QVariantList &args); + +protected: + bool readConfiguration(); + bool sourceRequestEvent(const QString &name); + bool updateSourceEvent(const QString &source); + QStringList sources() const; + + // configuration + // enable check external IP + QString checkExtIP; + // path to netctl command + QString cmd; + // command to check external IP + QString extIpCmd; + // path to ip command + QString ipCmd; + // path to directory with network device configuration + QString netDir; +}; + +#endif /* NETCTL_DE_H */ diff --git a/sources/dataengine/plasma-engine-netctl.desktop b/sources/dataengine/plasma-engine-netctl.desktop new file mode 100644 index 0000000..6423956 --- /dev/null +++ b/sources/dataengine/plasma-engine-netctl.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Netctl DataEngine +Comment=data engine for netctl +ServiceTypes=Plasma/DataEngine +Type=Service +Icon=netctl-gui + +X-KDE-ServiceTypes=Plasma/DataEngine +X-KDE-Library=plasma_engine_netctl +X-Plasma-EngineName=netctl + +X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis +X-KDE-PluginInfo-Email=esalexeev@gmail.com +X-KDE-PluginInfo-Name=netctl +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Category=Network +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/sources/icons/network-idle-128-128.png b/sources/icons/network-idle-128-128.png new file mode 100644 index 0000000..9112b1b Binary files /dev/null and b/sources/icons/network-idle-128-128.png differ diff --git a/sources/icons/network-idle-64x64.png b/sources/icons/network-idle-64x64.png new file mode 100644 index 0000000..f0f4f0e Binary files /dev/null and b/sources/icons/network-idle-64x64.png differ diff --git a/sources/icons/network-offline-64x64.png b/sources/icons/network-offline-64x64.png new file mode 100644 index 0000000..46c4e04 Binary files /dev/null and b/sources/icons/network-offline-64x64.png differ diff --git a/sources/netctl-gui.png b/sources/netctl-gui.png new file mode 100644 index 0000000..9112b1b Binary files /dev/null and b/sources/netctl-gui.png differ diff --git a/sources/plasmoid/CMakeLists.txt b/sources/plasmoid/CMakeLists.txt index a36b763..bcff5bb 100644 --- a/sources/plasmoid/CMakeLists.txt +++ b/sources/plasmoid/CMakeLists.txt @@ -15,7 +15,6 @@ include_directories (${CMAKE_SOURCE_DIR} # set sources set (PLUGIN_NAME ${SUBPROJECT}) file (GLOB SUBPROJECT_DESKTOP *.desktop) -file (GLOB SUBPROJECT_ICON *.png) file (GLOB SUBPROJECT_NOTIFY *.notifyrc) file (GLOB SUBPROJECT_SOURCE *.cpp) file (GLOB SUBPROJECT_UI *.ui) @@ -28,5 +27,4 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS}) # install install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}) install (FILES ${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) -install (FILES ${SUBPROJECT_ICON} DESTINATION ${ICON_INSTALL_DIR}) install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})