mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
alfa version of de: IT BUILDS!
This commit is contained in:
parent
1a5578dd73
commit
0d227e93e3
5
.gitignore
vendored
5
.gitignore
vendored
@ -15,3 +15,8 @@
|
|||||||
# Source archive
|
# Source archive
|
||||||
*.tar.xz
|
*.tar.xz
|
||||||
|
|
||||||
|
# Build directory
|
||||||
|
build/
|
||||||
|
sources/build/
|
||||||
|
sources/build/*/
|
||||||
|
|
||||||
|
6
LICENSE
6
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
|
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.
|
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.}
|
netctl-plasmoid
|
||||||
Copyright (C) {year} {name of author}
|
Copyright (C) 2014 Evgeniy Alekseev
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
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
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
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 program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
@ -49,3 +49,5 @@ endif ()
|
|||||||
if (BUILD_PLASMOID)
|
if (BUILD_PLASMOID)
|
||||||
add_subdirectory (plasmoid)
|
add_subdirectory (plasmoid)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
install (FILES netctl-gui.png DESTINATION ls share/pixmaps/netctl-gui.png)
|
||||||
|
18
sources/dataengine/netctl.conf
Normal file
18
sources/dataengine/netctl.conf
Normal file
@ -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
|
221
sources/dataengine/netctl.cpp
Normal file
221
sources/dataengine/netctl.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "netctl.h"
|
||||||
|
|
||||||
|
#include <Plasma/DataContainer>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
|
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<profileList.count(); i++)
|
||||||
|
if (profileList[i].split(QString(" "), QString::SkipEmptyParts).count() == 2) {
|
||||||
|
value = profileList[i].split(QString(" "), QString::SkipEmptyParts)[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), value);
|
||||||
|
}
|
||||||
|
else if (source == QString("extIp")) {
|
||||||
|
if (checkExtIP == QString("true")) {
|
||||||
|
command.start(extIpCmd);
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
cmdOutput = command.readAllStandardOutput();
|
||||||
|
if (cmdOutput != QString(""))
|
||||||
|
value = cmdOutput.split(QString("\n"), QString::SkipEmptyParts)[0];
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), value);
|
||||||
|
}
|
||||||
|
else if (source == QString("interfaces")) {
|
||||||
|
if (QDir(netDir).exists())
|
||||||
|
valueList = QDir(netDir).entryList(QDir::Dirs);
|
||||||
|
setData(source, QString("value"), valueList);
|
||||||
|
}
|
||||||
|
else if (source == QString("intIp")) {
|
||||||
|
if (QDir(netDir).exists()) {
|
||||||
|
valueList = QDir(netDir).entryList(QDir::Dirs);
|
||||||
|
for (int i=0; i<valueList.count(); i++) {
|
||||||
|
cmdOutput = QString("");
|
||||||
|
command.start(ipCmd + QString("ip addr show ") + valueList[i]);
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
cmdOutput = command.readAllStandardOutput();
|
||||||
|
if (cmdOutput != QString("")) {
|
||||||
|
QStringList deviceInfo = cmdOutput.split(QString("\n"), QString::SkipEmptyParts);
|
||||||
|
for (int j=0; j<deviceInfo.count(); j++)
|
||||||
|
if (deviceInfo[j].split(QString(" "), QString::SkipEmptyParts)[0] == QString("inet"))
|
||||||
|
value = deviceInfo[j].split(QString(" "), QString::SkipEmptyParts)[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), value);
|
||||||
|
}
|
||||||
|
else if (source == QString("profiles")) {
|
||||||
|
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<profileList.count(); i++)
|
||||||
|
if (profileList[i].split(QString(" "), QString::SkipEmptyParts).count() == 1)
|
||||||
|
valueList.append(profileList[i].split(QString(" "), QString::SkipEmptyParts)[0]);
|
||||||
|
else if (profileList[i].split(QString(" "), QString::SkipEmptyParts).count() == 2)
|
||||||
|
valueList.append(profileList[i].split(QString(" "), QString::SkipEmptyParts)[1]);
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), valueList);
|
||||||
|
}
|
||||||
|
else if (source == QString("statusBool")) {
|
||||||
|
command.start(cmd + QString(" list"));
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
cmdOutput = command.readAllStandardOutput();
|
||||||
|
value = QString("false");
|
||||||
|
if (cmdOutput != QString("")) {
|
||||||
|
QStringList profileList = cmdOutput.split(QString("\n"), QString::SkipEmptyParts);
|
||||||
|
for (int i=0; i<profileList.count(); i++)
|
||||||
|
if (profileList[i].split(QString(" "), QString::SkipEmptyParts).count() == 2) {
|
||||||
|
value = QString("true");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), value);
|
||||||
|
}
|
||||||
|
else if (source == QString("statusString")) {
|
||||||
|
command.start(cmd + QString(" list"));
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
cmdOutput = command.readAllStandardOutput();
|
||||||
|
QString currentProfile;
|
||||||
|
if (cmdOutput != QString("")) {
|
||||||
|
QStringList profileList = cmdOutput.split(QString("\n"), QString::SkipEmptyParts);
|
||||||
|
for (int i=0; i<profileList.count(); i++)
|
||||||
|
if (profileList[i].split(QString(" "), QString::SkipEmptyParts).count() == 2) {
|
||||||
|
currentProfile = profileList[i].split(QString(" "), QString::SkipEmptyParts)[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
command.start(cmd + QString(" status ") + currentProfile);
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
cmdOutput = command.readAllStandardOutput();
|
||||||
|
value = QString("static");
|
||||||
|
if (cmdOutput != QString("")) {
|
||||||
|
QStringList profile = cmdOutput.split(QString("\n"), QString::SkipEmptyParts);
|
||||||
|
for (int i=0; i<profile.count(); i++)
|
||||||
|
if (profile[i].split(QString(" "), QString::SkipEmptyParts)[0] == QString("Loaded:"))
|
||||||
|
if (profile[i].indexOf(QString("enabled")) > -1) {
|
||||||
|
value = QString("enabled");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setData(source, QString("value"), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
K_EXPORT_PLASMA_DATAENGINE(netctl, Netctl)
|
||||||
|
|
||||||
|
#include "netctl.moc"
|
49
sources/dataengine/netctl.h
Normal file
49
sources/dataengine/netctl.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef NETCTL_DE_H
|
||||||
|
#define NETCTL_DE_H
|
||||||
|
|
||||||
|
#include <Plasma/DataEngine>
|
||||||
|
|
||||||
|
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 */
|
20
sources/dataengine/plasma-engine-netctl.desktop
Normal file
20
sources/dataengine/plasma-engine-netctl.desktop
Normal file
@ -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
|
BIN
sources/icons/network-idle-128-128.png
Normal file
BIN
sources/icons/network-idle-128-128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
sources/icons/network-idle-64x64.png
Normal file
BIN
sources/icons/network-idle-64x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
sources/icons/network-offline-64x64.png
Normal file
BIN
sources/icons/network-offline-64x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
sources/netctl-gui.png
Normal file
BIN
sources/netctl-gui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -15,7 +15,6 @@ include_directories (${CMAKE_SOURCE_DIR}
|
|||||||
# set sources
|
# set sources
|
||||||
set (PLUGIN_NAME ${SUBPROJECT})
|
set (PLUGIN_NAME ${SUBPROJECT})
|
||||||
file (GLOB SUBPROJECT_DESKTOP *.desktop)
|
file (GLOB SUBPROJECT_DESKTOP *.desktop)
|
||||||
file (GLOB SUBPROJECT_ICON *.png)
|
|
||||||
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||||
file (GLOB SUBPROJECT_SOURCE *.cpp)
|
file (GLOB SUBPROJECT_SOURCE *.cpp)
|
||||||
file (GLOB SUBPROJECT_UI *.ui)
|
file (GLOB SUBPROJECT_UI *.ui)
|
||||||
@ -28,5 +27,4 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
|
|||||||
# install
|
# install
|
||||||
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
|
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||||
install (FILES ${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_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})
|
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})
|
||||||
|
Loading…
Reference in New Issue
Block a user