From bcbeb0cf974a0a4ea2841d5bb064edcf60e167c9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 11 Feb 2019 23:13:28 +0100 Subject: [PATCH] Fixes in new connection code. Demo server and manual connection work again --- .../configuration/nymeaconfiguration.cpp | 2 +- .../connection/discovery/nymeadiscovery.cpp | 6 +- .../connection/discovery/upnpdiscovery.cpp | 2 +- .../discovery/zeroconfdiscovery.cpp | 2 +- .../connection/nymeaconnection.cpp | 131 +++++++++++------- .../connection/nymeaconnection.h | 20 ++- libnymea-app-core/connection/nymeahost.cpp | 25 +++- libnymea-app-core/connection/nymeahost.h | 11 +- libnymea-app-core/connection/nymeahosts.cpp | 41 ++++-- libnymea-app-core/connection/nymeahosts.h | 5 +- libnymea-app-core/devicemanager.cpp | 2 - nymea-app/ui/RootItem.qml | 2 +- nymea-app/ui/SettingsPage.qml | 1 - nymea-app/ui/connection/ConnectPage.qml | 22 +-- nymea-app/ui/connection/ManualConnectPage.qml | 2 +- 15 files changed, 187 insertions(+), 87 deletions(-) diff --git a/libnymea-app-core/configuration/nymeaconfiguration.cpp b/libnymea-app-core/configuration/nymeaconfiguration.cpp index 71a3f176..5886b724 100644 --- a/libnymea-app-core/configuration/nymeaconfiguration.cpp +++ b/libnymea-app-core/configuration/nymeaconfiguration.cpp @@ -235,7 +235,7 @@ void NymeaConfiguration::getConfigurationsResponse(const QVariantMap ¶ms) tcpServerConfigurations()->clear(); foreach (const QVariant &tcpServerVariant, params.value("params").toMap().value("tcpServerConfigurations").toList()) { - qDebug() << "tcp server config:" << tcpServerVariant; +// qDebug() << "tcp server config:" << tcpServerVariant; QVariantMap tcpConfigMap = tcpServerVariant.toMap(); ServerConfiguration *config = new ServerConfiguration(tcpConfigMap.value("id").toString(), QHostAddress(tcpConfigMap.value("address").toString()), tcpConfigMap.value("port").toInt(), tcpConfigMap.value("authenticationEnabled").toBool(), tcpConfigMap.value("sslEnabled").toBool()); m_tcpServerConfigurations->addConfiguration(config); diff --git a/libnymea-app-core/connection/discovery/nymeadiscovery.cpp b/libnymea-app-core/connection/discovery/nymeadiscovery.cpp index 5dc0566f..274adb6b 100644 --- a/libnymea-app-core/connection/discovery/nymeadiscovery.cpp +++ b/libnymea-app-core/connection/discovery/nymeadiscovery.cpp @@ -124,10 +124,14 @@ void NymeaDiscovery::cacheHost(NymeaHost *host) if (remoteConnection) { connections.append(remoteConnection); } - Connection *lanConnection = host->connections()->bestMatch(Connection::BearerTypeWifi | Connection::BearerTypeEthernet); + Connection *lanConnection = host->connections()->bestMatch(Connection::BearerTypeLan); if (lanConnection) { connections.append(lanConnection); } + Connection *wanConnection = host->connections()->bestMatch(Connection::BearerTypeWan); + if (wanConnection) { + connections.append(wanConnection); + } Connection *btConnection = host->connections()->bestMatch(Connection::BearerTypeBluetooth); if (btConnection) { connections.append(btConnection); diff --git a/libnymea-app-core/connection/discovery/upnpdiscovery.cpp b/libnymea-app-core/connection/discovery/upnpdiscovery.cpp index 2853d363..90ef777e 100644 --- a/libnymea-app-core/connection/discovery/upnpdiscovery.cpp +++ b/libnymea-app-core/connection/discovery/upnpdiscovery.cpp @@ -254,7 +254,7 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply) qDebug() << "UPnP: Adding new connection to host:" << device->name() << url; bool sslEnabled = url.scheme() == "nymeas" || url.scheme() == "wss"; QString displayName = QString("%1:%2").arg(url.host()).arg(url.port()); - Connection *conn = new Connection(url, Connection::BearerTypeWifi, sslEnabled, displayName); + Connection *conn = new Connection(url, Connection::BearerTypeLan, sslEnabled, displayName); conn->setOnline(true); device->connections()->addConnection(conn); } diff --git a/libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp b/libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp index baaf3c8e..d30f1f46 100644 --- a/libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp +++ b/libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp @@ -126,7 +126,7 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry) if (!connection) { qDebug() << "Zeroconf: Adding new connection to host:" << host->name() << url.toString(); QString displayName = QString("%1:%2").arg(url.host()).arg(url.port()); - connection = new Connection(url, Connection::BearerTypeWifi, sslEnabled, displayName); + connection = new Connection(url, Connection::BearerTypeLan, sslEnabled, displayName); connection->setOnline(true); host->connections()->addConnection(connection); } else { diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app-core/connection/nymeaconnection.cpp index fbc87a87..730cc100 100644 --- a/libnymea-app-core/connection/nymeaconnection.cpp +++ b/libnymea-app-core/connection/nymeaconnection.cpp @@ -19,10 +19,12 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent) m_networkConfigManager = new QNetworkConfigurationManager(this); QObject::connect(m_networkConfigManager, &QNetworkConfigurationManager::configurationAdded, this, [this](const QNetworkConfiguration &config){ + Q_UNUSED(config) // qDebug() << "Network configuration added:" << config.name() << config.bearerTypeName() << config.purpose(); updateActiveBearers(); }); QObject::connect(m_networkConfigManager, &QNetworkConfigurationManager::configurationRemoved, this, [this](const QNetworkConfiguration &config){ + Q_UNUSED(config) // qDebug() << "Network configuration removed:" << config.name() << config.bearerTypeName() << config.purpose(); updateActiveBearers(); }); @@ -56,7 +58,7 @@ bool NymeaConnection::isTrusted(const QString &url) return false; } -Connection::BearerTypes NymeaConnection::availableBearerTypes() const +NymeaConnection::BearerTypes NymeaConnection::availableBearerTypes() const { return m_availableBearerTypes; } @@ -97,19 +99,28 @@ void NymeaConnection::setCurrentHost(NymeaHost *host) m_currentHost = nullptr; } + m_currentHost = host; emit currentHostChanged(); + if (!m_currentHost) { + qDebug() << "No current host."; + return; + } + + qDebug() << "Nymea host is" << m_currentHost->name() << m_currentHost->uuid(); + m_connectionStatus = ConnectionStatusConnecting; emit connectionStatusChanged(); - if (m_currentHost) { - connectInternal(m_currentHost); - } + connectInternal(m_currentHost); } Connection *NymeaConnection::currentConnection() const { + qDebug() << "Current connection:" << m_currentHost << m_currentTransport << m_transportCandidates.count(); + qDebug() << m_transportCandidates.keys(); + qDebug() << m_transportCandidates.value(m_currentTransport); if (!m_currentHost || !m_currentTransport) { return nullptr; } @@ -258,8 +269,10 @@ void NymeaConnection::onError(QAbstractSocket::SocketError error) emit connectionStatusChanged(); if (m_connectionStatus != ConnectionStatusSslUntrusted) { - QTimer::singleShot(1000, m_currentHost, [this](){ - connectInternal(m_currentHost); + QTimer::singleShot(1000, this, [this](){ + if (m_currentHost) { + connectInternal(m_currentHost); + } }); } } @@ -344,6 +357,10 @@ void NymeaConnection::onDisconnected() emit connectedChanged(false); } + if (!m_currentTransport) { + return; + } + // Try to reconnect, only if we're not waiting for SSL certs to be trusted. if (m_connectionStatus != ConnectionStatusSslUntrusted) { connectInternal(m_currentHost); @@ -352,16 +369,18 @@ void NymeaConnection::onDisconnected() void NymeaConnection::updateActiveBearers() { - Connection::BearerTypes availableBearerTypes; + NymeaConnection::BearerTypes availableBearerTypes; QList configs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active); // qDebug() << "Network configuations:" << configs.count(); foreach (const QNetworkConfiguration &config, configs) { qDebug() << "Candidate network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName(); - // NOTE: iOS doesn't correctly report bearer types. It'll be Unknown all the time -// availableBearerTypes.setFlag(Connection::BearerTypeUnknown); - + // NOTE: iOS doesn't correctly report bearer types. It'll be Unknown all the time. Let's hardcode it to WiFi for that... +#if defined(Q_OS_IOS) + availableBearerTypes.setFlag(NymeaConnection::BearerTypeWiFi); +#else availableBearerTypes.setFlag(qBearerTypeToNymeaBearerType(config.bearerType())); +#endif } // qDebug() << "Available bearers:" << availableBearerTypes; if (m_availableBearerTypes != availableBearerTypes) { @@ -394,31 +413,6 @@ void NymeaConnection::updateActiveBearers() } -Connection::BearerType NymeaConnection::qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const -{ - switch (type) { - case QNetworkConfiguration::BearerWLAN: - return Connection::BearerTypeWifi; - case QNetworkConfiguration::BearerEthernet: - return Connection::BearerTypeEthernet; - case QNetworkConfiguration::Bearer2G: - case QNetworkConfiguration::BearerCDMA2000: - case QNetworkConfiguration::BearerWCDMA: - case QNetworkConfiguration::BearerHSPA: - case QNetworkConfiguration::BearerWiMAX: - case QNetworkConfiguration::BearerEVDO: - case QNetworkConfiguration::BearerLTE: - case QNetworkConfiguration::Bearer3G: - case QNetworkConfiguration::Bearer4G: - return Connection::BearerTypeCloud; - case QNetworkConfiguration::BearerBluetooth: - return Connection::BearerTypeBluetooth; - case QNetworkConfiguration::BearerUnknown: - return Connection::BearerTypeUnknown; - } - return Connection::BearerTypeNone; -} - bool NymeaConnection::storePem(const QUrl &host, const QByteArray &pem) { @@ -476,8 +470,9 @@ void NymeaConnection::connect(NymeaHost *nymeaHost, Connection *connection) void NymeaConnection::connectInternal(NymeaHost *host) { - if (m_availableBearerTypes == Connection::BearerTypeNone) { - qDebug() << "No available bearer. Not connecting... (" << m_availableBearerTypes << ")"; + qDebug() << "Connecting. Available bearer types:" << m_availableBearerTypes; + if (m_availableBearerTypes == NymeaConnection::BearerTypeNone) { + qDebug() << "No available bearer. Not connecting..."; m_connectionStatus = ConnectionStatusNoBearerAvailable; emit connectionStatusChanged(); return; @@ -489,23 +484,39 @@ void NymeaConnection::connectInternal(NymeaHost *host) return; } - if (m_availableBearerTypes.testFlag(Connection::BearerTypeWifi) || m_availableBearerTypes.testFlag(Connection::BearerTypeEthernet)) { - Connection* lanConnection = host->connections()->bestMatch(Connection::BearerTypeWifi | Connection::BearerTypeEthernet); + if (m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeWiFi) + || m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeEthernet)) { + Connection* lanConnection = host->connections()->bestMatch(Connection::BearerTypeLan | Connection::BearerTypeWan); if (lanConnection) { - qDebug() << "Best candidate LAN connection:" << lanConnection->url(); + qDebug() << "Best candidate LAN/WAN connection:" << lanConnection->url(); connectInternal(lanConnection); } else { - qDebug() << "No available LAN connection to" << host->name(); + qDebug() << "No available LAN/WAN connection to" << host->name(); + } + } else if (m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeMobileData)) { + Connection* wanConnection = host->connections()->bestMatch(Connection::BearerTypeWan); + if (wanConnection) { + qDebug() << "Best candidate WAN connection:" << wanConnection->url(); + connectInternal(wanConnection); + } else { + qDebug() << "No available WAN connection to" << host->name(); } } - Connection* wanConnection = host->connections()->bestMatch(Connection::BearerTypeCloud); - if (wanConnection) { - qDebug() << "Best candidate WAN connection:" << wanConnection->url(); - connectInternal(wanConnection); + Connection* cloudConnection = host->connections()->bestMatch(Connection::BearerTypeCloud); + if (cloudConnection) { + qDebug() << "Best candidate Cloud connection:" << cloudConnection->url(); + connectInternal(cloudConnection); } else { - qDebug() << "No available WAN connection to" << host->name(); + qDebug() << "No available Cloud connection to" << host->name(); } + + if (m_transportCandidates.isEmpty()) { + m_connectionStatus = ConnectionStatusNoBearerAvailable; + } else { + m_connectionStatus = ConnectionStatusConnecting; + } + emit connectionStatusChanged(); } bool NymeaConnection::connectInternal(Connection *connection) @@ -539,10 +550,36 @@ bool NymeaConnection::connectInternal(Connection *connection) } m_transportCandidates.insert(newTransport, connection); - qDebug() << "Connecting to:" << connection->url(); + qDebug() << "Connecting to:" << connection->url() << newTransport << m_transportCandidates.value(newTransport); return newTransport->connect(connection->url()); } +NymeaConnection::BearerType NymeaConnection::qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const +{ + switch (type) { + case QNetworkConfiguration::BearerUnknown: + return BearerTypeAll; + case QNetworkConfiguration::BearerEthernet: + return BearerTypeEthernet; + case QNetworkConfiguration::BearerWLAN: + return BearerTypeWiFi; + case QNetworkConfiguration::Bearer2G: + case QNetworkConfiguration::BearerCDMA2000: + case QNetworkConfiguration::BearerWCDMA: + case QNetworkConfiguration::BearerHSPA: + case QNetworkConfiguration::BearerWiMAX: + case QNetworkConfiguration::BearerEVDO: + case QNetworkConfiguration::BearerLTE: + case QNetworkConfiguration::Bearer3G: + case QNetworkConfiguration::Bearer4G: + return BearerTypeMobileData; + case QNetworkConfiguration::BearerBluetooth: + // Note: Do not confuse this with the Bluetooth transport... For Qt, this means IP over BT, not RFCOMM as we do it. + return BearerTypeNone; + } + return BearerTypeAll; +} + void NymeaConnection::disconnect() { setCurrentHost(nullptr); diff --git a/libnymea-app-core/connection/nymeaconnection.h b/libnymea-app-core/connection/nymeaconnection.h index ad7c69a3..e5718a94 100644 --- a/libnymea-app-core/connection/nymeaconnection.h +++ b/libnymea-app-core/connection/nymeaconnection.h @@ -20,10 +20,22 @@ class NymeaConnection : public QObject Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY(NymeaHost* currentHost READ currentHost WRITE setCurrentHost NOTIFY currentHostChanged) Q_PROPERTY(Connection* currentConnection READ currentConnection NOTIFY currentConnectionChanged) - Q_PROPERTY(Connection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged) + Q_PROPERTY(NymeaConnection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged) Q_PROPERTY(ConnectionStatus connectionStatus READ connectionStatus NOTIFY connectionStatusChanged) public: + enum BearerType { + BearerTypeNone = 0x0, + BearerTypeEthernet = 0x1, + BearerTypeWiFi = 0x2, + BearerTypeMobileData = 0x4, + BearerTypeBluetooth = 0x8, + BearerTypeAll = 0xF + }; + Q_ENUM(BearerType) + Q_DECLARE_FLAGS(BearerTypes, BearerType) + Q_FLAG(BearerTypes) + enum ConnectionStatus { ConnectionStatusUnconnected, ConnectionStatusConnecting, @@ -48,7 +60,7 @@ public: Q_INVOKABLE void acceptCertificate(const QString &url, const QByteArray &pem); Q_INVOKABLE bool isTrusted(const QString &url); - Connection::BearerTypes availableBearerTypes() const; + NymeaConnection::BearerTypes availableBearerTypes() const; bool connected(); ConnectionStatus connectionStatus() const; @@ -84,12 +96,12 @@ private: void connectInternal(NymeaHost *host); bool connectInternal(Connection *connection); - Connection::BearerType qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const; + NymeaConnection::BearerType qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const; private: ConnectionStatus m_connectionStatus = ConnectionStatusUnconnected; QNetworkConfigurationManager *m_networkConfigManager = nullptr; - Connection::BearerTypes m_availableBearerTypes = Connection::BearerTypeNone; + NymeaConnection::BearerTypes m_availableBearerTypes = BearerTypeNone; QHash m_transportFactories; QHash m_transportCandidates; diff --git a/libnymea-app-core/connection/nymeahost.cpp b/libnymea-app-core/connection/nymeahost.cpp index 3e59ed3a..66015823 100644 --- a/libnymea-app-core/connection/nymeahost.cpp +++ b/libnymea-app-core/connection/nymeahost.cpp @@ -37,6 +37,11 @@ NymeaHost::NymeaHost(QObject *parent): }); } +NymeaHost::~NymeaHost() +{ + qDebug() << "Deleting host:" << this << m_name; +} + QUuid NymeaHost::uuid() const { return m_uuid; @@ -84,6 +89,11 @@ Connections::Connections(QObject *parent): } +Connections::~Connections() +{ + qDebug() << "Deleting connections" << this; +} + int Connections::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) @@ -172,7 +182,7 @@ Connection *Connections::bestMatch(Connection::BearerTypes bearerTypes) const { Connection *best = nullptr; foreach (Connection *c, m_connections) { -// qDebug() << "have connection:" << bearerTypes << c->url() << bearerTypes.testFlag(c->bearerType()); + qDebug() << "have connection:" << bearerTypes << c->url() << c->bearerType() << bearerTypes.testFlag(c->bearerType()); if ((bearerTypes & c->bearerType()) == Connection::BearerTypeNone) { continue; } @@ -208,6 +218,11 @@ Connection::Connection(const QUrl &url, Connection::BearerType bearerType, bool } +Connection::~Connection() +{ + qDebug() << "Deleting Connection" << this << parent() << parent()->parent(); +} + QUrl Connection::url() const { return m_url; @@ -250,16 +265,16 @@ int Connection::priority() const } switch(m_bearerType) { - case BearerTypeEthernet: + case BearerTypeLan: prio += 400; break; - case BearerTypeWifi: + case BearerTypeWan: prio += 300; break; - case BearerTypeBluetooth: + case BearerTypeCloud: prio += 200; break; - case BearerTypeCloud: + case BearerTypeBluetooth: prio += 100; break; default: diff --git a/libnymea-app-core/connection/nymeahost.h b/libnymea-app-core/connection/nymeahost.h index 1f62a336..8f3b43bf 100644 --- a/libnymea-app-core/connection/nymeahost.h +++ b/libnymea-app-core/connection/nymeahost.h @@ -41,10 +41,10 @@ class Connection: public QObject { public: enum BearerType { BearerTypeNone = 0x00, - BearerTypeWifi = 0x01, - BearerTypeEthernet = 0x02, - BearerTypeBluetooth = 0x04, - BearerTypeCloud = 0x08, + BearerTypeLan = 0x01, + BearerTypeWan = 0x02, + BearerTypeCloud = 0x04, + BearerTypeBluetooth = 0x08, BearerTypeUnknown = 0xFF, BearerTypeAll = 0xFF }; @@ -52,6 +52,7 @@ public: Q_DECLARE_FLAGS(BearerTypes, BearerType) Connection(const QUrl &url, BearerType bearerType, bool secure, const QString &displayName, QObject *parent = nullptr); + ~Connection(); QUrl url() const; BearerType bearerType() const; @@ -87,6 +88,7 @@ public: }; Q_ENUM(Roles) Connections(QObject* parent = nullptr); + ~Connections() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; @@ -121,6 +123,7 @@ class NymeaHost: public QObject public: explicit NymeaHost(QObject *parent = nullptr); + ~NymeaHost(); QUuid uuid() const; void setUuid(const QUuid &uuid); diff --git a/libnymea-app-core/connection/nymeahosts.cpp b/libnymea-app-core/connection/nymeahosts.cpp index 9793eefd..aae35377 100644 --- a/libnymea-app-core/connection/nymeahosts.cpp +++ b/libnymea-app-core/connection/nymeahosts.cpp @@ -84,11 +84,27 @@ void NymeaHosts::removeHost(NymeaHost *host) emit countChanged(); } +NymeaHost *NymeaHosts::createCloudHost(const QString &name, const QUrl &url) +{ + return createHost(name, url, Connection::BearerTypeCloud); +} + +NymeaHost *NymeaHosts::createLanHost(const QString &name, const QUrl &url) +{ + return createHost(name, url, Connection::BearerTypeLan); +} + +NymeaHost *NymeaHosts::createWanHost(const QString &name, const QUrl &url) +{ + return createHost(name, url, Connection::BearerTypeWan); +} + NymeaHost *NymeaHosts::createHost(const QString &name, const QUrl &url, Connection::BearerType bearerType) { NymeaHost *host = new NymeaHost(this); host->setName(name); Connection *connection = new Connection(url, bearerType, false, url.toString(), host); + connection->setOnline(true); host->connections()->addConnection(connection); addHost(host); return host; @@ -208,16 +224,25 @@ bool NymeaHostsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s for (int i = 0; i < host->connections()->rowCount(); i++) { // qDebug() << "checking host for available bearer" << host->name() << host->connections()->get(i)->url() << "available bearer types:" << m_nymeaConnection->availableBearerTypes() << "hosts bearer types" << host->connections()->get(i)->bearerType(); // Either enable a connection when the Bearer type is directly available - if (m_nymeaConnection->availableBearerTypes().testFlag(host->connections()->get(i)->bearerType())) { + switch (host->connections()->get(i)->bearerType()) { + case Connection::BearerTypeLan: + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); + break; + case Connection::BearerTypeWan: + case Connection::BearerTypeCloud: + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeEthernet); + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeWiFi); + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeMobileData); + break; + case Connection::BearerTypeBluetooth: + hasReachableConnection |= m_nymeaConnection->availableBearerTypes().testFlag(NymeaConnection::BearerTypeBluetooth); + break; + case Connection::BearerTypeUnknown: hasReachableConnection = true; break; - } - // or enable it if it is Cloud and we have access to LAN or WIFI - if (host->connections()->get(i)->bearerType() == Connection::BearerTypeCloud) { - if (m_nymeaConnection->availableBearerTypes().testFlag(Connection::BearerTypeWifi) || m_nymeaConnection->availableBearerTypes().testFlag(Connection::BearerTypeEthernet)) { - hasReachableConnection = true; - break; - } + case Connection::BearerTypeNone: + break; } } if (!hasReachableConnection) { diff --git a/libnymea-app-core/connection/nymeahosts.h b/libnymea-app-core/connection/nymeahosts.h index f92848c3..01578d86 100644 --- a/libnymea-app-core/connection/nymeahosts.h +++ b/libnymea-app-core/connection/nymeahosts.h @@ -49,7 +49,10 @@ public: void addHost(NymeaHost *host); void removeHost(NymeaHost *host); - Q_INVOKABLE NymeaHost* createHost(const QString &name, const QUrl &url, Connection::BearerType bearerType); + Q_INVOKABLE NymeaHost* createLanHost(const QString &name, const QUrl &url); + Q_INVOKABLE NymeaHost* createWanHost(const QString &name, const QUrl &url); + Q_INVOKABLE NymeaHost* createCloudHost(const QString &name, const QUrl &url); + NymeaHost* createHost(const QString &name, const QUrl &url, Connection::BearerType bearerType); Q_INVOKABLE NymeaHost *get(int index) const; Q_INVOKABLE NymeaHost *find(const QUuid &uuid); diff --git a/libnymea-app-core/devicemanager.cpp b/libnymea-app-core/devicemanager.cpp index 1ce074bd..58e41e52 100644 --- a/libnymea-app-core/devicemanager.cpp +++ b/libnymea-app-core/devicemanager.cpp @@ -149,8 +149,6 @@ void DeviceManager::getVendorsResponse(const QVariantMap ¶ms) } } - qDebug() << "start getting deviceClass at" << QDateTime::currentDateTime(); - m_jsonClient->sendCommand("Devices.GetSupportedDevices", this, "getSupportedDevicesResponse"); } diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index c70a0dda..50ed578f 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -98,7 +98,7 @@ Item { } Binding { - target: discovey + target: _discovey property: "discovering" when: engine.connection.currentHost === null value: true diff --git a/nymea-app/ui/SettingsPage.qml b/nymea-app/ui/SettingsPage.qml index 5dcdf8e2..df0dbc7f 100644 --- a/nymea-app/ui/SettingsPage.qml +++ b/nymea-app/ui/SettingsPage.qml @@ -178,5 +178,4 @@ Page { } } } - } diff --git a/nymea-app/ui/connection/ConnectPage.qml b/nymea-app/ui/connection/ConnectPage.qml index 19f11b58..38772482 100644 --- a/nymea-app/ui/connection/ConnectPage.qml +++ b/nymea-app/ui/connection/ConnectPage.qml @@ -60,7 +60,7 @@ Page { } onClicked: { if (index === 2) { - var host = discovery.nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222", Connection.BearerTypeCloud) + var host = discovery.nymeaHosts.createWanHost("Demo server", "nymea://nymea.nymea.io:2222") engine.connection.connect(host) } else { pageStack.push(model.get(index).page, {nymeaDiscovery: discovery}); @@ -144,10 +144,12 @@ Page { iconName: { switch (nymeaHost.connections.get(defaultConnectionIndex).bearerType) { - case Connection.BearerTypeWifi: + case Connection.BearerTypeLan: + case Connection.BearerTypeWan: + if (engine.connection.availableBearerTypes & NymeaConnection.BearerTypeEthernet != NymeaConnection.BearerTypeNone) { + return "../images/network-wired-symbolic.svg" + } return "../images/network-wifi-symbolic.svg"; - case Connection.BearerTypeEthernet: - return "../images/network-wired-symbolic.svg" case Connection.BearerTypeBluetooth: return "../images/bluetooth.svg"; case Connection.BearerTypeCloud: @@ -163,7 +165,7 @@ Page { progressive: false property bool isSecure: nymeaHost.connections.get(defaultConnectionIndex).secure property bool isTrusted: engine.connection.isTrusted(nymeaHostDelegate.nymeaHost.connections.get(defaultConnectionIndex).url) - property bool isOnline: nymeaHost.connections.get(defaultConnectionIndex).online + property bool isOnline: nymeaHost.connections.get(defaultConnectionIndex).bearerType !== Connection.BearerTypeWan ? nymeaHost.connections.get(defaultConnectionIndex).online : true tertiaryIconName: isSecure ? "../images/network-secure.svg" : "" tertiaryIconColor: isTrusted ? app.accentColor : Material.foreground secondaryIconName: !isOnline ? "../images/cloud-error.svg" : "" @@ -246,7 +248,7 @@ Page { visible: discovery.nymeaHosts.count === 0 text: qsTr("Demo mode (online)") onClicked: { - var host = nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222", Connection.BearerTypeCloud) + var host = nymeaHosts.createWanHost("Demo server", "nymea://nymea.nymea.io:2222") engine.connection.connect(host) } } @@ -363,10 +365,12 @@ Page { prominentSubText: false iconName: { switch (model.bearerType) { - case Connection.BearerTypeWifi: + case Connection.BearerTypeLan: + case Connection.BearerTypeWan: + if (engine.connection.availableBearerTypes & NymeaConnection.BearerTypeEthernet != NymeaConnection.BearerTypeNone) { + return "../images/network-wired-symbolic.svg" + } return "../images/network-wifi-symbolic.svg"; - case Connection.BearerTypeEthernet: - return "../images/network-wired-symbolic.svg" case Connection.BearerTypeBluetooth: return "../images/bluetooth.svg"; case Connection.BearerTypeCloud: diff --git a/nymea-app/ui/connection/ManualConnectPage.qml b/nymea-app/ui/connection/ManualConnectPage.qml index adea028e..d9492811 100644 --- a/nymea-app/ui/connection/ManualConnectPage.qml +++ b/nymea-app/ui/connection/ManualConnectPage.qml @@ -96,7 +96,7 @@ Page { } print("Try to connect ", rpcUrl) - var host = discovery.nymeaHosts.createHost("Manual connection", rpcUrl, Connection.BearerTypeCloud); + var host = discovery.nymeaHosts.createLanHost("Manual connection", rpcUrl); engine.connection.connect(host) } }