mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 23:29:58 +00:00
migrate to ksystemstats
This commit is contained in:
@ -14,5 +14,5 @@ include_directories(
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp)
|
||||
file(GLOB SUBPROJECT_HEADER *.h)
|
||||
|
||||
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
|
||||
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER} ksystemstatssource.cpp ksystemstatssource.h)
|
||||
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define ABSTRACTEXTSYSMONSOURCE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
@ -38,13 +38,14 @@ public:
|
||||
// used by extensions
|
||||
static int index(const QString &_source)
|
||||
{
|
||||
QRegExp rx("\\d+");
|
||||
rx.indexIn(_source);
|
||||
return rx.cap().toInt();
|
||||
QRegularExpression rx("\\d+");
|
||||
return rx.match(_source).captured().toInt();
|
||||
}
|
||||
|
||||
signals:
|
||||
void dataReceived(const QVariantHash &);
|
||||
void sourceAdded(const QString &_source);
|
||||
void sourceRemoved(const QString &_source);
|
||||
};
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ HDDTemperatureSource::~HDDTemperatureSource()
|
||||
QStringList HDDTemperatureSource::allHdd()
|
||||
{
|
||||
QStringList allDevices = QDir("/dev").entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$"));
|
||||
QStringList devices = allDevices.filter(QRegularExpression("^[hms]d[a-z]$"));
|
||||
for (int i = 0; i < devices.count(); i++)
|
||||
devices[i] = QString("/dev/%1").arg(devices.at(i));
|
||||
|
||||
|
143
sources/extsysmonsources/ksystemstatssource.cpp
Normal file
143
sources/extsysmonsources/ksystemstatssource.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/***************************************************************************
|
||||
* 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 "ksystemstatssource.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <systemstats/DBusInterface.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
KSystemStatsSource::KSystemStatsSource(QObject *_parent, const QStringList &_args)
|
||||
: AbstractExtSysMonSource(_parent, _args)
|
||||
{
|
||||
Q_ASSERT(_args.count() == 0);
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
qDBusRegisterMetaType<KSysGuard::SensorData>();
|
||||
qDBusRegisterMetaType<KSysGuard::SensorInfo>();
|
||||
qDBusRegisterMetaType<KSysGuard::SensorDataList>();
|
||||
qDBusRegisterMetaType<QHash<QString, KSysGuard::SensorInfo>>();
|
||||
|
||||
m_interface = new KSysGuard::SystemStats::DBusInterface(
|
||||
KSysGuard::SystemStats::ServiceName, KSysGuard::SystemStats::ObjectPath, QDBusConnection::sessionBus(), this);
|
||||
connect(m_interface, SIGNAL(newSensorData(KSysGuard::SensorDataList)), this,
|
||||
SLOT(updateData(KSysGuard::SensorDataList)));
|
||||
connect(m_interface, SIGNAL(sensorAdded(const QString &)), this, SLOT(sensorAdded(const QString &)));
|
||||
connect(m_interface, SIGNAL(sensorMetaDataChanged(const QHash<QString, KSysGuard::SensorInfo> &)), this,
|
||||
SLOT(updateSensor(const QHash<QString, KSysGuard::SensorInfo> &)));
|
||||
connect(m_interface, SIGNAL(sensorRemoved(const QString &)), this, SLOT(sensorRemoved(const QString &)));
|
||||
|
||||
loadSources();
|
||||
m_interface->subscribe(m_sources.keys());
|
||||
}
|
||||
|
||||
|
||||
KSystemStatsSource::~KSystemStatsSource()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QVariant KSystemStatsSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
return m_values.value(_source, {});
|
||||
}
|
||||
|
||||
|
||||
QVariantMap KSystemStatsSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
return m_sources.value(_source, QVariantMap()).toMap();
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::run() {}
|
||||
|
||||
|
||||
QStringList KSystemStatsSource::sources() const
|
||||
{
|
||||
return m_sources.keys();
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::sensorAdded(const QString &_sensor)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Sensor" << _sensor << "added";
|
||||
|
||||
auto sensors = QStringList(_sensor);
|
||||
|
||||
auto response = m_interface->sensors(sensors);
|
||||
response.waitForFinished();
|
||||
auto metadata = response.value();
|
||||
|
||||
updateSensor(metadata);
|
||||
|
||||
m_interface->subscribe(sensors);
|
||||
emit(sourceAdded(_sensor));
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::sensorRemoved(const QString &_sensor)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Sensor" << _sensor << "removed";
|
||||
|
||||
m_values.remove(_sensor);
|
||||
m_sources.remove(_sensor);
|
||||
emit(sourceRemoved(_sensor));
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::updateData(KSysGuard::SensorDataList _data)
|
||||
{
|
||||
for (auto &change : _data)
|
||||
m_values[change.sensorProperty] = change.payload;
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::updateSensor(const QHash<QString, KSysGuard::SensorInfo> &_sensor)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Sensors" << _sensor.keys() << "were updated";
|
||||
|
||||
for (auto it = _sensor.constBegin(); it != _sensor.constEnd(); it++) {
|
||||
auto value = it.value();
|
||||
|
||||
QVariantMap data;
|
||||
data["min"] = value.min;
|
||||
data["max"] = value.max;
|
||||
data["name"] = value.name;
|
||||
data["type"] = value.variantType;
|
||||
data["units"] = value.unit;
|
||||
|
||||
m_sources[it.key()] = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KSystemStatsSource::loadSources()
|
||||
{
|
||||
auto response = m_interface->allSensors();
|
||||
response.waitForFinished();
|
||||
auto metadata = response.value();
|
||||
|
||||
updateSensor(metadata);
|
||||
}
|
58
sources/extsysmonsources/ksystemstatssource.h
Normal file
58
sources/extsysmonsources/ksystemstatssource.h
Normal file
@ -0,0 +1,58 @@
|
||||
/***************************************************************************
|
||||
* 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 KSYSTEMSTATSSOURCE_H
|
||||
#define KSYSTEMSTATSSOURCE_H
|
||||
|
||||
#include <systemstats/SensorInfo.h>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
|
||||
|
||||
namespace KSysGuard::SystemStats
|
||||
{
|
||||
class DBusInterface;
|
||||
}
|
||||
|
||||
|
||||
class KSystemStatsSource : public AbstractExtSysMonSource
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KSystemStatsSource(QObject *_parent, const QStringList &_args);
|
||||
~KSystemStatsSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
public slots:
|
||||
void sensorAdded(const QString &_sensor);
|
||||
void sensorRemoved(const QString &_sensor);
|
||||
void updateData(KSysGuard::SensorDataList _data);
|
||||
void updateSensor(const QHash<QString, KSysGuard::SensorInfo> &_sensor);
|
||||
|
||||
private:
|
||||
KSysGuard::SystemStats::DBusInterface *m_interface = nullptr;
|
||||
QVariantHash m_values;
|
||||
QVariantHash m_sources;
|
||||
void loadSources();
|
||||
};
|
||||
|
||||
|
||||
#endif /* KSYSTEMSTATSSOURCE_H */
|
@ -80,7 +80,7 @@ QVariantMap ProcessesSource::initialData(const QString &_source) const
|
||||
void ProcessesSource::run()
|
||||
{
|
||||
QStringList allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
QStringList directories = allDirectories.filter(QRegExp("(\\d+)"));
|
||||
QStringList directories = allDirectories.filter(QRegularExpression("(\\d+)"));
|
||||
QStringList running;
|
||||
|
||||
for (auto &dir : directories) {
|
||||
|
Reference in New Issue
Block a user