mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
parent
7e42c8cb49
commit
4a6aaa95b0
@ -77,7 +77,7 @@ bool AWUpdateHelper::checkVersion()
|
|||||||
|
|
||||||
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
|
||||||
if (version != QString(VERSION)) {
|
if (version != QString(VERSION)) {
|
||||||
genMessageBox(i18n("Changelog of %1", VERSION),
|
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
|
||||||
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
|
||||||
QMessageBox::Ok)
|
QMessageBox::Ok)
|
||||||
->open();
|
->open();
|
||||||
|
@ -82,7 +82,6 @@ private:
|
|||||||
QString m_prefix = QString("");
|
QString m_prefix = QString("");
|
||||||
Redirect m_redirect = nothing;
|
Redirect m_redirect = nothing;
|
||||||
// internal properties
|
// internal properties
|
||||||
Q_PID childProcess = 0;
|
|
||||||
QVariantMap jsonFilters = QVariantMap();
|
QVariantMap jsonFilters = QVariantMap();
|
||||||
int times = 0;
|
int times = 0;
|
||||||
QVariantHash value;
|
QVariantHash value;
|
||||||
|
@ -18,10 +18,9 @@
|
|||||||
|
|
||||||
#include "hddtempsource.h"
|
#include "hddtempsource.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include <task/taskadds.h>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
@ -37,12 +36,29 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *parent,
|
|||||||
|
|
||||||
m_smartctl = m_cmd.contains(QString("smartctl"));
|
m_smartctl = m_cmd.contains(QString("smartctl"));
|
||||||
qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl;
|
qCInfo(LOG_ESM) << "Parse as smartctl" << m_smartctl;
|
||||||
|
|
||||||
|
for (auto device : m_devices) {
|
||||||
|
m_processes[device] = new QProcess(nullptr);
|
||||||
|
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
|
||||||
|
connect(m_processes[device],
|
||||||
|
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
|
||||||
|
&QProcess::finished),
|
||||||
|
[this, device](int, QProcess::ExitStatus) {
|
||||||
|
return updateValue(device);
|
||||||
|
});
|
||||||
|
m_processes[device]->waitForFinished(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HDDTemperatureSource::~HDDTemperatureSource()
|
HDDTemperatureSource::~HDDTemperatureSource()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
for (auto device : m_devices) {
|
||||||
|
m_processes[device]->kill();
|
||||||
|
m_processes[device]->deleteLater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -51,36 +67,11 @@ QVariant HDDTemperatureSource::data(QString source)
|
|||||||
qCDebug(LOG_ESM) << "Source" << source;
|
qCDebug(LOG_ESM) << "Source" << source;
|
||||||
|
|
||||||
QString device = source.remove(QString("hdd/temperature"));
|
QString device = source.remove(QString("hdd/temperature"));
|
||||||
float value = 0.0;
|
|
||||||
// run cmd
|
// run cmd
|
||||||
TaskResult process = runTask(QString("%1 %2").arg(m_cmd).arg(device));
|
if (m_processes[device]->state() == QProcess::NotRunning)
|
||||||
qCInfo(LOG_ESM) << "Cmd returns" << process.exitCode;
|
m_processes[device]->start(QString("%1 %2").arg(m_cmd).arg(device));
|
||||||
qCInfo(LOG_ESM) << "Error" << process.error;
|
|
||||||
|
|
||||||
// parse
|
return m_values[device];
|
||||||
QString qoutput
|
|
||||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
|
||||||
if (m_smartctl) {
|
|
||||||
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
|
||||||
if (!str.startsWith(QString("194")))
|
|
||||||
continue;
|
|
||||||
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
|
|
||||||
break;
|
|
||||||
value = str.split(QChar(' '), QString::SkipEmptyParts)
|
|
||||||
.at(9)
|
|
||||||
.toFloat();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
|
|
||||||
QString temp
|
|
||||||
= qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2);
|
|
||||||
temp.remove(QChar(0260)).remove(QChar('C'));
|
|
||||||
value = temp.toFloat();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,3 +99,42 @@ QStringList HDDTemperatureSource::sources() const
|
|||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HDDTemperatureSource::updateValue(const QString &device)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Called with device" << device;
|
||||||
|
|
||||||
|
qCInfo(LOG_LIB) << "Cmd returns" << m_processes[device]->exitCode();
|
||||||
|
QString qdebug
|
||||||
|
= QTextCodec::codecForMib(106)
|
||||||
|
->toUnicode(m_processes[device]->readAllStandardError())
|
||||||
|
.trimmed();
|
||||||
|
qCInfo(LOG_LIB) << "Error" << qdebug;
|
||||||
|
QString qoutput
|
||||||
|
= QTextCodec::codecForMib(106)
|
||||||
|
->toUnicode(m_processes[device]->readAllStandardOutput())
|
||||||
|
.trimmed();
|
||||||
|
qCInfo(LOG_LIB) << "Output" << qoutput;
|
||||||
|
|
||||||
|
// parse
|
||||||
|
if (m_smartctl) {
|
||||||
|
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
|
if (!str.startsWith(QString("194")))
|
||||||
|
continue;
|
||||||
|
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
|
||||||
|
continue;
|
||||||
|
m_values[device] = str.split(QChar(' '), QString::SkipEmptyParts)
|
||||||
|
.at(9)
|
||||||
|
.toFloat();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
|
||||||
|
QString temp
|
||||||
|
= qoutput.split(QChar(':'), QString::SkipEmptyParts).at(2);
|
||||||
|
temp.remove(QChar(0260)).remove(QChar('C'));
|
||||||
|
m_values[device] = temp.toFloat();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include "abstractextsysmonsource.h"
|
#include "abstractextsysmonsource.h"
|
||||||
|
|
||||||
|
|
||||||
|
class QProcess;
|
||||||
|
|
||||||
class HDDTemperatureSource : public AbstractExtSysMonSource
|
class HDDTemperatureSource : public AbstractExtSysMonSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -33,11 +35,17 @@ public:
|
|||||||
void run(){};
|
void run(){};
|
||||||
QStringList sources() const;
|
QStringList sources() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateValue(const QString &device);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// properties
|
||||||
|
QHash<QString, QProcess *> m_processes;
|
||||||
// configuration and values
|
// configuration and values
|
||||||
QString m_cmd;
|
QString m_cmd;
|
||||||
QStringList m_devices;
|
QStringList m_devices;
|
||||||
bool m_smartctl;
|
bool m_smartctl;
|
||||||
|
QHash<QString, QVariant> m_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user