diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml index 83422c2..3223645 100644 --- a/sources/awesome-widget/package/contents/ui/main.qml +++ b/sources/awesome-widget/package/contents/ui/main.qml @@ -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 diff --git a/sources/awesome-widget/plugin/awdataengineaggregator.cpp b/sources/awesome-widget/plugin/awdataengineaggregator.cpp index 431c20d..a743d27 100644 --- a/sources/awesome-widget/plugin/awdataengineaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataengineaggregator.cpp @@ -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(); diff --git a/sources/awesome-widget/plugin/awdataenginemapper.cpp b/sources/awesome-widget/plugin/awdataenginemapper.cpp index 9c2a9bd..7612fd1 100644 --- a/sources/awesome-widget/plugin/awdataenginemapper.cpp +++ b/sources/awesome-widget/plugin/awdataenginemapper.cpp @@ -17,7 +17,7 @@ #include "awdataenginemapper.h" -#include +#include #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; diff --git a/sources/awesome-widget/plugin/awkeycache.cpp b/sources/awesome-widget/plugin/awkeycache.cpp index d618cc2..5fd6fba 100644 --- a/sources/awesome-widget/plugin/awkeycache.cpp +++ b/sources/awesome-widget/plugin/awkeycache.cpp @@ -18,8 +18,8 @@ #include "awkeycache.h" -#include #include +#include #include #include @@ -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 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; } diff --git a/sources/awesome-widget/plugin/awkeyoperations.cpp b/sources/awesome-widget/plugin/awkeyoperations.cpp index b7ec39a..fc67cdd 100644 --- a/sources/awesome-widget/plugin/awkeyoperations.cpp +++ b/sources/awesome-widget/plugin/awkeyoperations.cpp @@ -18,7 +18,7 @@ #include "awkeyoperations.h" #include -#include +#include #include #include "awcustomkeyshelper.h" @@ -72,7 +72,6 @@ QHash 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); } } diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 922f8b6..f76bbe9 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -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()) diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index 6cd3309..6ae638d 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -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"; diff --git a/sources/awesome-widget/plugin/awpatternfunctions.cpp b/sources/awesome-widget/plugin/awpatternfunctions.cpp index 51695ef..d93c16a 100644 --- a/sources/awesome-widget/plugin/awpatternfunctions.cpp +++ b/sources/awesome-widget/plugin/awpatternfunctions.cpp @@ -130,7 +130,7 @@ QString AWPatternFunctions::insertAllKeys(QString _code, const QStringList &_key QList 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 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 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 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)); diff --git a/sources/awesomewidgets/awlistformatter.cpp b/sources/awesomewidgets/awlistformatter.cpp index de15406..10d0e91 100644 --- a/sources/awesomewidgets/awlistformatter.cpp +++ b/sources/awesomewidgets/awlistformatter.cpp @@ -97,7 +97,7 @@ void AWListFormatter::setFilter(const QString &_filter) qCDebug(LOG_LIB) << "Filter" << _filter; m_filter = _filter; - m_regex = QRegExp(m_filter); + m_regex = QRegularExpression(m_filter); } diff --git a/sources/awesomewidgets/awlistformatter.h b/sources/awesomewidgets/awlistformatter.h index 665e54b..87849ca 100644 --- a/sources/awesomewidgets/awlistformatter.h +++ b/sources/awesomewidgets/awlistformatter.h @@ -18,6 +18,8 @@ #ifndef AWLISTFORMATTER_H #define AWLISTFORMATTER_H +#include + #include "awabstractformatter.h" @@ -58,7 +60,7 @@ private: QString m_filter = ""; QString m_separator = ""; bool m_sorted = false; - QRegExp m_regex; + QRegularExpression m_regex; }; diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 433ec14..945f32d 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -20,6 +20,7 @@ #include +#include #include #include @@ -217,7 +218,7 @@ void ExtUpgrade::updateValue() QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed(); m_values[tag("pkgcount")] = [this](const QString &output) { return filter().isEmpty() ? output.split('\n', Qt::SkipEmptyParts).count() - null() - : output.split('\n', Qt::SkipEmptyParts).filter(QRegExp(filter())).count(); + : output.split('\n', Qt::SkipEmptyParts).filter(QRegularExpression(filter())).count(); }(qoutput); emit(dataReceived(m_values)); diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 2815425..e3632ef 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -92,7 +92,7 @@ QStringList DPAdds::dictKeys(const bool _sorted, const QString &_regexp) if (_sorted) allKeys.sort(); - return allKeys.filter(QRegExp(_regexp)); + return allKeys.filter(QRegularExpression(_regexp)); } diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 68b5e02..d7e2df5 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -41,6 +41,9 @@ ExtendedSysMon::ExtendedSysMon(QObject *_parent, const QVariantList &_args) // init aggregator m_aggregator = new ExtSysMonAggregator(this, m_configuration); + connect(m_aggregator, SIGNAL(sourceAdded(const QString &)), this, SIGNAL(sourceAdded(const QString &))); + connect(m_aggregator, SIGNAL(sourceRemoved(const QString &)), this, SIGNAL(sourceRemoved(const QString &))); + for (auto &source : m_aggregator->sources()) setData(source, m_aggregator->initialData(source)); } @@ -127,7 +130,7 @@ QHash ExtendedSysMon::updateConfiguration(QHash &_config) = new HDDTemperatureSource(this, QStringList({_config["HDDDEV"], _config["HDDTEMPCMD"]})); for (auto &source : hddTempItem->sources()) m_map[source] = hddTempItem; + // ksystemstats adapter + AbstractExtSysMonSource *ksystemstatsItem = new KSystemStatsSource(this, {}); + connect(ksystemstatsItem, SIGNAL(sourceAdded(const QString &)), this, SIGNAL(sourceAdded(const QString &))); + connect(ksystemstatsItem, SIGNAL(sourceRemoved(const QString &)), this, SIGNAL(sourceRemoved(const QString &))); + for (auto &source : ksystemstatsItem->sources()) + m_map[source] = ksystemstatsItem; // network AbstractExtSysMonSource *networkItem = new NetworkSource(this, QStringList()); for (auto &source : networkItem->sources()) diff --git a/sources/extsysmon/extsysmonaggregator.h b/sources/extsysmon/extsysmonaggregator.h index d47d216..ec9505c 100644 --- a/sources/extsysmon/extsysmonaggregator.h +++ b/sources/extsysmon/extsysmonaggregator.h @@ -35,6 +35,10 @@ public: [[nodiscard]] QVariantMap initialData(const QString &_source) const; [[nodiscard]] QStringList sources() const; +signals: + void sourceAdded(const QString &_source); + void sourceRemoved(const QString &_source); + private: void init(const QHash &_config); QHash m_map; diff --git a/sources/extsysmonsources/CMakeLists.txt b/sources/extsysmonsources/CMakeLists.txt index b5940f7..c1cb0e1 100644 --- a/sources/extsysmonsources/CMakeLists.txt +++ b/sources/extsysmonsources/CMakeLists.txt @@ -14,5 +14,5 @@ include_directories( file(GLOB SUBPROJECT_SOURCE *.cpp) file(GLOB SUBPROJECT_HEADER *.h) -add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER}) +add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER} ksystemstatssource.cpp ksystemstatssource.h) target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) diff --git a/sources/extsysmonsources/abstractextsysmonsource.h b/sources/extsysmonsources/abstractextsysmonsource.h index cfe1366..e48ff9a 100644 --- a/sources/extsysmonsources/abstractextsysmonsource.h +++ b/sources/extsysmonsources/abstractextsysmonsource.h @@ -19,7 +19,7 @@ #define ABSTRACTEXTSYSMONSOURCE_H #include -#include +#include #include @@ -38,13 +38,14 @@ public: // used by extensions static int index(const QString &_source) { - QRegExp rx("\\d+"); - rx.indexIn(_source); - return rx.cap().toInt(); + QRegularExpression rx("\\d+"); + return rx.match(_source).captured().toInt(); } signals: void dataReceived(const QVariantHash &); + void sourceAdded(const QString &_source); + void sourceRemoved(const QString &_source); }; diff --git a/sources/extsysmonsources/hddtempsource.cpp b/sources/extsysmonsources/hddtempsource.cpp index 322ffd1..6d3e640 100644 --- a/sources/extsysmonsources/hddtempsource.cpp +++ b/sources/extsysmonsources/hddtempsource.cpp @@ -61,7 +61,7 @@ HDDTemperatureSource::~HDDTemperatureSource() QStringList HDDTemperatureSource::allHdd() { QStringList allDevices = QDir("/dev").entryList(QDir::System, QDir::Name); - QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$")); + QStringList devices = allDevices.filter(QRegularExpression("^[hms]d[a-z]$")); for (int i = 0; i < devices.count(); i++) devices[i] = QString("/dev/%1").arg(devices.at(i)); diff --git a/sources/extsysmonsources/ksystemstatssource.cpp b/sources/extsysmonsources/ksystemstatssource.cpp new file mode 100644 index 0000000..0957471 --- /dev/null +++ b/sources/extsysmonsources/ksystemstatssource.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "ksystemstatssource.h" + +#include +#include + +#include "awdebug.h" + + +KSystemStatsSource::KSystemStatsSource(QObject *_parent, const QStringList &_args) + : AbstractExtSysMonSource(_parent, _args) +{ + Q_ASSERT(_args.count() == 0); + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; + + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType>(); + + m_interface = new KSysGuard::SystemStats::DBusInterface( + KSysGuard::SystemStats::ServiceName, KSysGuard::SystemStats::ObjectPath, QDBusConnection::sessionBus(), this); + connect(m_interface, SIGNAL(newSensorData(KSysGuard::SensorDataList)), this, + SLOT(updateData(KSysGuard::SensorDataList))); + connect(m_interface, SIGNAL(sensorAdded(const QString &)), this, SLOT(sensorAdded(const QString &))); + connect(m_interface, SIGNAL(sensorMetaDataChanged(const QHash &)), this, + SLOT(updateSensor(const QHash &))); + connect(m_interface, SIGNAL(sensorRemoved(const QString &)), this, SLOT(sensorRemoved(const QString &))); + + loadSources(); + m_interface->subscribe(m_sources.keys()); +} + + +KSystemStatsSource::~KSystemStatsSource() +{ + qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; +} + + +QVariant KSystemStatsSource::data(const QString &_source) +{ + qCDebug(LOG_ESS) << "Source" << _source; + + return m_values.value(_source, {}); +} + + +QVariantMap KSystemStatsSource::initialData(const QString &_source) const +{ + qCDebug(LOG_ESS) << "Source" << _source; + + return m_sources.value(_source, QVariantMap()).toMap(); +} + + +void KSystemStatsSource::run() {} + + +QStringList KSystemStatsSource::sources() const +{ + return m_sources.keys(); +} + + +void KSystemStatsSource::sensorAdded(const QString &_sensor) +{ + qCDebug(LOG_ESS) << "Sensor" << _sensor << "added"; + + auto sensors = QStringList(_sensor); + + auto response = m_interface->sensors(sensors); + response.waitForFinished(); + auto metadata = response.value(); + + updateSensor(metadata); + + m_interface->subscribe(sensors); + emit(sourceAdded(_sensor)); +} + + +void KSystemStatsSource::sensorRemoved(const QString &_sensor) +{ + qCDebug(LOG_ESS) << "Sensor" << _sensor << "removed"; + + m_values.remove(_sensor); + m_sources.remove(_sensor); + emit(sourceRemoved(_sensor)); +} + + +void KSystemStatsSource::updateData(KSysGuard::SensorDataList _data) +{ + for (auto &change : _data) + m_values[change.sensorProperty] = change.payload; +} + + +void KSystemStatsSource::updateSensor(const QHash &_sensor) +{ + qCDebug(LOG_ESS) << "Sensors" << _sensor.keys() << "were updated"; + + for (auto it = _sensor.constBegin(); it != _sensor.constEnd(); it++) { + auto value = it.value(); + + QVariantMap data; + data["min"] = value.min; + data["max"] = value.max; + data["name"] = value.name; + data["type"] = value.variantType; + data["units"] = value.unit; + + m_sources[it.key()] = data; + } +} + + +void KSystemStatsSource::loadSources() +{ + auto response = m_interface->allSensors(); + response.waitForFinished(); + auto metadata = response.value(); + + updateSensor(metadata); +} diff --git a/sources/extsysmonsources/ksystemstatssource.h b/sources/extsysmonsources/ksystemstatssource.h new file mode 100644 index 0000000..37c583c --- /dev/null +++ b/sources/extsysmonsources/ksystemstatssource.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef KSYSTEMSTATSSOURCE_H +#define KSYSTEMSTATSSOURCE_H + +#include + +#include "abstractextsysmonsource.h" + + +namespace KSysGuard::SystemStats +{ +class DBusInterface; +} + + +class KSystemStatsSource : public AbstractExtSysMonSource +{ + Q_OBJECT + +public: + explicit KSystemStatsSource(QObject *_parent, const QStringList &_args); + ~KSystemStatsSource() override; + QVariant data(const QString &_source) override; + [[nodiscard]] QVariantMap initialData(const QString &_source) const override; + void run() override; + [[nodiscard]] QStringList sources() const override; + +public slots: + void sensorAdded(const QString &_sensor); + void sensorRemoved(const QString &_sensor); + void updateData(KSysGuard::SensorDataList _data); + void updateSensor(const QHash &_sensor); + +private: + KSysGuard::SystemStats::DBusInterface *m_interface = nullptr; + QVariantHash m_values; + QVariantHash m_sources; + void loadSources(); +}; + + +#endif /* KSYSTEMSTATSSOURCE_H */ diff --git a/sources/extsysmonsources/processessource.cpp b/sources/extsysmonsources/processessource.cpp index 9d434e0..35c1a67 100644 --- a/sources/extsysmonsources/processessource.cpp +++ b/sources/extsysmonsources/processessource.cpp @@ -80,7 +80,7 @@ QVariantMap ProcessesSource::initialData(const QString &_source) const void ProcessesSource::run() { QStringList allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); - QStringList directories = allDirectories.filter(QRegExp("(\\d+)")); + QStringList directories = allDirectories.filter(QRegularExpression("(\\d+)")); QStringList running; for (auto &dir : directories) { diff --git a/sources/libraries.cmake b/sources/libraries.cmake index 4046f95..9bcf770 100644 --- a/sources/libraries.cmake +++ b/sources/libraries.cmake @@ -19,11 +19,11 @@ set(Qt_LIBRARIES # kf5 libraries find_package(ECM 0.0.11 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) -find_package(KF5 REQUIRED COMPONENTS I18n Notifications Plasma Service WindowSystem) +find_package(KF5 REQUIRED COMPONENTS I18n Notifications Plasma Service SysGuard WindowSystem) find_package(LibTaskManager REQUIRED) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) set(Kf5_INCLUDE ${I18n_INCLUDE_DIR} ${Notifications_INCLUDE_DIR} ${Plasma_INCLUDE_DIR}) -set(Kf5_LIBRARIES KF5::I18n KF5::Notifications KF5::Plasma KF5::WindowSystem PW::LibTaskManager) +set(Kf5_LIBRARIES KF5::I18n KF5::Notifications KF5::Plasma KF5::WindowSystem KSysGuard::Formatter KSysGuard::SystemStats PW::LibTaskManager) diff --git a/sources/test/testawpatternfunctions.cpp b/sources/test/testawpatternfunctions.cpp index 80fc975..bb74038 100644 --- a/sources/test/testawpatternfunctions.cpp +++ b/sources/test/testawpatternfunctions.cpp @@ -18,6 +18,7 @@ #include "testawpatternfunctions.h" +#include #include #include "awpatternfunctions.h" @@ -57,7 +58,7 @@ void TestAWPatternFunctions::test_findKeys() QStringList allKeys; for (int i = 0; i < count; i++) { auto key = AWTestLibrary::randomString(1, 20); - while (allKeys.indexOf(QRegExp(QString("^%1.*").arg(key))) != -1) + while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1) key = AWTestLibrary::randomString(1, 20); allKeys.append(key); }