diff --git a/libnymea-app-core/discovery/bluetoothservicediscovery.cpp b/libnymea-app-core/discovery/bluetoothservicediscovery.cpp index 9c211465..4fd928ff 100644 --- a/libnymea-app-core/discovery/bluetoothservicediscovery.cpp +++ b/libnymea-app-core/discovery/bluetoothservicediscovery.cpp @@ -1,6 +1,7 @@ #include "bluetoothservicediscovery.h" #include "discoverymodel.h" +#include "discoverydevice.h" #include @@ -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); +// } } } diff --git a/libnymea-app-core/discovery/discoverydevice.cpp b/libnymea-app-core/discovery/discoverydevice.cpp index 28588089..eaeee7bd 100644 --- a/libnymea-app-core/discovery/discoverydevice.cpp +++ b/libnymea-app-core/discovery/discoverydevice.cpp @@ -22,18 +22,12 @@ #include -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 PortConfigs::roleNames() const { QHash 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; diff --git a/libnymea-app-core/discovery/discoverydevice.h b/libnymea-app-core/discovery/discoverydevice.h index 47ccc7a5..dc04c2a9 100644 --- a/libnymea-app-core/discovery/discoverydevice.h +++ b/libnymea-app-core/discovery/discoverydevice.h @@ -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; diff --git a/libnymea-app-core/discovery/discoverymodel.cpp b/libnymea-app-core/discovery/discoverymodel.cpp index 303df72f..774ad4b8 100644 --- a/libnymea-app-core/discovery/discoverymodel.cpp +++ b/libnymea-app-core/discovery/discoverymodel.cpp @@ -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 DiscoveryModel::roleNames() const { QHash roles; - roles[DeviceTypeRole] = "deviceType"; roles[UuidRole] = "uuid"; roles[NameRole] = "name"; - roles[HostAddressRole] = "hostAddress"; - roles[BluetoothAddressRole] = "bluetoothAddress"; roles[VersionRole] = "version"; return roles; } diff --git a/libnymea-app-core/discovery/discoverymodel.h b/libnymea-app-core/discovery/discoverymodel.h index 5cd1c8bd..906fa340 100644 --- a/libnymea-app-core/discovery/discoverymodel.h +++ b/libnymea-app-core/discovery/discoverymodel.h @@ -23,8 +23,9 @@ #include #include +#include -#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(); diff --git a/libnymea-app-core/discovery/upnpdiscovery.cpp b/libnymea-app-core/discovery/upnpdiscovery.cpp index 4fb9249e..c2da5f56 100644 --- a/libnymea-app-core/discovery/upnpdiscovery.cpp +++ b/libnymea-app-core/discovery/upnpdiscovery.cpp @@ -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 &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) { diff --git a/libnymea-app-core/discovery/zeroconfdiscovery.cpp b/libnymea-app-core/discovery/zeroconfdiscovery.cpp index 6c41d291..e3ceae26 100644 --- a/libnymea-app-core/discovery/zeroconfdiscovery.cpp +++ b/libnymea-app-core/discovery/zeroconfdiscovery.cpp @@ -2,6 +2,7 @@ #include +#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); diff --git a/libnymea-app-core/engine.cpp b/libnymea-app-core/engine.cpp index 4cb99f14..b002fe55 100644 --- a/libnymea-app-core/engine.cpp +++ b/libnymea-app-core/engine.cpp @@ -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(); + } } } diff --git a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp b/libnymea-app-core/jsonrpc/jsonrpcclient.cpp index ef827b37..7107446b 100644 --- a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app-core/jsonrpc/jsonrpcclient.cpp @@ -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"); } diff --git a/libnymea-app-core/libnymea-app-core.h b/libnymea-app-core/libnymea-app-core.h index 54bd1744..aba96a99 100644 --- a/libnymea-app-core/libnymea-app-core.h +++ b/libnymea-app-core/libnymea-app-core.h @@ -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 + static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) diff --git a/libnymea-app-core/libnymea-app-core.pro b/libnymea-app-core/libnymea-app-core.pro index 2f4f433a..67e8f2b4 100644 --- a/libnymea-app-core/libnymea-app-core.pro +++ b/libnymea-app-core/libnymea-app-core.pro @@ -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 \ diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index f424d75d..895c817f 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -1,7 +1,10 @@ ui/Nymea.qml - ui/ConnectPage.qml + ui/connection/ConnectPage.qml + ui/connection/ManualConnectPage.qml + ui/connection/BluetoothDiscoveryPage.qml + ui/connection/ConnectingPage.qml ui/mainviews/DevicesPage.qml ui/NewDeviceWizard.qml ui/SettingsPage.qml @@ -212,8 +215,6 @@ ui/components/EmptyViewPlaceholder.qml ui/components/RemoveDeviceMethodDialog.qml ui/components/FancyHeader.qml - ui/connection/ManualConnectPage.qml - ui/connection/BluetoothDiscoveryPage.qml ui/images/awning/awning-100.svg ui/devicepages/AwningDevicePage.qml ui/images/awning/awning-000.svg diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index aaf5ed7c..c41c6440 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -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")) } } diff --git a/nymea-app/ui/SettingsPage.qml b/nymea-app/ui/SettingsPage.qml index 13a29eef..5dec62e5 100644 --- a/nymea-app/ui/SettingsPage.qml +++ b/nymea-app/ui/SettingsPage.qml @@ -30,6 +30,7 @@ Page { Label { Layout.fillWidth: true + elide: Text.ElideMiddle text: Engine.connection.url } Button { diff --git a/nymea-app/ui/ConnectPage.qml b/nymea-app/ui/connection/ConnectPage.qml similarity index 88% rename from nymea-app/ui/ConnectPage.qml rename to nymea-app/ui/connection/ConnectPage.qml index 4f3ad7ab..d3bec211 100644 --- a/nymea-app/ui/ConnectPage.qml +++ b/nymea-app/ui/connection/ConnectPage.qml @@ -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
%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" diff --git a/nymea-app/ui/connection/ConnectingPage.qml b/nymea-app/ui/connection/ConnectingPage.qml new file mode 100644 index 00000000..4cc0bd8d --- /dev/null +++ b/nymea-app/ui/connection/ConnectingPage.qml @@ -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() + } +} diff --git a/nymea-app/ui/connection/ManualConnectPage.qml b/nymea-app/ui/connection/ManualConnectPage.qml index 4c6d3c26..db1a04e4 100644 --- a/nymea-app/ui/connection/ManualConnectPage.qml +++ b/nymea-app/ui/connection/ManualConnectPage.qml @@ -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) + }) } } }