mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 16:07:19 +00:00
implement script feature to dataengine
This commit is contained in:
parent
2cd04e1f7f
commit
6a41fa2b8a
@ -33,4 +33,4 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS})
|
|||||||
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
|
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
|
||||||
install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})
|
install (FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})
|
||||||
install (DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})
|
install (DIRECTORY ${SUBPROJECT_SCRIPTS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME} USE_SOURCE_PERMISSIONS)
|
||||||
|
@ -71,6 +71,14 @@ int ExtScript::getInterval()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString ExtScript::getName()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtScript::getPrefix()
|
QString ExtScript::getPrefix()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -166,7 +174,7 @@ void ExtScript::readConfiguration()
|
|||||||
|
|
||||||
QMap<QString, QString> settings;
|
QMap<QString, QString> settings;
|
||||||
for (int i=0; i<dirs.count(); i++) {
|
for (int i=0; i<dirs.count(); i++) {
|
||||||
if (!QDir(dirs[i]).entryList().contains(name + QString(".conf"))) continue;
|
if (!QDir(dirs[i]).entryList(QDir::Files).contains(name + QString(".conf"))) continue;
|
||||||
QString fileName = dirs[i] + QDir::separator() + name + QString(".conf");
|
QString fileName = dirs[i] + QDir::separator() + name + QString(".conf");
|
||||||
QMap<QString, QString> newSettings = getConfigurationFromFile(fileName);
|
QMap<QString, QString> newSettings = getConfigurationFromFile(fileName);
|
||||||
for (int i=0; i<newSettings.keys().count(); i++)
|
for (int i=0; i<newSettings.keys().count(); i++)
|
||||||
@ -177,23 +185,24 @@ void ExtScript::readConfiguration()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QMap<QString, QVariant> ExtScript::run(const int time)
|
ExtScript::ScriptData ExtScript::run(const int time)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QMap<QString, QVariant> response;
|
ScriptData response;
|
||||||
if (time != interval) {
|
response.active = active;
|
||||||
response[QString("refresh")] = false;
|
response.name = name;
|
||||||
return response;
|
response.refresh = false;
|
||||||
}
|
if (!active) return response;
|
||||||
response[QString("refresh")] = true;
|
if (time != interval) return response;
|
||||||
|
response.refresh = true;
|
||||||
|
|
||||||
QStringList cmdList;
|
QStringList cmdList;
|
||||||
if (!prefix.isEmpty())
|
if (!prefix.isEmpty())
|
||||||
cmdList.append(prefix);
|
cmdList.append(prefix);
|
||||||
QString fullPath = name;
|
QString fullPath = name;
|
||||||
for (int i=0; i<dirs.count(); i++) {
|
for (int i=0; i<dirs.count(); i++) {
|
||||||
if (!QDir(dirs[i]).entryList().contains(name)) continue;
|
if (!QDir(dirs[i]).entryList(QDir::Files).contains(name)) continue;
|
||||||
fullPath = dirs[i] + QDir::separator() + name;
|
fullPath = dirs[i] + QDir::separator() + name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -210,15 +219,15 @@ QMap<QString, QVariant> ExtScript::run(const int time)
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput;
|
if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput;
|
||||||
break;
|
break;
|
||||||
case stderr2stdout:
|
case stderr2stdout:
|
||||||
response[QString("output")] = info + QString("\t") + qoutput;
|
response.output = info + QString("\t") + qoutput;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Debug" << info;
|
if (debug) qDebug() << PDEBUG << ":" << "Debug" << info;
|
||||||
response[QString("output")] = qoutput;
|
response.output = qoutput;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!output)
|
if (!output)
|
||||||
response[QString("output")] = QString::number(process.exitCode);
|
response.output = QString::number(process.exitCode);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,26 @@
|
|||||||
|
|
||||||
class ExtScript : public QObject
|
class ExtScript : public QObject
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
enum Redirect {
|
enum Redirect {
|
||||||
stdout2stderr = -1,
|
stdout2stderr = -1,
|
||||||
nothing,
|
nothing,
|
||||||
stderr2stdout
|
stderr2stdout
|
||||||
};
|
};
|
||||||
|
typedef struct {
|
||||||
|
bool active;
|
||||||
|
QString name;
|
||||||
|
QString output;
|
||||||
|
bool refresh;
|
||||||
|
} ScriptData;
|
||||||
|
|
||||||
public:
|
|
||||||
ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd = false);
|
ExtScript(const QString scriptName, const QStringList directories, const bool debugCmd = false);
|
||||||
~ExtScript();
|
~ExtScript();
|
||||||
// configuration
|
// configuration
|
||||||
void addDirectory(const QString dir);
|
void addDirectory(const QString dir);
|
||||||
QStringList directories();
|
QStringList directories();
|
||||||
int getInterval();
|
int getInterval();
|
||||||
|
QString getName();
|
||||||
QString getPrefix();
|
QString getPrefix();
|
||||||
Redirect getRedirect();
|
Redirect getRedirect();
|
||||||
bool hasOutput();
|
bool hasOutput();
|
||||||
@ -50,7 +57,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
QMap<QString, QVariant> run(const int time);
|
ScriptData run(const int time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// configuration
|
// configuration
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
# ACPI devices
|
# ACPI devices
|
||||||
#ACPIPATH=/sys/class/power_supply/
|
#ACPIPATH=/sys/class/power_supply/
|
||||||
|
|
||||||
# Custom command, separator is '@@'
|
|
||||||
#CUSTOM=curl ip4.telize.com
|
|
||||||
|
|
||||||
# Command which returns number of the current desktop
|
# Command which returns number of the current desktop
|
||||||
#DESKTOPCMD=qdbus org.kde.kwin /KWin currentDesktop
|
#DESKTOPCMD=qdbus org.kde.kwin /KWin currentDesktop
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#include <extscript.h>
|
||||||
#include <pdebug/pdebug.h>
|
#include <pdebug/pdebug.h>
|
||||||
#include <task/taskadds.h>
|
#include <task/taskadds.h>
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ ExtendedSysMon::ExtendedSysMon(QObject* parent, const QVariantList& args)
|
|||||||
|
|
||||||
setMinimumPollingInterval(333);
|
setMinimumPollingInterval(333);
|
||||||
readConfiguration();
|
readConfiguration();
|
||||||
|
initScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -146,6 +148,31 @@ QStringList ExtendedSysMon::getDesktopNames()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtendedSysMon::initScripts()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
// create directory at $HOME
|
||||||
|
QString localDir = KStandardDirs::locateLocal("data", "plasma_engine_extsysmon/scripts");
|
||||||
|
if (KStandardDirs::makeDir(localDir))
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
|
||||||
|
|
||||||
|
QStringList dirs = KGlobal::dirs()->findDirs("data", "plasma_engine_extsysmon/scripts");
|
||||||
|
QStringList names;
|
||||||
|
for (int i=0; i<dirs.count(); i++) {
|
||||||
|
QStringList files = QDir(dirs[i]).entryList(QDir::Files, QDir::Name);
|
||||||
|
for (int j=0; j<files.count(); j++) {
|
||||||
|
if (files[j].endsWith(QString(".conf"))) continue;
|
||||||
|
if (names.contains(files[j])) continue;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
|
||||||
|
names.append(files[j]);
|
||||||
|
externalScripts.append(new ExtScript(files[j], dirs, debug));
|
||||||
|
times.append(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList ExtendedSysMon::sources() const
|
QStringList ExtendedSysMon::sources() const
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -173,7 +200,6 @@ void ExtendedSysMon::readConfiguration()
|
|||||||
// pre-setup
|
// pre-setup
|
||||||
QMap<QString, QString> rawConfig;
|
QMap<QString, QString> rawConfig;
|
||||||
rawConfig[QString("ACPIPATH")] = QString("/sys/class/power_supply/");
|
rawConfig[QString("ACPIPATH")] = QString("/sys/class/power_supply/");
|
||||||
rawConfig[QString("CUSTOM")] = QString("curl ip4.telize.com");
|
|
||||||
rawConfig[QString("DESKTOP")] = QString("");
|
rawConfig[QString("DESKTOP")] = QString("");
|
||||||
rawConfig[QString("DESKTOPCMD")] = QString("qdbus org.kde.kwin /KWin currentDesktop");
|
rawConfig[QString("DESKTOPCMD")] = QString("qdbus org.kde.kwin /KWin currentDesktop");
|
||||||
rawConfig[QString("GPUDEV")] = QString("auto");
|
rawConfig[QString("GPUDEV")] = QString("auto");
|
||||||
@ -225,8 +251,7 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
|||||||
key = rawConfig.keys()[i];
|
key = rawConfig.keys()[i];
|
||||||
value = rawConfig[key];
|
value = rawConfig[key];
|
||||||
key.remove(QChar(' '));
|
key.remove(QChar(' '));
|
||||||
if ((key != QString("CUSTOM")) &&
|
if ((key != QString("DESKTOPCMD")) &&
|
||||||
(key != QString("DESKTOPCMD")) &&
|
|
||||||
(key != QString("HDDTEMPCMD")) &&
|
(key != QString("HDDTEMPCMD")) &&
|
||||||
(key != QString("PKGCMD")))
|
(key != QString("PKGCMD")))
|
||||||
value.remove(QChar(' '));
|
value.remove(QChar(' '));
|
||||||
@ -339,18 +364,6 @@ QMap<QString, QVariant> ExtendedSysMon::getCurrentDesktop(const QString cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtendedSysMon::getCustomCmd(const QString cmd)
|
|
||||||
{
|
|
||||||
if (debug) qDebug() << PDEBUG;
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
|
|
||||||
|
|
||||||
TaskResult process = runTask(QString("bash -c \"") + cmd + QString("\""));
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
|
||||||
|
|
||||||
return QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float ExtendedSysMon::getGpu(const QString device)
|
float ExtendedSysMon::getGpu(const QString device)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -595,9 +608,14 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
|||||||
setData(source, battery.keys()[i], battery[battery.keys()[i]].toInt());
|
setData(source, battery.keys()[i], battery[battery.keys()[i]].toInt());
|
||||||
}
|
}
|
||||||
} else if (source == QString("custom")) {
|
} else if (source == QString("custom")) {
|
||||||
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
for (int i=0; i<externalScripts.count(); i++) {
|
||||||
setData(source, QString("custom") + QString::number(i),
|
ExtScript::ScriptData data = externalScripts[i]->run(times[i]);
|
||||||
getCustomCmd(configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts)[i]));
|
if (!data.active) return true;
|
||||||
|
if (data.refresh) {
|
||||||
|
times[i] = 1;
|
||||||
|
setData(source, QString("custom") + QString::number(i), data.output);
|
||||||
|
} else
|
||||||
|
times[i]++;
|
||||||
}
|
}
|
||||||
} else if (source == QString("desktop")) {
|
} else if (source == QString("desktop")) {
|
||||||
QMap<QString, QVariant> desktop = getCurrentDesktop(configuration[QString("DESKTOPCMD")]);
|
QMap<QString, QVariant> desktop = getCurrentDesktop(configuration[QString("DESKTOPCMD")]);
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
#include <Plasma/DataEngine>
|
#include <Plasma/DataEngine>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
|
class ExtScript;
|
||||||
|
|
||||||
class ExtendedSysMon : public Plasma::DataEngine
|
class ExtendedSysMon : public Plasma::DataEngine
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -30,7 +33,6 @@ public:
|
|||||||
// update functions
|
// update functions
|
||||||
QMap<QString, QVariant> getBattery(const QString acpiPath);
|
QMap<QString, QVariant> getBattery(const QString acpiPath);
|
||||||
QMap<QString, QVariant> getCurrentDesktop(const QString cmd);
|
QMap<QString, QVariant> getCurrentDesktop(const QString cmd);
|
||||||
QString getCustomCmd(const QString cmd);
|
|
||||||
float getGpu(const QString device);
|
float getGpu(const QString device);
|
||||||
float getGpuTemp(const QString device);
|
float getGpuTemp(const QString device);
|
||||||
float getHddTemp(const QString cmd, const QString device);
|
float getHddTemp(const QString cmd, const QString device);
|
||||||
@ -49,14 +51,18 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// configuration
|
// configuration
|
||||||
QMap<QString, QString> configuration;
|
QMap<QString, QString> configuration;
|
||||||
|
QList<ExtScript *> externalScripts;
|
||||||
|
QList<int> times;
|
||||||
bool debug;
|
bool debug;
|
||||||
// reread configuration
|
// reread configuration
|
||||||
QString getAllHdd();
|
QString getAllHdd();
|
||||||
QString getAutoGpu();
|
QString getAutoGpu();
|
||||||
QString getAutoMpris();
|
QString getAutoMpris();
|
||||||
QStringList getDesktopNames();
|
QStringList getDesktopNames();
|
||||||
|
void initScripts();
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* EXTSYSMON_H */
|
#endif /* EXTSYSMON_H */
|
||||||
|
0
sources/ext-sysmon/scripts/aw-get-external-ip
Normal file → Executable file
0
sources/ext-sysmon/scripts/aw-get-external-ip
Normal file → Executable file
0
sources/ext-sysmon/scripts/aw-script-template
Normal file → Executable file
0
sources/ext-sysmon/scripts/aw-script-template
Normal file → Executable file
Loading…
Reference in New Issue
Block a user