mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
add support of multithreading to dataengine (only for custom command
now)
This commit is contained in:
parent
e205664fec
commit
926d112d22
@ -143,6 +143,17 @@ void ExtendedSysMon::readConfiguration()
|
|||||||
}
|
}
|
||||||
confFile.close();
|
confFile.close();
|
||||||
configuration = updateConfiguration(rawConfig);
|
configuration = updateConfiguration(rawConfig);
|
||||||
|
setCustomProcesses();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExtendedSysMon::setCustomProcesses()
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << "[DE]" << "[setCustomProcesses]";
|
||||||
|
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
||||||
|
customProcesses.append(new QProcess);
|
||||||
|
connect(customProcesses[i], SIGNAL(readyReadStandardOutput()), this, SLOT(setCustomCmd()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -206,19 +217,29 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ExtendedSysMon::getCustomCmd(const QString cmd)
|
void ExtendedSysMon::getCustomCmd(const QString cmd, const int number)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]";
|
if (debug) qDebug() << "[DE]" << "[getCustomCmd]";
|
||||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd;
|
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run function with cmd" << cmd;
|
||||||
QProcess command;
|
|
||||||
QString qoutput = QString("");
|
|
||||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\"");
|
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Run cmd" << QString("bash -c \"") + cmd + QString("\"");
|
||||||
command.start(QString("bash -c \"") + cmd + QString("\""));
|
customProcesses[number]->start(QString("bash -c \"") + cmd + QString("\""));
|
||||||
command.waitForFinished(-1);
|
}
|
||||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Cmd returns" << command.exitCode();
|
|
||||||
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
|
|
||||||
if (debug) qDebug() << "[DE]" << "[getCustomCmd]" << ":" << "Return" << qoutput;
|
void ExtendedSysMon::setCustomCmd()
|
||||||
return qoutput;
|
{
|
||||||
|
if (debug) qDebug() << "[DE]" << "[setCustomCmd]";
|
||||||
|
for (int i=0; i<customProcesses.count(); i++) {
|
||||||
|
QString value = QString("");
|
||||||
|
value = QTextCodec::codecForMib(106)->toUnicode(customProcesses[i]->readAllStandardOutput()).trimmed();
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Found output for cmd" << i;
|
||||||
|
if (debug) qDebug() << "[DE]" << "[setCustomCmd]" << ":" << "Return" << value;
|
||||||
|
QString source = QString("custom");
|
||||||
|
QString key = QString("custom") + QString::number(i);
|
||||||
|
setData(source, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -553,9 +574,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
|||||||
QString key;
|
QString key;
|
||||||
if (source == QString("custom")) {
|
if (source == QString("custom")) {
|
||||||
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
|
||||||
key = QString("custom") + QString::number(i);
|
getCustomCmd(configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts)[i], i);
|
||||||
QString value = getCustomCmd(configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts)[i]);
|
|
||||||
setData(source, key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (source == QString("gpu")) {
|
else if (source == QString("gpu")) {
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <Plasma/DataEngine>
|
#include <Plasma/DataEngine>
|
||||||
|
|
||||||
|
class QProcess;
|
||||||
|
|
||||||
class ExtendedSysMon : public Plasma::DataEngine
|
class ExtendedSysMon : public Plasma::DataEngine
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -27,7 +29,7 @@ class ExtendedSysMon : public Plasma::DataEngine
|
|||||||
public:
|
public:
|
||||||
ExtendedSysMon(QObject *parent, const QVariantList &args);
|
ExtendedSysMon(QObject *parent, const QVariantList &args);
|
||||||
// update functions
|
// update functions
|
||||||
QString getCustomCmd(const QString cmd);
|
void getCustomCmd(const QString cmd, const int number);
|
||||||
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);
|
||||||
@ -43,7 +45,12 @@ protected:
|
|||||||
bool updateSourceEvent(const QString &source);
|
bool updateSourceEvent(const QString &source);
|
||||||
QStringList sources() const;
|
QStringList sources() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void setCustomCmd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// processes
|
||||||
|
QList<QProcess*> customProcesses;
|
||||||
// configuration
|
// configuration
|
||||||
QMap<QString, QString> configuration;
|
QMap<QString, QString> configuration;
|
||||||
bool debug;
|
bool debug;
|
||||||
@ -51,6 +58,7 @@ private:
|
|||||||
QString getAllHdd();
|
QString getAllHdd();
|
||||||
QString getAutoGpu();
|
QString getAutoGpu();
|
||||||
void readConfiguration();
|
void readConfiguration();
|
||||||
|
void setCustomProcesses();
|
||||||
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user