add better ipv6 support

This commit is contained in:
Michael Zanetti 2018-07-26 00:08:09 +02:00
parent 5d955d09d4
commit 678ff9973b
17 changed files with 153 additions and 203 deletions

View File

@ -1,6 +1,7 @@
#include "bluetoothservicediscovery.h"
#include "discoverymodel.h"
#include "discoverydevice.h"
#include <QTimer>
@ -102,14 +103,16 @@ void BluetoothServiceDiscovery::onServiceDiscovered(const QBluetoothServiceInfo
if (serviceInfo.serviceClassUuids().first() == QBluetoothUuid(QUuid("997936b5-d2cd-4c57-b41b-c6048320cd2b"))) {
qDebug() << "BluetoothServiceDiscovery: Found nymea rfcom service!";
DiscoveryDevice* device = m_discoveryModel->find(serviceInfo.device().address());
if (!device) {
device = new DiscoveryDevice(DiscoveryDevice::DeviceTypeBluetooth, this);
qDebug() << "BluetoothServiceDiscovery: Adding new bluetooth host to model";
device->setName(QString("%1 (%2)").arg(serviceInfo.serviceName()).arg(serviceInfo.device().name()));
device->setBluetoothAddress(serviceInfo.device().address());
m_discoveryModel->addDevice(device);
}
// DiscoveryDevice* device = m_discoveryModel->find(serviceInfo.device().address());
// if (!device) {
// device = new DiscoveryDevice(DiscoveryDevice::DeviceTypeBluetooth, this);
// qDebug() << "BluetoothServiceDiscovery: Adding new bluetooth host to model";
// device->setName(QString("%1 (%2)").arg(serviceInfo.serviceName()).arg(serviceInfo.device().name()));
//// device->setBluetoothAddress(serviceInfo.device().address());
// PortConfig pc;
// m_discoveryModel->addDevice(device);
// }
}
}

View File

@ -22,18 +22,12 @@
#include <QUrl>
DiscoveryDevice::DiscoveryDevice(DeviceType deviceType, QObject *parent):
QObject(parent),
m_deviceType(deviceType)
DiscoveryDevice::DiscoveryDevice(QObject *parent):
QObject(parent)
{
m_portConfigs = new PortConfigs(this);
}
DiscoveryDevice::DeviceType DiscoveryDevice::deviceType() const
{
return m_deviceType;
}
QUuid DiscoveryDevice::uuid() const
{
return m_uuid;
@ -44,43 +38,6 @@ void DiscoveryDevice::setUuid(const QUuid &uuid)
m_uuid = uuid;
}
QHostAddress DiscoveryDevice::hostAddress() const
{
return m_hostAddress;
}
QString DiscoveryDevice::hostAddressString() const
{
return m_hostAddress.toString();
}
void DiscoveryDevice::setHostAddress(const QHostAddress &hostAddress)
{
if (m_hostAddress != hostAddress) {
m_hostAddress = hostAddress;
emit hostAddressChanged();
}
}
QBluetoothAddress DiscoveryDevice::bluetoothAddress() const
{
return m_bluetoothAddress;
}
QString DiscoveryDevice::bluetoothAddressString() const
{
return m_bluetoothAddress.toString();
}
void DiscoveryDevice::setBluetoothAddress(const QBluetoothAddress &bluetoothAddress)
{
if (m_bluetoothAddress == bluetoothAddress)
return;
m_bluetoothAddress = bluetoothAddress;
emit bluetoothAddressChanged();
}
QString DiscoveryDevice::name() const
{
return m_name;
@ -122,7 +79,11 @@ QString DiscoveryDevice::toUrl(int portConfigIndex)
QString ret = pc->protocol() == PortConfig::ProtocolNymeaRpc ? "nymea" : "ws";
ret += pc->sslEnabled() ? "s" : "";
ret += "://";
ret += m_hostAddress.toString();
if (pc->hostAddress().protocol() == QAbstractSocket::IPv4Protocol) {
ret += pc->hostAddress().toString();
} else if (pc->hostAddress().protocol() == QAbstractSocket::IPv6Protocol){
ret += "[" + pc->hostAddress().toString() + "]";
}
ret += ":";
ret += QString::number(pc->port());
return ret;
@ -142,6 +103,8 @@ int PortConfigs::rowCount(const QModelIndex &parent) const
QVariant PortConfigs::data(const QModelIndex &index, int role) const
{
switch (role) {
case RoleAddress:
return m_portConfigs.at(index.row())->hostAddressString();
case RolePort:
return m_portConfigs.at(index.row())->port();
case RoleProtocol:
@ -182,15 +145,17 @@ PortConfig* PortConfigs::get(int index) const
QHash<int, QByteArray> PortConfigs::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(RoleAddress, "address");
roles.insert(RolePort, "port");
roles.insert(RoleProtocol, "protocol");
roles.insert(RoleSSLEnabled, "sslEnabled");
return roles;
}
PortConfig::PortConfig(int port, QObject *parent):
PortConfig::PortConfig(const QHostAddress &hostAddress, int port, QObject *parent):
QObject(parent),
m_port(port)
m_port(port),
m_hostAddress(hostAddress)
{
}
@ -213,6 +178,20 @@ void PortConfig::setProtocol(PortConfig::Protocol protocol)
}
}
QHostAddress PortConfig::hostAddress() const
{
return m_hostAddress;
}
QString PortConfig::hostAddressString() const
{
if (m_hostAddress.protocol() == QAbstractSocket::IPv6Protocol){
return "[" + m_hostAddress.toString() + "]";
}
return m_hostAddress.toString();
}
bool PortConfig::sslEnabled() const
{
return m_sslEnabled;

View File

@ -34,6 +34,7 @@ class PortConfig: public QObject
Q_OBJECT
Q_PROPERTY(int port READ port CONSTANT)
Q_PROPERTY(Protocol protocol READ protocol NOTIFY protocolChanged)
Q_PROPERTY(QString hostAddress READ hostAddressString NOTIFY hostAddressChanged)
Q_PROPERTY(bool sslEnabled READ sslEnabled NOTIFY sslEnabledChanged)
public:
enum Protocol {
@ -41,22 +42,28 @@ public:
ProtocolWebSocket
};
Q_ENUM(Protocol)
PortConfig(int port, QObject *parent = nullptr);
PortConfig(const QHostAddress &hostAddress, int port, QObject *parent = nullptr);
int port() const;
Protocol protocol() const;
void setProtocol(Protocol protocol);
QHostAddress hostAddress() const;
QString hostAddressString() const;
void setHostAddress(const QString &hostAddress);
bool sslEnabled() const;
void setSslEnabled(bool sslEnabled);
signals:
void protocolChanged();
void hostAddressChanged();
void sslEnabledChanged();
private:
int m_port = -1;
QHostAddress m_hostAddress;
Protocol m_protocol = ProtocolNymeaRpc;
bool m_sslEnabled = false;
};
@ -67,6 +74,7 @@ class PortConfigs: public QAbstractListModel
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
enum Roles {
RoleAddress,
RolePort,
RoleProtocol,
RoleSSLEnabled
@ -95,36 +103,17 @@ private:
class DiscoveryDevice: public QObject
{
Q_OBJECT
Q_PROPERTY(DeviceType deviceType READ deviceType CONSTANT)
Q_PROPERTY(QUuid uuid READ uuid CONSTANT)
Q_PROPERTY(QString hostAddress READ hostAddressString NOTIFY hostAddressChanged)
Q_PROPERTY(QString bluetoothAddress READ bluetoothAddressString NOTIFY bluetoothAddressChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString version READ version NOTIFY versionChanged)
Q_PROPERTY(PortConfigs* portConfigs READ portConfigs CONSTANT)
public:
enum DeviceType {
DeviceTypeNetwork,
DeviceTypeBluetooth
};
Q_ENUM(DeviceType)
explicit DiscoveryDevice(DeviceType deviceType, QObject *parent = nullptr);
DeviceType deviceType() const;
explicit DiscoveryDevice(QObject *parent = nullptr);
QUuid uuid() const;
void setUuid(const QUuid &uuid);
QHostAddress hostAddress() const;
QString hostAddressString() const;
void setHostAddress(const QHostAddress &hostAddress);
QBluetoothAddress bluetoothAddress() const;
QString bluetoothAddressString() const;
void setBluetoothAddress(const QBluetoothAddress &bluetoothAddress);
QString name() const;
void setName(const QString &name);
@ -137,15 +126,10 @@ public:
signals:
void nameChanged();
void hostAddressChanged();
void bluetoothAddressChanged();
void versionChanged();
private:
DeviceType m_deviceType = DeviceTypeNetwork;
QUuid m_uuid;
QHostAddress m_hostAddress;
QBluetoothAddress m_bluetoothAddress;
QString m_name;
QString m_version;
PortConfigs *m_portConfigs = nullptr;

View File

@ -19,6 +19,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "discoverymodel.h"
#include "discoverydevice.h"
DiscoveryModel::DiscoveryModel(QObject *parent) :
QAbstractListModel(parent)
@ -38,24 +39,12 @@ QVariant DiscoveryModel::data(const QModelIndex &index, int role) const
DiscoveryDevice *device = m_devices.at(index.row());
switch (role) {
case DeviceTypeRole:
return device->deviceType();
case UuidRole:
return device->uuid();
case NameRole:
return device->name();
case HostAddressRole:
return device->hostAddress().toString();
case BluetoothAddressRole:
return device->bluetoothAddressString();
// case WebSocketUrlRole:
// return device.webSocketUrl();
// case PortRole:
// return device.port();
case VersionRole:
return device->version();
// case NymeaRpcUrlRole:
// return device.nymeaRpcUrl();
}
return QVariant();
}
@ -90,17 +79,6 @@ DiscoveryDevice *DiscoveryModel::find(const QUuid &uuid)
return nullptr;
}
DiscoveryDevice *DiscoveryModel::find(const QBluetoothAddress &bluetoothAddress)
{
foreach (DiscoveryDevice *device, m_devices) {
if (device->bluetoothAddress() == bluetoothAddress) {
return device;
}
}
return nullptr;
}
void DiscoveryModel::clearModel()
{
beginResetModel();
@ -112,11 +90,8 @@ void DiscoveryModel::clearModel()
QHash<int, QByteArray> DiscoveryModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[DeviceTypeRole] = "deviceType";
roles[UuidRole] = "uuid";
roles[NameRole] = "name";
roles[HostAddressRole] = "hostAddress";
roles[BluetoothAddressRole] = "bluetoothAddress";
roles[VersionRole] = "version";
return roles;
}

View File

@ -23,8 +23,9 @@
#include <QAbstractListModel>
#include <QList>
#include <QBluetoothAddress>
#include "discoverydevice.h"
class DiscoveryDevice;
class DiscoveryModel : public QAbstractListModel
{
@ -35,8 +36,6 @@ public:
DeviceTypeRole,
UuidRole,
NameRole,
HostAddressRole,
BluetoothAddressRole,
VersionRole
};
Q_ENUM(DeviceRole)
@ -50,7 +49,6 @@ public:
Q_INVOKABLE DiscoveryDevice *get(int index) const;
Q_INVOKABLE DiscoveryDevice *find(const QUuid &uuid);
Q_INVOKABLE DiscoveryDevice *find(const QBluetoothAddress &bluetoothAddress);
void clearModel();

View File

@ -163,7 +163,7 @@ void UpnpDiscovery::readData()
if (!m_foundDevices.contains(location) && isNymea) {
m_foundDevices.append(location);
qDebug() << "Getting server data from:" << location;
// qDebug() << "Getting server data from:" << location;
QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(location));
connect(reply, &QNetworkReply::sslErrors, [reply](const QList<QSslError> &errors){
reply->ignoreSslErrors(errors);
@ -205,7 +205,7 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
// Check for old style websocketURL and nymeaRpcURL
if (xml.name().toString() == "websocketURL") {
QUrl u(xml.readElementText());
PortConfig *pc = new PortConfig(u.port());
PortConfig *pc = new PortConfig(discoveredAddress, u.port());
pc->setProtocol(PortConfig::ProtocolWebSocket);
pc->setSslEnabled(u.scheme() == "wss");
portConfigList.append(pc);
@ -214,7 +214,7 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
if (xml.name().toString() == "nymeaRpcURL") {
QUrl u(xml.readElementText());
qDebug() << "have url" << u << u.scheme();
PortConfig *pc = new PortConfig(u.port());
PortConfig *pc = new PortConfig(discoveredAddress, u.port());
pc->setProtocol(PortConfig::ProtocolNymeaRpc);
pc->setSslEnabled(u.scheme() == "nymeas");
portConfigList.append(pc);
@ -223,7 +223,7 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
if (xml.name().toString() == "guhRpcURL") {
QUrl u(xml.readElementText());
qDebug() << "have url" << u << u.scheme();
PortConfig *pc = new PortConfig(u.port());
PortConfig *pc = new PortConfig(discoveredAddress, u.port());
pc->setProtocol(PortConfig::ProtocolNymeaRpc);
pc->setSslEnabled(u.scheme() == "guhs");
portConfigList.append(pc);
@ -238,7 +238,7 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
xml.readNext();
if (xml.name().toString() == "SCPDURL") {
QUrl u(xml.readElementText());
PortConfig *pc = new PortConfig(u.port());
PortConfig *pc = new PortConfig(discoveredAddress, u.port());
pc->setProtocol(u.scheme().startsWith("nymea") ? PortConfig::ProtocolNymeaRpc : PortConfig::ProtocolWebSocket);
pc->setSslEnabled(u.scheme() == "nymeas" || u.scheme() == "wss");
portConfigList.append(pc);
@ -264,12 +264,11 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
DiscoveryDevice* device = m_discoveryModel->find(uuid);
if (!device) {
device = new DiscoveryDevice(DiscoveryDevice::DeviceTypeNetwork, m_discoveryModel);
device = new DiscoveryDevice(m_discoveryModel);
device->setUuid(uuid);
qDebug() << "Adding new host to model";
m_discoveryModel->addDevice(device);
}
device->setHostAddress(discoveredAddress);
device->setName(name);
device->setVersion(version);
foreach (PortConfig *pc, portConfigList) {

View File

@ -2,6 +2,7 @@
#include <QUuid>
#include "discoverydevice.h"
ZeroconfDiscovery::ZeroconfDiscovery(DiscoveryModel *discoveryModel, QObject *parent) :
QObject(parent),
@ -11,13 +12,13 @@ ZeroconfDiscovery::ZeroconfDiscovery(DiscoveryModel *discoveryModel, QObject *pa
m_zeroconfJsonRPC = new QZeroConf(this);
connect(m_zeroconfJsonRPC, &QZeroConf::serviceAdded, this, &ZeroconfDiscovery::serviceEntryAdded);
connect(m_zeroconfJsonRPC, &QZeroConf::serviceUpdated, this, &ZeroconfDiscovery::serviceEntryAdded);
m_zeroconfJsonRPC->startBrowser("_jsonrpc._tcp");
m_zeroconfJsonRPC->startBrowser("_jsonrpc._tcp", QAbstractSocket::AnyIPProtocol);
qDebug() << "created service browser for _jsonrpc._tcp:" << m_zeroconfJsonRPC->browserExists();
m_zeroconfWebSocket = new QZeroConf(this);
connect(m_zeroconfWebSocket, &QZeroConf::serviceAdded, this, &ZeroconfDiscovery::serviceEntryAdded);
connect(m_zeroconfWebSocket, &QZeroConf::serviceUpdated, this, &ZeroconfDiscovery::serviceEntryAdded);
m_zeroconfWebSocket->startBrowser("_ws._tcp");
m_zeroconfWebSocket->startBrowser("_ws._tcp", QAbstractSocket::AnyIPProtocol);
qDebug() << "created service browser for _ws._tcp:" << m_zeroconfWebSocket->browserExists();
#else
qDebug() << "Zeroconf support not compiled in. Zeroconf will not be available.";
@ -41,10 +42,10 @@ bool ZeroconfDiscovery::discovering() const
#ifdef WITH_ZEROCONF
void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry)
{
if (!entry.name().startsWith("nymea") || entry.ip().isNull()) {
if (!entry.name().startsWith("nymea") || (entry.ip().isNull() && entry.ipv6().isNull())) {
return;
}
// qDebug() << "zeroconf service discovered" << entry << entry.txt() << entry.type();
// qDebug() << "zeroconf service discovered" << entry << entry.ip() << entry.ipv6() << entry.txt() << entry.type();
QString uuid;
bool sslEnabled = false;
@ -70,18 +71,17 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry)
DiscoveryDevice* device = m_discoveryModel->find(uuid);
if (!device) {
device = new DiscoveryDevice(DiscoveryDevice::DeviceTypeNetwork, m_discoveryModel);
device = new DiscoveryDevice(m_discoveryModel);
device->setUuid(uuid);
qDebug() << "ZeroConf: Adding new host to model";
m_discoveryModel->addDevice(device);
}
device->setHostAddress(entry.ip());
device->setName(serverName);
device->setVersion(version);
PortConfig *portConfig = device->portConfigs()->find(entry.port());
if (!portConfig) {
qDebug() << "ZeroConf: Adding new port config";
portConfig = new PortConfig(entry.port());
portConfig = new PortConfig(!entry.ip().isNull() ? entry.ip() : entry.ipv6(), entry.port());
device->portConfigs()->insert(portConfig);
}
portConfig->setProtocol(entry.type() == "_ws._tcp" ? PortConfig::ProtocolWebSocket : PortConfig::ProtocolNymeaRpc);

View File

@ -111,6 +111,8 @@ void Engine::onConnectedChanged()
void Engine::onDeviceManagerFetchingChanged()
{
if (!m_deviceManager->fetchingData()) {
m_tagsManager->init();
if (m_jsonRpcClient->ensureServerVersion("1.7")) {
m_tagsManager->init();
}
}
}

View File

@ -243,7 +243,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request)
{
QVariantMap newRequest = request;
newRequest.insert("token", m_token);
// qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson(QJsonDocument::Compact) + "\n");
}

View File

@ -9,6 +9,7 @@
#include "devicediscovery.h"
#include "discovery/nymeadiscovery.h"
#include "discovery/discoverymodel.h"
#include "discovery/discoverydevice.h"
#include "interfacesmodel.h"
#include "rulemanager.h"
#include "models/rulesfiltermodel.h"
@ -50,6 +51,8 @@
#include "ruletemplates/statedescriptortemplate.h"
#include "ruletemplates/ruleactiontemplate.h"
#include <QtQml/qqml.h>
static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)

View File

@ -61,7 +61,6 @@ SOURCES += \
models/tagsproxymodel.cpp \
tagsmanager.cpp \
wifisetup/wirelessaccesspointsproxy.cpp \
models/tagsproxymodel.cpp \
ruletemplates/ruletemplate.cpp \
ruletemplates/ruletemplates.cpp \
ruletemplates/eventdescriptortemplate.cpp \

View File

@ -1,7 +1,10 @@
<RCC>
<qresource prefix="/">
<file>ui/Nymea.qml</file>
<file>ui/ConnectPage.qml</file>
<file>ui/connection/ConnectPage.qml</file>
<file>ui/connection/ManualConnectPage.qml</file>
<file>ui/connection/BluetoothDiscoveryPage.qml</file>
<file>ui/connection/ConnectingPage.qml</file>
<file>ui/mainviews/DevicesPage.qml</file>
<file>ui/NewDeviceWizard.qml</file>
<file>ui/SettingsPage.qml</file>
@ -212,8 +215,6 @@
<file>ui/components/EmptyViewPlaceholder.qml</file>
<file>ui/components/RemoveDeviceMethodDialog.qml</file>
<file>ui/components/FancyHeader.qml</file>
<file>ui/connection/ManualConnectPage.qml</file>
<file>ui/connection/BluetoothDiscoveryPage.qml</file>
<file>ui/images/awning/awning-100.svg</file>
<file>ui/devicepages/AwningDevicePage.qml</file>
<file>ui/images/awning/awning-000.svg</file>

View File

@ -42,7 +42,7 @@ ApplicationWindow {
}
Component.onCompleted: {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
}
Connections {
@ -77,7 +77,7 @@ ApplicationWindow {
print("calling init. Auth required:", Engine.jsonRpcClient.authenticationRequired, "initial setup required:", Engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", Engine.jsonRpcClient.connected)
pageStack.clear()
if (!Engine.connection.connected) {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
return;
}
@ -101,7 +101,7 @@ ApplicationWindow {
} else if (Engine.jsonRpcClient.connected) {
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
} else {
pageStack.push(Qt.resolvedUrl("ConnectPage.qml"))
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
}
}

View File

@ -30,6 +30,7 @@ Page {
Label {
Layout.fillWidth: true
elide: Text.ElideMiddle
text: Engine.connection.url
}
Button {

View File

@ -3,7 +3,7 @@ import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import Nymea 1.0
import "components"
import "../components"
Page {
id: root
@ -13,7 +13,12 @@ Page {
Component.onCompleted: {
print("completed connectPage. last connected host:", settings.lastConnectedHost)
if (settings.lastConnectedHost.length > 0) {
pageStack.push(connectingPage)
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
page.cancel.connect(function() {
Engine.connection.disconnect();
pageStack.pop(root, StackView.Immediate);
pageStack.push(discoveyPage)
})
Engine.connection.connect(settings.lastConnectedHost)
} else {
pageStack.push(discoveryPage)
@ -55,17 +60,18 @@ Page {
default:
errorMessage = qsTr("Un unknown error happened. We're very sorry for that. (Error code: %1)").arg(error);
}
pageStack.pop(root, StackView.Immediate)
pageStack.push(discoveryPage)
print("opening ErrorDialog with message:", errorMessage, error)
var comp = Qt.createComponent(Qt.resolvedUrl("components/ErrorDialog.qml"))
var comp = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml"))
var popup = comp.createObject(app, {text: errorMessage})
popup.open()
pageStack.pop(root)
pageStack.push(discoveryPage)
}
onConnectedChanged: {
if (!connected) {
pageStack.pop(root)
pageStack.pop(root, StackView.Immediate)
pageStack.push(discoveryPage)
}
}
@ -79,8 +85,8 @@ Page {
header: FancyHeader {
title: qsTr("Connect %1").arg(app.systemName)
model: ListModel {
ListElement { iconSource: "../images/network-vpn.svg"; text: qsTr("Manual connection"); page: "connection/ManualConnectPage.qml" }
ListElement { iconSource: "../images/bluetooth.svg"; text: qsTr("Wireless setup"); page: "connection/BluetoothDiscoveryPage.qml"; }
ListElement { iconSource: "../images/network-vpn.svg"; text: qsTr("Manual connection"); page: "ManualConnectPage.qml" }
ListElement { iconSource: "../images/bluetooth.svg"; text: qsTr("Wireless setup"); page: "BluetoothDiscoveryPage.qml"; }
ListElement { iconSource: "../images/private-browsing.svg"; text: qsTr("Demo mode"); page: "" }
ListElement { iconSource: "../images/stock_application.svg"; text: qsTr("App settings"); page: "AppSettingsPage.qml" }
}
@ -92,8 +98,11 @@ Page {
pageStack.push(model.get(index).page);
break;
case 2:
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
page.cancel.connect(function() {
Engine.connection.disconnect()
})
Engine.connection.connect("nymea://nymea.nymea.io:2222")
pageStack.push(connectingPage)
break;
}
}
@ -200,19 +209,11 @@ Page {
swipe.enabled: discoveryDeviceDelegate.discoveryDevice.deviceType === DiscoveryDevice.DeviceTypeNetwork
onClicked: {
switch (discoveryDeviceDelegate.discoveryDevice.deviceType) {
case DiscoveryDevice.DeviceTypeNetwork:
Engine.connection.connect(discoveryDeviceDelegate.discoveryDevice.toUrl(discoveryDeviceDelegate.defaultPortConfigIndex))
break;
case DiscoveryDevice.DeviceTypeBluetooth:
Engine.connection.connect("rfcom://bluetooth.local?mac=" + model.bluetoothAddress + "&name=" + model.name)
break;
default:
console.warn("Could not connect, unknown type")
break;
}
pageStack.push(connectingPage)
Engine.connection.connect(discoveryDeviceDelegate.discoveryDevice.toUrl(discoveryDeviceDelegate.defaultPortConfigIndex))
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
page.cancel.connect(function() {
Engine.connection.disconnect()
})
}
swipe.right: MouseArea {
@ -276,7 +277,10 @@ Page {
visible: discovery.discoveryModel.count === 0
text: qsTr("Demo mode (online)")
onClicked: {
pageStack.push(connectingPage)
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
page.cancel.connect(function() {
Engine.connection.disconnect()
})
Engine.connection.connect("nymea://nymea.nymea.io:2222")
}
}
@ -299,40 +303,6 @@ Page {
}
}
Component {
id: connectingPage
Page {
ColumnLayout {
id: columnLayout
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins }
spacing: app.margins
BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: parent.visible
}
Label {
text: qsTr("Connecting to<br>%1").arg(Engine.connection.url)
font.pixelSize: app.largeFont
Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
}
}
Button {
text: qsTr("Cancel")
anchors { left: parent.left; top: columnLayout.bottom; right: parent.right }
anchors.margins: app.margins
onClicked: {
Engine.connection.disconnect()
pageStack.pop(root);
pageStack.push(discoveryPage);
}
}
}
}
Component {
id: certDialogComponent
@ -511,14 +481,6 @@ Page {
Layout.fillWidth: true
elide: Text.ElideRight
}
Label {
text: "IP Address:"
}
Label {
text: dialog.discoveryDevice.hostAddress
Layout.fillWidth: true
elide: Text.ElideRight
}
ThinDivider { Layout.columnSpan: 2 }
Label {
Layout.columnSpan: 2
@ -542,7 +504,9 @@ Page {
ColumnLayout {
Layout.fillWidth: true
Label {
text: qsTr("Port: %1").arg(model.port)
Layout.fillWidth: true
elide: Text.ElideMiddle
text: "%1:%2".arg(model.address).arg(model.port)
}
Label {
text: model.protocol === PortConfig.ProtocolNymeaRpc ? "nymea-rpc" : "websocket"

View File

@ -0,0 +1,37 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import Nymea 1.0
import "../components"
Page {
id: root
signal cancel()
ColumnLayout {
id: columnLayout
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins }
spacing: app.margins
BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: parent.visible
}
Label {
text: qsTr("Trying to connect...")
font.pixelSize: app.largeFont
Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
}
}
Button {
text: qsTr("Cancel")
anchors { left: parent.left; top: columnLayout.bottom; right: parent.right }
anchors.margins: app.margins
onClicked: root.cancel()
}
}

View File

@ -5,6 +5,7 @@ import Nymea 1.0
import "../components"
Page {
id: root
objectName: "manualConnectPage"
header: GuhHeader {
text: qsTr("Manual connection")
@ -96,7 +97,11 @@ Page {
print("Try to connect ", rpcUrl)
Engine.connection.connect(rpcUrl)
pageStack.push(connectingPage)
var page = pageStack.push(Qt.resolvedUrl("ConnectingPage.qml"))
page.cancel.connect(function() {
Engine.connection.disconnect()
pageStack.pop(root)
})
}
}
}