Libksysguard

SensorGroup.cpp
1 /*
2  Copyright (C) 2020 Marco Martin <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "SensorGroup_p.h"
21 
22 #include <QRegularExpression>
23 #include <QDebug>
24 #include <KLocalizedString>
25 
26 namespace KSysGuard
27 {
28 
29 SensorGroup::SensorGroup()
30 {
31  retranslate();
32 }
33 
34 SensorGroup::~SensorGroup()
35 {}
36 
37 void SensorGroup::retranslate()
38 {
39  m_sensorNames.clear();
40  m_segmentNames.clear();
41 
42  m_sensorNames[QStringLiteral("cpu/cpu\\d+/usage")] = i18nc("Total load sensor of all cores", "[Group] Total Usage");
43  m_sensorNames[QStringLiteral("cpu/cpu\\d+/user")] = i18nc("All cores user load sensors", "[Group] User Usage");
44  m_sensorNames[QStringLiteral("cpu/cpu\\d+/system")] = i18nc("All cores user system sensors", "[Group] System Usage");
45  m_sensorNames[QStringLiteral("cpu/cpu\\d+/wait")] = i18nc("All cores wait load sensors", "[Group] Wait Usage");
46  m_sensorNames[QStringLiteral("cpu/cpu\\d+/frequency")] = i18nc("All cores clock frequency sensors", "[Group] Clock Frequency");
47  m_sensorNames[QStringLiteral("cpu/cpu\\d+/temperature")] = i18nc("All cores temperature sensors", "[Group] Temperature");
48  m_sensorNames[QStringLiteral("cpu/cpu\\d+/name")] = i18nc("All cores names", "[Group] Name");
49 
50  m_sensorNames[QStringLiteral("partitions/(?!all).*/usedspace")] = i18n("[Group] Used");
51  m_sensorNames[QStringLiteral("partitions/(?!all).*/freespace")] = i18n("[Group] Available");
52  m_sensorNames[QStringLiteral("partitions/(?!all).*/filllevel")] = i18n("[Group] Percentage Used");
53  m_sensorNames[QStringLiteral("partitions/(?!all).*/total")] = i18n("[Group] Total Size");
54 
55  m_sensorNames[QStringLiteral("network/(?!all).*/network")] = i18n("[Group] Network Name");
56  m_sensorNames[QStringLiteral("network/(?!all).*/ipv4address")] = i18n("[Group] IPv4 Address");
57  m_sensorNames[QStringLiteral("network/(?!all).*/ipv6address")] = i18n("[Group] IPv6 Address");
58  m_sensorNames[QStringLiteral("network/(?!all).*/signal")] = i18n("[Group] Signal Strength");
59  m_sensorNames[QStringLiteral("network/(?!all).*/download")] = i18n("[Group] Download Rate");
60  m_sensorNames[QStringLiteral("network/(?!all).*/totalDownload")] = i18n("[Group] Total Downloaded");
61  m_sensorNames[QStringLiteral("network/(?!all).*/upload")] = i18n("[Group] Upload Rate");
62  m_sensorNames[QStringLiteral("network/(?!all).*/totalUpload")] = i18n("[Group] Total Uploaded");
63 
64  m_sensorNames[QStringLiteral("disk/(?!all).*/name")] = i18n("[Group] Name");
65  m_sensorNames[QStringLiteral("disk/(?!all).*/total")] = i18n("[Group] Total Space");
66  m_sensorNames[QStringLiteral("disk/(?!all).*/used")] = i18n("[Group] Used Space");
67  m_sensorNames[QStringLiteral("disk/(?!all).*/free")] = i18n("[Group] Free Space");
68  m_sensorNames[QStringLiteral("disk/(?!all).*/read")] = i18n("[Group] Read Rate");
69  m_sensorNames[QStringLiteral("disk/(?!all).*/write")] = i18n("[Group] Write Rate");
70  m_sensorNames[QStringLiteral("disk/(?!all).*/usedPercent")] = i18n("[Group] Percentage Used");
71  m_sensorNames[QStringLiteral("disk/(?!all).*/freePercent")] = i18n("[Group] Percentage Free");
72 
73  m_segmentNames[QLatin1String("cpu\\d+")] = i18n("[Group] CPU");
74  m_segmentNames[QLatin1String("disk/(?!all).*")] = i18n("[Group] Disk");
75  m_segmentNames[QLatin1String("(?!all).*")] = i18n("[Group]");
76 }
77 
78 QString SensorGroup::groupRegexForId(const QString &key)
79 {
80 
81  QRegularExpression cpuExpr(QStringLiteral("cpu/cpu\\d+/(.*)"));
82  QRegularExpression netExpr(QStringLiteral("network/(?!all).*/(.*)$"));
83  QRegularExpression partitionsExpr(QStringLiteral("partitions/(?!all).*/(.*)$"));
84  QRegularExpression diskExpr(QStringLiteral("disk/(?!all).*/(.*)"));
85 
86  if (key.contains(cpuExpr)) {
87  QString expr = key;
88  return expr.replace(cpuExpr, QStringLiteral("cpu/cpu\\d+/\\1"));
89 
90  } else if (key.contains(netExpr)) {
91  QString expr = key;
92  return expr.replace(netExpr, QStringLiteral("network/(?!all).*/\\1"));
93 
94  } else if (key.contains(partitionsExpr)) {
95  QString expr = key;
96  return expr.replace(partitionsExpr, QStringLiteral("partitions/(?!all).*/\\1"));
97 
98  } else if (key.contains(diskExpr)) {
99  QString expr = key;
100  return expr.replace(diskExpr, QStringLiteral("disk/(?!all).*/\\1"));
101  }
102 
103  return QString();
104 }
105 
106 QString SensorGroup::sensorNameForRegEx(const QString &expr)
107 {
108  if (m_sensorNames.contains(expr)) {
109  return m_sensorNames.value(expr);
110  }
111 
112  return expr;
113 }
114 
115 QString SensorGroup::segmentNameForRegEx(const QString &expr)
116 {
117  if (m_segmentNames.contains(expr)) {
118  return m_segmentNames.value(expr);
119  }
120 
121  return expr;
122 }
123 
124 } // namespace KSysGuard
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString i18n(const char *text, const TYPE &arg...)
QString & replace(int position, int n, QChar after)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.