Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/TrafficMonitor.qml
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.2 | 21 | import QtQuick 2.2 | ||
22 | import org.kde.kcoreaddons 1.0 as KCoreAddons | 22 | import org.kde.kcoreaddons 1.0 as KCoreAddons | ||
23 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | 23 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | ||
24 | import org.kde.plasma.components 2.0 as PlasmaComponents | 24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
25 | 25 | | |||
26 | Item { | 26 | Item { | ||
27 | property QtObject dataEngine: null | 27 | property real rxBytes: 0 | ||
28 | property string deviceName | 28 | property real txBytes: 0 | ||
29 | property alias interval: timer.interval | ||||
29 | 30 | | |||
30 | height: visible ? plotter.height + units.gridUnit : 0 | 31 | height: visible ? plotter.height + units.gridUnit : 0 | ||
31 | 32 | | |||
32 | Repeater { | 33 | Repeater { | ||
33 | model: 5 | 34 | model: 5 | ||
34 | 35 | | |||
35 | PlasmaComponents.Label { | 36 | PlasmaComponents.Label { | ||
36 | anchors { | 37 | anchors { | ||
37 | left: parent.left | 38 | left: parent.left | ||
38 | top: parent.top | 39 | top: parent.top | ||
39 | topMargin: Math.round(units.gridUnit / 3) + (index * plotter.height / 5) | 40 | topMargin: Math.round(units.gridUnit / 3) + (index * plotter.height / 5) | ||
40 | } | 41 | } | ||
41 | height: paintedHeight | 42 | height: paintedHeight | ||
42 | font.pointSize: theme.smallestFont.pointSize | 43 | font.pointSize: theme.smallestFont.pointSize | ||
43 | lineHeight: 1.75 | 44 | lineHeight: 1.75 | ||
44 | text: KCoreAddons.Format.formatByteSize((plotter.maxValue * 1024) * (1 - index / 5)) | 45 | text: KCoreAddons.Format.formatByteSize(plotter.maxValue * (1 - index / 5)) + i18n("/s") | ||
45 | } | 46 | } | ||
46 | } | 47 | } | ||
47 | 48 | | |||
48 | KQuickControlsAddons.Plotter { | 49 | KQuickControlsAddons.Plotter { | ||
49 | id: plotter | 50 | id: plotter | ||
50 | property variant downloadColor: theme.highlightColor | 51 | property variant downloadColor: theme.highlightColor | ||
51 | property variant uploadColor: Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | 52 | property variant uploadColor: Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | ||
52 | // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately | 53 | // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately | ||
Show All 17 Lines | 66 | dataSets: [ | |||
70 | }, | 71 | }, | ||
71 | KQuickControlsAddons.PlotData { | 72 | KQuickControlsAddons.PlotData { | ||
72 | id: uploadPlotData | 73 | id: uploadPlotData | ||
73 | label: i18n("Upload") | 74 | label: i18n("Upload") | ||
74 | color: plotter.uploadColor | 75 | color: plotter.uploadColor | ||
75 | } | 76 | } | ||
76 | ] | 77 | ] | ||
77 | 78 | | |||
78 | Connections { | 79 | Timer { | ||
79 | target: dataEngine; | 80 | id: timer | ||
80 | onNewData: { | 81 | repeat: true | ||
81 | if (sourceName.indexOf("network/interfaces/" + deviceName) != 0) { | 82 | running: parent.visible | ||
82 | return; | 83 | property real prevRxBytes | ||
83 | } | 84 | property real prevTxBytes | ||
84 | var rx = dataEngine.data[dataEngine.downloadSource]; | 85 | Component.onCompleted: { | ||
85 | var tx = dataEngine.data[dataEngine.uploadSource]; | 86 | prevRxBytes = rxBytes | ||
86 | if (rx === undefined || rx.value === undefined || | 87 | prevTxBytes = txBytes | ||
87 | tx === undefined || tx.value === undefined) { | 88 | } | ||
88 | return; | 89 | onTriggered: { | ||
89 | } | 90 | var rxSpeed = (rxBytes - prevRxBytes) * 1000 / interval | ||
90 | 91 | var txSpeed = (txBytes - prevTxBytes) * 1000 / interval | |||
91 | plotter.addSample([rx.value, tx.value]); | 92 | prevRxBytes = rxBytes | ||
93 | prevTxBytes = txBytes | ||||
94 | plotter.addSample([rxSpeed, txSpeed]); | ||||
92 | } | 95 | } | ||
93 | } | 96 | } | ||
94 | } | 97 | } | ||
95 | } | 98 | } |