do not derive from qwidget in aggregates

This commit is contained in:
2024-03-21 18:08:19 +02:00
parent 33a41bb6c0
commit 67640cccdc
35 changed files with 428 additions and 444 deletions

View File

@ -18,6 +18,7 @@
#include "awdataengineaggregator.h"
#include <QDBusConnection>
#include <ksysguard/formatter/Unit.h>
#include <ksysguard/systemstats/DBusInterface.h>
#include "awdebug.h"
@ -33,15 +34,12 @@ AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
qDBusRegisterMetaType<KSysGuard::SensorDataList>();
qDBusRegisterMetaType<QHash<QString, KSysGuard::SensorInfo>>();
m_interface = new KSysGuard::SystemStats::DBusInterface(
KSysGuard::SystemStats::ServiceName, KSysGuard::SystemStats::ObjectPath, QDBusConnection::sessionBus(), this);
m_interface = new KSysGuard::SystemStats::DBusInterface();
connect(m_interface, SIGNAL(newSensorData(KSysGuard::SensorDataList)), this,
SLOT(updateData(KSysGuard::SensorDataList)));
connect(m_interface, SIGNAL(sensorMetaDataChanged(const QHash<QString, KSysGuard::SensorInfo> &)), this,
SLOT(updateSensors(const QHash<QString, KSysGuard::SensorInfo> &)));
connect(m_interface, SIGNAL(sensorAdded(const QString &)), this, SLOT(sensorAdded(const QString &)));
connect(m_interface, SIGNAL(sensorRemoved(const QString &)), this, SLOT(sensorRemoved(const QString &)));
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::newSensorData, this, &AWDataEngineAggregator::updateData);
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorMetaDataChanged, this, &AWDataEngineAggregator::updateSensors);
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorAdded, this, &AWDataEngineAggregator::sensorAdded);
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorRemoved, this, &AWDataEngineAggregator::sensorRemoved);
loadSources();
}
@ -52,6 +50,7 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
disconnectSources();
m_interface->deleteLater();
}
@ -61,6 +60,12 @@ void AWDataEngineAggregator::disconnectSources()
}
bool AWDataEngineAggregator::isValidSensor(const KSysGuard::SensorInfo &_sensor)
{
return _sensor.unit != KSysGuard::UnitInvalid;
}
void AWDataEngineAggregator::loadSources()
{
auto response = m_interface->allSensors();
@ -68,14 +73,12 @@ void AWDataEngineAggregator::loadSources()
auto sensors = response.value();
updateSensors(sensors);
for (auto &sensor : sensors.keys())
sensorAdded(sensor);
}
void AWDataEngineAggregator::reconnectSources(const int interval)
{
qCDebug(LOG_AW) << "Reconnect all sources with update interval" << interval;
qCDebug(LOG_AW) << "Reconnect all sensors with update interval" << interval;
disconnectSources();
m_interface->subscribe(m_sensors.keys());
@ -84,7 +87,7 @@ void AWDataEngineAggregator::reconnectSources(const int interval)
void AWDataEngineAggregator::dropSource(const QString &_source)
{
qCDebug(LOG_AW) << "Disconnect source" << _source;
qCDebug(LOG_AW) << "Disconnect sensor" << _source;
m_interface->unsubscribe({_source});
}
@ -94,6 +97,15 @@ void AWDataEngineAggregator::sensorAdded(const QString &_sensor)
{
qCDebug(LOG_AW) << "New sensor added" << _sensor;
// check if sensor is actually valid
auto response = m_interface->sensors({_sensor});
response.waitForFinished();
auto info = response.value();
if (info.count() != 1)
return;
qCWarning(LOG_AW) << info.keys();
m_interface->subscribe({_sensor});
}
@ -114,6 +126,9 @@ void AWDataEngineAggregator::updateData(KSysGuard::SensorDataList _data)
void AWDataEngineAggregator::updateSensors(const QHash<QString, KSysGuard::SensorInfo> &_sensors)
{
for (auto sensor = _sensors.cbegin(); sensor != _sensors.cend(); ++sensor)
for (auto sensor = _sensors.cbegin(); sensor != _sensors.cend(); ++sensor) {
if (!isValidSensor(sensor.value()))
continue;
m_sensors.insert(sensor.key(), sensor.value());
}
}

View File

@ -40,6 +40,7 @@ public:
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
~AWDataEngineAggregator() override;
void disconnectSources();
[[nodiscard]] bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
void loadSources();
void reconnectSources(const int interval);

View File

@ -92,14 +92,14 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
auto netRegExp = QRegularExpression("^network/.*/(download|upload)$");
auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$");
if (_source == "battery/ac") {
if (_source == "extsysmon/battery/ac") {
// AC
m_map.insert(_source, "ac");
m_formatter["ac"] = AWKeysAggregator::FormatterType::ACFormat;
} else if (_source.startsWith("battery/")) {
} else if (_source.startsWith("extsysmon/battery/")) {
// battery stats
QString key = _source;
key.remove("battery/");
key.remove("extsysmon/battery/");
m_map.insert(_source, key);
m_formatter[key] = _source.contains("rate") ? AWKeysAggregator::FormatterType::Float
: AWKeysAggregator::FormatterType::IntegerThree;
@ -124,21 +124,21 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
key = QString("cpucl%1").arg(key);
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
} else if (_source.startsWith("custom")) {
} else if (_source.startsWith("extsysmon/custom")) {
// custom
QString key = _source;
key.remove("custom/");
key.remove("extsysmon/custom/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "desktop/current/name") {
} else if (_source == "extsysmon/desktop/current/name") {
// current desktop name
m_map.insert(_source, "desktop");
m_formatter["desktop"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "desktop/current/number") {
} else if (_source == "extsysmon/desktop/current/number") {
// current desktop number
m_map.insert(_source, "ndesktop");
m_formatter["ndesktop"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "desktop/total/number") {
} else if (_source == "extsysmon/desktop/total/number") {
// desktop count
m_map.insert(_source, "tdesktops");
m_formatter["tdesktops"] = AWKeysAggregator::FormatterType::NoFormat;
@ -162,11 +162,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
}
} else if (_source == "gpu/load") {
} else if (_source == "extsysmon/gpuload/load") {
// gpu load
m_map.insert(_source, "gpu");
m_formatter["gpu"] = AWKeysAggregator::FormatterType::Float;
} else if (_source == "gpu/temperature") {
} else if (_source == "extsysmon/gputemp/temperature") {
// gpu temperature
m_map.insert(_source, "gputemp");
m_formatter["gputemp"] = AWKeysAggregator::FormatterType::Temperature;
@ -213,7 +213,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat;
}
} else if (_source.startsWith("hdd/temperature")) {
} else if (_source.startsWith("extsysmon/hdd/temperature")) {
// hdd temperature
QString device = _source;
device.remove("hdd/temperature");
@ -254,18 +254,18 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// gb
m_map.insert(_source, "memusedgb");
m_formatter["memusedgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
} else if (_source == "network/current/name") {
} else if (_source == "extsysmon/network/device") {
// network device
m_map.insert(_source, "netdev");
m_formatter["netdev"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "network/current/ssid") {
} else if (_source == "extsysmon/network/ssid") {
// current ssid
m_map.insert(_source, "ssid");
m_formatter["ssid"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source.startsWith("network/response")) {
} else if (_source.startsWith("extsysmon/requests/response")) {
// network response
QString key = _source;
key.remove("network/");
key.remove("extsysmon/requests/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source.contains(netRegExp)) {
@ -300,34 +300,34 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat;
}
} else if (_source.startsWith("upgrade")) {
} else if (_source.startsWith("extsysmon/upgrade")) {
// package manager
QString key = _source;
key.remove("upgrade/");
key.remove("extsysmon/upgrade/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::IntegerThree;
} else if (_source.startsWith("player")) {
} else if (_source.startsWith("extsysmon/player")) {
// player
QString key = _source;
key.remove("player/");
key.remove("extsysmon/player/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "ps/running/count") {
} else if (_source == "extsysmon/ps/running/count") {
// running processes count
m_map.insert(_source, "pscount");
m_formatter["pscount"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source == "ps/running/list") {
} else if (_source == "extsysmon/ps/running/list") {
// list of running processes
m_map.insert(_source, "ps");
m_formatter["ps"] = AWKeysAggregator::FormatterType::List;
} else if (_source == "ps/total/count") {
} else if (_source == "extsysmon/ps/total/count") {
// total processes count
m_map.insert(_source, "pstot");
m_formatter["pstot"] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source.startsWith("quotes")) {
} else if (_source.startsWith("extsysmon/quotes")) {
// quotes
QString key = _source;
key.remove("quotes/");
key.remove("extsysmon/quotes/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Quotes;
} else if (_source == "memory/swap/free") {
@ -377,35 +377,35 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
// timestamp
m_map.insert(_source, "tstime");
m_formatter["tstime"] = AWKeysAggregator::FormatterType::Timestamp;
} else if (_source == "system/brightness") {
} else if (_source == "extsysmon/system/brightness") {
m_map.insert(_source, "brightness");
m_formatter["brightness"] = AWKeysAggregator::FormatterType::IntegerThree;
} else if (_source == "system/volume") {
} else if (_source == "extsysmon/system/volume") {
m_map.insert(_source, "volume");
m_formatter["volume"] = AWKeysAggregator::FormatterType::IntegerThree;
} else if (_source == "system/uptime") {
} else if (_source == "os/system/uptime") {
// uptime
m_map.insert(_source, "uptime");
m_formatter["uptime"] = AWKeysAggregator::FormatterType::Uptime;
// custom uptime
m_map.insert(_source, "cuptime");
m_formatter["cuptime"] = AWKeysAggregator::FormatterType::UptimeCustom;
} else if (_source.startsWith("weather/temperature")) {
} else if (_source.startsWith("extsysmon/weather/temperature")) {
// temperature
QString key = _source;
key.remove("weather/");
key.remove("extsysmon/weather/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
} else if (_source.startsWith("weather/")) {
} else if (_source.startsWith("extsysmon/weather/")) {
// other weather
QString key = _source;
key.remove("weather/");
key.remove("extsysmon/weather/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
} else if (_source.startsWith("load/load")) {
} else if (_source.startsWith("extsysmon/load/load")) {
// load source
QString key = _source;
key.remove("load/");
key.remove("extsysmon/load/");
m_map.insert(_source, key);
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
}

View File

@ -114,8 +114,7 @@ QStringList AWFormatterHelper::rightKeys()
void AWFormatterHelper::editItems()
{
repaintList();
int ret = exec();
auto ret = exec();
qCInfo(LOG_AW) << "Dialog returns" << ret;
}
@ -200,20 +199,20 @@ QPair<QString, AWAbstractFormatter::FormatterClass> AWFormatterHelper::readMetad
QSettings settings(_filePath, QSettings::IniFormat);
settings.beginGroup("Desktop Entry");
QString name = settings.value("Name", _filePath).toString();
QString type = settings.value("X-AW-Type", "NoFormat").toString();
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type);
auto name = settings.value("Name", _filePath).toString();
auto type = settings.value("X-AW-Type", "NoFormat").toString();
auto formatter = defineFormatterClass(type);
settings.endGroup();
return QPair<QString, AWAbstractFormatter::FormatterClass>(name, formatter);
}
void AWFormatterHelper::doCreateItem()
void AWFormatterHelper::doCreateItem(QListWidget *_widget)
{
QStringList selection = {"NoFormat", "DateTime", "Float", "List", "Script", "String", "Json"};
bool ok;
QString select = QInputDialog::getItem(this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
auto select = QInputDialog::getItem(nullptr, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
if (!ok) {
qCWarning(LOG_AW) << "No type selected";
return;
@ -223,18 +222,18 @@ void AWFormatterHelper::doCreateItem()
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(select);
switch (formatter) {
case AWAbstractFormatter::FormatterClass::DateTime:
return createItem<AWDateTimeFormatter>();
return createItem<AWDateTimeFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::Float:
return createItem<AWFloatFormatter>();
return createItem<AWFloatFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::List:
return createItem<AWListFormatter>();
return createItem<AWListFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::Script:
return createItem<AWScriptFormatter>();
return createItem<AWScriptFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::String:
return createItem<AWStringFormatter>();
return createItem<AWStringFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::Json:
return createItem<AWJsonFormatter>();
return createItem<AWJsonFormatter>(_widget);
case AWAbstractFormatter::FormatterClass::NoFormat:
return createItem<AWNoFormatter>();
return createItem<AWNoFormatter>(_widget);
}
}

View File

@ -51,7 +51,7 @@ private:
void initFormatters();
[[nodiscard]] static QPair<QString, AWAbstractFormatter::FormatterClass> readMetadata(const QString &_filePath);
// parent methods
void doCreateItem() override;
void doCreateItem(QListWidget *_widget) override;
// properties
QHash<QString, AWAbstractFormatter *> m_formatters;
QHash<QString, AWAbstractFormatter *> m_formattersClasses;

View File

@ -56,21 +56,16 @@ AWKeys::AWKeys(QObject *_parent)
createDBusInterface();
// update key data if required
connect(m_keyOperator, SIGNAL(updateKeys(const QStringList &)), this, SLOT(reinitKeys(const QStringList &)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTextData()));
connect(m_keyOperator, &AWKeyOperations::updateKeys, this, &AWKeys::reinitKeys);
connect(m_timer, &QTimer::timeout, this, &AWKeys::updateTextData);
// transfer signal from AWDataAggregator object to QML ui
connect(m_dataAggregator, SIGNAL(toolTipPainted(const QString &)), this,
SIGNAL(needToolTipToBeUpdated(const QString &)));
connect(m_dataAggregator, &AWDataAggregator::toolTipPainted, [this](const QString &_tooltip) { emit(needToolTipToBeUpdated(_tooltip)); });
connect(this, SIGNAL(dropSourceFromDataengine(const QString &)), m_dataEngineAggregator,
SLOT(dropSource(const QString &)));
connect(m_dataEngineAggregator,
SIGNAL(dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &, const KSysGuard::SensorDataList &)), this,
SLOT(dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &, const KSysGuard::SensorDataList &)));
connect(this, &AWKeys::dropSourceFromDataengine, m_dataEngineAggregator, &AWDataEngineAggregator::dropSource);
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, this, &AWKeys::dataUpdated);
// transfer signal from dataengine to update source list
connect(m_dataEngineAggregator, SIGNAL(deviceAdded(const QString &)), m_keyOperator,
SLOT(addDevice(const QString &)));
connect(m_dataEngineAggregator, &AWDataEngineAggregator::deviceAdded, m_keyOperator, &AWKeyOperations::addDevice);
}
@ -373,7 +368,7 @@ void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo
// update data or drop source if there are no matches and exit
if (tags.isEmpty()) {
qCInfo(LOG_AW) << "Source" << _source << "not found";
qCInfo(LOG_AW) << "Sensor" << _source << "not found";
return emit(dropSourceFromDataengine(_source));
}