summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@digia.com>2014-11-08 18:02:13 +0100
committerGatis Paeglis <gatis.paeglis@theqtcompany.com>2014-12-02 13:06:28 +0200
commit0a79fd900e3dd5cd7849f038532916ec6b8d6d91 (patch)
treecb91db1dcca86c774609c6efd8e3af0315bcdff8
parent92ee9380d360ca1c01c351ed6d5106e1799b0889 (diff)
Adapt launchersettings to the B2Qt.Wifi 1.0 API
Change-Id: I36154eb52c533b490cb77cd75f4e495edae09604 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r--basicsuite/launchersettings/WifiGroupBox.qml86
-rw-r--r--basicsuite/launchersettings/WifiNetworkList.qml115
-rw-r--r--basicsuite/launchersettings/main.qml4
3 files changed, 120 insertions, 85 deletions
diff --git a/basicsuite/launchersettings/WifiGroupBox.qml b/basicsuite/launchersettings/WifiGroupBox.qml
index 3ce35c9..5eab3f2 100644
--- a/basicsuite/launchersettings/WifiGroupBox.qml
+++ b/basicsuite/launchersettings/WifiGroupBox.qml
@@ -41,55 +41,69 @@
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
-import Qt.labs.wifi 0.1
+import B2Qt.Wifi 1.0
ColumnLayout {
+ anchors.fill: parent
- anchors.fill:parent
-
- WifiManager {
- id: wifiManager
- scanning: backendReady
+ Binding {
+ target: WifiManager
+ property: "scanning"
+ value: networkList.visible
}
- ColumnLayout {
- anchors.fill: parent
-
- RowLayout {
+ RowLayout {
- Button {
- id: wifiOnOffButton
- Layout.fillWidth: true
- style: SettingsButtonStyle {}
- text: (wifiManager.backendReady) ? "Switch Off" : "Switch On"
- onClicked: {
- if (wifiManager.backendReady) {
- if (networkList.visible)
- networkList.visible = false
- wifiManager.stop()
- } else {
- wifiManager.start()
- }
+ Button {
+ id: wifiOnOffButton
+ Layout.fillWidth: true
+ style: SettingsButtonStyle {}
+ onClicked: {
+ if (WifiManager.backendState === WifiManager.Running) {
+ if (networkList.visible)
+ networkList.visible = false
+ WifiManager.stop()
+ } else if (WifiManager.backendState === WifiManager.NotRunning) {
+ WifiManager.start()
}
}
- Button {
- id: listNetworksButton
- Layout.fillWidth: true
- style: SettingsButtonStyle {}
- visible: wifiManager.backendReady
- text: (networkList.visible) ? "Hide wifi networks"
- : "List available wifi networks"
- onClicked: networkList.visible = !networkList.visible
+ function updateButtonText(backendState)
+ {
+ if (backendState === WifiManager.Initializing)
+ wifiOnOffButton.text = "Initializing..."
+ if (backendState === WifiManager.Terminating)
+ wifiOnOffButton.text = "Terminating..."
+ if (backendState === WifiManager.NotRunning)
+ wifiOnOffButton.text = "Switch On"
+ if (backendState === WifiManager.Running)
+ wifiOnOffButton.text = "Switch Off"
+ }
+
+ Component.onCompleted: updateButtonText(WifiManager.backendState)
+ Connections {
+ target: WifiManager
+ onBackendStateChanged: wifiOnOffButton.updateButtonText(backendState)
}
}
- WifiNetworkList {
- id: networkList
- implicitHeight: engine.centimeter(7)
+ Button {
+ id: listNetworksButton
Layout.fillWidth: true
- visible: false
- clip: true
+ style: SettingsButtonStyle {}
+ visible: WifiManager.backendState === WifiManager.Running
+ text: networkList.visible ? "Hide wifi networks"
+ : "List available wifi networks"
+ onClicked: networkList.visible = !networkList.visible
}
}
+
+ WifiNetworkList {
+ id: networkList
+ implicitHeight: engine.centimeter(7)
+ Layout.fillWidth: true
+ visible: false
+ clip: true
+ }
}
+
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)
}
}
}
diff --git a/basicsuite/launchersettings/main.qml b/basicsuite/launchersettings/main.qml
index c698aaf..3e73107 100644
--- a/basicsuite/launchersettings/main.qml
+++ b/basicsuite/launchersettings/main.qml
@@ -43,7 +43,7 @@ import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Enterprise.VirtualKeyboard.Settings 1.2
-import Qt.labs.wifi 0.1 as Wifi
+import B2Qt.Wifi 1.0
import B2Qt.Utils 1.0
Rectangle {
@@ -259,7 +259,7 @@ Rectangle {
function createWifiGroupBox()
{
- if (Wifi.Interface.wifiSupported()) {
+ if (WifiDevice.wifiSupported()) {
var component = Qt.createComponent("WifiGroupBox.qml")
var wifi = component.createObject(wifiOptions.contentItem)
if (wifi)