Commit d21cb2e7 authored by George Vogiatzis's avatar George Vogiatzis Committed by Nate Graham
Browse files

Add byte display option in Network Monitor plasmoid

Summary:
Add the option to select between byte and bit display in Network Monitor plasmoid.
Bug: 383019

{F7826928}

Reviewers: #vdg, #plasma, ngraham

Reviewed By: #vdg, ngraham

Subscribers: ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26124
parent cd6e94a7
......@@ -13,6 +13,14 @@
<label>The interval in milliseconds to update the data shown.</label>
<default>2000</default>
</entry>
<entry name="displayUnit" type="Enum">
<label>The unit used to display the data.</label>
<choices>
<choice name="Byte" value="0"/>
<choice name="bit" value="1"/>
</choices>
<default>1</default>
</entry>
</group>
</kcfg>
......@@ -26,4 +26,9 @@ ConfigModel {
icon: "network-workgroup"
source: "netConfig.qml"
}
ConfigCategory {
name: i18n("Display")
icon: "network-workgroup"
source: "displayConfig.qml"
}
}
/*
* Copyright 2019 George Vogiatzis <Gvgeo@protonmail.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 or
* (at your option) any later version.
*
* This program 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.5 as Kirigami
Kirigami.FormLayout {
property int cfg_displayUnit: plasmoid.configuration.displayUnit
QQC2.ButtonGroup {
id: displayUnitGroup
}
QQC2.RadioButton {
id: byteDisplayUnit
QQC2.ButtonGroup.group: displayUnitGroup
Kirigami.FormData.label: i18nc("@label", "Display unit:")
text: i18nc("@option:radio", "Byte")
checked: cfg_displayUnit == 0
onClicked: if (checked) {cfg_displayUnit = 0;}
}
QQC2.RadioButton {
id: bitDisplayUnit
QQC2.ButtonGroup.group: displayUnitGroup
text: i18nc("@option:radio", "bit")
checked: cfg_displayUnit == 1
onClicked: if (checked) {cfg_displayUnit = 1;}
}
}
......@@ -24,6 +24,7 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
import org.kde.kcoreaddons 1.0 as KCoreAddons
Applet {
id: root
......@@ -41,14 +42,19 @@ Applet {
delegate: DoublePlotter {
function formatData(data) {
var value = data.value * 1024 * 8
if (value > (1024 * 1024)) {
return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1));
if (plasmoid.configuration.displayUnit === 0) {
var value = data.value * 1024
return i18nc("%1 is the displayed data transfer speed in bytes per second", "%1/s", KCoreAddons.Format.formatByteSize(value));
} else {
var value = data.value * 1024 * 8
if (value > (1024 * 1024)) {
return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1));
}
if (value > 1024) {
return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024));
}
return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value);
}
if (value > 1024) {
return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024));
}
return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment