Changeset View
Changeset View
Standalone View
Standalone View
applets/systemmonitor/net/contents/ui/net.qml
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.0 | 21 | import QtQuick 2.0 | ||
22 | import QtQuick.Layouts 1.1 | 22 | import QtQuick.Layouts 1.1 | ||
23 | import org.kde.plasma.plasmoid 2.0 | 23 | import org.kde.plasma.plasmoid 2.0 | ||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | 24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | 25 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
26 | import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons | 26 | import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons | ||
27 | import org.kde.kcoreaddons 1.0 as KCoreAddons | ||||
27 | 28 | | |||
28 | Applet { | 29 | Applet { | ||
29 | id: root | 30 | id: root | ||
30 | 31 | | |||
31 | onSourceAdded: { | 32 | onSourceAdded: { | ||
32 | if (source.indexOf("network/interfaces/lo/") !== -1) { | 33 | if (source.indexOf("network/interfaces/lo/") !== -1) { | ||
33 | return; | 34 | return; | ||
34 | } | 35 | } | ||
35 | var match = source.match(/^network\/interfaces\/(\w+)\/transmitter\/data$/); | 36 | var match = source.match(/^network\/interfaces\/(\w+)\/transmitter\/data$/); | ||
36 | if (match) { | 37 | if (match) { | ||
37 | var rxSource = "network/interfaces/" + match[1] + "/receiver/data"; | 38 | var rxSource = "network/interfaces/" + match[1] + "/receiver/data"; | ||
38 | root.addSource(source, match[1], rxSource, match[1]); | 39 | root.addSource(source, match[1], rxSource, match[1]); | ||
39 | } | 40 | } | ||
40 | } | 41 | } | ||
41 | 42 | | |||
42 | delegate: DoublePlotter { | 43 | delegate: DoublePlotter { | ||
43 | function formatData(data) { | 44 | function formatData(data) { | ||
45 | if (plasmoid.configuration.displayUnit === 0) { | ||||
46 | var value = data.value * 1024 | ||||
47 | return i18nc("%1 is the displayed data transfer speed in bytes per second", "%1/s", KCoreAddons.Format.formatByteSize(value)); | ||||
48 | } else { | ||||
44 | var value = data.value * 1024 * 8 | 49 | var value = data.value * 1024 * 8 | ||
45 | if (value > (1024 * 1024)) { | 50 | if (value > (1024 * 1024)) { | ||
46 | return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1)); | 51 | return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1)); | ||
47 | } | 52 | } | ||
48 | if (value > 1024) { | 53 | if (value > 1024) { | ||
49 | return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024)); | 54 | return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024)); | ||
50 | } | 55 | } | ||
51 | return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value); | 56 | return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value); | ||
52 | } | 57 | } | ||
53 | } | 58 | } | ||
54 | } | 59 | } | ||
60 | } |