some intermediate commit

This commit is contained in:
arcan1s 2014-10-30 01:05:09 +03:00
parent 6a784d2e28
commit 45c248b101
7 changed files with 333 additions and 0 deletions

View File

@ -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})

View File

@ -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 <QDebug>
#include <QDir>
#include <pdebug/pdebug.h>
#include <task/taskadds.h>
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<dirs.count(); i++)
if (dirs[i] == absPath) return;
dirs.append(absPath);
}
QStringList ExtScript::directories()
{
if (debug) qDebug() << PDEBUG;
return dirs;
}
int ExtScript::getInterval()
{
if (debug) qDebug() << PDEBUG;
return interval;
}
QString ExtScript::getPrefix()
{
if (debug) qDebug() << PDEBUG;
return prefix;
}
ExtScript::Redirect ExtScript::getRedirect()
{
if (debug) qDebug() << PDEBUG;
return redirect;
}
bool ExtScript::hasOutput()
{
if (debug) qDebug() << PDEBUG;
return output;
}
bool ExtScript::isActive()
{
if (debug) qDebug() << PDEBUG;
return active;
}
void ExtScript::setActive(const bool state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
active = state;
}
void ExtScript::setDirectories(const QStringList directories)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Directories" << directories;
for (int i=0; i<directories.count(); i++)
addDirectory(directories[i]);
}
void ExtScript::setHasOutput(const bool state)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
output = state;
}
void ExtScript::setInterval(const int inter)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Interval" << inter;
if (inter <= 0) return;
interval = inter;
}
void ExtScript::setPrefix(const QString pref)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Prefix" << pref;
prefix = pref;
}
void ExtScript::setRedirect(const Redirect redir)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Redirect" << redir;
redirect = redir;
}
void ExtScript::readConfiguration()
{
if (debug) qDebug() << PDEBUG;
QMap<QString, QString> settings;
for (int i=0; i<dirs.count(); i++) {
if (!QDir(dirs[i]).entryList().contains(name + QString(".conf"))) continue;
QString fileName = dirs[i] + QDir::separator() + name + QString(".conf");
QMap<QString, QString> newSettings = getConfigurationFromFile(fileName);
for (int i=0; i<newSettings.keys().count(); i++)
settings[newSettings.keys()[i]] = newSettings[newSettings.keys()[i]];
}
fromExternalConfiguration(settings);
}
void ExtScript::fromExternalConfiguration(const QMap<QString, QString> 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<QString, QString> ExtScript::getConfigurationFromFile(const QString fileName)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "File" << fileName;
QMap<QString, QString> 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.keys().count(); i++)
if (debug) qDebug() << PDEBUG << ":" << settings.keys()[i] + QString("=") + settings[settings.keys()[i]];
return settings;
}
QMap<QString, QString> ExtScript::toExternalConfiguration()
{
if (debug) qDebug() << PDEBUG;
}

View File

@ -0,0 +1,72 @@
/***************************************************************************
* 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/ *
***************************************************************************/
#ifndef EXTSCRIPT_H
#define EXTSCRIPT_H
#include <QObject>
#include <QStringList>
class ExtScript : public QObject
{
enum Redirect {
stdout2stderr = -1,
nothing,
stderr2stdout
};
public:
ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd = false);
~ExtScript();
// configuration
void addDirectory(const QString dir);
QStringList directories();
int getInterval();
QString getPrefix();
Redirect getRedirect();
bool hasOutput();
bool isActive();
void setActive(const bool state = true);
void setDirectories(const QStringList directories);
void setHasOutput(const bool state = true);
void setInterval(const int inter = 1);
void setPrefix(const QString pref = QString(""));
void setRedirect(const Redirect redir);
public slots:
void readConfiguration();
private:
// configuration
void fromExternalConfiguration(const QMap<QString, QString> settings);
QMap<QString, QString> getConfigurationFromFile(const QString fileName);
QMap<QString, QString> 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 */

View File

@ -0,0 +1,3 @@
#!/bin/bash
curl ip4.telize.com

View File

@ -0,0 +1,5 @@
ACTIVE=true
INTERVAL=1
PREFIX=
OUTPUT=true
REDIRECT=0

View File

@ -0,0 +1,3 @@
#!/usr/bin/python
print ("Hello the f$%king world!")

View File

@ -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