mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 15:19:58 +00:00
migrate to ksystemstats
This commit is contained in:
@ -84,7 +84,7 @@ Item {
|
||||
|
||||
Plasmoid.icon: "utilities-system-monitor"
|
||||
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
||||
Plasmoid.associatedApplication: "ksysguard"
|
||||
Plasmoid.associatedApplication: "plasma-systemmonitor"
|
||||
|
||||
|
||||
// ui
|
||||
|
@ -28,15 +28,14 @@ AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines["systemmonitor"] = m_consumer->dataEngine("systemmonitor");
|
||||
m_dataEngines["extsysmon"] = m_consumer->dataEngine("extsysmon");
|
||||
m_dataEngines["time"] = m_consumer->dataEngine("time");
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
m_newSourceConnection
|
||||
= connect(m_dataEngines["systemmonitor"], &Plasma::DataEngine::sourceAdded, [this](const QString &source) {
|
||||
= connect(m_dataEngines["extsysmon"], &Plasma::DataEngine::sourceAdded, [this](const QString &source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines["systemmonitor"]->connectSource(source, parent(), 1000);
|
||||
m_dataEngines["extsysmon"]->connectSource(source, parent(), 1000);
|
||||
});
|
||||
|
||||
// required to define Qt::QueuedConnection for signal-slot connection
|
||||
@ -67,15 +66,14 @@ void AWDataEngineAggregator::reconnectSources(const int _interval)
|
||||
|
||||
disconnectSources();
|
||||
|
||||
m_dataEngines["systemmonitor"]->connectAllSources(parent(), (uint)_interval);
|
||||
m_dataEngines["extsysmon"]->connectAllSources(parent(), (uint)_interval);
|
||||
m_dataEngines["time"]->connectSource("Local", parent(), 1000);
|
||||
|
||||
m_newSourceConnection = connect(
|
||||
m_dataEngines["systemmonitor"], &Plasma::DataEngine::sourceAdded, [this, _interval](const QString &source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines["systemmonitor"]->connectSource(source, parent(), (uint)_interval);
|
||||
});
|
||||
m_newSourceConnection = connect(m_dataEngines["extsysmon"], &Plasma::DataEngine::sourceAdded,
|
||||
[this, _interval](const QString &source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines["extsysmon"]->connectSource(source, parent(), (uint)_interval);
|
||||
});
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
createQueuedConnection();
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "awdataenginemapper.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awformatterhelper.h"
|
||||
@ -81,15 +81,16 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
|
||||
// regular expressions
|
||||
QRegExp cpuRegExp = QRegExp("cpu/cpu.*/TotalLoad");
|
||||
QRegExp cpuclRegExp = QRegExp("cpu/cpu.*/clock");
|
||||
QRegExp hddrRegExp = QRegExp("disk/.*/Rate/rblk");
|
||||
QRegExp hddwRegExp = QRegExp("disk/.*/Rate/wblk");
|
||||
QRegExp mountFillRegExp = QRegExp("partitions/.*/filllevel");
|
||||
QRegExp mountFreeRegExp = QRegExp("partitions/.*/freespace");
|
||||
QRegExp mountUsedRegExp = QRegExp("partitions/.*/usedspace");
|
||||
QRegExp netRegExp = QRegExp("network/interfaces/.*/(receiver|transmitter)/data$");
|
||||
QRegExp netTotalRegExp = QRegExp("network/interfaces/.*/(receiver|transmitter)/dataTotal$");
|
||||
auto cpuRegExp = QRegularExpression("^cpu/cpu.*/usage$");
|
||||
auto cpuclRegExp = QRegularExpression("^cpu/cpu.*/frequency$");
|
||||
auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
auto hddrRegExp = QRegularExpression("^disk/.*/read$");
|
||||
auto hddwRegExp = QRegularExpression("^disk/.*/write$");
|
||||
auto mountFillRegExp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
auto mountFreeRegExp = QRegularExpression("^disk/.*/free$");
|
||||
auto mountUsedRegExp = QRegularExpression("^disk/.*/used$");
|
||||
auto netRegExp = QRegularExpression("^network/.*/(download|upload)$");
|
||||
auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$");
|
||||
|
||||
if (_source == "battery/ac") {
|
||||
// AC
|
||||
@ -102,17 +103,17 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = _source.contains("rate") ? AWKeysAggregator::FormatterType::Float
|
||||
: AWKeysAggregator::FormatterType::IntegerThree;
|
||||
} else if (_source == "cpu/system/TotalLoad") {
|
||||
} else if (_source == "cpu/all/usage") {
|
||||
// cpu
|
||||
m_map.insert(_source, "cpu");
|
||||
m_formatter["cpu"] = AWKeysAggregator::FormatterType::Float;
|
||||
} else if (_source.contains(cpuRegExp)) {
|
||||
// cpus
|
||||
QString key = _source;
|
||||
key.remove("cpu/").remove("/TotalLoad");
|
||||
key.remove("cpu/").remove("/usage");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Float;
|
||||
} else if (_source == "cpu/system/AverageClock") {
|
||||
} else if (_source == "cpu/all/averageFrequency") {
|
||||
// cpucl
|
||||
m_map.insert(_source, "cpucl");
|
||||
m_formatter["cpucl"] = AWKeysAggregator::FormatterType::Integer;
|
||||
@ -144,7 +145,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source.contains(hddrRegExp)) {
|
||||
// read speed
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
device.remove("disk/").remove("/read");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddr%1").arg(index);
|
||||
@ -154,7 +155,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source.contains(hddwRegExp)) {
|
||||
// write speed
|
||||
QString device = _source;
|
||||
device.remove("/Rate/wblk");
|
||||
device.remove("disk/").remove("/write");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddw%1").arg(index);
|
||||
@ -172,8 +173,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source.contains(mountFillRegExp)) {
|
||||
// fill level
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
device.remove("disk/").remove("/usedPercent");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hdd%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
@ -185,8 +186,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source.contains(mountFreeRegExp)) {
|
||||
// free space
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/freespace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
device.remove("disk/").remove("/free");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddfreemb%1").arg(index);
|
||||
@ -200,8 +201,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source.contains(mountUsedRegExp)) {
|
||||
// used
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/usedspace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
device.remove("disk/").remove("/used");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddmb%1").arg(index);
|
||||
@ -222,14 +223,14 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||
}
|
||||
} else if (_source.startsWith("cpu/system/loadavg")) {
|
||||
} else if (_source.startsWith("cpu/loadaverages/loadaverage")) {
|
||||
// load average
|
||||
QString time = _source;
|
||||
time.remove("cpu/system/loadavg");
|
||||
time.remove("cpu/loadaverages/loadaverage");
|
||||
QString key = QString("la%1").arg(time);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::FloatTwoSymbols;
|
||||
} else if (_source == "mem/physical/application") {
|
||||
} else if (_source == "memory/physical/application") {
|
||||
// app memory
|
||||
// mb
|
||||
m_map.insert(_source, "memmb");
|
||||
@ -237,7 +238,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "memgb");
|
||||
m_formatter["memgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/free") {
|
||||
} else if (_source == "memory/physical/free") {
|
||||
// free memory
|
||||
// mb
|
||||
m_map.insert(_source, "memfreemb");
|
||||
@ -245,7 +246,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "memfreegb");
|
||||
m_formatter["memfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/used") {
|
||||
} else if (_source == "memory/physical/used") {
|
||||
// used memory
|
||||
// mb
|
||||
m_map.insert(_source, "memusedmb");
|
||||
@ -269,8 +270,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
QString type = _source.contains("download") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[1]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1kb%2").arg(type).arg(index);
|
||||
@ -287,8 +288,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
}
|
||||
} else if (_source.contains(netTotalRegExp)) {
|
||||
// network data total
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
QString type = _source.contains("download") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[1]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1totkb%2").arg(type).arg(index);
|
||||
@ -329,7 +330,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
key.remove("quotes/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Quotes;
|
||||
} else if (_source == "mem/swap/free") {
|
||||
} else if (_source == "memory/swap/free") {
|
||||
// free swap
|
||||
// mb
|
||||
m_map.insert(_source, "swapfreemb");
|
||||
@ -337,7 +338,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "swapfreegb");
|
||||
m_formatter["swapfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/swap/used") {
|
||||
} else if (_source == "memory/swap/used") {
|
||||
// used swap
|
||||
// mb
|
||||
m_map.insert(_source, "swapmb");
|
||||
@ -345,7 +346,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "swapgb");
|
||||
m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source.startsWith("lmsensors/")) {
|
||||
} else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp)
|
||||
|| _source == "cpu/all/averageTemperature") {
|
||||
// temperature
|
||||
int index = m_devices["temp"].indexOf(_source);
|
||||
// HACK on DE initialization there are no units key
|
||||
@ -354,8 +356,8 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
if (index > -1) {
|
||||
QString key = QString("temp%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = _units == "°C" ? AWKeysAggregator::FormatterType::Temperature
|
||||
: AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = _units == "500" ? AWKeysAggregator::FormatterType::Temperature
|
||||
: AWKeysAggregator::FormatterType::Integer;
|
||||
}
|
||||
} else if (_source == "Local") {
|
||||
// time
|
||||
@ -382,7 +384,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
} else if (_source == "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;
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include "awkeycache.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QNetworkInterface>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
@ -40,18 +40,7 @@ bool AWKeyCache::addKeyToCache(const QString &_type, const QString &_key)
|
||||
for (auto &number : cache.allKeys())
|
||||
cachedValues.append(cache.value(number).toString());
|
||||
|
||||
if (_type == "hdd") {
|
||||
QStringList allDevices = QDir("/dev").entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$"));
|
||||
for (auto &dev : devices) {
|
||||
QString device = QString("/dev/%1").arg(dev);
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << _type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), device);
|
||||
}
|
||||
} else if (_type == "net") {
|
||||
if (_type == "net") {
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (auto &interface : rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
@ -93,7 +82,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
|
||||
// insert depending keys, refer to AWKeys::calculateValues()
|
||||
// hddtotmb*
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotmb"))) {
|
||||
for (auto &key : _allKeys.filter(QRegularExpression("^hddtotmb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove("hddtotmb");
|
||||
@ -101,7 +90,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
used << QString("hddfreemb%1").arg(index) << QString("hddmb%1").arg(index);
|
||||
}
|
||||
// hddtotgb*
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotgb"))) {
|
||||
for (auto &key : _allKeys.filter(QRegularExpression("^hddtotgb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove("hddtotgb");
|
||||
@ -138,7 +127,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
for (auto &key : netKeys) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
QStringList filt = _allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
|
||||
QStringList filt = _allKeys.filter(QRegularExpression(QString("^%1[0-9]{1,}").arg(key)));
|
||||
for (auto &filtered : filt)
|
||||
used << filtered;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "awkeyoperations.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QThread>
|
||||
|
||||
#include "awcustomkeyshelper.h"
|
||||
@ -72,7 +72,6 @@ QHash<QString, QStringList> AWKeyOperations::devices() const
|
||||
void AWKeyOperations::updateCache()
|
||||
{
|
||||
// update network and hdd list
|
||||
addKeyToCache("hdd");
|
||||
addKeyToCache("net");
|
||||
}
|
||||
|
||||
@ -98,7 +97,7 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
for (int i = 0; i < m_devices["temp"].count(); i++)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// hdd
|
||||
for (int i = 0; i < m_devices["mount"].count(); i++) {
|
||||
for (int i = 0; i < m_devices["disk"].count(); i++) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
allKeys.append(QString("hddgb%1").arg(i));
|
||||
allKeys.append(QString("hddfreemb%1").arg(i));
|
||||
@ -106,9 +105,6 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("hddtotmb%1").arg(i));
|
||||
allKeys.append(QString("hddtotgb%1").arg(i));
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (int i = 0; i < m_devices["disk"].count(); i++) {
|
||||
allKeys.append(QString("hddr%1").arg(i));
|
||||
allKeys.append(QString("hddw%1").arg(i));
|
||||
}
|
||||
@ -206,7 +202,7 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
qCDebug(LOG_AW) << "Requested key" << _key;
|
||||
|
||||
QString stripped = _key;
|
||||
stripped.remove(QRegExp("\\d+"));
|
||||
stripped.remove(QRegularExpression("\\d+"));
|
||||
QString output;
|
||||
|
||||
if (_key.startsWith("bar")) {
|
||||
@ -217,31 +213,27 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
AbstractExtItem *item = m_extScripts->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("^hdd[rw]"))) {
|
||||
} else if (_key.contains(QRegularExpression("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb|r|w)"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("hdd[rw]"));
|
||||
index.remove(QRegularExpression("^hdd(mb|gb|freemb|freegb|totmb|totgb|r|w)"));
|
||||
output = m_devices["disk"][index.toInt()];
|
||||
} else if (_key.contains(QRegExp("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^hdd(|mb|gb|freemb|freegb|totmb|totgb)"));
|
||||
output = m_devices["mount"][index.toInt()];
|
||||
} else if (_key.startsWith("hddtemp")) {
|
||||
QString index = _key;
|
||||
index.remove("hddtemp");
|
||||
output = m_devices["hdd"][index.toInt()];
|
||||
} else if (_key.contains(QRegExp("^(down|up)[0-9]"))) {
|
||||
} else if (_key.contains(QRegularExpression("^(down|up)[0-9]"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^(down|up)"));
|
||||
index.remove(QRegularExpression("^(down|up)"));
|
||||
output = m_devices["net"][index.toInt()];
|
||||
} else if (_key.startsWith("pkgcount")) {
|
||||
AbstractExtItem *item = m_extUpgrade->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
} else if (_key.contains(QRegularExpression("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
AbstractExtItem *item = m_extQuotes->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
} else if (_key.contains(QRegularExpression("(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
AbstractExtItem *item = m_extWeather->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
@ -280,7 +272,7 @@ void AWKeyOperations::editItem(const QString &_type)
|
||||
qCDebug(LOG_AW) << "Item type" << _type;
|
||||
|
||||
if (_type == "graphicalitem") {
|
||||
QStringList keys = dictKeys().filter(QRegExp("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
QStringList keys = dictKeys().filter(QRegularExpression("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
keys.sort();
|
||||
m_graphicalItems->setConfigArgs(keys);
|
||||
return m_graphicalItems->editItems();
|
||||
@ -302,18 +294,15 @@ void AWKeyOperations::addDevice(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
|
||||
QRegExp diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)");
|
||||
QRegExp mountRegexp = QRegExp("partitions/.*/filllevel");
|
||||
auto diskRegexp = QRegularExpression("^disk/.*/total$");
|
||||
auto cpuTemperatureRegexp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
|
||||
if (_source.contains(diskRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
device.remove("disk/").remove("/total");
|
||||
addKeyToCache("disk", device);
|
||||
} else if (_source.contains(mountRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
addKeyToCache("mount", device);
|
||||
} else if (_source.startsWith("lmsensors")) {
|
||||
} else if (_source.startsWith("lmsensors") || _source.contains(cpuTemperatureRegexp)
|
||||
|| _source == "cpu/all/averageTemperature") {
|
||||
addKeyToCache("temp", _source);
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ QStringList AWKeys::dictKeys(const bool _sorted, const QString &_regexp) const
|
||||
if (_sorted)
|
||||
allKeys.sort();
|
||||
|
||||
return allKeys.filter(QRegExp(_regexp));
|
||||
return allKeys.filter(QRegularExpression(_regexp));
|
||||
}
|
||||
|
||||
|
||||
@ -253,20 +253,20 @@ void AWKeys::updateTextData()
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
QStringList mountDevices = m_keyOperator->devices("mount");
|
||||
QStringList mountDevices = m_keyOperator->devices("disk");
|
||||
for (auto &device : mountDevices) {
|
||||
int index = mountDevices.indexOf(device);
|
||||
m_values[QString("hddtotmb%1").arg(index)]
|
||||
= m_values[QString("hddfreemb%1").arg(index)].toFloat() + m_values[QString("hddmb%1").arg(index)].toFloat();
|
||||
m_values[QString("hddtotgb%1").arg(index)]
|
||||
= m_values[QString("hddfreegb%1").arg(index)].toFloat() + m_values[QString("hddgb%1").arg(index)].toFloat();
|
||||
m_values[QString("hddtotmb%1").arg(index)] = m_values[QString("hddfreemb%1").arg(index)].toDouble()
|
||||
+ m_values[QString("hddmb%1").arg(index)].toDouble();
|
||||
m_values[QString("hddtotgb%1").arg(index)] = m_values[QString("hddfreegb%1").arg(index)].toDouble()
|
||||
+ m_values[QString("hddgb%1").arg(index)].toDouble();
|
||||
}
|
||||
|
||||
// memtot*
|
||||
m_values["memtotmb"] = m_values["memusedmb"].toInt() + m_values["memfreemb"].toInt();
|
||||
m_values["memtotgb"] = m_values["memusedgb"].toFloat() + m_values["memfreegb"].toFloat();
|
||||
m_values["memtotmb"] = m_values["memusedmb"].toLongLong() + m_values["memfreemb"].toLongLong();
|
||||
m_values["memtotgb"] = m_values["memusedgb"].toDouble() + m_values["memfreegb"].toDouble();
|
||||
// mem
|
||||
m_values["mem"] = 100.0f * m_values["memmb"].toFloat() / m_values["memtotmb"].toFloat();
|
||||
m_values["mem"] = 100.0f * m_values["memmb"].toDouble() / m_values["memtotmb"].toDouble();
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
int netIndex = m_keyOperator->devices("net").indexOf(m_values["netdev"].toString());
|
||||
@ -282,10 +282,10 @@ void AWKeys::calculateValues()
|
||||
m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// swaptot*
|
||||
m_values["swaptotmb"] = m_values["swapmb"].toInt() + m_values["swapfreemb"].toInt();
|
||||
m_values["swaptotgb"] = m_values["swapgb"].toFloat() + m_values["swapfreegb"].toFloat();
|
||||
m_values["swaptotmb"] = m_values["swapmb"].toLongLong() + m_values["swapfreemb"].toLongLong();
|
||||
m_values["swaptotgb"] = m_values["swapgb"].toDouble() + m_values["swapfreegb"].toDouble();
|
||||
// swap
|
||||
m_values["swap"] = 100.0f * m_values["swapmb"].toFloat() / m_values["swaptotmb"].toFloat();
|
||||
m_values["swap"] = 100.0f * m_values["swapmb"].toDouble() / m_values["swaptotmb"].toDouble();
|
||||
|
||||
// user defined keys
|
||||
for (auto &key : m_keyOperator->userKeys())
|
||||
|
@ -64,19 +64,19 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
// case block
|
||||
switch (m_mapper->formatter(_key)) {
|
||||
case FormatterType::Float:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::FloatTwoSymbols:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 2);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 2);
|
||||
break;
|
||||
case FormatterType::Integer:
|
||||
output = QString("%1").arg(_data.toFloat(), 4, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 4, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerFive:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerThree:
|
||||
output = QString("%1").arg(_data.toFloat(), 3, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 3, 'f', 0);
|
||||
break;
|
||||
case FormatterType::List:
|
||||
output = _data.toStringList().join(',');
|
||||
@ -85,21 +85,21 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
output = _data.toBool() ? m_acOnline : m_acOffline;
|
||||
break;
|
||||
case FormatterType::MemGBFormat:
|
||||
output = QString("%1").arg(_data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toDouble() / (1024.0 * 1024.0 * 1024.0), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::MemMBFormat:
|
||||
output = QString("%1").arg(_data.toFloat() / 1024.0, 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble() / (1024.0 * 1024.0), 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::NetSmartFormat:
|
||||
output = [](const float value) {
|
||||
if (value > 1024.0)
|
||||
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
||||
output = [](const double value) {
|
||||
if (value > 1024.0 * 1024.0)
|
||||
return QString("%1").arg(value / (1024.0 * 1024.0), 4, 'f', 1);
|
||||
else
|
||||
return QString("%1").arg(value, 4, 'f', 0);
|
||||
}(_data.toFloat());
|
||||
return QString("%1").arg(value / 1024.0, 4, 'f', 0);
|
||||
}(_data.toDouble());
|
||||
break;
|
||||
case FormatterType::NetSmartUnits:
|
||||
if (_data.toFloat() > 1024.0)
|
||||
if (_data.toDouble() > 1024.0 * 1024.0)
|
||||
output = m_translate ? i18n("MB/s") : "MB/s";
|
||||
else
|
||||
output = m_translate ? i18n("KB/s") : "KB/s";
|
||||
|
@ -130,7 +130,7 @@ QString AWPatternFunctions::insertAllKeys(QString _code, const QStringList &_key
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_all", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("%1: $%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
@ -146,7 +146,7 @@ QString AWPatternFunctions::insertKeyCount(QString _code, const QStringList &_ke
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_count", _code);
|
||||
for (auto &function : found) {
|
||||
int count = _keys.filter(QRegExp(function.body)).count();
|
||||
int count = _keys.filter(QRegularExpression(function.body)).count();
|
||||
|
||||
_code.replace(function.what, QString::number(count));
|
||||
}
|
||||
@ -162,7 +162,7 @@ QString AWPatternFunctions::insertKeyNames(QString _code, const QStringList &_ke
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_names", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
@ -178,7 +178,7 @@ QString AWPatternFunctions::insertKeys(QString _code, const QStringList &_keys)
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_keys", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("$%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
|
Reference in New Issue
Block a user