mobile: enable switching BT on/off during session.

This commit implements possible switching BT on and off during a session,
so not needing a restart of the app when the user forgot to switch
it on when starting the app.

For this, the following needed to be done: 1) create a handler that
reacts on local BT device status changes. 2) repopulate the connection
list in the download screen when a BT status change is detected.

Notice the subtile change of the Q_INVOKABLE btEnabled() function
to a Q_PROPERTY. This gives a nice dynamic behaviour when
switching BT on/off with the app open.

Fixes: #556

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2017-10-12 09:43:40 +02:00
parent fa5e685279
commit ba4058667a
5 changed files with 41 additions and 5 deletions

View file

@ -12,6 +12,7 @@
#include <QElapsedTimer>
#include <QTimer>
#include <QDateTime>
#include <QBluetoothLocalDevice>
#include "qt-models/divelistmodel.h"
#include "qt-models/gpslistmodel.h"
@ -77,6 +78,23 @@ extern "C" int gitProgressCB(const char *text)
return 0;
}
void QMLManager::btHostModeChange(QBluetoothLocalDevice::HostMode state)
{
BTDiscovery *btDiscovery = BTDiscovery::instance();
qDebug() << "btHostModeChange to " << state;
if (state != QBluetoothLocalDevice::HostPoweredOff) {
connectionListModel.removeAllAddresses();
btDiscovery->BTDiscoveryReDiscover();
m_btEnabled = btDiscovery->btAvailable();
} else {
connectionListModel.removeAllAddresses();
set_non_bt_addresses();
m_btEnabled = false;
}
emit btEnabledChanged();
}
QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_verboseEnabled(false),
reply(0),
@ -117,6 +135,8 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
// to QML, but that doesn't seem to always work
BTDiscovery *btDiscovery = BTDiscovery::instance();
m_btEnabled = btDiscovery->btAvailable();
connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged,
this, &QMLManager::btHostModeChange);
#else
m_btEnabled = false;
#endif
@ -1659,6 +1679,11 @@ bool QMLManager::btEnabled() const
return m_btEnabled;
}
void QMLManager::setBtEnabled(bool value)
{
m_btEnabled = value;
}
#if defined (Q_OS_ANDROID)
void writeToAppLogFile(QString logText)