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
wilder-5.18
George Vogiatzis 6 years ago committed by Nate Graham
parent cd6e94a776
commit d21cb2e7a9
  1. 8
      applets/systemmonitor/common/contents/config/main.xml
  2. 5
      applets/systemmonitor/net/contents/config/config.qml
  3. 54
      applets/systemmonitor/net/contents/ui/displayConfig.qml
  4. 20
      applets/systemmonitor/net/contents/ui/net.qml

@ -13,6 +13,14 @@
<label>The interval in milliseconds to update the data shown.</label> <label>The interval in milliseconds to update the data shown.</label>
<default>2000</default> <default>2000</default>
</entry> </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> </group>
</kcfg> </kcfg>

@ -26,4 +26,9 @@ ConfigModel {
icon: "network-workgroup" icon: "network-workgroup"
source: "netConfig.qml" source: "netConfig.qml"
} }
ConfigCategory {
name: i18n("Display")
icon: "network-workgroup"
source: "displayConfig.qml"
}
} }

@ -0,0 +1,54 @@
/*
* 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.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
import org.kde.kcoreaddons 1.0 as KCoreAddons
Applet { Applet {
id: root id: root
@ -41,14 +42,19 @@ Applet {
delegate: DoublePlotter { delegate: DoublePlotter {
function formatData(data) { function formatData(data) {
var value = data.value * 1024 * 8 if (plasmoid.configuration.displayUnit === 0) {
if (value > (1024 * 1024)) { var value = data.value * 1024
return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1)); 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);
} }
} }
} }

Loading…
Cancel
Save