From 0a79fd900e3dd5cd7849f038532916ec6b8d6d91 Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Sat, 8 Nov 2014 18:02:13 +0100 Subject: Adapt launchersettings to the B2Qt.Wifi 1.0 API Change-Id: I36154eb52c533b490cb77cd75f4e495edae09604 Reviewed-by: Laszlo Agocs --- basicsuite/launchersettings/WifiNetworkList.qml | 115 ++++++++++++++---------- 1 file changed, 68 insertions(+), 47 deletions(-) (limited to 'basicsuite/launchersettings/WifiNetworkList.qml') diff --git a/basicsuite/launchersettings/WifiNetworkList.qml b/basicsuite/launchersettings/WifiNetworkList.qml index bbc99b0..80acaa5 100644 --- a/basicsuite/launchersettings/WifiNetworkList.qml +++ b/basicsuite/launchersettings/WifiNetworkList.qml @@ -40,36 +40,27 @@ ****************************************************************************/ import QtQuick 2.2 import QtQuick.Controls 1.2 -import Qt.labs.wifi 0.1 +import B2Qt.Wifi 1.0 Item { Component { id: listDelegate Rectangle { + id: networkBox property bool expanded: false - property bool connected: wifiManager.connectedSSID == network.ssid - property bool actingNetwork: networkView.currentNetworkSsid == network.ssid + property bool isCurrentNetwork: WifiManager.currentSSID === ssid + property bool connected: isCurrentNetwork && WifiManager.networkState === WifiManager.Connected property int notExpandedHeight: ssidLabel.height + bssidLabel.height + engine.mm(4) property int expandedHeight: notExpandedHeight + passwordInput.height + connectionButton.height + engine.mm(7) property int connectedExpandedHeight: notExpandedHeight + connectionButton.height + engine.mm(4) - height: (expanded ? (connected ? connectedExpandedHeight : expandedHeight) : notExpandedHeight) + height: expanded ? (connected ? connectedExpandedHeight : expandedHeight) : notExpandedHeight width: parent.width - clip: true // ### fixme + clip: true color: "#5C5C5C" border.color: "black" border.width: 1 - onExpandedChanged: { - if (expanded) { - if (networkView.hasExpandedDelegate) - networkView.expandedDelegate.expanded = false - networkView.expandedDelegate = this - } else { - networkView.expandedDelegate = 0 - } - } - - Component.onDestruction: if (expanded) networkView.expandedDelegate = 0 + Component.onDestruction: if (expanded) networkView.expandedNetworkBox = null onHeightChanged: if (expanded) networkView.positionViewAtIndex(index, ListView.Contain) Behavior on height { NumberAnimation { duration: 500; easing.type: Easing.InOutCubic } } @@ -83,7 +74,8 @@ Item { font.pixelSize: engine.smallFontSize() font.bold: true color: "#E6E6E6" - text: network.ssid + (actingNetwork ? networkView.networkStateText : ""); + text: isCurrentNetwork ? ssid + networkView.networkStateText : ssid + Component.onCompleted: networkView.setNetworkStateText(WifiManager.networkState) } Text { @@ -92,7 +84,7 @@ Item { anchors.left: parent.left anchors.margins: engine.mm(1) anchors.leftMargin: engine.mm(6) - text: network.bssid + text: bssid color: "#E6E6E6" font.pixelSize: ssidLabel.font.pixelSize * 0.8 } @@ -102,10 +94,10 @@ Item { anchors.top: bssidLabel.top anchors.left: bssidLabel.right anchors.leftMargin: engine.mm(7) - text: (network.supportsWPA2 ? "WPA2 " : "") - + (network.supportsWPA ? "WPA " : "") - + (network.supportsWEP ? "WEP " : "") - + (network.supportsWPS ? "WPS " : ""); + text: (supportsWPA2 ? "WPA2 " : "") + + (supportsWPA ? "WPA " : "") + + (supportsWEP ? "WEP " : "") + + (supportsWPS ? "WPS " : ""); color: "#E6E6E6" font.pixelSize: ssidLabel.font.pixelSize * 0.8 font.italic: true @@ -123,7 +115,7 @@ Item { border.color: "#212126" // ### TODO - Qt Wifi library should provide alternative methods // of describing signal strength besides dBm. - property int strengthBarWidth: Math.max(100 + network.signalStrength, 0) / 100 * parent.width + property int strengthBarWidth: Math.max(100 + signalStrength, 0) / 100 * parent.width onStrengthBarWidthChanged: { if (strengthBarWidth > parent.width * 0.55) signalStrengthBar.width = parent.width * 0.55 @@ -135,7 +127,19 @@ Item { MouseArea { anchors.fill: parent - onClicked: parent.expanded = !expanded + onClicked: handleNetworkBoxExpanding() + } + + function handleNetworkBoxExpanding() + { + expanded = !expanded + if (expanded) { + if (networkView.hasExpandedNetworkBox) + networkView.expandedNetworkBox.expanded = false + networkView.expandedNetworkBox = networkBox + } else { + networkView.expandedNetworkBox = null + } } TextField { @@ -160,41 +164,58 @@ Item { width: passwordInput.width anchors.horizontalCenter: parent.horizontalCenter text: connected ? "Disconnect" : "Connect" - onClicked: connected ? wifiManager.disconnect() - : wifiManager.connect(network, passwordInput.text); + onClicked: { + if (connected) { + WifiManager.disconnect() + } else { + config.ssid = ssid; + config.passphrase = passwordInput.text + var supportedProtocols; + if (supportsWPA) supportedProtocols += "WPA " + if (supportsWPA2) supportedProtocols += "WPA2 " + if (supportsWEP) supportedProtocols += "WEP " + if (supportsWPS) supportedProtocols += "WPS " + config.protocol = supportedProtocols + if (!WifiManager.connect(config)) + print("failed to connect: " + WifiManager.lastError) + } + } } } } + WifiConfiguration { + id: config + } + ListView { id: networkView anchors.fill: parent - model: wifiManager.networks + model: WifiManager.networks delegate: listDelegate property string networkStateText: "" - property string currentNetworkSsid: "" - property variant expandedDelegate: 0 - property bool hasExpandedDelegate: expandedDelegate != 0 + property QtObject expandedNetworkBox: null + property bool hasExpandedNetworkBox: expandedNetworkBox !== null + + function setNetworkStateText(networkState) { + if (networkState === WifiManager.ObtainingIPAddress) + networkView.networkStateText = " (obtaining ip..)" + else if (networkState === WifiManager.DhcpRequestFailed) + networkView.networkStateText = " (dhcp request failed)" + else if (networkState === WifiManager.Connected) + networkView.networkStateText = " (connected)" + else if (networkState === WifiManager.Authenticating) + networkView.networkStateText = " (authenticating..)" + else if (networkState === WifiManager.HandshakeFailed) + networkView.networkStateText = " (wrong password)" + else if (networkState === WifiManager.Disconnected) + networkView.networkStateText = "" + } Connections { - target: wifiManager - onNetworkStateChanged: { - networkView.currentNetworkSsid = network.ssid - var networkStateText = "" - var state = wifiManager.networkState - if (state == WifiManager.ObtainingIPAddress) - networkStateText = " (obtaining ip..)" - else if (state == WifiManager.DhcpRequestFailed) - networkStateText = " (dhcp request failed)" - else if (state == WifiManager.Connected) - networkStateText = " (connected)" - else if (state == WifiManager.Authenticating) - networkStateText = " (authenticating..)" - else if (state == WifiManager.HandshakeFailed) - networkStateText = " (wrong password)" - networkView.networkStateText = networkStateText - } + target: WifiManager + onNetworkStateChanged: networkView.setNetworkStateText(networkState) } } } -- cgit v1.2.3