Allow disabling individual discovery methods
Also don't actually start scanning the network while discovering is false so we have a chance to pop up the permission dialog beforehandpull/529/head
parent
c478310c52
commit
ed4e04cbd7
|
|
@ -48,13 +48,6 @@ NymeaDiscovery::NymeaDiscovery(QObject *parent) : QObject(parent)
|
|||
|
||||
loadFromDisk();
|
||||
|
||||
m_upnp = new UpnpDiscovery(m_nymeaHosts, this);
|
||||
m_zeroConf = new ZeroconfDiscovery(m_nymeaHosts, this);
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
m_bluetooth = new BluetoothServiceDiscovery(m_nymeaHosts, this);
|
||||
#endif
|
||||
|
||||
m_cloudPollTimer.setInterval(5000);
|
||||
connect(&m_cloudPollTimer, &QTimer::timeout, this, [this](){
|
||||
if (m_awsClient && m_awsClient->isLoggedIn()) {
|
||||
|
|
@ -80,13 +73,25 @@ void NymeaDiscovery::setDiscovering(bool discovering)
|
|||
|
||||
m_discovering = discovering;
|
||||
if (discovering) {
|
||||
// ZeroConf is always in discovery mode, nothing to do...
|
||||
if (m_zeroconfDiscoveryEnabled) {
|
||||
if (!m_zeroConf) {
|
||||
m_zeroConf = new ZeroconfDiscovery(m_nymeaHosts, this);
|
||||
}
|
||||
}
|
||||
|
||||
// Start UPnP discovery
|
||||
if (m_upnpDiscoveryEnabled) {
|
||||
if (!m_upnp) {
|
||||
m_upnp = new UpnpDiscovery(m_nymeaHosts, this);
|
||||
}
|
||||
m_upnp->discover();
|
||||
}
|
||||
|
||||
// Start Bluetooth discovery if HW is available
|
||||
if (m_bluetooth) {
|
||||
if (m_bluetoothDiscoveryEnabled) {
|
||||
if (!m_bluetooth) {
|
||||
m_bluetooth = new BluetoothServiceDiscovery(m_nymeaHosts, this);
|
||||
}
|
||||
m_bluetooth->discover();
|
||||
}
|
||||
|
||||
|
|
@ -97,10 +102,21 @@ void NymeaDiscovery::setDiscovering(bool discovering)
|
|||
m_awsClient->fetchDevices();
|
||||
}
|
||||
} else {
|
||||
if (m_zeroConf) {
|
||||
m_zeroConf->deleteLater();
|
||||
m_zeroConf = nullptr;
|
||||
}
|
||||
|
||||
if (m_upnp) {
|
||||
m_upnp->stopDiscovery();
|
||||
m_upnp->deleteLater();
|
||||
m_upnp = nullptr;
|
||||
}
|
||||
|
||||
if (m_bluetooth) {
|
||||
m_bluetooth->stopDiscovery();
|
||||
m_bluetooth->deleteLater();
|
||||
m_bluetooth = nullptr;
|
||||
}
|
||||
|
||||
m_cloudPollTimer.stop();
|
||||
|
|
@ -171,6 +187,45 @@ void NymeaDiscovery::cacheHost(NymeaHost *host)
|
|||
settings.endGroup();
|
||||
}
|
||||
|
||||
bool NymeaDiscovery::zeroconfDiscoveryEnable() const
|
||||
{
|
||||
return m_zeroconfDiscoveryEnabled;
|
||||
}
|
||||
|
||||
bool NymeaDiscovery::bluetoothDiscoveryEnabled() const
|
||||
{
|
||||
return m_bluetoothDiscoveryEnabled;
|
||||
}
|
||||
|
||||
bool NymeaDiscovery::upnpDiscoveryEnabled() const
|
||||
{
|
||||
return m_upnpDiscoveryEnabled;
|
||||
}
|
||||
|
||||
void NymeaDiscovery::setZeroconfDiscoveryEnabled(bool zeroconfDiscoveryEnabled)
|
||||
{
|
||||
if (m_zeroconfDiscoveryEnabled != zeroconfDiscoveryEnabled) {
|
||||
m_zeroconfDiscoveryEnabled = zeroconfDiscoveryEnabled;
|
||||
emit zeroconfDiscoveryEnabledChanged(m_zeroconfDiscoveryEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void NymeaDiscovery::setBluetoothDiscoveryEnabled(bool bluetoothDiscoveryEnabled)
|
||||
{
|
||||
if (m_bluetoothDiscoveryEnabled != bluetoothDiscoveryEnabled) {
|
||||
m_bluetoothDiscoveryEnabled = bluetoothDiscoveryEnabled;
|
||||
emit bluetoothDiscoveryEnabledChanged(m_bluetoothDiscoveryEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void NymeaDiscovery::setUpnpDiscoveryEnabled(bool upnpDiscoveryEnabled)
|
||||
{
|
||||
if (m_upnpDiscoveryEnabled != upnpDiscoveryEnabled) {
|
||||
m_upnpDiscoveryEnabled = upnpDiscoveryEnabled;
|
||||
emit upnpDiscoveryEnabledChanged(m_upnpDiscoveryEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void NymeaDiscovery::syncCloudDevices()
|
||||
{
|
||||
for (int i = 0; i < m_awsClient->awsDevices()->rowCount(); i++) {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@ class NymeaDiscovery : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool discovering READ discovering WRITE setDiscovering NOTIFY discoveringChanged)
|
||||
Q_PROPERTY(bool bluetoothDiscoveryEnabled READ bluetoothDiscoveryEnabled WRITE setBluetoothDiscoveryEnabled NOTIFY bluetoothDiscoveryEnabledChanged)
|
||||
Q_PROPERTY(bool zeroconfDiscoveryEnabled READ zeroconfDiscoveryEnable WRITE setZeroconfDiscoveryEnabled NOTIFY zeroconfDiscoveryEnabledChanged)
|
||||
Q_PROPERTY(bool upnpDiscoveryEnabled READ upnpDiscoveryEnabled WRITE setUpnpDiscoveryEnabled NOTIFY upnpDiscoveryEnabledChanged)
|
||||
|
||||
Q_PROPERTY(AWSClient* awsClient READ awsClient WRITE setAwsClient NOTIFY awsClientChanged)
|
||||
|
||||
Q_PROPERTY(NymeaHosts* nymeaHosts READ nymeaHosts CONSTANT)
|
||||
|
|
@ -66,12 +70,25 @@ public:
|
|||
|
||||
Q_INVOKABLE void cacheHost(NymeaHost* host);
|
||||
|
||||
bool zeroconfDiscoveryEnable() const;
|
||||
bool bluetoothDiscoveryEnabled() const;
|
||||
bool upnpDiscoveryEnabled() const;
|
||||
|
||||
public slots:
|
||||
void setZeroconfDiscoveryEnabled(bool zeroconfDiscoveryEnabled);
|
||||
void setBluetoothDiscoveryEnabled(bool bluetoothDiscoveryEnabled);
|
||||
void setUpnpDiscoveryEnabled(bool upnpDiscoveryEnabled);
|
||||
|
||||
signals:
|
||||
void discoveringChanged();
|
||||
void awsClientChanged();
|
||||
|
||||
void serverUuidResolved(const QUuid &uuid, const QString &url);
|
||||
|
||||
void zeroconfDiscoveryEnabledChanged(bool zeroconfDiscoveryEnabled);
|
||||
void bluetoothDiscoveryEnabledChanged(bool bluetoothDiscoveryEnabled);
|
||||
void upnpDiscoveryEnabledChanged(bool upnpDiscoveryEnabled);
|
||||
|
||||
private slots:
|
||||
void syncCloudDevices();
|
||||
|
||||
|
|
@ -93,6 +110,9 @@ private:
|
|||
|
||||
QList<QUuid> m_pendingHostResolutions;
|
||||
|
||||
bool m_zeroconfDiscoveryEnabled = true;
|
||||
bool m_bluetoothDiscoveryEnabled = true;
|
||||
bool m_upnpDiscoveryEnabled = true;
|
||||
};
|
||||
|
||||
#endif // NYMEADISCOVERY_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue