@@ -37,20 +37,24 @@ Item {
3737 property bool showRamMonitor: plasmoid .configuration .showRamMonitor
3838 property bool memoryInPercent: plasmoid .configuration .memoryInPercent
3939 property bool showMemoryInPercent: memoryInPercent
40+ property bool showNetMonitor: plasmoid .configuration .showNetMonitor
4041 property double fontScale: (plasmoid .configuration .fontScale / 100 )
42+ property int downloadMaxKBs: plasmoid .configuration .downloadMaxKBs
43+ property int uploadMaxKBs: plasmoid .configuration .uploadMaxKBs
4144
4245 property color warningColor: theme .neutralTextColor
4346 property int graphGranularity: 20
4447
4548 // Component properties
49+ property int containerCount: (showCpuMonitor? 1 : 0 ) + (showRamMonitor? 1 : 0 ) + (showNetMonitor? 1 : 0 )
4650 property int itemMargin: 5
4751 property double parentWidth: parent === null ? 0 : parent .width
4852 property double parentHeight: parent === null ? 0 : parent .height
4953 property double itemWidth: vertical ? ( verticalLayout ? parentWidth : (parentWidth - itemMargin) / 2 ) : ( verticalLayout ? (parentHeight - itemMargin) / 2 : parentHeight )
5054 property double itemHeight: itemWidth
5155 property double fontPixelSize: itemHeight * fontScale
52- property double widgetWidth: showCpuMonitor && showRamMonitor && ! verticalLayout ? itemWidth* 2 + itemMargin : itemWidth
53- property double widgetHeight: showCpuMonitor && showRamMonitor && verticalLayout ? itemWidth* 2 + itemMargin : itemWidth
56+ property double widgetWidth: ! verticalLayout ? ( itemWidth* containerCount + itemMargin* (containerCount) * 2 ) : itemWidth
57+ property double widgetHeight: verticalLayout ? ( itemWidth* containerCount + itemMargin* (containerCount) * 2 ) : itemWidth
5458
5559 Layout .preferredWidth : widgetWidth
5660 Layout .maximumWidth : widgetWidth
@@ -66,15 +70,12 @@ Item {
6670 }
6771
6872 onFontPixelSizeChanged: {
69- cpuMonitor .firstLineInfoLabel .font .pixelSize = fontPixelSize
70- cpuMonitor .firstLineValueLabel .font .pixelSize = fontPixelSize
71- cpuMonitor .secondLineInfoLabel .font .pixelSize = fontPixelSize
72- cpuMonitor .secondLineValueLabel .font .pixelSize = fontPixelSize
73-
74- ramMonitor .firstLineInfoLabel .font .pixelSize = fontPixelSize
75- ramMonitor .firstLineValueLabel .font .pixelSize = fontPixelSize
76- ramMonitor .secondLineInfoLabel .font .pixelSize = fontPixelSize
77- ramMonitor .secondLineValueLabel .font .pixelSize = fontPixelSize
73+ for (var monitor of [cpuMonitor, ramMonitor, netMonitor]) {
74+ monitor .firstLineInfoLabel .font .pixelSize = fontPixelSize
75+ monitor .firstLineValueLabel .font .pixelSize = fontPixelSize
76+ monitor .secondLineInfoLabel .font .pixelSize = fontPixelSize
77+ monitor .secondLineValueLabel .font .pixelSize = fontPixelSize
78+ }
7879 }
7980
8081 // Graph data
@@ -93,15 +94,22 @@ Item {
9394 property string swap: " mem/swap/"
9495 property string swapUsed: swap + " used"
9596 property string swapFree: swap + " free"
97+ property string networkInterface: " network/interfaces/" + plasmoid .configuration .networkSensorInterface + " /"
98+ property string downloadTotal: networkInterface + " receiver/data"
99+ property string uploadTotal: networkInterface + " transmitter/data"
96100
97101 property double totalCpuLoad: .0
98102 property int averageCpuClock: 0
99103 property int ramUsedBytes: 0
100104 property double ramUsedProportion: 0
101105 property int swapUsedBytes: 0
102106 property double swapUsedProportion: 0
107+ property double downloadKBs: 0
108+ property double uploadKBs: 0
109+ property double downloadProportion: 0
110+ property double uploadProportion: 0
103111
104- connectedSources: [memFree, memUsed, memApplication, swapUsed, swapFree, averageClock, totalLoad ]
112+ connectedSources: [memFree, memUsed, memApplication, swapUsed, swapFree, averageClock, totalLoad, downloadTotal, uploadTotal ]
105113
106114 onNewData: {
107115 if (data .value === undefined ) {
@@ -122,6 +130,14 @@ Item {
122130 averageCpuClock = parseInt (data .value )
123131 allUsageProportionChanged ()
124132 }
133+ else if (sourceName == downloadTotal) {
134+ downloadKBs = parseFloat (data .value )
135+ downloadProportion = fitDownloadRate (data .value )
136+ }
137+ else if (sourceName == uploadTotal) {
138+ uploadKBs = parseFloat (data .value )
139+ uploadProportion = fitUploadRate (data .value )
140+ }
125141 }
126142 interval: 1000 * plasmoid .configuration .updateInterval
127143 }
@@ -144,6 +160,20 @@ Item {
144160 return (usage / (parseFloat (usage) + parseFloat (swapFree .value )))
145161 }
146162
163+ function fitDownloadRate (rate ) {
164+ if (! downloadMaxKBs) {
165+ return 0
166+ }
167+ return (rate / downloadMaxKBs)
168+ }
169+
170+ function fitUploadRate (rate ) {
171+ if (! uploadMaxKBs) {
172+ return 0
173+ }
174+ return (rate / uploadMaxKBs)
175+ }
176+
147177 ListModel {
148178 id: cpuGraphModel
149179 }
@@ -156,27 +186,48 @@ Item {
156186 id: swapGraphModel
157187 }
158188
159- function allUsageProportionChanged () {
160- var totalCpuProportion = dataSource .totalCpuLoad
161- var totalRamProportion = dataSource .ramUsedProportion
162- var totalSwapProportion = dataSource .swapUsedProportion
163-
164- cpuMonitor .firstLineValueLabel .text = Math .round (totalCpuProportion * 100 ) + ' %'
165- cpuMonitor .firstLineValueLabel .color = totalCpuProportion > 0.9 ? warningColor : theme .textColor
166- cpuMonitor .secondLineValueLabel .text = Functions .getHumanReadableClock (dataSource .averageCpuClock )
189+ ListModel {
190+ id: uploadGraphModel
191+ }
167192
168- ramMonitor .firstLineValueLabel .text = showMemoryInPercent ? Math .round (totalRamProportion * 100 ) + ' %' : Functions .getHumanReadableMemory (dataSource .ramUsedBytes )
169- ramMonitor .firstLineValueLabel .color = totalRamProportion > 0.9 ? warningColor : theme .textColor
170- ramMonitor .secondLineValueLabel .text = showMemoryInPercent ? Math .round (totalSwapProportion * 100 ) + ' %' : Functions .getHumanReadableMemory (dataSource .swapUsedBytes )
171- ramMonitor .secondLineValueLabel .color = totalSwapProportion > 0.9 ? warningColor : theme .textColor
172- ramMonitor .secondLineValueLabel .visible = ! ramMonitor .secondLineInfoLabel .visible && totalSwapProportion > 0
193+ ListModel {
194+ id: downloadGraphModel
195+ }
173196
197+ function allUsageProportionChanged () {
174198 if (showCpuMonitor) {
199+ var totalCpuProportion = dataSource .totalCpuLoad
200+
201+ cpuMonitor .firstLineValueLabel .text = Math .round (totalCpuProportion * 100 ) + ' %'
202+ cpuMonitor .firstLineValueLabel .color = totalCpuProportion > 0.9 ? warningColor : theme .textColor
203+ cpuMonitor .secondLineValueLabel .text = Functions .getHumanReadableClock (dataSource .averageCpuClock )
204+
175205 Functions .addGraphData (cpuGraphModel, totalCpuProportion, graphGranularity)
176206 }
207+
177208 if (showRamMonitor) {
209+ var totalRamProportion = dataSource .ramUsedProportion
210+ var totalSwapProportion = dataSource .swapUsedProportion
211+
178212 Functions .addGraphData (ramGraphModel, totalRamProportion, graphGranularity)
179213 Functions .addGraphData (swapGraphModel, totalSwapProportion, graphGranularity)
214+
215+ ramMonitor .firstLineValueLabel .text = showMemoryInPercent ? Math .round (totalRamProportion * 100 ) + ' %' : Functions .getHumanReadableMemory (dataSource .ramUsedBytes )
216+ ramMonitor .firstLineValueLabel .color = totalRamProportion > 0.9 ? warningColor : theme .textColor
217+ ramMonitor .secondLineValueLabel .text = showMemoryInPercent ? Math .round (totalSwapProportion * 100 ) + ' %' : Functions .getHumanReadableMemory (dataSource .swapUsedBytes )
218+ ramMonitor .secondLineValueLabel .color = totalSwapProportion > 0.9 ? warningColor : theme .textColor
219+ ramMonitor .secondLineValueLabel .visible = ! ramMonitor .secondLineInfoLabel .visible && totalSwapProportion > 0
220+ }
221+
222+ if (showNetMonitor) {
223+ var totalDownloadProportion = dataSource .downloadProportion
224+ var totalUploadProportion = dataSource .uploadProportion
225+
226+ Functions .addGraphData (uploadGraphModel, totalUploadProportion, graphGranularity)
227+ Functions .addGraphData (downloadGraphModel, totalDownloadProportion, graphGranularity)
228+
229+ netMonitor .firstLineValueLabel .text = Functions .getHumanReadableNetRate (dataSource .downloadKBs )
230+ netMonitor .secondLineValueLabel .text = Functions .getHumanReadableNetRate (dataSource .uploadKBs )
180231 }
181232 }
182233
@@ -218,6 +269,24 @@ Item {
218269 secondGraphBarColor: theme .negativeTextColor
219270 }
220271
272+ GraphItem {
273+ id: netMonitor
274+ width: itemWidth
275+ height: itemHeight
276+ anchors .left : parent .left
277+ anchors .leftMargin : (showCpuMonitor && ! verticalLayout ? itemWidth + itemMargin: 0 ) + (showRamMonitor && ! verticalLayout ? itemWidth + itemMargin : 0 )
278+ anchors .top : parent .top
279+ anchors .topMargin : (showCpuMonitor && verticalLayout ? itemWidth + itemMargin: 0 ) + (showRamMonitor && verticalLayout ? itemWidth + itemMargin : 0 )
280+
281+ visible: showNetMonitor
282+ firstLineInfoText: ' Down'
283+ secondLineInfoText: ' Up'
284+ secondLineInfoTextColor: theme .positiveTextColor
285+ firstGraphModel: downloadGraphModel
286+ secondGraphModel: uploadGraphModel
287+ secondGraphBarColor: theme .positiveTextColor
288+ }
289+
221290 // Click action
222291 MouseArea {
223292 id: mouseArea
0 commit comments