Libksysguard

SensorGroup.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "SensorGroup_p.h"
8
9#include <KLocalizedString>
10#include <QDebug>
11#include <QRegularExpression>
12
13namespace KSysGuard
14{
15SensorGroup::SensorGroup()
16{
17 retranslate();
18}
19
20SensorGroup::~SensorGroup()
21{
22}
23
24void SensorGroup::retranslate()
25{
26 m_sensorNames.clear();
27 m_segmentNames.clear();
28
29 m_sensorNames[QStringLiteral("cpu/cpu\\d+/usage")] = i18nc("Total load sensor of all cores", "[Group] Total Usage");
30 m_sensorNames[QStringLiteral("cpu/cpu\\d+/user")] = i18nc("All cores user load sensors", "[Group] User Usage");
31 m_sensorNames[QStringLiteral("cpu/cpu\\d+/system")] = i18nc("All cores user system sensors", "[Group] System Usage");
32 m_sensorNames[QStringLiteral("cpu/cpu\\d+/wait")] = i18nc("All cores wait load sensors", "[Group] Wait Usage");
33 m_sensorNames[QStringLiteral("cpu/cpu\\d+/frequency")] = i18nc("All cores clock frequency sensors", "[Group] Clock Frequency");
34 m_sensorNames[QStringLiteral("cpu/cpu\\d+/temperature")] = i18nc("All cores temperature sensors", "[Group] Temperature");
35 m_sensorNames[QStringLiteral("cpu/cpu\\d+/name")] = i18nc("All cores names", "[Group] Name");
36
37 m_sensorNames[QStringLiteral("partitions/(?!all).*/usedspace")] = i18n("[Group] Used");
38 m_sensorNames[QStringLiteral("partitions/(?!all).*/freespace")] = i18n("[Group] Available");
39 m_sensorNames[QStringLiteral("partitions/(?!all).*/filllevel")] = i18n("[Group] Percentage Used");
40 m_sensorNames[QStringLiteral("partitions/(?!all).*/total")] = i18n("[Group] Total Size");
41
42 m_sensorNames[QStringLiteral("network/(?!all).*/network")] = i18n("[Group] Network Name");
43 m_sensorNames[QStringLiteral("network/(?!all).*/ipv4address")] = i18n("[Group] IPv4 Address");
44 m_sensorNames[QStringLiteral("network/(?!all).*/ipv6address")] = i18n("[Group] IPv6 Address");
45 m_sensorNames[QStringLiteral("network/(?!all).*/signal")] = i18n("[Group] Signal Strength");
46 m_sensorNames[QStringLiteral("network/(?!all).*/download")] = i18n("[Group] Download Rate");
47 m_sensorNames[QStringLiteral("network/(?!all).*/downloadBits")] = i18n("[Group] Download Rate");
48 m_sensorNames[QStringLiteral("network/(?!all).*/totalDownload")] = i18n("[Group] Total Downloaded");
49 m_sensorNames[QStringLiteral("network/(?!all).*/upload")] = i18n("[Group] Upload Rate");
50 m_sensorNames[QStringLiteral("network/(?!all).*/uploadBits")] = i18n("[Group] Upload Rate");
51 m_sensorNames[QStringLiteral("network/(?!all).*/totalUpload")] = i18n("[Group] Total Uploaded");
52
53 m_sensorNames[QStringLiteral("disk/(?!all).*/name")] = i18n("[Group] Name");
54 m_sensorNames[QStringLiteral("disk/(?!all).*/total")] = i18n("[Group] Total Space");
55 m_sensorNames[QStringLiteral("disk/(?!all).*/used")] = i18n("[Group] Used Space");
56 m_sensorNames[QStringLiteral("disk/(?!all).*/free")] = i18n("[Group] Free Space");
57 m_sensorNames[QStringLiteral("disk/(?!all).*/read")] = i18n("[Group] Read Rate");
58 m_sensorNames[QStringLiteral("disk/(?!all).*/write")] = i18n("[Group] Write Rate");
59 m_sensorNames[QStringLiteral("disk/(?!all).*/usedPercent")] = i18n("[Group] Percentage Used");
60 m_sensorNames[QStringLiteral("disk/(?!all).*/freePercent")] = i18n("[Group] Percentage Free");
61
62 m_segmentNames[QLatin1String("cpu\\d+")] = i18n("[Group] CPU");
63 m_segmentNames[QLatin1String("disk/(?!all).*")] = i18n("[Group] Disk");
64 m_segmentNames[QLatin1String("(?!all).*")] = i18n("[Group]");
65}
66
67QString SensorGroup::groupRegexForId(const QString &key)
68{
69 QRegularExpression cpuExpr(QStringLiteral("cpu/cpu\\d+/(.*)"));
70 QRegularExpression netExpr(QStringLiteral("network/(?!all).*/(.*)$"));
71 QRegularExpression partitionsExpr(QStringLiteral("partitions/(?!all).*/(.*)$"));
72 QRegularExpression diskExpr(QStringLiteral("disk/(?!all).*/(.*)"));
73
74 if (key.contains(cpuExpr)) {
75 QString expr = key;
76 return expr.replace(cpuExpr, QStringLiteral("cpu/cpu\\d+/\\1"));
77
78 } else if (key.contains(netExpr)) {
79 QString expr = key;
80 return expr.replace(netExpr, QStringLiteral("network/(?!all).*/\\1"));
81
82 } else if (key.contains(partitionsExpr)) {
83 QString expr = key;
84 return expr.replace(partitionsExpr, QStringLiteral("partitions/(?!all).*/\\1"));
85
86 } else if (key.contains(diskExpr)) {
87 QString expr = key;
88 return expr.replace(diskExpr, QStringLiteral("disk/(?!all).*/\\1"));
89 }
90
91 return QString();
92}
93
94QString SensorGroup::sensorNameForRegEx(const QString &expr)
95{
96 if (m_sensorNames.contains(expr)) {
97 return m_sensorNames.value(expr);
98 }
99
100 return expr;
101}
102
103QString SensorGroup::segmentNameForRegEx(const QString &expr)
104{
105 if (m_segmentNames.contains(expr)) {
106 return m_segmentNames.value(expr);
107 }
108
109 return expr;
110}
111
112} // namespace KSysGuard
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void clear()
bool contains(const Key &key) const const
T value(const Key &key) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:48:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.