Skip to content

Commit

Permalink
feat(data): add threshold for cpu temp and memory
Browse files Browse the repository at this point in the history
This is from @Starrah (Starrah@ef29040)
  • Loading branch information
orblazer committed Apr 27, 2023
1 parent 809467e commit 28bafad
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 15 deletions.
24 changes: 24 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@
<entry name="networkSendingTotal" type="Double">
<default>100000.0</default>
</entry>

<entry name="thresholdWarningCpuTemp" type="Double">
<default>85.0</default>
</entry>
<entry name="thresholdCriticalCpuTemp" type="Double">
<default>105.0</default>
</entry>
<entry name="thresholdWarningMemory" type="Int">
<default>70</default>
</entry>
<entry name="thresholdCriticalMemory" type="Int">
<default>90</default>
</entry>
</group>

<group name="Appearance">
Expand Down Expand Up @@ -115,6 +128,17 @@
</entry>
<entry name="netUpColor" type="Color">
</entry>

<entry name="customWarningColor" type="Bool">
<default>false</default>
</entry>
<entry name="warningColor" type="Color">
</entry>
<entry name="customCriticalColor" type="Bool">
<default>false</default>
</entry>
<entry name="criticalColor" type="Color">
</entry>
</group>

</kcfg>
42 changes: 28 additions & 14 deletions package/contents/ui/components/TwoSensorsGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ Item {
// Graph properties
readonly property int historyAmount: plasmoid.configuration.historyAmount
readonly property int interval: plasmoid.configuration.updateInterval * 1000
property var thresholds: [undefined, undefined]
property var colors: [theme.highlightColor, theme.textColor]

// Text properties
property bool secondLabelWhenZero: true
property var textColors: [theme.textColor, theme.textColor]
property var thresholdColors: [theme.neutralTextColor, theme.negativeTextColor]

// Bind properties
onSensorsChanged: sensorsModel._updateSensors()
Expand Down Expand Up @@ -157,27 +160,26 @@ Item {
// Set default text when doesn't have sensors
if (sensorsLength === 0) {
if (textContainer.valueVisible) {
_updateData(0, undefined)
_updateData(1, undefined)
_updateData(0, undefined);
_updateData(1, undefined);
}
return;
}

// Update values
chart._sensorData1 = sensorsModel.getData(0)
chart._sensorData2 = sensorsModel.getData(1)

chart._sensorData1 = sensorsModel.getData(0);
chart._sensorData2 = sensorsModel.getData(1);
if (chart._sensorData1) {
firstChartSource.value = chart._sensorData1.value
firstChartSource.value = chart._sensorData1.value;
}
if (chart._sensorData2) {
secondChartSource.value = chart._sensorData2.value
secondChartSource.value = chart._sensorData2.value;
}

// Update labels
if (textContainer.valueVisible) {
_updateData(0, chart._sensorData1)
_updateData(1, chart._sensorData2)
_updateData(0, chart._sensorData1);
_updateData(1, chart._sensorData2);
}
}

Expand All @@ -188,12 +190,13 @@ Item {
// Update label
if (index === 0) {
// is first line
firstLineLabel.visible = true;
firstLineLabel.color = textColors[0];
if (typeof value === 'undefined') {
firstLineLabel.text = '...';
firstLineLabel.visible = true;
} else {
firstLineLabel.text = data.formattedValue;
firstLineLabel.visible = true;
_setThresholdColor(firstLineLabel, 0, data.value)
}
} else if (index === 1) {
// is second line
Expand All @@ -202,16 +205,27 @@ Item {
secondLineLabel.visible = secondLabelWhenZero;
} else {
secondLineLabel.text = data.formattedValue;
secondLineLabel.visible = data.value !== 0 || secondLabelWhenZero;
secondLineLabel.visible = secondLabelWhenZero || data.value !== 0;
_setThresholdColor(secondLineLabel, 1, data.value)
}
}
}

function _setThresholdColor(label, line, value) {
if (typeof thresholds[line] !== 'undefined') {
if (value >= thresholds[line][1]) {
label.color = thresholdColors[1];
} else if (value >= thresholds[line][1]) {
label.color = thresholdColors[line];
}
}
}

function _showValueInLabel() {
// Show first line
_updateData(0, chart._sensorData1)
_updateData(0, chart._sensorData1);
// Show second line
_updateData(1, chart._sensorData2)
_updateData(1, chart._sensorData2);
chart.showValueWhenMouseMove();
}

Expand Down
22 changes: 22 additions & 0 deletions package/contents/ui/config/ConfigAppearance.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick 2.2
import QtQuick.Controls 2.12 as QtControls
import QtQuick.Layouts 1.1 as QtLayouts
import org.kde.kirigami 2.6 as Kirigami
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import "../controls" as RMControls

Expand Down Expand Up @@ -30,9 +31,15 @@ QtLayouts.ColumnLayout {
property alias cfg_netDownColor: netDownColor.value
property alias cfg_customNetUpColor: netUpColor.checked
property alias cfg_netUpColor: netUpColor.value
property alias cfg_customWarningColor: warningColor.checked
property alias cfg_warningColor: warningColor.value
property alias cfg_customCriticalColor: criticalColor.checked
property alias cfg_criticalColor: criticalColor.value

property color primaryColor: theme.highlightColor
property color positiveColor: theme.positiveTextColor
property color neutralColor: theme.neutralTextColor
property color negativeColor: theme.negativeTextColor

PlasmaComponents.TabBar {
id: bar
Expand Down Expand Up @@ -229,6 +236,21 @@ QtLayouts.ColumnLayout {
dialogTitle: i18n("Choose network sending graph color")
defaultColor: positiveColor
}

RMControls.ColorSelector {
id: warningColor
Kirigami.FormData.label: i18n("Threshold warning color:")

dialogTitle: i18n("Choose text color when the value is in warning status")
defaultColor: neutralColor
}
RMControls.ColorSelector {
id: criticalColor
Kirigami.FormData.label: i18n("Threshold critical color:")

dialogTitle: i18n("Choose text color when the value is in critical status")
defaultColor: negativeColor
}
}
}
}
118 changes: 118 additions & 0 deletions package/contents/ui/config/ConfigData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ QtLayouts.ColumnLayout {
readonly property var networkDialect: Functions.getNetworkDialectInfo(plasmoid.configuration.networkUnit)
property double cfg_networkReceivingTotal: 0.0
property double cfg_networkSendingTotal: 0.0
property double cfg_thresholdWarningCpuTemp: 0
property double cfg_thresholdCriticalCpuTemp: 0
property alias cfg_thresholdWarningMemory: thresholdWarningMemory.value
property alias cfg_thresholdCriticalMemory: thresholdCriticalMemory.value

readonly property var networkSpeedOptions: [{
"label": i18n("Custom"),
Expand Down Expand Up @@ -60,6 +64,11 @@ QtLayouts.ColumnLayout {
iconSource: "preferences-system-network"
text: i18n("Network")
}
PlasmaComponents.TabButton {
tab: thresholdPage
iconSource: "dialog-warning"
text: i18n("Thresholds")
}
}

// Views
Expand Down Expand Up @@ -231,5 +240,114 @@ QtLayouts.ColumnLayout {
}
}
}

// Threshold
Kirigami.FormLayout {
id: thresholdPage
wideMode: true

QtLayouts.GridLayout {
QtLayouts.Layout.fillWidth: true
columns: 3
columnSpacing: Kirigami.Units.largeSpacing

PlasmaComponents.Label {
id: warningText
text: i18n("Warning")
font.pointSize: PlasmaCore.Theme.defaultFont.pointSize * 1.2
}

// Separator
Rectangle {
width: thresholdWarningMemory.implicitWidth - warningText.contentWidth - Kirigami.Units.largeSpacing
color: "transparent"
}

PlasmaComponents.Label {
text: i18n("Critical")
font.pointSize: PlasmaCore.Theme.defaultFont.pointSize * 1.2
}
}

QtLayouts.GridLayout {
Kirigami.FormData.label: i18n("CPU Temperature:")
QtLayouts.Layout.fillWidth: true
columns: 2
rowSpacing: Kirigami.Units.smallSpacing
columnSpacing: Kirigami.Units.largeSpacing

RMControls.SpinBox {
id: thresholdWarningCpuTemp
Kirigami.FormData.label: i18n("Warning")
QtLayouts.Layout.fillWidth: true
decimals: 1
stepSize: 1
minimumValue: 0.1
maximumValue: 120

textFromValue: function (value, locale) {
return valueToText(value, locale) + " °C";
}
onValueChanged: {
if (cfg_thresholdWarningCpuTemp !== valueReal) {
cfg_thresholdWarningCpuTemp = valueReal;
dataPage.configurationChanged();
}
}
Component.onCompleted: {
valueReal = parseFloat(plasmoid.configuration.thresholdWarningCpuTemp);
}
}
RMControls.SpinBox {
id: thresholdCriticalCpuTemp
Kirigami.FormData.label: i18n("Critical")
QtLayouts.Layout.fillWidth: true
decimals: 1
stepSize: 1
minimumValue: 0.1
maximumValue: 120

textFromValue: function (value, locale) {
return valueToText(value, locale) + " °C";
}
onValueChanged: {
if (cfg_thresholdCriticalCpuTemp !== valueReal) {
cfg_thresholdCriticalCpuTemp = valueReal;
dataPage.configurationChanged();
}
}
Component.onCompleted: {
valueReal = parseFloat(plasmoid.configuration.thresholdCriticalCpuTemp);
}
}
}

QtLayouts.GridLayout {
Kirigami.FormData.label: i18n("Physical Memory Usage:")
QtLayouts.Layout.fillWidth: true
columns: 2
rowSpacing: Kirigami.Units.smallSpacing
columnSpacing: Kirigami.Units.largeSpacing

RMControls.SpinBox {
id: thresholdWarningMemory
Kirigami.FormData.label: i18n("Warning")
QtLayouts.Layout.fillWidth: true

textFromValue: function (value, locale) {
return value + " %";
}
}
RMControls.SpinBox {
id: thresholdCriticalMemory
Kirigami.FormData.label: i18n("Critical")
QtLayouts.Layout.fillWidth: true

textFromValue: function (value, locale) {
return value + " %";
}
}
}
}
}
}
Loading

0 comments on commit 28bafad

Please sign in to comment.