bring back demo mode

This commit is contained in:
Michael Zanetti 2019-02-06 12:07:00 +01:00
parent f75b66c0ff
commit a2272f9699
5 changed files with 22 additions and 5 deletions

View File

@ -428,6 +428,8 @@ void NymeaConnection::connectInternal(NymeaHost *host)
if (lanConnection) {
qDebug() << "Best candidate LAN connection:" << lanConnection->url();
connectInternal(lanConnection);
} else {
qDebug() << "No available LAN connection to" << host->name();
}
}
@ -436,6 +438,8 @@ void NymeaConnection::connectInternal(NymeaHost *host)
if (wanConnection) {
qDebug() << "Best candidate WAN connection:" << wanConnection->url();
connectInternal(wanConnection);
} else {
qDebug() << "No available WAN connection to" << host->name();
}
}
}

View File

@ -170,12 +170,10 @@ Connection* Connections::get(int index) const
Connection *Connections::bestMatch(Connection::BearerTypes bearerTypes) const
{
QList<Connection::BearerType> bearerPreference = {Connection::BearerTypeEthernet, Connection::BearerTypeWifi, Connection::BearerTypeCloud, Connection::BearerTypeBluetooth, Connection::BearerTypeNone};
Connection *best = nullptr;
// qDebug() << "Bestmatch" << m_connections.count();
foreach (Connection *c, m_connections) {
// qDebug() << "have connection:" << bearerTypes << c->url() << bearerTypes.testFlag(c->bearerType());
if (!bearerTypes.testFlag(c->bearerType())) {
if ((bearerTypes & c->bearerType()) == Connection::BearerTypeNone) {
continue;
}
if (!best) {

View File

@ -22,6 +22,7 @@
#include "connection/discovery/nymeadiscovery.h"
#include "nymeahost.h"
#include "connection/nymeaconnection.h"
#include <QUuid>
NymeaHosts::NymeaHosts(QObject *parent) :
QAbstractListModel(parent)
@ -83,6 +84,17 @@ void NymeaHosts::removeHost(NymeaHost *host)
emit countChanged();
}
NymeaHost *NymeaHosts::createHost(const QString &name, const QUrl &url)
{
NymeaHost *host = new NymeaHost(this);
host->setUuid(QUuid::createUuid());
host->setName(name);
Connection *connection = new Connection(url, Connection::BearerTypeAll, false, url.toString(), host);
host->connections()->addConnection(connection);
addHost(host);
return host;
}
NymeaHost *NymeaHosts::get(int index) const
{
if (index < 0 || index >= m_hosts.count()) {

View File

@ -49,6 +49,7 @@ public:
void addHost(NymeaHost *host);
void removeHost(NymeaHost *host);
Q_INVOKABLE NymeaHost* createHost(const QString &name, const QUrl &url);
Q_INVOKABLE NymeaHost *get(int index) const;
Q_INVOKABLE NymeaHost *find(const QUuid &uuid);

View File

@ -60,7 +60,8 @@ Page {
}
onClicked: {
if (index === 2) {
root.connectToHost("nymea://nymea.nymea.io:2222")
var host = discovery.nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222")
engine.connection.connect(host)
} else {
pageStack.push(model.get(index).page, {nymeaDiscovery: discovery});
}
@ -266,7 +267,8 @@ Page {
visible: discovery.nymeaHosts.count === 0
text: qsTr("Demo mode (online)")
onClicked: {
root.connectToHost("nymea://nymea.nymea.io:2222")
var host = nymeaHosts.createHost("Demo server", "nymea://nymea.nymea.io:2222")
engine.connection.connect(host)
}
}