refactor: simplify sources processing

This commit is contained in:
2024-03-28 11:14:45 +02:00
parent 0bcceefd47
commit 2b1b099c57
68 changed files with 429 additions and 981 deletions

View File

@ -17,28 +17,17 @@
#include "customsource.h"
#include <ksysguard/formatter/Unit.h>
#include <ksysguard/systemstats/SensorInfo.h>
#include "awdebug.h"
#include "extscript.h"
CustomSource::CustomSource(QObject *_parent, const QStringList &_args)
: AbstractExtSysMonSource(_parent, _args)
CustomSource::CustomSource(QObject *_parent)
: AbstractExtSysMonSource(_parent)
{
Q_ASSERT(_args.count() == 0);
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_extScripts = new ExtItemAggregator<ExtScript>(nullptr, "scripts");
m_extScripts = new ExtItemAggregator<ExtScript>(this, "scripts");
m_extScripts->initSockets();
m_sources = getSources();
}
CustomSource::~CustomSource()
{
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
@ -51,30 +40,13 @@ QVariant CustomSource::data(const QString &_source)
}
KSysGuard::SensorInfo *CustomSource::initialData(const QString &_source) const
QHash<QString, KSysGuard::SensorInfo *> CustomSource::sources() const
{
qCDebug(LOG_ESS) << "Source" << _source;
auto result = QHash<QString, KSysGuard::SensorInfo *>();
auto data = new KSysGuard::SensorInfo();
data->name = QString("Custom command '%1' output").arg(m_extScripts->itemByTagNumber(index(_source))->uniq());
data->variantType = QVariant::String;
data->unit = KSysGuard::UnitNone;
return data;
}
QStringList CustomSource::sources() const
{
return m_sources;
}
QStringList CustomSource::getSources()
{
QStringList sources;
for (auto &item : m_extScripts->activeItems())
sources.append(item->tag("custom"));
result.insert(item->tag("custom"),
makeSensorInfo(QString("Custom command '%1' output").arg(item->uniq()), QVariant::String));
return sources;
return result;
}