From 45c248b101d3a0d02d8f54033503d5ae8392c909 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 30 Oct 2014 01:05:09 +0300 Subject: [PATCH] some intermediate commit --- sources/ext-sysmon/CMakeLists.txt | 2 + sources/ext-sysmon/extscript.cpp | 233 ++++++++++++++++++ sources/ext-sysmon/extscript.h | 72 ++++++ sources/ext-sysmon/scripts/aw-get-external-ip | 3 + .../scripts/aw-get-external-ip.conf | 5 + sources/ext-sysmon/scripts/aw-script-template | 3 + .../scripts/aw-script-template.conf | 15 ++ 7 files changed, 333 insertions(+) create mode 100644 sources/ext-sysmon/extscript.cpp create mode 100644 sources/ext-sysmon/extscript.h create mode 100644 sources/ext-sysmon/scripts/aw-get-external-ip create mode 100644 sources/ext-sysmon/scripts/aw-get-external-ip.conf create mode 100644 sources/ext-sysmon/scripts/aw-script-template create mode 100644 sources/ext-sysmon/scripts/aw-script-template.conf diff --git a/sources/ext-sysmon/CMakeLists.txt b/sources/ext-sysmon/CMakeLists.txt index 3355f57..3878a3c 100644 --- a/sources/ext-sysmon/CMakeLists.txt +++ b/sources/ext-sysmon/CMakeLists.txt @@ -19,6 +19,7 @@ file (RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_ file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp) set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h) file (GLOB SUBPROJECT_CONF *.conf) +set (SUBPROJECT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts) # prepare configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}) @@ -32,3 +33,4 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS}) install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR}) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR}) install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR}) +install (DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME}) diff --git a/sources/ext-sysmon/extscript.cpp b/sources/ext-sysmon/extscript.cpp new file mode 100644 index 0000000..9bc4345 --- /dev/null +++ b/sources/ext-sysmon/extscript.cpp @@ -0,0 +1,233 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets 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. * + * * + * awesome-widgets 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 awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "extscript.h" + +#include +#include + +#include +#include + + +ExtScript::ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd) + : QObject(0), + name(scriptName), + dirs(directories), + debug(debugCmd) +{ +} + + +ExtScript::~ExtScript() +{ + if (debug) qDebug() << PDEBUG; +} + + +void ExtScript::addDirectory(const QString dir) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Directory" << dir; + + QString absPath = QDir(dir).absolutePath(); + if (!QDir(absPath).exists()) return; + for (int i=0; i settings; + for (int i=0; i newSettings = getConfigurationFromFile(fileName); + for (int i=0; i settings) +{ + if (settings.contains(QString("ACTIVE"))) { + if (settings[QString("ACTIVE")] == QString("true")) + setActive(true); + else + setActive(false); + } + if (settings.contains(QString("INTERVAL"))) { + setInterval(settings[QString("INTERVAL")].toInt()); + } + if (settings.contains(QString("PREFIX"))) { + setPrefix(settings[QString("PREFIX")]); + } + if (settings.contains(QString("OUTPUT"))) { + if (settings[QString("OUTPUT")] == QString("true")) + setHasOutput(true); + else + setHasOutput(false); + } + if (settings.contains(QString("REDIRECT"))) { + setRedirect((Redirect)settings[QString("REDIRECT")].toInt()); + } +} + + +QMap ExtScript::getConfigurationFromFile(const QString fileName) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "File" << fileName; + + QMap settings; + QFile configFile(fileName); + QString fileStr; + if (!configFile.open(QIODevice::ReadOnly)) return settings; + while (true) { + fileStr = QString(configFile.readLine()).trimmed(); + if ((fileStr.isEmpty()) && (!configFile.atEnd())) continue; + if ((fileStr[0] == QChar('#')) && (!configFile.atEnd())) continue; + if ((fileStr[0] == QChar(';')) && (!configFile.atEnd())) continue; + if (fileStr.contains(QChar('='))) + settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1]; + if (configFile.atEnd()) break; + } + configFile.close(); + for (int i=0; i settings); + QMap getConfigurationFromFile(const QString fileName); + QMap toExternalConfiguration(); + // properties + bool active = true; + QString name; + QStringList dirs; + int interval = 1; + bool output = true; + QString prefix = QString(""); + Redirect redirect = nothing; + // other + bool debug; +}; + + +#endif /* EXTSCRIPT_H */ diff --git a/sources/ext-sysmon/scripts/aw-get-external-ip b/sources/ext-sysmon/scripts/aw-get-external-ip new file mode 100644 index 0000000..60b9621 --- /dev/null +++ b/sources/ext-sysmon/scripts/aw-get-external-ip @@ -0,0 +1,3 @@ +#!/bin/bash + +curl ip4.telize.com diff --git a/sources/ext-sysmon/scripts/aw-get-external-ip.conf b/sources/ext-sysmon/scripts/aw-get-external-ip.conf new file mode 100644 index 0000000..f5650f0 --- /dev/null +++ b/sources/ext-sysmon/scripts/aw-get-external-ip.conf @@ -0,0 +1,5 @@ +ACTIVE=true +INTERVAL=1 +PREFIX= +OUTPUT=true +REDIRECT=0 diff --git a/sources/ext-sysmon/scripts/aw-script-template b/sources/ext-sysmon/scripts/aw-script-template new file mode 100644 index 0000000..0995f2c --- /dev/null +++ b/sources/ext-sysmon/scripts/aw-script-template @@ -0,0 +1,3 @@ +#!/usr/bin/python + +print ("Hello the f$%king world!") diff --git a/sources/ext-sysmon/scripts/aw-script-template.conf b/sources/ext-sysmon/scripts/aw-script-template.conf new file mode 100644 index 0000000..041912e --- /dev/null +++ b/sources/ext-sysmon/scripts/aw-script-template.conf @@ -0,0 +1,15 @@ +# is this script is active? +ACTIVE=false +# update interval in default plasmoid interval +INTERVAL=1 +# does this script have output? +# set to 'false' if it is an action and will not show in the plasmoid +OUTPUT=true +# prefix to run this script. Usually this field should be blank, +# but you may want to set command (e.g. script language) directly +PREFIX= +# redirect output streams +# -1: stdout to stderr +# 0: do nothing +# 1: stderr to stdout +REDIRECT=0