mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-29 05:30:41 +00:00
Merge branch 'dynamic-bt' of https://github.com/janmulder/subsurface
This commit is contained in:
commit
0039c61dce
9 changed files with 65 additions and 15 deletions
|
@ -60,6 +60,12 @@ BTDiscovery::BTDiscovery(QObject *parent)
|
||||||
}
|
}
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
#if defined(BT_SUPPORT)
|
#if defined(BT_SUPPORT)
|
||||||
|
BTDiscoveryReDiscover();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void BTDiscovery::BTDiscoveryReDiscover()
|
||||||
|
{
|
||||||
#if !defined(Q_OS_IOS)
|
#if !defined(Q_OS_IOS)
|
||||||
if (localBtDevice.isValid() &&
|
if (localBtDevice.isValid() &&
|
||||||
localBtDevice.hostMode() == QBluetoothLocalDevice::HostConnectable) {
|
localBtDevice.hostMode() == QBluetoothLocalDevice::HostConnectable) {
|
||||||
|
@ -100,7 +106,6 @@ BTDiscovery::BTDiscovery(QObject *parent)
|
||||||
m_btValid = false;
|
m_btValid = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BTDiscovery::~BTDiscovery()
|
BTDiscovery::~BTDiscovery()
|
||||||
|
|
|
@ -46,6 +46,8 @@ public:
|
||||||
void getBluetoothDevices();
|
void getBluetoothDevices();
|
||||||
#endif
|
#endif
|
||||||
QList<btVendorProduct> getBtDcs();
|
QList<btVendorProduct> getBtDcs();
|
||||||
|
QBluetoothLocalDevice localBtDevice;
|
||||||
|
void BTDiscoveryReDiscover();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static BTDiscovery *m_instance;
|
static BTDiscovery *m_instance;
|
||||||
|
@ -59,7 +61,6 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QList<struct btPairedDevice> btPairedDevices;
|
QList<struct btPairedDevice> btPairedDevices;
|
||||||
QBluetoothLocalDevice localBtDevice;
|
|
||||||
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
|
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -42,3 +42,10 @@ void ConnectionListModel::addAddress(const QString address)
|
||||||
m_addresses.append(address);
|
m_addresses.append(address);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionListModel::removeAllAddresses()
|
||||||
|
{
|
||||||
|
beginRemoveRows(QModelIndex(), 0, rowCount());
|
||||||
|
m_addresses.clear();
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
QString address(int idx) const;
|
QString address(int idx) const;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
void addAddress(const QString address);
|
void addAddress(const QString address);
|
||||||
|
void removeAllAddresses();
|
||||||
private:
|
private:
|
||||||
QStringList m_addresses;
|
QStringList m_addresses;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@ void init_ui();
|
||||||
|
|
||||||
void run_ui();
|
void run_ui();
|
||||||
void exit_ui();
|
void exit_ui();
|
||||||
|
void set_non_bt_addresses();
|
||||||
|
|
||||||
#if defined(SUBSURFACE_MOBILE)
|
#if defined(SUBSURFACE_MOBILE)
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
|
@ -17,8 +17,8 @@ Kirigami.Page {
|
||||||
|
|
||||||
property alias dcImportModel: importModel
|
property alias dcImportModel: importModel
|
||||||
property bool divesDownloaded: false
|
property bool divesDownloaded: false
|
||||||
property bool btEnabled: manager.btEnabled()
|
property bool btEnabled: manager.btEnabled
|
||||||
property string btMessage: manager.btEnabled() ? "" : qsTr("Bluetooth is not enabled")
|
property string btMessage: manager.btEnabled ? "" : qsTr("Bluetooth is not enabled")
|
||||||
|
|
||||||
DCDownloadThread {
|
DCDownloadThread {
|
||||||
id: downloadThread
|
id: downloadThread
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QBluetoothLocalDevice>
|
||||||
|
|
||||||
#include "qt-models/divelistmodel.h"
|
#include "qt-models/divelistmodel.h"
|
||||||
#include "qt-models/gpslistmodel.h"
|
#include "qt-models/gpslistmodel.h"
|
||||||
|
@ -77,6 +78,23 @@ extern "C" int gitProgressCB(const char *text)
|
||||||
return 0;
|
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),
|
QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
||||||
m_verboseEnabled(false),
|
m_verboseEnabled(false),
|
||||||
reply(0),
|
reply(0),
|
||||||
|
@ -117,6 +135,8 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
||||||
// to QML, but that doesn't seem to always work
|
// to QML, but that doesn't seem to always work
|
||||||
BTDiscovery *btDiscovery = BTDiscovery::instance();
|
BTDiscovery *btDiscovery = BTDiscovery::instance();
|
||||||
m_btEnabled = btDiscovery->btAvailable();
|
m_btEnabled = btDiscovery->btAvailable();
|
||||||
|
connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged,
|
||||||
|
this, &QMLManager::btHostModeChange);
|
||||||
#else
|
#else
|
||||||
m_btEnabled = false;
|
m_btEnabled = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1659,6 +1679,11 @@ bool QMLManager::btEnabled() const
|
||||||
return m_btEnabled;
|
return m_btEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QMLManager::setBtEnabled(bool value)
|
||||||
|
{
|
||||||
|
m_btEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined (Q_OS_ANDROID)
|
#if defined (Q_OS_ANDROID)
|
||||||
|
|
||||||
void writeToAppLogFile(QString logText)
|
void writeToAppLogFile(QString logText)
|
||||||
|
|
|
@ -45,6 +45,7 @@ class QMLManager : public QObject {
|
||||||
Q_PROPERTY(QString progressMessage READ progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
|
Q_PROPERTY(QString progressMessage READ progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
|
||||||
Q_PROPERTY(bool libdcLog READ libdcLog WRITE setLibdcLog NOTIFY libdcLogChanged)
|
Q_PROPERTY(bool libdcLog READ libdcLog WRITE setLibdcLog NOTIFY libdcLogChanged)
|
||||||
Q_PROPERTY(bool developer READ developer WRITE setDeveloper NOTIFY developerChanged)
|
Q_PROPERTY(bool developer READ developer WRITE setDeveloper NOTIFY developerChanged)
|
||||||
|
Q_PROPERTY(bool btEnabled READ btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QMLManager();
|
QMLManager();
|
||||||
|
@ -124,6 +125,9 @@ public:
|
||||||
bool developer() const;
|
bool developer() const;
|
||||||
void setDeveloper(bool value);
|
void setDeveloper(bool value);
|
||||||
|
|
||||||
|
bool btEnabled() const;
|
||||||
|
void setBtEnabled(bool value);
|
||||||
|
|
||||||
typedef void (QMLManager::*execute_function_type)();
|
typedef void (QMLManager::*execute_function_type)();
|
||||||
DiveListSortModel *dlSortModel;
|
DiveListSortModel *dlSortModel;
|
||||||
|
|
||||||
|
@ -134,7 +138,7 @@ public:
|
||||||
bool showPin() const;
|
bool showPin() const;
|
||||||
void setShowPin(bool enable);
|
void setShowPin(bool enable);
|
||||||
Q_INVOKABLE void setStatusbarColor(QColor color);
|
Q_INVOKABLE void setStatusbarColor(QColor color);
|
||||||
Q_INVOKABLE bool btEnabled() const;
|
void btHostModeChange(QBluetoothLocalDevice::HostMode state);
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
void writeToAppLogFile(QString logText);
|
void writeToAppLogFile(QString logText);
|
||||||
|
@ -258,6 +262,7 @@ signals:
|
||||||
void progressMessageChanged();
|
void progressMessageChanged();
|
||||||
void libdcLogChanged();
|
void libdcLogChanged();
|
||||||
void developerChanged();
|
void developerChanged();
|
||||||
|
void btEnabledChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,6 +30,19 @@
|
||||||
|
|
||||||
QObject *qqWindowObject = NULL;
|
QObject *qqWindowObject = NULL;
|
||||||
|
|
||||||
|
void set_non_bt_addresses() {
|
||||||
|
#if defined(Q_OS_ANDROID)
|
||||||
|
connectionListModel.addAddress("FTDI");
|
||||||
|
#elif defined(Q_OS_LINUX) // since this is in the else, it does NOT include Android
|
||||||
|
connectionListModel.addAddress("/dev/ttyS0");
|
||||||
|
connectionListModel.addAddress("/dev/ttyS1");
|
||||||
|
connectionListModel.addAddress("/dev/ttyS2");
|
||||||
|
connectionListModel.addAddress("/dev/ttyS3");
|
||||||
|
// this makes debugging so much easier - use the simulator
|
||||||
|
connectionListModel.addAddress("/tmp/ttyS1");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void init_ui()
|
void init_ui()
|
||||||
{
|
{
|
||||||
init_qt_late();
|
init_qt_late();
|
||||||
|
@ -76,16 +89,8 @@ void run_ui()
|
||||||
ctxt->setContextProperty("diveModel", sortModel);
|
ctxt->setContextProperty("diveModel", sortModel);
|
||||||
ctxt->setContextProperty("gpsModel", gpsSortModel);
|
ctxt->setContextProperty("gpsModel", gpsSortModel);
|
||||||
ctxt->setContextProperty("vendorList", vendorList);
|
ctxt->setContextProperty("vendorList", vendorList);
|
||||||
#if defined(Q_OS_ANDROID)
|
set_non_bt_addresses();
|
||||||
connectionListModel.addAddress("FTDI");
|
|
||||||
#elif defined(Q_OS_LINUX) // since this is in the else, it does NOT include Android
|
|
||||||
connectionListModel.addAddress("/dev/ttyS0");
|
|
||||||
connectionListModel.addAddress("/dev/ttyS1");
|
|
||||||
connectionListModel.addAddress("/dev/ttyS2");
|
|
||||||
connectionListModel.addAddress("/dev/ttyS3");
|
|
||||||
// this makes debugging so much easier - use the simulator
|
|
||||||
connectionListModel.addAddress("/tmp/ttyS1");
|
|
||||||
#endif
|
|
||||||
ctxt->setContextProperty("connectionListModel", &connectionListModel);
|
ctxt->setContextProperty("connectionListModel", &connectionListModel);
|
||||||
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
|
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue