summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-06-05 19:41:57 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-06-11 13:55:41 -0700
commitb14a522f4f308aed41ab49b5529cc10c05168716 (patch)
tree2b3540e4aeefbe9c21ab9d3af1af2b07a4f503e0 /mobile-widgets/qmlmanager.cpp
parent3b993fbaad0738efe54e797b60e4f49270951323 (diff)
downloadsubsurface-b14a522f4f308aed41ab49b5529cc10c05168716.tar.gz
QML UI: move BT handling into core code
This shouldn't be part of the UI (qmlmanager), but part of our overall handling of dive computers and BT devices. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp168
1 files changed, 3 insertions, 165 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 856dec03b..96bdab51e 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -94,28 +94,9 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
alreadySaving(false)
{
#if defined(BT_SUPPORT)
- if (localBtDevice.isValid() &&
- localBtDevice.hostMode() == QBluetoothLocalDevice::HostConnectable) {
- btPairedDevices.clear();
- QString localDeviceName = "localDevice " + localBtDevice.name() + " is valid, starting discovery";
- appendTextToLog(localDeviceName.toUtf8().data());
-#if defined(Q_OS_LINUX)
- discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
- connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &QMLManager::btDeviceDiscovered);
- discoveryAgent->start();
-#endif
-#if defined(Q_OS_ANDROID)
- getBluetoothDevices();
-#endif
- for (int i = 0; i < btPairedDevices.length(); i++) {
- qDebug() << "Paired =" << btPairedDevices[i].name << btPairedDevices[i].address.toString();
- }
-#if defined(Q_OS_LINUX)
- discoveryAgent->stop();
-#endif
- } else {
- appendTextToLog("localBtDevice isn't valid");
- }
+ // ensure that we start the BTDiscovery - this should be triggered by the export of the class
+ // to QML, but that doesn't seem to always work
+ BTDiscovery *btDiscovery = BTDiscovery::instance();
#endif
m_instance = this;
m_lastDevicePixelRatio = qApp->devicePixelRatio();
@@ -217,78 +198,6 @@ void QMLManager::mergeLocalRepo()
process_dives(true, false);
}
-#if defined(BT_SUPPORT)
-
-extern void addBtUuid(QBluetoothUuid uuid);
-
-void QMLManager::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
-{
- btPairedDevice this_d;
- this_d.address = device.address();
- this_d.name = device.name();
- btPairedDevices.append(this_d);
-
- QString newDevice = device.name();
-
- // all the HW OSTC BT computers show up as "OSTC" + some other text, depending on model
- if (newDevice.startsWith("OSTC"))
- newDevice = "OSTC 3";
- QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
- foreach (QBluetoothUuid id, serviceUuids) {
- addBtUuid(id);
- qDebug() << id.toByteArray();
- }
- appendTextToLog("Found new device " + newDevice + " (" + device.address().toString() + ")");
- QString vendor, product;
- foreach (vendor, productList.keys()) {
- if (productList[vendor].contains(newDevice)) {
- appendTextToLog("this could be a " + vendor + " " +
- (newDevice == "OSTC 3" ? "OSTC family" : newDevice));
- struct btVendorProduct btVP;
- btVP.btdi = device;
- btVP.vendorIdx = vendorList.indexOf(vendor);
- btVP.productIdx = productList[vendor].indexOf(newDevice);
- qDebug() << "adding new btDCs entry" << newDevice << btVP.vendorIdx << btVP.productIdx;
- btDCs << btVP;
- }
- }
-}
-#endif
-
-int QMLManager::getVendorIndex()
-{
-#if defined(BT_SUPPORT)
- if (!btDCs.isEmpty()) {
- qDebug() << "getVendorIdx" << btDCs.first().vendorIdx;
- return btDCs.first().vendorIdx;
- }
-#endif
- return -1;
-}
-
-int QMLManager::getProductIndex()
-{
-#if defined(BT_SUPPORT)
- if (!btDCs.isEmpty()) {
- qDebug() << "getProductIdx" << btDCs.first().productIdx;
- return btDCs.first().productIdx;
- }
-#endif
- return -1;
-}
-
-QString QMLManager::getBtAddress()
-{
-#if BT_SUPPORT
- if (!btDCs.isEmpty()) {
- QString btAddr = btDCs.first().btdi.address().toString();
- qDebug() << "getBtAddress" << btAddr;
- return btAddr;
- }
- return QString();
-#endif
-}
-
void QMLManager::finishSetup()
{
// Initialize cloud credentials.
@@ -1611,74 +1520,3 @@ void QMLManager::setShowPin(bool enable)
m_showPin = enable;
emit showPinChanged();
}
-
-QStringList QMLManager::getDCListFromVendor(const QString& vendor)
-{
- return productList[vendor];
-}
-
-// Android: As Qt is not able to pull the pairing data from a device, i
-// a lengthy discovery process is needed to see what devices are paired. On
-// https://forum.qt.io/topic/46075/solved-bluetooth-list-paired-devices
-// user s.frings74 does, however, present a solution to this using JNI.
-// Currently, this code is taken "as is".
-
-void QMLManager::getBluetoothDevices()
-{
-#if defined(Q_OS_ANDROID) && defined(BT_SUPPORT)
- struct QMLManager::btPairedDevice result;
- // Query via Android Java API.
-
- // returns a BluetoothAdapter
- QAndroidJniObject adapter=QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter","getDefaultAdapter","()Landroid/bluetooth/BluetoothAdapter;");
- if (checkException("BluetoothAdapter.getDefaultAdapter()", &adapter)) {
- return;
- }
- // returns a Set<BluetoothDevice>
- QAndroidJniObject pairedDevicesSet=adapter.callObjectMethod("getBondedDevices","()Ljava/util/Set;");
- if (checkException("BluetoothAdapter.getBondedDevices()", &pairedDevicesSet)) {
- return;
- }
- jint size=pairedDevicesSet.callMethod<jint>("size");
- checkException("Set<BluetoothDevice>.size()", &pairedDevicesSet);
- if (size > 0) {
- // returns an Iterator<BluetoothDevice>
- QAndroidJniObject iterator=pairedDevicesSet.callObjectMethod("iterator","()Ljava/util/Iterator;");
- if (checkException("Set<BluetoothDevice>.iterator()", &iterator)) {
- return;
- }
- for (int i = 0; i < size; i++) {
- // returns a BluetoothDevice
- QAndroidJniObject dev=iterator.callObjectMethod("next","()Ljava/lang/Object;");
- if (checkException("Iterator<BluetoothDevice>.next()", &dev)) {
- continue;
- }
-
- result.address = QBluetoothAddress(dev.callObjectMethod("getAddress","()Ljava/lang/String;").toString());
- result.name = dev.callObjectMethod("getName", "()Ljava/lang/String;").toString();
-
- btPairedDevices.append(result);
- }
-}
-#endif
-}
-
-#if defined(Q_OS_ANDROID)
-bool QMLManager::checkException(const char* method, const QAndroidJniObject *obj)
-{
- static QAndroidJniEnvironment env;
- bool result = false;
-
- if (env->ExceptionCheck()) {
- qCritical("Exception in %s", method);
- env->ExceptionDescribe();
- env->ExceptionClear();
- result=true;
- }
- if (!(obj == NULL || obj->isValid())) {
- qCritical("Invalid object returned by %s", method);
- result=true;
- }
- return result;
-}
-#endif