Warning, /plasma/plasma-bigscreen/kcms/wifi/ui/DeviceConnectionItem.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2019 Aditya Mehra <aix.m@outlook.com>
0003 SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
0004
0005 SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007
0008 import QtQuick 2.14
0009 import QtQuick.Layouts 1.14
0010 import QtQuick.Controls 2.14
0011 import org.kde.plasma.core 2.0 as PlasmaCore
0012 import org.kde.plasma.components 3.0 as PlasmaComponents
0013 import org.kde.kirigami 2.12 as Kirigami
0014 import org.kde.mycroft.bigscreen 1.0 as BigScreen
0015 import Qt5Compat.GraphicalEffects
0016 import org.kde.plasma.networkmanagement as PlasmaNM
0017 import org.kde.coreaddons 1.0 as KCoreAddons
0018
0019 Item {
0020 id: delegateSettingsItem
0021 property bool activating: model.ConnectionState == PlasmaNM.Enums.Activating
0022 property bool deactivating: model.ConnectionState == PlasmaNM.Enums.Deactivating
0023 property bool predictableWirelessPassword: !model.Uuid && model.Type == PlasmaNM.Enums.Wireless &&
0024 (model.SecurityType == PlasmaNM.Enums.StaticWep || model.SecurityType == PlasmaNM.Enums.WpaPsk ||
0025 model.SecurityType == PlasmaNM.Enums.Wpa2Psk || model.SecurityType == PlasmaNM.Enums.SAE)
0026 property real rxBytes: 0
0027 property real txBytes: 0
0028 readonly property ListView listView: ListView.view
0029 property bool showSpeed: ConnectionState == PlasmaNM.Enums.Activated &&
0030 (Type == PlasmaNM.Enums.Wired ||
0031 Type == PlasmaNM.Enums.Wireless ||
0032 Type == PlasmaNM.Enums.Gsm ||
0033 Type == PlasmaNM.Enums.Cdma)
0034 width: listView.width
0035 height: listView.height
0036
0037 Component.onCompleted: {
0038 if (model.ConnectionState == PlasmaNM.Enums.Activated) {
0039 connectionModel.setDeviceStatisticsRefreshRateMs(DevicePath, showSpeed ? 2000 : 0)
0040 }
0041 }
0042
0043 function itemText() {
0044 if (model.ConnectionState == PlasmaNM.Enums.Activating) {
0045 if (model.Type == PlasmaNM.Enums.Vpn)
0046 return model.VpnState
0047 else
0048 return model.DeviceState
0049 } else if (model.ConnectionState == PlasmaNM.Enums.Deactivating) {
0050 if (model.Type == PlasmaNM.Enums.Vpn)
0051 return model.VpnState
0052 else
0053 return model.DeviceState
0054 } else if (model.ConnectionState == PlasmaNM.Enums.Deactivated) {
0055 var result = model.LastUsed
0056 if (model.SecurityType > PlasmaNM.Enums.NoneSecurity)
0057 result += ", " + model.SecurityTypeString
0058 return result
0059 } else if (model.ConnectionState == PlasmaNM.Enums.Activated) {
0060 return i18n("Connected")
0061 }
0062 }
0063
0064 function itemSignalIcon(signalState) {
0065 if (signalState <= 25){
0066 return "network-wireless-connected-25"
0067 } else if (signalState <= 50){
0068 return "network-wireless-connected-50"
0069 } else if (signalState <= 75){
0070 return "network-wireless-connected-75"
0071 } else if (signalState <= 100){
0072 return "network-wireless-connected-100"
0073 } else {
0074 return "network-wireless-connected-00"
0075 }
0076 }
0077
0078 onShowSpeedChanged: {
0079 connectionModel.setDeviceStatisticsRefreshRateMs(DevicePath, showSpeed ? 2000 : 0)
0080 }
0081
0082 Timer {
0083 id: timer
0084 repeat: true
0085 interval: 2000
0086 running: showSpeed
0087 property real prevRxBytes
0088 property real prevTxBytes
0089 Component.onCompleted: {
0090 prevRxBytes = RxBytes
0091 prevTxBytes = TxBytes
0092 }
0093 onTriggered: {
0094 rxBytes = (RxBytes - prevRxBytes) * 1000 / interval
0095 txBytes = (TxBytes - prevTxBytes) * 1000 / interval
0096 prevRxBytes = RxBytes
0097 prevTxBytes = TxBytes
0098 }
0099 }
0100
0101 ColumnLayout {
0102 id: colLayoutSettingsItem
0103 anchors {
0104 fill: parent
0105 margins: Kirigami.Units.largeSpacing
0106 }
0107
0108 Item {
0109 Layout.fillWidth: true
0110 Layout.preferredHeight: model.ConnectionState == PlasmaNM.Enums.Activated ? parent.height : parent.height / 3
0111 Layout.alignment: Qt.AlignTop
0112
0113 Kirigami.Icon {
0114 id: dIcon
0115 anchors.top: parent.top
0116 anchors.horizontalCenter: parent.horizontalCenter
0117 width: parent.width
0118 height: width / 3
0119 source: switch(model.Type){
0120 case PlasmaNM.Enums.Wireless:
0121 return itemSignalIcon(model.Signal)
0122 case PlasmaNM.Enums.Wired:
0123 return "network-wired-activated"
0124 }
0125 }
0126
0127 Kirigami.Heading {
0128 id: label2
0129 width: parent.width
0130 anchors.top: dIcon.bottom
0131 anchors.topMargin: Kirigami.Units.largeSpacing
0132 horizontalAlignment: Text.AlignHCenter
0133 wrapMode: Text.WordWrap
0134 level: 2
0135 maximumLineCount: 2
0136 elide: Text.ElideRight
0137 color: Kirigami.Theme.textColor
0138 text: model.ItemUniqueName
0139 }
0140
0141 Kirigami.Separator {
0142 id: lblSept
0143 anchors.top: label2.bottom
0144 anchors.topMargin: Kirigami.Units.largeSpacing
0145 height: 1
0146 anchors.left: parent.left
0147 anchors.leftMargin: Kirigami.Units.largeSpacing
0148 anchors.right: parent.right
0149 anchors.rightMargin: Kirigami.Units.largeSpacing
0150 }
0151
0152 Rectangle {
0153 id: setCntStatus
0154 width: parent.width
0155 height: Kirigami.Units.gridUnit * 2
0156 anchors.top: lblSept.bottom
0157 anchors.topMargin: Kirigami.Units.smallSpacing
0158 color: Kirigami.Theme.backgroundColor
0159
0160 Item {
0161 anchors.fill: parent
0162
0163 RowLayout {
0164 anchors.centerIn: parent
0165 Kirigami.Icon {
0166 Layout.preferredWidth: Kirigami.Units.iconSizes.medium
0167 Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0168 source: Qt.resolvedUrl("images/green-tick-thick.svg")
0169 visible: model.ConnectionState == PlasmaNM.Enums.Activated ? 1 : 0
0170 }
0171 Kirigami.Heading {
0172 level: 3
0173 text: itemText()
0174 }
0175 }
0176 }
0177 }
0178
0179 Kirigami.Separator {
0180 id: lblSept2
0181 anchors.top: setCntStatus.bottom
0182 anchors.topMargin: Kirigami.Units.smallSpacing
0183 height: 1
0184 anchors.left: parent.left
0185 anchors.leftMargin: Kirigami.Units.largeSpacing
0186 anchors.right: parent.right
0187 anchors.rightMargin: Kirigami.Units.largeSpacing
0188 }
0189
0190 DetailsText {
0191 id: detailsTxtArea
0192 visible: true
0193 details: ConnectionDetails
0194 connected: model.ConnectionState == PlasmaNM.Enums.Activated ? 1 : 0
0195 connectionType: model.Type
0196 clip: true
0197 anchors {
0198 left: parent.left
0199 right: parent.right
0200 top: lblSept2.bottom
0201 topMargin: Kirigami.Units.largeSpacing
0202 bottom: lblSept3.top
0203 bottomMargin: Kirigami.Units.smallSpacing
0204 }
0205 }
0206
0207 Kirigami.Separator {
0208 id: lblSept3
0209 anchors.bottom: label3.top
0210 anchors.bottomMargin: Kirigami.Units.smallSpacing
0211 visible: model.ConnectionState == PlasmaNM.Enums.Activated ? 1 : 0
0212 height: 1
0213 anchors.left: parent.left
0214 anchors.leftMargin: Kirigami.Units.largeSpacing
0215 anchors.right: parent.right
0216 anchors.rightMargin: Kirigami.Units.largeSpacing
0217 }
0218
0219 RowLayout {
0220 id: label3
0221 width: parent.width
0222 anchors.bottom: parent.bottom
0223 anchors.bottomMargin: Kirigami.Units.smallSpacing
0224 visible: model.ConnectionState == PlasmaNM.Enums.Activated ? 1 : 0
0225
0226 Kirigami.Heading {
0227 Layout.fillWidth: true
0228 Layout.alignment: Qt.AlignLeft
0229 Layout.leftMargin: Kirigami.Units.largeSpacing
0230 wrapMode: Text.WordWrap
0231 level: 3
0232 maximumLineCount: 1
0233 elide: Text.ElideRight
0234 color: Kirigami.Theme.textColor
0235 text: i18n("Speed")
0236 }
0237
0238 PlasmaComponents.Label {
0239 Layout.alignment: Qt.AlignRight
0240 Layout.maximumWidth: Kirigami.Units.gridUnit * 4
0241 text: "⬇ " + KCoreAddons.Format.formatByteSize(rxBytes)
0242 }
0243
0244 PlasmaComponents.Label {
0245 Layout.alignment: Qt.AlignRight
0246 Layout.maximumWidth: Kirigami.Units.gridUnit * 4
0247 text: "⬆ " + KCoreAddons.Format.formatByteSize(txBytes)
0248 }
0249 }
0250 }
0251
0252 Item {
0253 Layout.fillWidth: true
0254 Layout.preferredHeight: Kirigami.Units.gridUnit
0255 }
0256 }
0257 }