refactor: simplify sources processing

Also fix desktop source
This commit is contained in:
2024-03-28 11:14:45 +02:00
parent 0bcceefd47
commit a35b57e5d2
69 changed files with 552 additions and 1087 deletions

View File

@ -15,31 +15,19 @@
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "requestsource.h"
#include <ksysguard/formatter/Unit.h>
#include <ksysguard/systemstats/SensorInfo.h>
#include "awdebug.h"
#include "extnetworkrequest.h"
RequestSource::RequestSource(QObject *_parent, const QStringList &_args)
: AbstractExtSysMonSource(_parent, _args)
RequestSource::RequestSource(QObject *_parent)
: AbstractExtSysMonSource(_parent)
{
Q_ASSERT(_args.count() == 0);
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
m_extNetRequest = new ExtItemAggregator<ExtNetworkRequest>(nullptr, "requests");
m_extNetRequest->initSockets();
m_sources = getSources();
}
RequestSource::~RequestSource()
{
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
}
@ -47,44 +35,18 @@ QVariant RequestSource::data(const QString &_source)
{
qCDebug(LOG_ESS) << "Source" << _source;
int ind = index(_source);
if (!m_values.contains(_source)) {
QVariantHash data = m_extNetRequest->itemByTagNumber(ind)->run();
for (auto &key : data.keys())
m_values[key] = data[key];
}
QVariant value = m_values.take(_source);
return value;
// there are only one value
return dataByItem(m_extNetRequest, _source).values().first();
}
KSysGuard::SensorInfo *RequestSource::initialData(const QString &_source) const
QHash<QString, KSysGuard::SensorInfo *> RequestSource::sources() const
{
qCDebug(LOG_ESS) << "Source" << _source;
auto result = QHash<QString, KSysGuard::SensorInfo *>();
int ind = index(_source);
auto data = new KSysGuard::SensorInfo();
if (_source.startsWith("response")) {
data->name = QString("Network response for %1").arg(m_extNetRequest->itemByTagNumber(ind)->uniq());
data->variantType = QVariant::String;
data->unit = KSysGuard::UnitNone;
}
return data;
}
QStringList RequestSource::sources() const
{
return m_sources;
}
QStringList RequestSource::getSources()
{
QStringList sources;
for (auto &item : m_extNetRequest->activeItems())
sources.append(item->tag("response"));
result.insert(item->tag("response"),
makeSensorInfo(QString("Network response for %1").arg(item->uniq()), QVariant::String));
return sources;
return result;
}