diff options
-rw-r--r-- | core/btdiscovery.cpp | 48 | ||||
-rw-r--r-- | core/btdiscovery.h | 20 | ||||
-rw-r--r-- | core/downloadfromdcthread.cpp | 22 | ||||
-rw-r--r-- | mobile-widgets/qml/DownloadFromDiveComputer.qml | 11 |
4 files changed, 62 insertions, 39 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 5a93174a6..2362c5b4b 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -52,6 +52,13 @@ BTDiscovery::BTDiscovery(QObject *parent) #endif #if defined(Q_OS_ANDROID) && defined(BT_SUPPORT) getBluetoothDevices(); + // and add the paired devices to the internal data + // So behaviour is same on Linux/Bluez stack and + // Android/Java stack with respect to discovery + for (int i = 0; i < btPairedDevices.length(); i++) { + btDeviceDiscoveredMain(btPairedDevices[i]); + + } #endif for (int i = 0; i < btPairedDevices.length(); i++) { qDebug() << "Paired =" << btPairedDevices[i].name << btPairedDevices[i].address.toString(); @@ -92,51 +99,58 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device) this_d.address = device.address(); this_d.name = device.name(); btPairedDevices.append(this_d); - struct btVendorProduct btVP; - - QString newDevice; - dc_descriptor_t *newDC = getDeviceType(device.name()); - if (newDC) - newDevice = dc_descriptor_get_product(newDC); - else - newDevice = device.name(); QList<QBluetoothUuid> serviceUuids = device.serviceUuids(); foreach (QBluetoothUuid id, serviceUuids) { addBtUuid(id); qDebug() << id.toByteArray(); } - qDebug() << "Found new device:" << newDevice << device.address(); + + btDeviceDiscoveredMain(this_d); +} + +void BTDiscovery::btDeviceDiscoveredMain(const btPairedDevice &device) +{ + btVendorProduct btVP; + + QString newDevice; + dc_descriptor_t *newDC = getDeviceType(device.name); + if (newDC) + newDevice = dc_descriptor_get_product(newDC); + else + newDevice = device.name; + + qDebug() << "Found new device:" << newDevice << device.address; QString vendor; if (newDC) foreach (vendor, productList.keys()) { if (productList[vendor].contains(newDevice)) { qDebug() << "this could be a " + vendor + " " + (newDevice == "OSTC 3" ? "OSTC family" : newDevice); - btVP.btdi = device; + btVP.btpdi = device; btVP.dcDescriptor = newDC; btVP.vendorIdx = vendorList.indexOf(vendor); btVP.productIdx = productList[vendor].indexOf(newDevice); - qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();; + qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;; btDCs << btVP; break; } } - productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")"); + productList[QObject::tr("Paired Bluetooth Devices")].append(device.name + " (" + device.address.toString() + ")"); - btVP.btdi = device; + btVP.btpdi = device; btVP.dcDescriptor = newDC; btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices")); - btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name); - qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address(); + btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(device.name); + qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address; btAllDevices << btVP; } -QList <struct btVendorProduct> BTDiscovery::getBtDcs() +QList<BTDiscovery::btVendorProduct> BTDiscovery::getBtDcs() { return btDCs; } -QList <struct btVendorProduct> BTDiscovery::getBtAllDevices() +QList <BTDiscovery::btVendorProduct> BTDiscovery::getBtAllDevices() { return btAllDevices; } diff --git a/core/btdiscovery.h b/core/btdiscovery.h index 301c4195d..72ed39a07 100644 --- a/core/btdiscovery.h +++ b/core/btdiscovery.h @@ -11,12 +11,7 @@ #include <QBluetoothUuid> #include "core/libdivecomputer.h" -struct btVendorProduct { - QBluetoothDeviceInfo btdi; - dc_descriptor_t *dcDescriptor; - int vendorIdx; - int productIdx; -}; + static dc_descriptor_t *getDeviceType(QString btName); @@ -39,12 +34,21 @@ public: QBluetoothAddress address; QString name; }; + + struct btVendorProduct { + btPairedDevice btpdi; + dc_descriptor_t *dcDescriptor; + int vendorIdx; + int productIdx; + }; + void btDeviceDiscovered(const QBluetoothDeviceInfo &device); + void btDeviceDiscoveredMain(const btPairedDevice &device); #if defined(Q_OS_ANDROID) void getBluetoothDevices(); #endif - QList<struct btVendorProduct> getBtDcs(); - QList<struct btVendorProduct> getBtAllDevices(); + QList<btVendorProduct> getBtDcs(); + QList<btVendorProduct> getBtAllDevices(); #endif private: static BTDiscovery *m_instance; diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index a98ab17b2..98130b730 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -245,8 +245,8 @@ device_data_t* DCDeviceData::internalData() int DCDeviceData::getDetectedVendorIndex(const QString ¤tText) { #if defined(BT_SUPPORT) - QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); + QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); + QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); // Pick the vendor of the first confirmed find of a DC (if any), but // only return a true vendor, and not our virtual one @@ -268,7 +268,7 @@ int DCDeviceData::getDetectedProductIndex(const QString ¤tVendorText, const QString ¤tProductText) { #if defined(BT_SUPPORT) - QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); + QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); // Display in the QML UI, the first found dive computer that is been // detected as a possible real dive computer (and not some other paired @@ -291,14 +291,14 @@ QString DCDeviceData::getDetectedDeviceAddress(const QString ¤tVendorText, const QString ¤tProductText) { #if defined(BT_SUPPORT) - QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); + QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); + QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); // Pull the BT address from the first found dive computer that is been // detected as a possible real dive computer (and not some other paired // BT device if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) { - QString btAddr = btDCs.first().btdi.address().toString(); + QString btAddr = btDCs.first().btpdi.address.toString(); qDebug() << "getDetectedDeviceAddress" << btAddr; return btAddr; } @@ -307,7 +307,7 @@ QString DCDeviceData::getDetectedDeviceAddress(const QString ¤tVendorText, // unsure being a dive computer if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) { int i = productList[currentVendorText].indexOf(currentProductText); - QString btAddr = btAllDevices[i].btdi.address().toString(); + QString btAddr = btAllDevices[i].btpdi.address.toString(); qDebug() << "getDetectedDeviceAddress" << btAddr; return btAddr; } @@ -319,8 +319,8 @@ QString DCDeviceData::getDeviceDescriptorVendor(const QString ¤tVendorText const QString ¤tProductText) { #if defined(BT_SUPPORT) - QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); + QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); + QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); // Pull the vendor from the first found dive computer that is been // detected as a possible real dive computer (and not some other paired @@ -347,8 +347,8 @@ QString DCDeviceData::getDeviceDescriptorProduct(const QString ¤tVendorTex const QString ¤tProductText) { #if defined(BT_SUPPORT) - QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); + QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); + QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); // Pull the product from the first found dive computer that is been // detected as a possible real dive computer (and not some other paired diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index 66504c866..05a549227 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -53,13 +53,14 @@ Kirigami.Page { GridLayout { columns: 2 Kirigami.Label { text: qsTr(" Vendor name: ") } + property var vendoridx: downloadThread.data().getDetectedVendorIndex("") ComboBox { id: comboVendor Layout.fillWidth: true model: vendorList - currentIndex: downloadThread.data().getDetectedVendorIndex(currentText) + currentIndex: parent.vendoridx onCurrentTextChanged: { - comboProduct.model = downloadThread.data().getProductListFromVendor(comboVendor.currentText) + comboProduct.model = downloadThread.data().getProductListFromVendor(currentText) if (currentIndex == downloadThread.data().getDetectedVendorIndex(currentText)) comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex(currentText, comboProduct.currentText) } @@ -67,9 +68,13 @@ Kirigami.Page { Kirigami.Label { text: qsTr(" Dive Computer:") } ComboBox { id: comboProduct + property var productidx: downloadThread.data().getDetectedProductIndex(comboVendor.currentText, currentText) Layout.fillWidth: true model: null - currentIndex: -1 + currentIndex: productidx + onModelChanged: { + currentIndex = productidx + } } Kirigami.Label { text: qsTr("Bluetooth download:") } CheckBox { |