diff options
Diffstat (limited to 'src/qtdevicesettings/wifisettingsplugin')
8 files changed, 450 insertions, 0 deletions
diff --git a/src/qtdevicesettings/wifisettingsplugin/WifiManagerView.qml b/src/qtdevicesettings/wifisettingsplugin/WifiManagerView.qml new file mode 100644 index 0000000..71115d5 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/WifiManagerView.qml @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.wifi 1.0 +import B2Qt.Wifi 1.0 + +Item { + id: root + Component.onCompleted: { + if (WifiManager.backendState === WifiManager.NotRunning) { + WifiManager.start(); + } + else if (WifiManager.backendState == WifiManager.Running) { + WifiManager.scanning = true; + } + } + + WifiConfiguration { + id: config + property bool connected: WifiManager.networkState === WifiManager.Connected + } + + ColumnLayout { + id: content + anchors.fill: parent + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + + TextLabel { + text: qsTr("Selected network ") + width: root.width*0.382 + horizontalAlignment: Text.AlignRight + } + + CustomCombobox { + id: networkSelection + model: WifiManager.networks + width: Math.round(200 * Flat.FlatStyle.scaleFactor) + textRole: "ssid" + Component.onCompleted: { + setSelectIndexToVal(WifiManager.currentSSID, "ssid"); + } + onSelectedIndexChanged : { + var ssid = networkSelection.textValue; + config.ssid = ssid; + if (WifiManager.currentSSID !== ssid || !config.connected) { + connectView.visible = true; + } + } + delegate: WifiSelectorDelegate { } + } + + Image { + id: warning + anchors.verticalCenter: parent.verticalCenter + source: "../icons/Alert_yellow_1x.png" + visible: WifiManager.state === WifiManager.HandshakeFailed || + WifiManager.state === WifiManager.DhcpRequestFailed + } + } + + Button { + id: disconnect + text: qsTr("Disconnect") + visible: config.connected + onClicked: { + WifiManager.disconnect(); + networkSelection.currentIndex = -1; + } + } + + GroupBox { + id: connectView + title: qsTr("Enter a password") + flat: false + visible: false + ColumnLayout { + Row { + id: errorView + property alias text: text.text + visible: text.text !== "" + + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Image { + source: "../icons/Alert_yellow_1x.png" + } + Text { + id: text + color: "#face20" + text: "" + } + } + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: false + TextLabel { + text: qsTr("User name") + width: root.width*0.382 + horizontalAlignment: Text.AlignRight + } + TextField { + text: "" + inputMethodHints: Qt.ImhNoPredictiveText + } + } + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Password") + horizontalAlignment: Text.AlignRight + } + TextField { + id: password + text: "" + echoMode: TextInput.Password + inputMethodHints: Qt.ImhNoPredictiveText + } + } + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Button { + text: qsTr("Connect") + onClicked: { + config.passphrase = password.text + if (!WifiManager.connect(config)) { + print("failed to connect: " + WifiManager.lastError) + errorView.text = qsTr("Invalid password"); + } + else { + connectView.visible = false + } + } + } + Button { + text: qsTr("Cancel") + onClicked:connectView.visible = false + } + } + } + } + } +} diff --git a/src/qtdevicesettings/wifisettingsplugin/WifiSelectorDelegate.qml b/src/qtdevicesettings/wifisettingsplugin/WifiSelectorDelegate.qml new file mode 100644 index 0000000..cea3750 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/WifiSelectorDelegate.qml @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.wifi 1.0 + +Item { + id: root + property bool checkable: true + property bool checked: false + property bool pressed: false + signal clicked() + + MouseArea { + id: delegateButton + anchors.fill: parent + hoverEnabled: true + onPressed: root.pressed = true + onClicked: root.clicked() + onEntered: checked = !checked + + Rectangle { + anchors.fill: parent + color: root.checked ? Flat.FlatStyle.disabledColor : "transparent" + opacity: root.checked ? 0.15 : 1.0 + } + Rectangle { + color: Flat.FlatStyle.darkFrameColor + width: parent.width + height: Flat.FlatStyle.onePixel + anchors.bottom: parent.bottom + } + TextLabel { + id: text + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.margins: Math.round(10 * Flat.FlatStyle.scaleFactor) + horizontalAlignment: Text.AlignLeft + text: modelData["ssid"] + } + WifiSignalMonitor { + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + anchors.margins: Math.round(10 * Flat.FlatStyle.scaleFactor) + height: Math.round(parent.height * .8) + width: height + signalStrength: modelData["signalStrength"] + } + } +} diff --git a/src/qtdevicesettings/wifisettingsplugin/WifiSignalMonitor.qml b/src/qtdevicesettings/wifisettingsplugin/WifiSignalMonitor.qml new file mode 100644 index 0000000..e3ab0c8 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/WifiSignalMonitor.qml @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 + +Item { + id: root + + property bool scanning: false + property int signalStrength: 100 + property bool connected: false + + onSignalStrengthChanged: { + sprite.visible = true; + + if (signalStrength < 10) { + sprite.visible = false; + } + else if (signalStrength < 30) { + sprite.currentFrame = 0; + } + else if (signalStrength < 60) { + sprite.currentFrame = 1; + } + else if (signalStrength < 80) { + sprite.currentFrame = 2; + } + else if (signalStrength <= 100) { + sprite.currentFrame = 3; + } + } + + Image { + anchors.fill: parent + source: "../icons/Wifi_lightgray_2x.png" + } + + AnimatedSprite { + id: sprite + anchors.fill: parent + source: connected ? "../icons/WifiAnim_qt_2x.png" : "../icons/WifiAnim_black_2x.png" + frameDuration: 500 + frameCount: 4 + currentFrame: 3 + frameSync: false + frameWidth: 32 + frameHeight: 32 + loops: 40 + running: scanning + } +} diff --git a/src/qtdevicesettings/wifisettingsplugin/icons.qrc b/src/qtdevicesettings/wifisettingsplugin/icons.qrc new file mode 100644 index 0000000..ac67804 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/icons.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>../icons/Wifi_lightgray_2x.png</file> + <file>../icons/WifiAnim_black_2x.png</file> + <file>../icons/Alert_yellow_1x.png</file> + </qresource> +</RCC> diff --git a/src/qtdevicesettings/wifisettingsplugin/plugin.cpp b/src/qtdevicesettings/wifisettingsplugin/plugin.cpp new file mode 100644 index 0000000..c87f68a --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/plugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/qqml.h> +#include <qcoreapplication.h> + +class WifiSettingsQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.wifi")); + const QString prefix = "qrc:"; + qmlRegisterType(QUrl(prefix + "WifiManagerView.qml"), uri, 1, 0, "WifiManagerView"); + qmlRegisterType(QUrl(prefix + "WifiSignalMonitor.qml"), uri, 1, 0, "WifiSignalMonitor"); + qmlRegisterType(QUrl(prefix + "WifiSelectorDelegate.qml"), uri, 1, 0, "WifiSelectorDelegate"); + + } +}; + +#include "plugin.moc" diff --git a/src/qtdevicesettings/wifisettingsplugin/qml.qrc b/src/qtdevicesettings/wifisettingsplugin/qml.qrc new file mode 100644 index 0000000..b43e801 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/qml.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>WifiManagerView.qml</file> + <file>WifiSignalMonitor.qml</file> + <file>WifiSelectorDelegate.qml</file> + </qresource> +</RCC> diff --git a/src/qtdevicesettings/wifisettingsplugin/qmldir b/src/qtdevicesettings/wifisettingsplugin/qmldir new file mode 100644 index 0000000..d5c237e --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/qmldir @@ -0,0 +1,2 @@ +module com.theqtcompany.settings.wifi +plugin qmlwifiplugin diff --git a/src/qtdevicesettings/wifisettingsplugin/wifisettingsplugin.pro b/src/qtdevicesettings/wifisettingsplugin/wifisettingsplugin.pro new file mode 100644 index 0000000..aa50429 --- /dev/null +++ b/src/qtdevicesettings/wifisettingsplugin/wifisettingsplugin.pro @@ -0,0 +1,26 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml + +uri = com.theqtcompany.settings.wifi + +DESTDIR = imports/Wifi +TARGET = qmlwifiplugin + +SOURCES += plugin.cpp + +pluginfiles.files += \ + qmldir \ + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +target.path = $$installPath +pluginfiles.path += $$installPath +INSTALLS += target pluginfiles + + +RESOURCES += \ + icons.qrc \ + qml.qrc + +HEADERS += |