diff --git a/CHANGELOG b/CHANGELOG index e01a42cedc10db7792757c82cfd465eaa361da81..a78b4838f3decb776652f32a0cbf3dd0915ab284 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Version 2.0 + +Rewritten to use new sensor API. +Improved plotter smoothing, doubled amount of plot history. + Version 1.03 Fixed disk space for drives larger than 2TiB. Minor code clean up. diff --git a/README.md b/README.md index 5982e020a3eb6737686129171ebcc63983c53bd6..8d5509e6dae98d1ec0be024686e9c31a0771a127 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Plasmoid to view several Items from system Monitor. Each Item has its own toolti ## Requirements -Plasma 5 shell (plasma >= 5.7) +Plasma 5 shell (plasma >= 5.7), Starting with Version 2.0 (plasma > 20.0). ## Installation -(plasma > 5.20) may need to install ksysguardd. +Version 1.03 and below, with plasma > 5.20 may need to install ksysguardd. ### From store.kde.org diff --git a/dbusmodel/dbusmodel.cpp b/dbusmodel/dbusmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5d6b6e9921241557d5c48d67294da96405e6579 --- /dev/null +++ b/dbusmodel/dbusmodel.cpp @@ -0,0 +1,129 @@ +/* + * Copyright 2021 Barry Strong <bstrong@softtechok.com> + * + * This file is part of System Monitor Plasmoid + * + * System Monitor Plasmoid 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. + * + * System Monitor Plasmoid 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 System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <QtDBus/QtDBus> +#include "dbusmodel.h" + + +DbusModel::DbusModel(QObject *parent) : QObject(parent) +{ + QDBusConnection dbusCon = QDBusConnection::sessionBus(); + dbusIface = new QDBusInterface("org.kde.ksystemstats", "/", "org.kde.ksystemstats", dbusCon); + dbusCon.connect("org.kde.ksystemstats", "/", "org.kde.ksystemstats", "newSensorData", this, SLOT(newSensorData(QDBusMessage))); +} + +DbusModel::~DbusModel() +{ + if (sensorList.count() != 0) + dbusIface->call("unsubscribe", sensorList); + dbusIface->disconnect(); +} + +void DbusModel::sensors(const QStringList &args) { + if (sensorList.count() != 0) + dbusIface->call("unsubscribe", sensorList); + sensorList = args; + if (sensorList.count() != 0) + dbusIface->call("subscribe", sensorList); +} + +QStringList DbusModel::sensors() const { + return sensorList; +} + +QStringList DbusModel::allSensors(const QString &filter) { + QStringList wrk; + QString key; + + const auto reply = dbusIface->call("allSensors").arguments().at(0).value<QDBusArgument>(); + reply.beginMap(); + while (!reply.atEnd()) { + reply.beginMapEntry(); + reply >> key; + if (key.indexOf(filter) == 0) + wrk.append(key); + reply.endMapEntry(); + } + return wrk; +} + +double DbusModel::doubleData(const QString &key) { + struct dbusrec data; + QStringList skey; + + if (key == "") { + return 0; + } else { + skey.append(key); + auto reply = dbusIface->call("sensorData",skey); + const auto result = reply.arguments().at(0).value<QDBusArgument>(); + result.beginArray(); + if (!result.atEnd()) { + result.beginStructure(); + result >> data.name >> data.value; + result.endStructure(); + result.endArray(); + return data.value.toDouble(); + } else { + return 0; + } + } +} + +QString DbusModel::stringData(const QString &key) { + struct dbusrec data; + QStringList skey; + + if (key == "") { + return 0; + } else { + skey.append(key); + auto reply = dbusIface->call("sensorData",skey); + const auto result = reply.arguments().at(0).value<QDBusArgument>(); + result.beginArray(); + if (!result.atEnd()) { + result.beginStructure(); + result >> data.name >> data.value; + result.endStructure(); + result.endArray(); + return data.value.toString(); + } else { + return ""; + } + } +} + +void DbusModel::newSensorData(const QDBusMessage &arg) { + struct dbusrec data; + QStringList keys; + QVariantList values; + + const auto reply = arg.arguments().at(0).value<QDBusArgument>(); + reply.beginArray(); + while (!reply.atEnd()) { + reply.beginStructure(); + reply >> data.name; + reply >> data.value; + keys.append(data.name); + values.append(data.value); + reply.endStructure(); + } + reply.endArray(); + emit newSensorData(keys, values); +} diff --git a/dbusmodel/dbusmodel.h b/dbusmodel/dbusmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..fe369d1abc6d10e2187aa08a19841b1b224becf4 --- /dev/null +++ b/dbusmodel/dbusmodel.h @@ -0,0 +1,70 @@ +/* + * Copyright 2021 Barry Strong <bstrong@softtechok.com> + * + * This file is part of System Monitor Plasmoid + * + * System Monitor Plasmoid 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. + * + * System Monitor Plasmoid 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 System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DBUSMODEL_H +#define DBUSMODEL_H + +#include <QtDBus/QtDBus> +#include <QtQml/qqml.h> + +struct dbusrec { + QString name; + QVariant value; +}; + +struct SensorInfo { + QString name; + QString shortName; + QString description; + quint32 Type; + quint32 unit; + qreal min = 0; + qreal max = 0; +}; + +class DbusModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(QStringList sensors READ sensors WRITE sensors) + QML_NAMED_ELEMENT(Dbus) + +public: + DbusModel(QObject *parent=nullptr); + ~DbusModel() override; + + QStringList sensors() const; + void sensors(const QStringList &args); + +private: + QStringList sensorList; + QDBusInterface* dbusIface; + +signals: + void newSensorData(const QStringList keys, const QVariantList values); + +public slots: + QStringList allSensors(const QString &filter); + double doubleData(const QString &key); + QString stringData(const QString &key); + +private slots: + void newSensorData(const QDBusMessage &arg); +}; + +#endif // DBUSMODEL_H diff --git a/dbusmodel/plugin.cpp b/dbusmodel/plugin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8fb2b86a17e79a5f72ab69420d44f006ef14e1ae --- /dev/null +++ b/dbusmodel/plugin.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2021 Barry Strong <bstrong@softtechok.com> + * + * This file is part of System Monitor Plasmoid + * + * System Monitor Plasmoid 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. + * + * System Monitor Plasmoid 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 System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <QtQml/QQmlEngineExtensionPlugin> + +class QDbusModelPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) +}; + +#include "plugin.moc" diff --git a/plasmoid/contents/config/main.xml b/plasmoid/contents/config/main.xml index 3968ba31a40b354060e768519e493c3f41029508..0ecbe6aea69a7127afb4e65d4e3800e3f4083b0c 100755 --- a/plasmoid/contents/config/main.xml +++ b/plasmoid/contents/config/main.xml @@ -134,9 +134,9 @@ <entry name="cpuIOWaitColor" type="Color"> <default>green</default> </entry> - <entry name="cpuNiceColor" type="Color"> +<!-- <entry name="cpuNiceColor" type="Color"> <default>yellow</default> - </entry> + </entry> --> <entry name="memAppsColor" type="Color"> <default>blue</default> </entry> diff --git a/plasmoid/contents/ui/Cpu.qml b/plasmoid/contents/ui/Cpu.qml index 88d29b3aacaa3a57b1e722269280d0b9ef0b4218..a007daadfc879cea79e377c6ca6f64c6a62046a6 100755 --- a/plasmoid/contents/ui/Cpu.qml +++ b/plasmoid/contents/ui/Cpu.qml @@ -22,10 +22,18 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.ksysguard.sensors 1.0 as Sensors +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [1, 0, 0, 0, 0] // cores, system, user, io wait, nice + property var values: [1, 0, 0, 0] // cores, system, user, io wait + property var work: [1, 0, 0, 0] + property var cpuValues: [ + { value:0, count: 0}, + { value:0, count: 0}, + { value:0, count: 0}, + { value:0, count: 0}] property bool showBorder: true property bool compactView: false @@ -54,7 +62,7 @@ Rectangle { property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red" property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue" property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green" - property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" +// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" sourceComponent: plasmoid.configuration.cpuBarGraph ? barGraph : undefined Component { id: barGraph @@ -62,20 +70,19 @@ Rectangle { Repeater { model: numCores Rectangle { - property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2 - property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3 - property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4 - property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5 + property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1 + property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2 + property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3 x: (index * barWidth) + rectangle.border.width y: rectangle.border.width BarGraph { width: barWidth height: barHeight - segments: 4 + segments: 3 devisor: 100 showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView - config: [sysColor, userColor, waitColor, niceColor] - barValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx], values[niceIdx]] + config: [sysColor, userColor, waitColor] + barValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]] } } } @@ -89,7 +96,7 @@ Rectangle { property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red" property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue" property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green" - property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" +// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" property int xDem: 1 property int yDem: 1 sourceComponent: plasmoid.configuration.cpuCircularGraph ? circleGraph : undefined @@ -114,15 +121,14 @@ Rectangle { CircleGraph { width: (rectangle.width - (rectangle.border.width * 2)) / xDem height: (rectangle.height - (rectangle.border.width * 2)) / yDem - property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2 - property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3 - property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4 - property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5 - config: [sysColor, userColor, waitColor, niceColor] + property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1 + property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2 + property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3 + config: [sysColor, userColor, waitColor] devisor: 100 - segments: 4 + segments: 3 showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView - segValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx], values[niceIdx]] + segValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]] Component.onCompleted: reArrange() } } @@ -145,7 +151,7 @@ Rectangle { property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red" property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue" property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green" - property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" +// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow" sourceComponent: plasmoid.configuration.cpuPlotterGraph ? plotGraph : undefined Component { id: plotGraph @@ -158,16 +164,14 @@ Rectangle { PlotterGraph { width: plotWidth height: Math.floor(plotHeight) - property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2 - property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3 - property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4 - property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5 - config: [sysColor, userColor, waitColor, niceColor] + property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1 + property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2 + property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3 + config: [sysColor, userColor, waitColor] devisor: 100 - plots: 4 + plots: 3 showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView - plotValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx], - values[niceIdx], values[1]] + plotValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]] } } } @@ -203,80 +207,131 @@ Rectangle { var system var user var wait - var nice - system = Number(values[2]).toFixed(2) - user = Number(values[3]).toFixed(2) - wait = Number(values[4]).toFixed(2) - nice = Number(values[5]).toFixed(2) + system = Number(values[1]).toFixed(2) + user = Number(values[2]).toFixed(2) + wait = Number(values[3]).toFixed(2) ws = qsTr("System: ") + spaceit(system) + "%\n" ws = ws + qsTr("User: ") + spaceit(user) + "%\n" ws = ws + qsTr("IO Wait: ") + spaceit(wait) + "%\n" - ws = ws + qsTr("Nice: ") + spaceit(nice) + "%\n" - total = Number(system) + Number(user) + Number(wait) + Number(nice) + total = Number(system) + Number(user) + Number(wait) ws = ws + qsTr("Total ") + spaceit(total.toFixed(2)) + "%" return ws } } } } - - PlasmaCore.DataSource { - engine: "systemmonitor" - interval: plasmoid.configuration.updateInterval * 100 - property int numCores: 1 - connectedSources: { - var srcs = [] - - srcs.push("system/cores") - srcs.push("cpu/system/sys") - srcs.push("cpu/system/user") - srcs.push("cpu/system/wait") - srcs.push("cpu/system/nice") - if (numCores > 1) { - for (var idx = 0; idx < numCores; idx++) { - srcs.push("cpu/cpu" + idx + "/sys") - srcs.push("cpu/cpu" + idx + "/user") - srcs.push("cpu/cpu" + idx + "/wait") - srcs.push("cpu/cpu" + idx + "/nice") - } - } - return srcs - } - - onNewData: { - var cpuValues - - cpuValues = values - if (data.value !== undefined) { - if (sourceName == "system/cores") { + + Dbus { + id : dbus1 + property var coreCount: 0 + property var sensorList: [] + property var valueIdx: 0 + property var sensorKey + + sensors: ["cpu/all/system", + "cpu/all/user", + "cpu/all/wait"] + + onNewSensorData: { + coreCount = dbus1.doubleData("cpu/all/coreCount") + if (coreCount >= 1) { + if (!plasmoid.configuration.showCores) coreCount = 1 + if (coreCount != work[0]) { + sensorList = [] + sensorList.push("cpu/all/system") + sensorList.push("cpu/all/user") + sensorList.push("cpu/all/wait") if (plasmoid.configuration.showCores) { - numCores = Number(data.value) - cpuValues[0] = numCores + for (var idx = 0; idx < coreCount; idx++) { + valueIdx = (idx * 3) + 4 + cpuValues[valueIdx] = {value: 0, count: 0} + cpuValues[valueIdx + 1] = {value: 0, count: 0} + cpuValues[valueIdx + 2] = {value: 0, count: 0} + sensorList.push("cpu/cpu" +idx + "/system") + sensorList.push("cpu/cpu" +idx + "/user") + sensorList.push("cpu/cpu" +idx + "/wait") + } + work[0] = coreCount } else { - numCores = Number(1) - cpuValues[0] = numCores + work[0] = 1 } - } - if (sourceName == "cpu/system/sys") cpuValues[2] = Number(data.value) - if (sourceName == "cpu/system/user") cpuValues[3] = Number(data.value) - if (sourceName == "cpu/system/wait") cpuValues[4] = Number(data.value) - if (sourceName == "cpu/system/nice") cpuValues[5] = Number(data.value) - if (numCores > 1) { - for (var idx = 0; idx < numCores; idx++) { - if (sourceName == "cpu/cpu" + idx + "/sys") cpuValues[((idx + 1) *4) + 2] = Number(data.value) - if (sourceName == "cpu/cpu" + idx + "/user") cpuValues[((idx + 1) *4) + 3] = Number(data.value) - if (sourceName == "cpu/cpu" + idx + "/wait") cpuValues[((idx + 1) *4) + 4] = Number(data.value) - if (sourceName == "cpu/cpu" + idx + "/nice") cpuValues[((idx + 1) *4) + 5] = Number(data.value) + dbus1.sensors = sensorList + } else { + for (var idx = 0; idx < keys.length; idx++) { + sensorKey = keys[idx] + switch (sensorKey) { + case "cpu/all/system": + cpuValues[1].value += values[idx] + cpuValues[1].count += 1 + break; + case "cpu/all/user": + cpuValues[2].value += values[idx] + cpuValues[2].count += 1 + break; + case "cpu/all/wait": + cpuValues[3].value += values[idx] + cpuValues[3].count += 1 + break; + } + if (work[0] > 1) { + if (sensorKey.indexOf("cpu/cpu") == 0) { + for (var idy = 0; idy < work[0]; idy++) { + if (sensorKey.indexOf("cpu/cpu" + idy) == 0) { + valueIdx = (idy * 3) + 4 + switch (sensorKey) { + case "cpu/cpu" + idy + "/system": + cpuValues[valueIdx].value += values[idx] + cpuValues[valueIdx].count += 1 + break; + case "cpu/cpu" + idy + "/user": + cpuValues[valueIdx + 1].value += values[idx] + cpuValues[valueIdx + 1].count += 1 + break; + case "cpu/cpu" + idy + "/wait": + cpuValues[valueIdx + 2].value += values[idx] + cpuValues[valueIdx + 2].count += 1 + break; + } + } + } + } + } } } - if (cpuValues[1] === 0) { - cpuValues[1] = 1 - } else { - cpuValues[1] = 0 + } + } + } + + Timer { + interval: plasmoid.configuration.updateInterval * 100 + running: true + repeat: true + property var valueIdx: 0 + property var cpuItem + + onTriggered: { + for (var idx = 1; idx <= 3; idx++) { + cpuItem = cpuValues[idx] + if (cpuItem.count > 0) + work[idx] = cpuItem.value / cpuItem.count + cpuItem.value = 0 + cpuItem.count = 0 + } + if (work[0] > 1) { + for (var idy = 0; idy < work[0]; idy++) { + valueIdx = (idy * 3) + 4 + for (var idz = 0; idz < 3; idz++) { + cpuItem = cpuValues[valueIdx + idz] + if (cpuItem.count > 0) { + work[valueIdx + idz] = cpuItem.value / cpuItem.count + cpuItem.value = 0 + cpuItem.count = 0 + } + } } - values = cpuValues } + values = work } } } diff --git a/plasmoid/contents/ui/DiskIO.qml b/plasmoid/contents/ui/DiskIO.qml old mode 100755 new mode 100644 index cc2699fa99c51e24f04e86f022e8c69db5c72013..10b8b436dc5a6b0ad481fc0325baf1ff355c8647 --- a/plasmoid/contents/ui/DiskIO.qml +++ b/plasmoid/contents/ui/DiskIO.qml @@ -22,10 +22,17 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [1, 0, "", 0, 0] // Number of disks, toggle, label, BSread, BSwrite + property var values: [1, "", 0, 0] // Number of disks, label, BSread, BSwrite + property var work: [1, "", 0, 0] + property var duValues: [ + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}] property bool showBorder: true property bool compactView: false property int scale: 1024 @@ -53,9 +60,9 @@ Rectangle { Repeater { model: numDisk Rectangle { - property int diskLabel: (index * 3) + 2 - property int readRate: (index * 3) + 3 - property int writeRate: (index * 3) + 4 + property int diskLabel: (index * 4) + 1 + property int readRate: (index * 4) + 2 + property int writeRate: (index * 4) + 3 x: (index * barWidth) + rectangle.border.width y: rectangle.border.width DualBarGraph { @@ -103,9 +110,9 @@ Rectangle { id: circGraph width: (rectangle.width - (rectangle.border.width * 2)) / xDem height: (rectangle.height - (rectangle.border.width * 2)) / yDem - property int diskLabel: (index * 3) + 2 - property int readRate: (index * 3) + 3 - property int writeRate: (index * 3) + 4 + property int diskLabel: (index * 4) + 1 + property int readRate: (index * 4) + 2 + property int writeRate: (index * 4) + 3 config: [readColor, writeColor] devisor: scale showLabels: plasmoid.configuration.showLabels && !compactView @@ -137,13 +144,14 @@ Rectangle { DualPlotterGraph { width: plotWidth height: Math.floor(plotHeight) - property int diskLabel: (index * 3) + 2 - property int readRate: (index * 3) + 3 - property int writeRate: (index * 3) + 4 + property int diskLabel: (index * 4) + 1 + property int readRate: (index * 4) + 2 + property int writeRate: (index * 4) + 3 config: [readColor, writeColor] plots: 2 showLabels: plasmoid.configuration.showLabels && !compactView - plotValues: [values[diskLabel], values[readRate], values[writeRate], values[1]] + + plotValues: [values[diskLabel], values[readRate], values[writeRate]] } } } @@ -165,15 +173,20 @@ Rectangle { } function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 + if (v >= 1073741824) { + v = v / 1073741824 v = spaceit(v) + v.toFixed(2) + " GBS" } else { - if ( v >= 1024 ) { - v = v / 1024 + if ( v >= 1048576 ) { + v = v / 1048576 v = spaceit(v) + v.toFixed(2) + " MBS" } else { - v = spaceit(v) + v.toFixed(2) + " KBS" + if (v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KBS" + } else { + v = spaceit(v) + v.toFixed(2) + " BS" + } } } return v @@ -201,12 +214,12 @@ Rectangle { ws = "" numDisk = values[0] - 1 for (var idx = 0; idx <= numDisk; idx++) { - index = idx * 3 - read = values[index + 3] - write = values[index + 4] + index = idx * 4 + read = values[index + 2] + write = values[index + 3] if (isNaN(read)) read = 0 if (isNaN(write)) write = 0 - ws += values[index + 2] + "\n" + ws += values[index + 1] + "\n" ws = ws + qsTr("Read: ") + scaleit(read) + "\n" ws = ws + qsTr("Write: ") + scaleit(write) if (idx < numDisk) @@ -218,89 +231,115 @@ Rectangle { } } + Dbus { + id: dbus1 + property var sensorKey + property var valueIdx + property var configKey + + onNewSensorData: { + for (var idx = 0; idx < keys.length; idx++ ) { + sensorKey = keys[idx] + for (var idy = 0; idy < work[0]; idy++) { + configKey = plasmoid.configuration.dioSources[idy] + if (sensorKey.indexOf(configKey) == 0) { + valueIdx = (idy * 4) + 2 + switch (sensorKey) { + case configKey + "/read": + duValues[valueIdx].value += values[idx] + duValues[valueIdx].count += 1 + break; + case configKey + "/write": + duValues[valueIdx + 1].value += values[idx] + duValues[valueIdx + 1].count += 1 + break; + } + } + } + } + } + } + function addSources() { - var idx + var keyidx var count - var name - var result - var res + var key = "" + var sensors = [] + var sensorList = [] count = 0 - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^disk\/(sd.|nvme.n.)_[(][^\/]*\/Rate\/totalio$') - if (result !== null) { - if (plasmoid.configuration.dioSources.indexOf(result[1]) >= 0) { - res = name.replace("totalio", "rblk") - dataSource.connectSource(res) - res = name.replace("totalio", "wblk") - dataSource.connectSource(res) - values[(count * 3) + 2] = result[1] + sensors = dbus1.allSensors("disk/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/name")) { + keyidx = sensors[idx].indexOf("/name") + key = sensors[idx].slice(0,keyidx) + if (plasmoid.configuration.dioSources.indexOf(key) >= 0) { + sensorList.push(key + "/read") + sensorList.push(key + "/write") + if (count > 0) { + duValues[(count * 4)] = {value:0, count:0} + duValues[(count * 4) + 1] = {value:0, count:0} + duValues[(count * 4) + 2] = {value:0, count:0} + duValues[(count * 4) + 3] = {value:0, count:0} + } count += 1 } } } - values[0] = count + if (plasmoid.configuration.dioSources.indexOf("disk/all") >= 0) { + sensorList.push("disk/all/read") + sensorList.push("disk/all/write") + if (count > 0) { + duValues[(count * 4)] = {value:0, count:0} + duValues[(count * 4) + 1] = {value:0, count:0} + duValues[(count * 4) + 2] = {value:0, count:0} + duValues[(count * 4) + 3] = {value:0, count:0} + } + count += 1 + } + dbus1.sensors = sensorList + work[0] = count } Component.onCompleted: { addSources() } - function updateScale(value) { - if (value > scale) - scale = value - } - - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + Timer { interval: plasmoid.configuration.updateInterval * 100 - onSourcesChanged: { - addSources() - } - - onNewData: { - var idx - var duValues - var result - - duValues = values - scale *= .9 - if (scale < 1024) - scale = 1024 - if (data.value !== undefined) { - for (idx = 0; idx < duValues[0]; idx++) { - result = sourceName.match('^disk\/(sd.|nvme.n.)_[(][^\/]*\/Rate\/rblk$') - if (result !== null) { - if (duValues[(idx * 3) + 2 ] === result[1]) { - updateScale(data.value) - duValues[(idx * 3) + 3] = Number(data.value) - } + running: true + repeat: true + property var valueIdx + property var duItem + + onTriggered: { + if (plasmoid.configuration.dioSources != "") { + work[0] = plasmoid.configuration.dioSources.length + for (var idx = 0; idx < work[0]; idx++) { + valueIdx = (idx * 4) + 1 + if (plasmoid.configuration.dioSources[idx] == "disk/all" ) { + work[valueIdx] = "All" + } else { + work[valueIdx] = + dbus1.stringData(plasmoid.configuration.dioSources[idx] + "/name") } - result = sourceName.match('^disk\/(sd.|nvme.n.)_[(][^\/]*\/Rate\/wblk$') - if (result !== null) { - if (duValues[(idx * 3) + 2 ] === result[1]) { - updateScale(data.value) - duValues[(idx * 3) + 4] = Number(data.value) + for (var idy = 1; idy <= 2; idy++) { + duItem = duValues[valueIdx + idy] + if (duItem.count > 0) { + work[valueIdx + idy] = duItem.value / duItem.count + duItem.value = 0 + duItem.count = 0 } } } - if (duValues[1] === 0) { - duValues[1] = 1 - } else { - duValues[1] = 0 - } - values = duValues } + values = work } } - + Connections { target: plasmoid.configuration - onDioSourcesChanged: { - while (dataSource.connectedSources.length > 0) - dataSource.connectedSources.pop() + function onDioSourcesChanged() { addSources() } } diff --git a/plasmoid/contents/ui/DiskSpace.qml b/plasmoid/contents/ui/DiskSpace.qml index 11bc5b214f2b7ba1770600fa6a07c38f1c2635de..09e0f357c3400cc06b1dabd7cb7328aa74cf6df6 100755 --- a/plasmoid/contents/ui/DiskSpace.qml +++ b/plasmoid/contents/ui/DiskSpace.qml @@ -22,14 +22,22 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [1, 0, "", 0, 0] // Number of disks, toggle, label, freespace, usedspace + property var values: [1, "", 0, 0, 0, 0] // Number of disks, label, Used Percent, freespace, usedspace, totalspace + property var work: [1, "", 0, 0, 0, 0] + property var dsValues: [ + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}] property bool showBorder: true property bool compactView: false - radius: 3 color: "transparent" border { @@ -52,19 +60,18 @@ Rectangle { Repeater { model: numDisk Rectangle { - property int diskLabel: (index * 3) + 2 - property int freeSpace: (index * 3) + 3 - property int usedSpace: (index * 3) + 4 + property int diskLabel: (index * 6) + 1 + property int usedPercent: (index * 6) + 2 x: (index * barWidth) + rectangle.border.width y: rectangle.border.width BarGraph { width: barWidth height: barHeight segments: 1 - devisor: values[freeSpace] + values[usedSpace] + devisor: 100 showLabels: plasmoid.configuration.showLabels && !compactView config: [diskColor] - barValues: [values[diskLabel], values[usedSpace]] + barValues: [values[diskLabel], values[usedPercent]] } } } @@ -100,14 +107,13 @@ Rectangle { id: circGraph width: (rectangle.width - (rectangle.border.width * 2)) / xDem height: (rectangle.height - (rectangle.border.width * 2)) / yDem - property int diskLabel: (index * 3) + 2 - property int freeSpace: (index * 3) + 3 - property int usedSpace: (index * 3) + 4 + property int diskLabel: (index * 6) + 1 + property int usedPercent: (index * 6) + 2 config: [diskColor] - devisor: values[freeSpace] + values[usedSpace] + devisor: 100 segments: 1 showLabels: plasmoid.configuration.showLabels && !compactView - segValues: [values[diskLabel], values[usedSpace]] + segValues: [values[diskLabel], values[usedPercent]] Component.onCompleted: reArrange() } } @@ -135,15 +141,13 @@ Rectangle { PlotterGraph { width: plotWidth height: Math.floor(plotHeight) - property int diskLabel: (index * 3) + 2 - property int freeSpace: (index * 3) + 3 - property int usedSpace: (index * 3) + 4 - property int toggle: Number(values[1]) + property int diskLabel: (index * 6) + 1 + property int usedPercent: (index * 6) + 2 config: [diskColor] - devisor: values[freeSpace] + values[usedSpace] + devisor: 100 plots: 1 showLabels: plasmoid.configuration.showLabels && !compactView - plotValues: [values[diskLabel], values[usedSpace], values[1]] + plotValues: [values[diskLabel], values[usedPercent]] } } } @@ -165,16 +169,21 @@ Rectangle { } function scaleit (v) { - if (v >= 1073741824) { - v = v / 1073741824 + if (v >= 1099511627776) { + v = v / 1099511627776 v = spaceit(v) + v.toFixed(2) + " TiB" } else { - if ( v >= 1048576 ) { - v = v / 1048576 + if ( v >= 1073741824 ) { + v = v / 1073741824 v = spaceit(v) + v.toFixed(2) + " GiB" } else { - v = v / 1024 - v = spaceit(v) + v.toFixed(2) + " MiB" + if (v >= 1048579) { + v = v / 1048579 + v = spaceit(v) + v.toFixed(2) + " MiB" + } else { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KiB" + } } } return v @@ -200,15 +209,13 @@ Rectangle { var numDisk ws = "" - numDisk = values[0] - 1 - for (var idx = 0; idx <= numDisk; idx++) { - index = idx * 3 + numDisk = values[0] + for (var idx = 0; idx < numDisk; idx++) { + index = idx * 6 free = values[index + 3] used = values[index + 4] - if (isNaN(free)) free = 0 - if (isNaN(used)) used = 0 - total = Number(free) + Number(used) - ws += values[index + 2] + "\n" + total = values[index + 5] + ws += values[index + 1] + "\n" ws += qsTr("Used: ") + scaleit(used) + "\n" ws += qsTr("Free: ") + scaleit(free) + "\n" ws += qsTr("Total: ") + scaleit(total) @@ -221,76 +228,132 @@ Rectangle { } } + Dbus { + id: dbus1 + property var sensorKey + property var valueIdx + property var configKey + + onNewSensorData: { + for (var idx = 0; idx < keys.length; idx++) { + sensorKey = keys[idx] + for (var idy = 0; idy < work[0]; idy++) { + configKey = plasmoid.configuration.dsSources[idy] + if (sensorKey.indexOf(configKey) == 0) { + valueIdx = (idy * 6) + 2 + switch (sensorKey) { + case configKey + "/usedPercent": + dsValues[valueIdx].value += values[idx] + dsValues[valueIdx].count += 1 + break; + case configKey + "/free": + dsValues[valueIdx + 1].value += values[idx] + dsValues[valueIdx + 1].count += 1 + break; + case configKey + "/used": + dsValues[valueIdx + 2].value += values[idx] + dsValues[valueIdx + 2].count += 1 + break; + case configKey + "/total": + dsValues[valueIdx + 3].value += values[idx] + dsValues[valueIdx + 3].count += 1 + break; + } + } + } + } + } + } + function addSources() { - var idx + var nameIdx var count - var name - var result + var key = "" + var sensors = [] + var sensorList = [] count = 0 - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^partitions(.+)\/filllevel$') - if (result !== null) { - if (plasmoid.configuration.dsSources.indexOf(result[1]) >= 0) { - dataSource.connectSource("partitions" + result[1] + "/freespace") - dataSource.connectSource("partitions" + result[1] + "/usedspace") - values[(count * 3) + 2] = result[1] + sensors = dbus1.allSensors("disk/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/name")) { + nameIdx = sensors[idx].indexOf("/name") + key = sensors[idx].slice(0,nameIdx) + if (plasmoid.configuration.dsSources.indexOf(key) >= 0) { + sensorList.push(key + "/usedPercent") + sensorList.push(key + "/free") + sensorList.push(key + "/used") + sensorList.push(key + "/total") + if (count > 0) { + dsValues[(count * 6)] = {value:0, count:0} + dsValues[(count * 6) + 1] = {value:0, count:0} + dsValues[(count * 6) + 2] = {value:0, count:0} + dsValues[(count * 6) + 3] = {value:0, count:0} + dsValues[(count * 6) + 4] = {value:0, count:0} + dsValues[(count * 6) + 5] = {value:0, count:0} + } count += 1 } } } - values[0] = count + if (plasmoid.configuration.dsSources.indexOf("disk/all") >= 0) { + sensorList.push("disk/all/usedPercent") + sensorList.push("disk/all/free") + sensorList.push("disk/all/used") + sensorList.push("disk/all/total") + if (count > 0) { + dsValues[(count * 6)] = {value:0, count:0} + dsValues[(count * 6) + 1] = {value:0, count:0} + dsValues[(count * 6) + 2] = {value:0, count:0} + dsValues[(count * 6) + 3] = {value:0, count:0} + dsValues[(count * 6) + 4] = {value:0, count:0} + dsValues[(count * 6) + 5] = {value:0, count:0} + } + count += 1 + } + dbus1.sensors = sensorList + work[0] = count } Component.onCompleted: { addSources() } - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + Timer { interval: plasmoid.configuration.updateInterval * 100 - onSourcesChanged: { - addSources() - } - - onNewData: { - var idx - var dsValues - var result - - dsValues = values - if (data.value !== undefined) { - for (idx = 0; idx < dsValues[0]; idx++) { - result = sourceName.match('^partitions(.+)\/freespace$') - if (result !== null) { - if (dsValues[(idx * 3) + 2 ] === result[1]) - dsValues[(idx * 3) + 3] = Number(data.value) + running: true + repeat: true + property var valueIdx + property var dsItem + + onTriggered: { + if (plasmoid.configuration.dsSources != "") { + work[0] = plasmoid.configuration.dsSources.length + for (var idx = 0; idx < work[0]; idx++) { + valueIdx = (idx * 6) + 1 + if (plasmoid.configuration.dsSources[idx] == "disk/all" ) { + work[valueIdx] = "All" + } else { + work[valueIdx] = + dbus1.stringData(plasmoid.configuration.dsSources[idx] + "/name") } - result = sourceName.match('^partitions(.+)\/usedspace$') - if (result !== null) { - if (dsValues[(idx * 3) + 2 ] === result[1]) - dsValues[(idx * 3) + 4] = Number(data.value) + for (var idy = 1; idy <= 4; idy++ ) { + dsItem = dsValues[valueIdx + idy] + if (dsItem.count > 0) { + work[valueIdx + idy] = dsItem.value / dsItem.count + dsItem.value = 0 + dsItem.count = 0 + } } } - if (dsValues[1] === 0) { - dsValues[1] = 1 - } else { - dsValues[1] = 0 - } - values = dsValues } + values = work } } Connections { target: plasmoid.configuration - onDsSourcesChanged: { - while (dataSource.connectedSources.length > 0) - dataSource.connectedSources.pop() + function onDsSourcesChanged() { addSources() - } } } diff --git a/plasmoid/contents/ui/DualBarGraph.qml b/plasmoid/contents/ui/DualBarGraph.qml index 04f1aeeb110ba383b7e2942fce5b161f2e5871c2..5d324a8292a9f005e60400d6582743dd0a073fcb 100755 --- a/plasmoid/contents/ui/DualBarGraph.qml +++ b/plasmoid/contents/ui/DualBarGraph.qml @@ -23,17 +23,11 @@ Canvas { property var config: [] property var barValues: [] property int segments: 1 - property double devisor: 1 + property double devisor: 1024 property bool showLabels: false onConfigChanged: requestPaint() onBarValuesChanged: requestPaint() - QtObject { - id: data - property real wdevisor: 1 - property int ndevisor: 1 - } - onPaint: { var yLoc var gradient @@ -45,22 +39,23 @@ Canvas { var pw function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 - v = v.toFixed(0) + " GBs" + if (v >= 1073741824) { + v = v / 1073741824 + v = spaceit(v) + v.toFixed(2) + " GBs" } else { - if ( v >= 1024 ) { - v = v / 1024 - v = v.toFixed(0) + " MBs" + if ( v >= 1048576 ) { + v = v / 1048576 + v = spaceit(v) + v.toFixed(2) + " MBs" } else { - v = v.toFixed(0) + " KBs" + if (v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KBs" + } } } return v } - pwidth = Math.ceil(width) - ctx = getContext("2d") - ctx.clearRect(0, 0, pwidth, height) + function drawBar(index) { if (index === 0) { xLocStart = 0 @@ -89,23 +84,21 @@ Canvas { ctx.fill() } } - data.wdevisor = data.wdevisor * .75 - pw = Math.trunc(Math.log2(data.wdevisor)) + + pwidth = Math.ceil(width) + ctx = getContext("2d") + ctx.clearRect(0, 0, pwidth, height) + devisor = devisor / 2 + if (barValues[1] > devisor) + devisor = barValues[1] + if (barValues[2] > devisor) + devisor = barValues[2] + pw = 0 + while (Math.pow(2, pw) < devisor) + pw += 1 devisor = Math.pow(2, pw) - data.ndevisor = devisor - if (barValues[1] > data.ndevisor) - data.ndevisor = barValues[1] - if (barValues[2] > data.ndevisor) - data.ndevisor = barValues[2] - if (devisor < data.ndevisor) { - pw = 0 - while (Math.pow(2, pw) < data.ndevisor) - pw += 1 - devisor = Math.pow(2, pw) - data.wdevisor = devisor * 2 - } - if (devisor < 1) - devisor = 1 + if (devisor < 1024) + devisor = 1024 drawBar(0) drawBar(1) if(showLabels) { diff --git a/plasmoid/contents/ui/DualCircleGraph.qml b/plasmoid/contents/ui/DualCircleGraph.qml index 87dedbc1ae10bf231d1d7bfbf2354f0568a3fee4..a96fa5d3404c57d6fe1ce3eb5ce3daf972df8134 100755 --- a/plasmoid/contents/ui/DualCircleGraph.qml +++ b/plasmoid/contents/ui/DualCircleGraph.qml @@ -23,17 +23,11 @@ Canvas { property var config: [] property var segValues: [] property int segments: 3 - property double devisor: 1 + property double devisor: 1024 property bool showLabels: false onConfigChanged: requestPaint() onSegValuesChanged: requestPaint() - QtObject { - id: data - property real wdevisor: 1 - property int ndevisor: 1 - } - onPaint: { var centreX var centreY @@ -66,16 +60,20 @@ Canvas { endAngle = radians + startAngle drawArc(startAngle, endAngle, arcColor, index) } - function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 - v = v.toFixed(0) + " GBs" + + function scaleit (v) { + if (v >= 1073741824) { + v = v / 1073741824 + v = spaceit(v) + v.toFixed(2) + " GBs" } else { - if ( v >= 1024 ) { - v = v / 1024 - v = v.toFixed(0) + " MBs" + if ( v >= 1048576 ) { + v = v / 1048576 + v = spaceit(v) + v.toFixed(2) + " MBs" } else { - v = v.toFixed(0) + " KBs" + if (v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KBs" + } } } return v @@ -101,21 +99,21 @@ Canvas { ctx.arc(centreX, centreY, diameter, startAngle, endAngle, false) ctx.arc(centreX, centreY, halfDiam, startAngle, endAngle, false) ctx.stroke() - data.wdevisor = data.wdevisor * .75 - pw = Math.trunc(Math.log2(data.wdevisor)) + + + devisor = devisor / 2 + if (segValues[1] > devisor) + devisor = segValues[1] + if (segValues[2] > devisor) + devisor = segValues[2] + pw = 0 + while (Math.pow(2, pw) < devisor) + pw += 1 devisor = Math.pow(2, pw) - data.ndevisor = devisor - if (segValues[1] > data.ndevisor) - data.ndevisor = segValues[1] - if (segValues[2] > data.ndevisor) - data.ndevisor = segValues[2] - if (devisor < data.ndevisor) { - pw = 0 - while (Math.pow(2, pw) < data.ndevisor) - pw += 1 - devisor = Math.pow(2, pw) - data.wdevisor = devisor * 2 - } + if (devisor < 1024) + devisor = 1024 + + startAngle = Math.PI / 2 showArc(segValues[1], config[0], 0) startAngle = Math.PI / 2 diff --git a/plasmoid/contents/ui/DualPlotterGraph.qml b/plasmoid/contents/ui/DualPlotterGraph.qml index 8151ac9c5e48e91615fc5b025d4ed50e24be86f4..127c8b0ed09c68f39f1289a90275f5ba2c2ac838 100644 --- a/plasmoid/contents/ui/DualPlotterGraph.qml +++ b/plasmoid/contents/ui/DualPlotterGraph.qml @@ -24,7 +24,7 @@ Canvas { id: plotCanvas property var config: [] property int plots: 0 - property double devisor: 1 + property double devisor: 1024 property var plotValues: [] property bool showLabels: false @@ -32,7 +32,7 @@ Canvas { id: data property var graphValues: [] property int numValues: 0 - property int maxValues: 33 + property int maxValues: 61 property real segSize: width / (maxValues - 1 ) property bool valuesChanged : false property var paths: [] @@ -60,7 +60,7 @@ Canvas { Component { id: curve - PathCurve {} + PathCubic {} } Path { @@ -77,33 +77,51 @@ Canvas { var clr var pw var alpha + var xDiff function addPoint(xLoc, yLoc) { if (data.paths.length < pointCnt + 1) { - if (pointCnt === 0) { + if (data.smoothing) { + data.paths[pointCnt] = curve.createObject(plotCanvas, {}) + } else { data.paths[pointCnt] = line.createObject(plotCanvas, {}) + } + } + if (data.smoothing) { + data.paths[pointCnt].x = Math.round(xLoc) + data.paths[pointCnt].y = Math.round(yLoc) + if (pointCnt == 0) { + data.paths[pointCnt].control1X = plot.startX + data.paths[pointCnt].control1Y = plot.startY + data.paths[pointCnt].control2X = xLoc + data.paths[pointCnt].control2Y = yLoc } else { - if (data.smoothing) { - data.paths[pointCnt] = curve.createObject(plotCanvas, {}) - } else { - data.paths[pointCnt] = line.createObject(plotCanvas, {}) - } + xDiff = ((data.paths[pointCnt - 1].x - xLoc) / 2) + data.paths[pointCnt].control1X = data.paths[pointCnt - 1].x - xDiff + data.paths[pointCnt].control1Y = data.paths[pointCnt - 1].y + data.paths[pointCnt].control2X = xLoc + xDiff + data.paths[pointCnt].control2Y = yLoc } + } else { + data.paths[pointCnt].x = Math.round(xLoc) + data.paths[pointCnt].y = Math.round(yLoc) } - data.paths[pointCnt].x = Math.round(xLoc) - data.paths[pointCnt].y = Math.round(yLoc) pointCnt += 1 } + function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 - v = v.toFixed(0) + " GBs" + if (v >= 1073741824) { + v = v / 1073741824 + v = spaceit(v) + v.toFixed(2) + " GBs" } else { - if ( v >= 1024 ) { - v = v / 1024 - v = v.toFixed(0) + " MBs" + if ( v >= 1048576 ) { + v = v / 1048576 + v = spaceit(v) + v.toFixed(2) + " MBs" } else { - v = v.toFixed(0) + " KBs" + if (v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KBs" + } } } return v @@ -131,7 +149,7 @@ Canvas { ctx = getContext("2d") ctx.clearRect(0, 0, width, Math.ceil(height)) if (data.numValues > 1) { - devisor = 1 + devisor = 1024 for (idy = 0; idy < plots; idy++) { for (idx = 0; idx < data.numValues; idx++) { if (data.graphValues[idy][idx] > devisor) diff --git a/plasmoid/contents/ui/Memory.qml b/plasmoid/contents/ui/Memory.qml index e7775324f66419d9677d04f5afed005ba54a630d..246fa973ab91280a2658ad6f328fc810288da419 100755 --- a/plasmoid/contents/ui/Memory.qml +++ b/plasmoid/contents/ui/Memory.qml @@ -22,10 +22,21 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [0, 0, 0, 0] // maxMem, appMem, buffMem, cacheMem + property var values: [0, 0, 0, 0, 0, 0, 0, 0] // maxMem, appMem, buffMem, cacheMem + property var work: [0, 0, 0, 0, 0, 0, 0, 0] + property var memValues: [ + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}] property bool showBorder: true radius: 3 @@ -50,7 +61,7 @@ Rectangle { width: rectangle.width - (rectangle.border.width * 2) height: rectangle.height - (rectangle.border.width * 2) segments: 3 - devisor: values[0] + devisor: 100 config: [appsColor, buffColor, cacheColor] barValues: [0, values[1], values[2], values[3]] } @@ -70,7 +81,7 @@ Rectangle { height: rectangle.height - (rectangle.border.width * 2) config: [appColor, buffColor, cacheColor] segments: 3 - devisor: values[0] + devisor: 100 segValues: [0, values[1], values[2], values[3]] } } @@ -88,7 +99,7 @@ Rectangle { width: rectangle.width - (rectangle.border.width * 2) height: rectangle.height - (rectangle.border.width * 2) config: [appColor, buffColor, cacheColor] - devisor: values[0] + devisor: 100 plots: 3 plotValues: values } @@ -109,15 +120,18 @@ Rectangle { } function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 + if (v >= 1073741824) { + v = v / 1073741824 v = spaceit(v) + v.toFixed(2) + " GiB" } else { - if ( v >= 1024 ) { - v = v / 1024 + if ( v >= 1048576 ) { + v = v / 1048576 v = spaceit(v) + v.toFixed(2) + " MiB" } else { - v = spaceit(v) + v.toFixed(2) + " KiB" + if ( v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KiB" + } } } return v @@ -136,48 +150,85 @@ Rectangle { color: border.color text: { var ws - ws = qsTr("Total Memory: ") + scaleit(values[0]) + "\n" - ws = ws + qsTr("Application Memory: ") + scaleit(values[1]) + "\n" - ws = ws + qsTr("Buffer Memory: ") + scaleit(values[2]) + "\n" - ws = ws + qsTr("Cache Memory: ") + scaleit(values[3]) + "\n" - ws = ws + qsTr("Free Memory: ") + scaleit(values[0] - - values[1] - values[2] - values[3]) + ws = qsTr("Total Memory: ") + scaleit(values[4]) + "\n" + ws = ws + qsTr("Application Memory: ") + scaleit(values[5]) + "\n" + ws = ws + qsTr("Buffer Memory: ") + scaleit(values[6]) + "\n" + ws = ws + qsTr("Cache Memory: ") + scaleit(values[7]) + "\n" + ws = ws + qsTr("Free Memory: ") + scaleit(values[8]) return ws } } } } - - PlasmaCore.DataSource { - engine: "systemmonitor" - interval: plasmoid.configuration.updateInterval * 100 - connectedSources: { - var srcs = [] - srcs.push("mem/physical/application") - srcs.push("mem/physical/buf") - srcs.push("mem/physical/cached") - return srcs - } - onNewData: { - var memValues - - memValues = values - if (data.value !== undefined && data.max !== undefined) { - if (sourceName == "mem/physical/application") { - memValues[0] = Number(data.max) - memValues[1] = Number(data.value) - } - if (sourceName == "mem/physical/buf") { - memValues[0] = Number(data.max) - memValues[2] = Number(data.value) + + Dbus { + id : dbus1 + property var sensorKey + + sensors: ["memory/physical/applicationPercent", + "memory/physical/bufferPercent", + "memory/physical/cachePercent", + "memory/physical/total", + "memory/physical/application", + "memory/physical/buffer", + "memory/physical/cache"] + + onNewSensorData: { + for ( var idx = 0; idx < keys.length; idx++) { + sensorKey = keys[idx] + if (sensorKey.indexOf("memory/physical") == 0) { + switch (sensorKey) { + case "memory/physical/applicationPercent": + memValues[1].value += values[idx] + memValues[1].count += 1 + break; + case "memory/physical/bufferPercent": + memValues[2].value += values[idx] + memValues[2].count += 1 + break; + case "memory/physical/cachePercent": + memValues[3].value += values[idx] + memValues[3].count += 1 + break; + case "memory/physical/total": + memValues[4].value += values[idx] + memValues[4].count += 1 + break; + case "memory/physical/application": + memValues[5].value += values[idx] + memValues[5].count += 1 + break; + case "memory/physical/buffer": + memValues[6].value += values[idx] + memValues[6].count += 1 + break; + case "memory/physical/cache": + memValues[7].value += values[idx] + memValues[7].count += 1 + break; + } } - if (sourceName == "mem/physical/cached") { - memValues[0] = Number(data.max) - memValues[3] = Number(data.value) + } + } + } + + Timer { + interval: plasmoid.configuration.updateInterval * 100 + running: true + repeat: true + property var memItem + + onTriggered: { + for (var idx = 1; idx <= 7; idx ++) { + memItem = memValues[idx] + if (memItem.count > 0 ) { + work[idx] = memItem.value / memItem.count + memItem.value = 0 + memItem.count = 0 } - values = memValues } + work[8] = work[4] - work[5] - work[6] - work[7] + values = work } } } - diff --git a/plasmoid/contents/ui/Network.qml b/plasmoid/contents/ui/Network.qml index 4645d102ecfbaa37d27bfc45071486cae7d1fea1..433eaf3a047cf3814393a286a056992b8b570a2d 100755 --- a/plasmoid/contents/ui/Network.qml +++ b/plasmoid/contents/ui/Network.qml @@ -22,10 +22,17 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [1, 0, "", 0, 0] // Number of interfaces, toggle, label, Download, Upload + property var values: [1, "", 0, 0] // Number of interfaces, label, Download, Upload + property var work: [1, "", 0, 0] + property var netValues: [ + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}] property bool showBorder: true property bool compactView: false property int scale: 1024 @@ -53,9 +60,9 @@ Rectangle { Repeater { model: numNet Rectangle { - property int netLabel: (index * 3) + 2 - property int downRate: (index * 3) + 3 - property int upRate: (index * 3) + 4 + property int netLabel: (index * 4) + 1 + property int downRate: (index * 4) + 2 + property int upRate: (index * 4) + 3 x: (index * barWidth) + rectangle.border.width y: rectangle.border.width DualBarGraph { @@ -103,9 +110,9 @@ Rectangle { id: circGraph width: (rectangle.width - (rectangle.border.width * 2)) / xDem height: (rectangle.height - (rectangle.border.width * 2)) / yDem - property int netLabel: (index * 3) + 2 - property int downRate: (index * 3) + 3 - property int upRate: (index * 3) + 4 + property int netLabel: (index * 4) + 1 + property int downRate: (index * 4) + 2 + property int upRate: (index * 4) + 3 config: [downColor, upColor] devisor: scale showLabels: plasmoid.configuration.showLabels && !compactView @@ -137,9 +144,9 @@ Rectangle { DualPlotterGraph { width: plotWidth height: Math.floor(plotHeight) - property int netLabel: (index * 3) + 2 - property int downRate: (index * 3) + 3 - property int upRate: (index * 3) + 4 + property int netLabel: (index * 4) + 1 + property int downRate: (index * 4) + 2 + property int upRate: (index * 4) + 3 config: [downColor, upColor] plots: 2 showLabels: plasmoid.configuration.showLabels && !compactView @@ -165,15 +172,20 @@ Rectangle { } function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 + if (v >= 1073741824) { + v = v / 1073741824 v = spaceit(v) + v.toFixed(2) + " GBS" } else { - if ( v >= 1024 ) { - v = v / 1024 + if ( v >= 1048576 ) { + v = v / 1048576 v = spaceit(v) + v.toFixed(2) + " MBS" } else { - v = spaceit(v) + v.toFixed(2) + " KBS" + if (v >= 1024) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KBS" + } else { + v = spaceit(v) + v.toFixed(2) + " BS" + } } } return v @@ -201,12 +213,12 @@ Rectangle { ws = "" numNet = values[0] - 1 for (var idx = 0; idx <= numNet; idx++) { - index = idx * 3 - down = values[index + 3] - up = values[index + 4] + index = idx * 4 + down = values[index + 2] + up = values[index + 3] if (isNaN(down)) down = 0 if (isNaN(up)) up = 0 - ws += values[index + 2] + "\n" + ws += values[index + 1] + "\n" ws = ws + qsTr("Down: ") + scaleit(down) + "\n" ws = ws + qsTr("Up: ") + scaleit(up) if (idx < numNet) @@ -218,84 +230,115 @@ Rectangle { } } + Dbus { + id: dbus1 + property var sensorKey + property var valueIdx + property var configKey + + onNewSensorData: { + for (var idx = 0; idx < keys.length; idx++ ) { + sensorKey = keys[idx] + for (var idy = 0; idy < work[0]; idy++) { + configKey = plasmoid.configuration.netSources[idy] + if (sensorKey.indexOf(configKey) == 0) { + valueIdx = (idy * 4) + 2 + switch (sensorKey) { + case configKey + "/download": + netValues[valueIdx].value += values[idx] + netValues[valueIdx].count += 1 + break; + case configKey + "/upload": + netValues[valueIdx + 1].value += values[idx] + netValues[valueIdx + 1].count += 1 + break; + } + } + } + } + } + } + function addSources() { - var idx + var keyidx var count - var name - var result - var res + var key = "" + var sensors = [] + var sensorList = [] count = 0 - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^network\/interfaces\/((?!lo).+)\/transmitter\/dataTotal$') - if (result !== null) { - if (plasmoid.configuration.netSources.indexOf(result[1]) >= 0) { - res = name.replace("transmitter\/dataTotal", "receiver\/data") - dataSource.connectSource(res) - res = name.replace("transmitter\/dataTotal", "transmitter\/data") - dataSource.connectSource(res) - values[(count * 3) + 2] = result[1] + sensors = dbus1.allSensors("network/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/network")) { + keyidx = sensors[idx].indexOf("/network") + key = sensors[idx].slice(0,keyidx) + if (plasmoid.configuration.netSources.indexOf(key) >= 0) { + sensorList.push(key + "/download") + sensorList.push(key + "/upload") + if (count > 0) { + netValues[(count * 4)] = {value:0, count:0} + netValues[(count * 4) + 1] = {value:0, count:0} + netValues[(count * 4) + 2] = {value:0, count:0} + netValues[(count * 4) + 3] = {value:0, count:0} + } count += 1 } } } - values[0] = count + if (plasmoid.configuration.netSources.indexOf("network/all") >= 0) { + sensorList.push("network/all/download") + sensorList.push("network/all/upload") + if (count > 0) { + netValues[(count * 4)] = {value:0, count:0} + netValues[(count * 4) + 1] = {value:0, count:0} + netValues[(count * 4) + 2] = {value:0, count:0} + netValues[(count * 4) + 3] = {value:0, count:0} + } + count += 1 + } + dbus1.sensors = sensorList + work[0] = count } Component.onCompleted: { addSources() } - function updateScale(value) { - if (value > scale) - scale = value - } - - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + Timer { interval: plasmoid.configuration.updateInterval * 100 - onSourcesChanged: { - addSources() - } - - onNewData: { - var idx - var duValues - var result - - duValues = values - scale *= .9 - if (scale < 1024) - scale = 1024 - if (data.value !== undefined) { - for (idx = 0; idx < duValues[0]; idx++) { - result = sourceName.match('^network\/interfaces\/((?!lo).+)\/receiver\/data$') - if (result !== null) { - if (duValues[(idx * 3) + 2 ] === result[1]) { - updateScale(data.value) - duValues[(idx * 3) + 3] = Number(data.value) - } + running: true + repeat: true + property var valueIdx + property var netItem + + onTriggered: { + if (plasmoid.configuration.netSources != "") { + work[0] = plasmoid.configuration.netSources.length + for (var idx = 0; idx < work[0]; idx++) { + valueIdx = (idx * 4) + 1 + if (plasmoid.configuration.netSources[idx] == "network/all" ) { + work[valueIdx] = "All" + } else { + work[valueIdx] = + dbus1.stringData(plasmoid.configuration.netSources[idx] + "/network") } - result = sourceName.match('^network\/interfaces\/((?!lo).+)\/transmitter\/data$') - if (result !== null) { - if (duValues[(idx * 3) + 2 ] === result[1]) { - updateScale(data.value) - duValues[(idx * 3) + 4] = Number(data.value) + for (var idy = 1; idy <= 2; idy++) { + netItem = netValues[valueIdx + idy] + if (netItem.count > 0) { + work[valueIdx + idy] = netItem.value / netItem.count + netItem.value = 0 + netItem.count = 0 } } } - values = duValues } + values = work } } Connections { target: plasmoid.configuration - onNetSourcesChanged: { - while (dataSource.connectedSources.length > 0) - dataSource.connectedSources.pop() + function onNetSourcesChanged() { addSources() } } diff --git a/plasmoid/contents/ui/PlotterGraph.qml b/plasmoid/contents/ui/PlotterGraph.qml index c691e9e190ae6de15aaa95ca231b9eb571237b77..62a8b6dbc3b21fcc0af4a6001f0d310638ddee78 100644 --- a/plasmoid/contents/ui/PlotterGraph.qml +++ b/plasmoid/contents/ui/PlotterGraph.qml @@ -31,7 +31,7 @@ Canvas { id: data property var graphValues: [] property int numValues: 0 - property int maxValues: 33 + property int maxValues: 61 property real segSize: width / (maxValues - 1 ) property bool valuesChanged : false property var paths: [] @@ -59,7 +59,7 @@ Canvas { Component { id: curve - PathCurve {} + PathCubic {} } Path { @@ -74,23 +74,38 @@ Canvas { var pointCnt var curXLoc var curYLoc + var xDiff function addPoint(xLoc, yLoc) { if (data.paths.length < pointCnt + 1) { - if (pointCnt === 0) { + if (data.smoothing) { + data.paths[pointCnt] = curve.createObject(plotCanvas, {}) + } else { data.paths[pointCnt] = line.createObject(plotCanvas, {}) + } + } + if (data.smoothing) { + data.paths[pointCnt].x = Math.round(xLoc) + data.paths[pointCnt].y = Math.round(yLoc) + if (pointCnt == 0) { + data.paths[pointCnt].control1X = plot.startX + data.paths[pointCnt].control1Y = plot.startY + data.paths[pointCnt].control2X = xLoc + data.paths[pointCnt].control2Y = yLoc } else { - if (data.smoothing) { - data.paths[pointCnt] = curve.createObject(plotCanvas, {}) - } else { - data.paths[pointCnt] = line.createObject(plotCanvas, {}) - } + xDiff = ((data.paths[pointCnt - 1].x - xLoc) / 2) + data.paths[pointCnt].control1X = data.paths[pointCnt - 1].x - xDiff + data.paths[pointCnt].control1Y = data.paths[pointCnt - 1].y + data.paths[pointCnt].control2X = xLoc + xDiff + data.paths[pointCnt].control2Y = yLoc } + } else { + data.paths[pointCnt].x = Math.round(xLoc) + data.paths[pointCnt].y = Math.round(yLoc) } - data.paths[pointCnt].x = Math.round(xLoc) - data.paths[pointCnt].y = Math.round(yLoc) pointCnt += 1 } + if (data.reset) { data.paths.length = 0 data.reset = false diff --git a/plasmoid/contents/ui/Swap.qml b/plasmoid/contents/ui/Swap.qml index 3f0eac220c6e0741e3786212a12d6b347af28134..8839b8987c3548e578e759c524f0c6a47a3d0086 100755 --- a/plasmoid/contents/ui/Swap.qml +++ b/plasmoid/contents/ui/Swap.qml @@ -22,10 +22,17 @@ import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.components 2.0 as PlasmaComponents +import DbusModel 1.0 Rectangle { id: rectangle - property var values: [0, 0] // swapFree, swapUsed + property var values: [0, 0, 0, 0] // used %, total swap, swapUsed, swapFree + property var work: [0, 0, 0, 0] + property var swapValues: [ + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}, + {value:0, count:0}] property bool showBorder: true radius: 3 color: "transparent" @@ -47,9 +54,9 @@ Rectangle { width: rectangle.width - (rectangle.border.width * 2) height: rectangle.height - (rectangle.border.width * 2) segments: 1 - devisor: values[0] + values[1] + devisor: 100 config: [usedColor] - barValues: [0, values[1]] + barValues: [0, values[0]] } } } @@ -65,8 +72,8 @@ Rectangle { height: rectangle.height - (rectangle.border.width * 2) config: [usedColor] segments: 1 - devisor: values[0] + values[1] - segValues: [0, values[1]] + devisor: 100 + segValues: [0, values[0]] } } } @@ -81,9 +88,9 @@ Rectangle { width: rectangle.width - (rectangle.border.width * 2) height: rectangle.height - (rectangle.border.width * 2) config: [usedColor] - devisor: values[0] + values[1] + devisor: 100 plots: 1 - plotValues: values + plotValues: [0, values[0]] } } } @@ -102,20 +109,25 @@ Rectangle { } function scaleit (v) { - if (v >= 1048576) { - v = v / 1048576 + if (v >= 1073741824) { + v = v / 1073741824 v = spaceit(v) + v.toFixed(2) + " GiB" } else { - if ( v >= 1024 ) { - v = v / 1024 + if ( v >= 1048576 ) { + v = v / 1048576 v = spaceit(v) + v.toFixed(2) + " MiB" } else { - v = spaceit(v) + v.toFixed(2) + " KiB" + if ( v >= 1024 ) { + v = v / 1024 + v = spaceit(v) + v.toFixed(2) + " KiB" + } else { + v = spaceit(v) + v.toFixed(2) + " iB" + } } } return v } - + PlasmaCore.ToolTipArea { anchors.fill: parent interactive: true @@ -129,40 +141,67 @@ Rectangle { color: border.color text: { var ws - ws = qsTr("Total Swap: ") + scaleit(values[0] + values[1]) + "\n" - ws = ws + qsTr("Used Swap: ") + scaleit(values[1]) + "\n" - ws = ws + qsTr("Free Swap: ") + scaleit(values[0]) + ws = qsTr("Total Swap: ") + scaleit(values[1]) + "\n" + ws = ws + qsTr("Used Swap: ") + scaleit(values[2]) + "\n" + ws = ws + qsTr("Free Swap: ") + scaleit(values[3]) return ws } } } } - - PlasmaCore.DataSource { - engine: "systemmonitor" - interval: plasmoid.configuration.updateInterval * 1000 - property int numCores: 1 - connectedSources: { - var srcs = [] - - srcs.push("mem/swap/free") - srcs.push("mem/swap/used") - return srcs + + Dbus { + id : dbus1 + property var sensorKey + + sensors: ["memory/swap/usedPercent", + "memory/swap/total", + "memory/swap/used", + "memory/swap/free"] + + onNewSensorData: { + for (var idx = 0; idx < keys.length; idx++) { + sensorKey = keys[idx] + if (sensorKey.indexOf("memory/swap") == 0) { + switch(sensorKey) { + case "memory/swap/usedPercent": + swapValues[0].value += values[idx] + swapValues[0].count += 1 + break; + case "memory/swap/total": + swapValues[1].value += values[idx] + swapValues[1].count += 1 + break; + case "memory/swap/used": + swapValues[2].value += values[idx] + swapValues[2].count += 1 + break; + case "memory/swap/free": + swapValues[3].value += values[idx] + swapValues[3].count += 1 + break; + } + } + } } - onNewData: { - var swapValues - swapValues = values - - if (data.value !== undefined && data.max !== undefined) { - if (sourceName == "mem/swap/free") swapValues[0] = Number(data.value) - if (sourceName == "mem/swap/used") swapValues[1] = Number(data.value) - if (swapValues[2] === 0) { - swapValues[2] = 1 - } else { - swapValues[2] = 0 + } + + Timer { + interval: plasmoid.configuration.updateInterval * 100 + running: true + repeat: true + property var swapItem + + onTriggered: { + for (var idx = 0; idx < 4; idx++) { + swapItem = swapValues[idx] + if (swapItem.count > 0) { + work[idx] = swapItem.value / swapItem.count + swapItem.value = 0 + swapItem.count = 0 } - values = swapValues } + values = work } } } diff --git a/plasmoid/contents/ui/configColors.qml b/plasmoid/contents/ui/configColors.qml index 23ba5c694f8c8a72165e35ae2f18c78fb438a35f..28f76d379478f91312fdec5d7b881c071199ec57 100755 --- a/plasmoid/contents/ui/configColors.qml +++ b/plasmoid/contents/ui/configColors.qml @@ -27,7 +27,7 @@ Item { property alias cfg_cpuSystemColor: cpuSystemColorPicker.color property alias cfg_cpuUserColor: cpuUserColorPicker.color property alias cfg_cpuIOWaitColor: cpuIOWaitColorPicker.color - property alias cfg_cpuNiceColor: cpuNiceColorPicker.color +// property alias cfg_cpuNiceColor: cpuNiceColorPicker.color property alias cfg_memAppsColor: memAppsColorPicker.color property alias cfg_memBuffColor: memBuffColorPicker.color property alias cfg_memCacheColor: memCacheColorPicker.color @@ -50,7 +50,7 @@ Item { Text { id: cpuColors Layout.row: 1 - Layout.column: 1 + Layout.column: 3 font.bold: true text: qsTr("CPU") } @@ -58,7 +58,7 @@ Item { Label { id: systemColor Layout.row: 2 - Layout.column: 0 + Layout.column: 2 text: qsTr("System:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -67,14 +67,14 @@ Item { KQuickControls.ColorButton { id: cpuSystemColorPicker Layout.row: 2 - Layout.column: 1 + Layout.column: 3 enabled: customColors.checked } Label { id: userColor Layout.row: 3 - Layout.column: 0 + Layout.column: 2 text: qsTr("User:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -83,14 +83,14 @@ Item { KQuickControls.ColorButton { id: cpuUserColorPicker Layout.row: 3 - Layout.column: 1 + Layout.column: 3 enabled: customColors.checked } Label { id: ioWaitColor Layout.row: 4 - Layout.column: 0 + Layout.column: 2 text: qsTr("IO Wait:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -99,25 +99,25 @@ Item { KQuickControls.ColorButton { id: cpuIOWaitColorPicker Layout.row: 4 - Layout.column: 1 + Layout.column: 3 enabled: customColors.checked } - Label { - id: niceColor - Layout.row: 5 - Layout.column: 0 - text: qsTr("Nice:") - Layout.alignment: Qt.AlignRight | Qt.AlignVCenter - enabled: customColors.checked - } +// Label { +// id: niceColor +// Layout.row: 5 +// Layout.column: 0 +// text: qsTr("Nice:") +// Layout.alignment: Qt.AlignRight | Qt.AlignVCenter +// enabled: customColors.checked +// } - KQuickControls.ColorButton { - id: cpuNiceColorPicker - Layout.row: 5 - Layout.column: 1 - enabled: customColors.checked - } +// KQuickControls.ColorButton { +// id: cpuNiceColorPicker +// Layout.row: 5 +// Layout.column: 1 +// enabled: customColors.checked +// } Text { id: rowspacer @@ -186,7 +186,7 @@ Item { Text { id: diskColors Layout.row: 1 - Layout.column: 3 + Layout.column: 1 font.bold: true text: qsTr("Disk") } @@ -194,7 +194,7 @@ Item { Label { id: diskReadColor Layout.row: 2 - Layout.column: 2 + Layout.column: 0 text: qsTr("Read:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -202,7 +202,7 @@ Item { KQuickControls.ColorButton { Layout.row: 2 - Layout.column: 3 + Layout.column: 1 id: diskIOReadColorPicker enabled: customColors.checked } @@ -210,7 +210,7 @@ Item { Label { id: diskWriteColor Layout.row: 3 - Layout.column: 2 + Layout.column: 0 text: qsTr("Write:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -219,14 +219,14 @@ Item { KQuickControls.ColorButton { id: diskIOWriteColorPicker Layout.row: 3 - Layout.column: 3 + Layout.column: 1 enabled: customColors.checked } Label { id: diskColor Layout.row: 4 - Layout.column: 2 + Layout.column: 0 text: qsTr("Disk Space:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -235,14 +235,14 @@ Item { KQuickControls.ColorButton { id: diskSpaceColorPicker Layout.row: 4 - Layout.column: 3 + Layout.column: 1 enabled: customColors.checked } Label { id: swapColor Layout.row: 5 - Layout.column: 2 + Layout.column: 0 text: qsTr("Swap:") Layout.alignment: Qt.AlignRight | Qt.AlignVCenter enabled: customColors.checked @@ -251,7 +251,7 @@ Item { KQuickControls.ColorButton { id: swapColorPicker Layout.row: 5 - Layout.column: 3 + Layout.column: 1 enabled: customColors.checked } diff --git a/plasmoid/contents/ui/configDiskIO.qml b/plasmoid/contents/ui/configDiskIO.qml index e11c80b2801f5b8ec339278c0ea2d412bbb69c04..f8fea5cabf0a9c91bca8c82f2e3aedce06ba2406 100755 --- a/plasmoid/contents/ui/configDiskIO.qml +++ b/plasmoid/contents/ui/configDiskIO.qml @@ -21,6 +21,7 @@ import QtQuick 2.1 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore +import DbusModel 1.0 Item { property var cfg_dioSources: [] @@ -34,19 +35,19 @@ Item { Repeater { model: sources CheckBox { - text: qsTr(model.name) + text: model.name checked: model.checked onCheckedChanged: { var idx if(!data.loading) { if (checked) { - idx = cfg_dioSources.indexOf(model.name) + idx = cfg_dioSources.indexOf(model.keyid) if (idx < 0) { - cfg_dioSources.push(model.name) + cfg_dioSources.push(model.keyid) } } else { - idx = cfg_dioSources.indexOf(model.name) + idx = cfg_dioSources.indexOf(model.keyid) cfg_dioSources.splice(idx, 1) } cfg_dioSourcesChanged(); @@ -59,39 +60,47 @@ Item { ListModel { id: sources } - - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + + Dbus { + id : dbus1 } Component.onCompleted: { var idx var cfgLength - var name - var result + var dskName + var sensors = [] + var nameIdx + var key data.loading = true - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^disk\/(sd.|nvme.n.)_[(][^\/]*\/Rate\/totalio$') - if (result !== null) { - if (cfg_dioSources.indexOf(result[1]) < 0) { - sources.append({name:result[1], checked: false}) + cfg_dioSources = plasmoid.configuration['dioSources'] + sensors = dbus1.allSensors("disk/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/name")) { + nameIdx = sensors[idx].indexOf("/name") + key = sensors[idx].slice(0,nameIdx) + dskName = dbus1.stringData(sensors[idx]) + if (cfg_dioSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: dskName, checked: false}) } else { - sources.append({name:result[1], checked: true}) + sources.append({keyid:key, name: dskName, checked: true}) } } } - cfgLength = cfg_dioSources.length + key = "disk/all" + dskName = "All" + if (cfg_dioSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: dskName, checked: false}) + } else { + sources.append({keyid:key, name: dskName, checked: true}) + } cfg_dioSources.length = 0 for (idx = 0; idx < sources.count; idx++) { - if (sources.get(idx).checked) { - cfg_dioSources.push(sources.get(idx).name) - } + if (sources.get(idx).checked) + cfg_dioSources.push(sources.get(idx).keyid) } - if (cfg_dioSources.length !== cfgLength) - plasmoid.configuration['dioSources'] = cfg_dioSources + plasmoid.configuration['dioSources'] = cfg_dioSources data.loading = false } } diff --git a/plasmoid/contents/ui/configDiskSpace.qml b/plasmoid/contents/ui/configDiskSpace.qml index 8666a41f4f796992302a794df721e41d093f3941..c32a150f5feab414d074648d793a883e30310585 100644 --- a/plasmoid/contents/ui/configDiskSpace.qml +++ b/plasmoid/contents/ui/configDiskSpace.qml @@ -21,7 +21,7 @@ import QtQuick 2.1 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore - +import DbusModel 1.0 Item { property var cfg_dsSources: [] @@ -35,19 +35,19 @@ Item { Repeater { model: sources CheckBox { - text: qsTr(model.name) + text: model.name checked: model.checked onCheckedChanged: { var idx if(!data.loading) { if (checked) { - idx = cfg_dsSources.indexOf(model.name) + idx = cfg_dsSources.indexOf(model.keyid) if (idx < 0) { - cfg_dsSources.push(model.name) + cfg_dsSources.push(model.keyid) } } else { - idx = cfg_dsSources.indexOf(model.name) + idx = cfg_dsSources.indexOf(model.keyid) cfg_dsSources.splice(idx, 1) } cfg_dsSourcesChanged(); @@ -61,38 +61,45 @@ Item { id: sources } - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + Dbus { + id : dbus1 } Component.onCompleted: { - var idx var cfgLength - var name - var result + var dskName + var sensors = [] + var nameIdx + var key data.loading = true - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^partitions(.+)\/filllevel$') - if (result !== null) { - if (cfg_dsSources.indexOf(result[1]) < 0) { - sources.append({name:result[1], checked: false}) + cfg_dsSources = plasmoid.configuration['dsSources'] + sensors = dbus1.allSensors("disk/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/name")) { + nameIdx = sensors[idx].indexOf("/name") + key = sensors[idx].slice(0,nameIdx) + dskName = dbus1.stringData(sensors[idx]) + if (cfg_dsSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: dskName, checked: false}) } else { - sources.append({name:result[1], checked: true}) + sources.append({keyid:key, name: dskName, checked: true}) } } } - cfgLength = cfg_dsSources.length + key = "disk/all" + dskName = "All" + if (cfg_dsSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: dskName, checked: false}) + } else { + sources.append({keyid:key, name: dskName, checked: true}) + } cfg_dsSources.length = 0 for (idx = 0; idx < sources.count; idx++) { - if (sources.get(idx).checked) { - cfg_dsSources.push(sources.get(idx).name) - } + if (sources.get(idx).checked) + cfg_dsSources.push(sources.get(idx).keyid) } - if (cfg_dsSources.length !== cfgLength) - plasmoid.configuration['dsSources'] = cfg_dsSources + plasmoid.configuration['dsSources'] = cfg_dsSources data.loading = false } } diff --git a/plasmoid/contents/ui/configNetwork.qml b/plasmoid/contents/ui/configNetwork.qml index b04ee155681d7ba5e133a58068626b3b89331e53..fb40e129f400099289b094900f2e6d7195451481 100644 --- a/plasmoid/contents/ui/configNetwork.qml +++ b/plasmoid/contents/ui/configNetwork.qml @@ -21,7 +21,7 @@ import QtQuick 2.1 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore - +import DbusModel 1.0 Item { property var cfg_netSources: [] @@ -35,19 +35,19 @@ Item { Repeater { model: sources CheckBox { - text: qsTr(model.name) + text: model.name checked: model.checked onCheckedChanged: { var idx if(!data.loading) { if (checked) { - idx = cfg_netSources.indexOf(model.name) + idx = cfg_netSources.indexOf(model.keyid) if (idx < 0) { - cfg_netSources.push(model.name) + cfg_netSources.push(model.keyid) } } else { - idx = cfg_netSources.indexOf(model.name) + idx = cfg_netSources.indexOf(model.keyid) cfg_netSources.splice(idx, 1) } cfg_netSourcesChanged(); @@ -61,38 +61,45 @@ Item { id: sources } - PlasmaCore.DataSource { - id: dataSource - engine: "systemmonitor" + Dbus { + id : dbus1 } - + Component.onCompleted: { - var idx var cfgLength - var name - var result + var netName + var sensors = [] + var nameIdx + var key data.loading = true - for (idx in dataSource.sources) { - name = dataSource.sources[idx] - result = name.match('^network\/interfaces\/((?!lo).+)\/transmitter\/dataTotal$') - if (result !== null) { - if (cfg_netSources.indexOf(result[1]) < 0) { - sources.append({name:result[1], checked: false}) + cfg_netSources = plasmoid.configuration['netSources'] + sensors = dbus1.allSensors("network/"); + for (var idx = 0; idx < sensors.length; idx++) { + if (sensors[idx].endsWith("/network")) { + nameIdx = sensors[idx].indexOf("/network") + key = sensors[idx].slice(0,nameIdx) + netName = dbus1.stringData(sensors[idx]) + if (cfg_netSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: netName, checked: false}) } else { - sources.append({name:result[1], checked: true}) + sources.append({keyid:key, name: netName, checked: true}) } } } - cfgLength = cfg_netSources.length + key = "network/all" + netName = "All" + if (cfg_netSources.indexOf(key) < 0 ) { + sources.append({keyid:key, name: netName, checked: false}) + } else { + sources.append({keyid:key, name: netName, checked: true}) + } cfg_netSources.length = 0 for (idx = 0; idx < sources.count; idx++) { - if (sources.get(idx).checked) { - cfg_netSources.push(sources.get(idx).name) - } + if (sources.get(idx).checked) + cfg_netSources.push(sources.get(idx).keyid) } - if (cfg_netSources.length !== cfgLength) - plasmoid.configuration['netSources'] = cfg_netSources + plasmoid.configuration['netSources'] = cfg_netSources data.loading = false } } diff --git a/plasmoid/contents/ui/imports/DbusModel/libqmldbusmodelplugin.so b/plasmoid/contents/ui/imports/DbusModel/libqmldbusmodelplugin.so new file mode 100755 index 0000000000000000000000000000000000000000..169c048bdc67b923b1396e095b8f1bccf2d65b0e Binary files /dev/null and b/plasmoid/contents/ui/imports/DbusModel/libqmldbusmodelplugin.so differ diff --git a/plasmoid/contents/ui/imports/DbusModel/plugins.qmltypes b/plasmoid/contents/ui/imports/DbusModel/plugins.qmltypes new file mode 100644 index 0000000000000000000000000000000000000000..ed2b11a444fee5c613279e11ce4edf08bd4682f1 --- /dev/null +++ b/plasmoid/contents/ui/imports/DbusModel/plugins.qmltypes @@ -0,0 +1,18 @@ +import QtQuick.tooling 1.2 + +// This file describes the plugin-supplied types contained in the library. +// It is used for QML tooling purposes only. +// +// This file was auto-generated by qmltyperegistrar. + +Module { + dependencies: ["QtQuick 2.0"] + Component { + file: "dbusmodel.h" + name: "DbusModel" + prototype: "QObject" + exports: ["DbusModel/Dbus 1.0"] + exportMetaObjectRevisions: [0] + Property { name: "count"; type: "int"; isReadonly: true } + } +} diff --git a/plasmoid/contents/ui/qmldir b/plasmoid/contents/ui/qmldir new file mode 100644 index 0000000000000000000000000000000000000000..05defa504afe43e08eaed42a952b22f1bbfa2523 --- /dev/null +++ b/plasmoid/contents/ui/qmldir @@ -0,0 +1 @@ +plugin qmldbusmodelplugin ./imports/DbusModel diff --git a/plasmoid/metadata.json b/plasmoid/metadata.json new file mode 100644 index 0000000000000000000000000000000000000000..1b8fc0b6a9f489d5e6ea6788510cb05d4566e426 --- /dev/null +++ b/plasmoid/metadata.json @@ -0,0 +1,23 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "bstrong@softtechok.com", + "Name": "Barry Strong" + } + ], + "Category": "System Information", + "Description": "Shows System Monitor Information", + "Icon": "org.kde.plasma.systemloadviewer", + "Id": "com.softtechok.systemmonitorplasmoid", + "License": "GPL3+", + "Name": "System Monitor Plasmoid", + "ServiceTypes": [ + "Plasma/Applet" + ], + "Version": "1.02", + "Website": "https://www.opencode.net/bstrong5280" + }, + "X-Plasma-API": "declarativeappletscript", + "X-Plasma-MainScript": "ui/main.qml" +}