Commit 27197f5d authored by Marco Martin's avatar Marco Martin
Browse files

store client side the regular expressions

store client side the regular expressions and user readable names for
all sensors
parent 69ecec28
......@@ -8,6 +8,7 @@ set(sensors_LIB_SRCS
Sensor.cpp
SensorDataModel.cpp
SensorTreeModel.cpp
SensorGroup.cpp
SensorQuery.cpp
SensorDaemonInterface.cpp
)
......
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <QRegularExpression>
#include <QDebug>
#include <KLocalizedString>
namespace KSysGuard
{
QString groupRegexForId(const QString &key)
{
QRegularExpression cpuExpr(QStringLiteral("cpu/cpu\\d+/(.*)"));
QRegularExpression netRecExpr(QStringLiteral("network/interfaces/.*/receiver/(.*)"));
QRegularExpression netTransExpr(QStringLiteral("network/interfaces/.*/transmitter/(.*)"));
QRegularExpression partitionsExpr(QStringLiteral("partitions/.*/(.*)$"));
if (key.contains(cpuExpr)) {
QString expr = key;
return expr.replace(cpuExpr, QStringLiteral("cpu/cpu\\d+/\\1"));
} else if (key.contains(netRecExpr)) {
QString expr = key;
return expr.replace(netRecExpr, QStringLiteral("network/interfaces/.*/receiver/\\1"));
} else if (key.contains(netTransExpr)) {
QString expr = key;
return expr.replace(netTransExpr, QStringLiteral("network/interfaces/.*/transmitter/\\1"));
} else if (key.contains(partitionsExpr)) {
QString expr = key;
return expr.replace(partitionsExpr, QStringLiteral("partitions/.*/\\1"));
}
return QString();
}
QString sensorNameForRegEx(const QString &expr)
{
if (expr == QStringLiteral("cpu/cpu\\d+/TotalLoad")) {
return i18nc("Total load sensor of all cores", "[Group] CPU (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/user")) {
return i18nc("All cores user load sensors", "[Group] User Load (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/nice")) {
return i18nc("All cores nice load sensors", "[Group] Nice Load (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/sys")) {
return i18nc("All cores user system sensors", "[Group] System Load (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/idle")) {
return i18nc("All cores idle load sensors", "[Group] Idle Load (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/wait")) {
return i18nc("All cores wait load sensors", "[Group] Wait Load (%)");
} else if (expr == QStringLiteral("cpu/cpu\\d+/clock")) {
return i18nc("All cores clock frequency sensors", "[Group] Clock Frequency (MHz)");
} else if (expr == QStringLiteral("partitions/.*/usedspace")) {
return i18n("[Group] Used (KiB)");
} else if (expr == QStringLiteral("partitions/.*/freespace")) {
return i18n("[Group] Available (KiB)");
} else if (expr == QStringLiteral("partitions/.*/filllevel")) {
return i18n("[Group] Percentage Used (%)");
} else if (expr == QStringLiteral("partitions/.*/total")) {
return i18n("[Group] Total Size (KiB)");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/data")) {
return i18n("[Group] Received Data Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/dataTotal")) {
return i18n("[Group] Received Data");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/packets")) {
return i18n("[Group] Received Packets Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/packetsTotal")) {
return i18n("[Group] Received Packets");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/errors")) {
return i18n("[Group] Receiver Errors Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/errorsTotal")) {
return i18n("[Group] Receiver Errors");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/drops")) {
return i18n("[Group] Receiver Drops Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/dropsTotal")) {
return i18n("[Group] Receiver Drops");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/fifo")) {
return i18n("[Group] Receiver Fifo Overruns Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/fifoTotal")) {
return i18n("[Group] Receiver Fifo Overruns");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/frame")) {
return i18n("[Group] Receiver Frame Errors Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/frameTotal")) {
return i18n("[Group] Receiver Frame Errors");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/compressed")) {
return i18n("[Group] Compressed Packets Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/compressedTotal")) {
return i18n("[Group] Compressed Packets");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/multicast")) {
return i18n("[Group] Received Multicast Packets Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/receiver/multicastTotal")) {
return i18n("[Group] Multicast Packets");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/data")) {
return i18n("[Group] Sent Data Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/dataTotal")) {
return i18n("[Group] Sent Data ");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/packets")) {
return i18n("[Group] Sent Packets Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/packetsTotal")) {
return i18n("[Group] Sent Packets");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/errors")) {
return i18n("[Group] Transmitter Errors Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/errorsTotal")) {
return i18n("[Group] Transmitter Errors");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/drops")) {
return i18n("[Group] Transmitter Drops Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/dropsTotal")) {
return i18n("[Group] Transmitter Drops");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/fifo")) {
return i18n("[Group] Transmitter FIFO Overruns Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/fifoTotal")) {
return i18n("[Group] FIFO Overruns");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/collisions")) {
return i18n("[Group] Transmitter Collisions Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/collisionsTotal")) {
return i18n("[Group] Transmitter Collisions");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/carrier")) {
return i18n("[Group] Transmitter Carrier Losses Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/carrierTotal")) {
return i18n("[Group] Transmitter Carrier Losses");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/compressed")) {
return i18n("[Group] Transmitter Compressed Packets Rate");
} else if (expr == QStringLiteral("network/interfaces/.*/transmitter/compressedTotal")) {
return i18n("[Group] Transmitter Compressed Packets");
}
return QString();
}
QString segmentNameForRegEx(const QString &expr)
{
if (expr == QLatin1String("cpu\\d+")) {
return i18n("[Group] CPU");
} else if (expr == QLatin1String("disk\\d+")) {
return i18n("[Group] Disk");
} else if (expr == QLatin1String(".*")) {
return i18n("[Group]");
}
return expr;
}
} // namespace KSysGuard
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include <QString>
namespace KSysGuard
{
QString groupRegexForId(const QString &key);
QString sensorNameForRegEx(const QString &expr);
QString segmentNameForRegEx(const QString &expr);
} // namespace KSysGuard
......@@ -32,6 +32,7 @@
#include "SensorDaemonInterface_p.h"
#include "SensorInfo_p.h"
#include "SensorQuery.h"
#include "SensorGroup_p.h"
using namespace KSysGuard;
......@@ -108,10 +109,9 @@ void SensorTreeModel::Private::addSensor(const QString &sensorId, const SensorIn
return;
}
if (sensorId.contains(QRegularExpression(QStringLiteral("\\d+")))) {
QString sensorIdExpr = sensorId;
sensorIdExpr.replace(QRegularExpression(QStringLiteral("(\\d+)")), QStringLiteral("\\d+"));
QString sensorIdExpr = groupRegexForId(sensorId);
if (!sensorIdExpr.isEmpty()) {
if (m_groupMatches.contains(sensorIdExpr)) {
m_groupMatches[sensorIdExpr]++;
} else {
......@@ -120,12 +120,7 @@ void SensorTreeModel::Private::addSensor(const QString &sensorId, const SensorIn
if (m_groupMatches[sensorIdExpr] == 2) {
SensorInfo newInfo;
newInfo.name = info.name;
newInfo.name.replace(QRegularExpression(QStringLiteral("(\\d+)")), QStringLiteral("*"));
newInfo.name = i18nc("Show that this item is not a single sensor but a group of sensors", "[Group] %1", newInfo.name);
newInfo.shortName = info.shortName;
newInfo.shortName.replace(QRegularExpression(QStringLiteral("(\\d+)")), QStringLiteral("*"));
newInfo.shortName = i18nc("Show that this item is not a single sensor but a group of sensors", "[Group] %1", newInfo.shortName);
newInfo.name = sensorNameForRegEx(sensorIdExpr);
newInfo.description = info.description;
newInfo.variantType = info.variantType;
KSysGuard::Unit unit = info.unit;
......@@ -140,7 +135,6 @@ void SensorTreeModel::Private::addSensor(const QString &sensorId, const SensorIn
for (auto segment : segments) {
auto child = item->children.value(segment, nullptr);
if (child) {
item = child;
......@@ -307,7 +301,7 @@ QVariant SensorTreeModel::data(const QModelIndex &index, int role) const
return info.name;
}
return item->segment;
return segmentNameForRegEx(item->segment);
// Only leaf nodes are valid sensors
} else if (role == SensorId) {
if (rowCount(index)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment