diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-06-10 10:09:56 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-06-12 09:55:27 -0700 |
commit | 790c0dcfc876d50b21791ad7b81f693796e2173b (patch) | |
tree | 3ab9032be99ca11d666eb4188fca05e950dbd579 /core/downloadfromdcthread.cpp | |
parent | c7a35098008b215b1cccad512c4c568cd618f2c6 (diff) | |
download | subsurface-790c0dcfc876d50b21791ad7b81f693796e2173b.tar.gz |
QML UI: add internal admin for virtual vendor
Added a list of paired BT devices for the "Paired BT Devices" vendor. The
devices under this vendor represent all BT devces that can be found
from the local BT interface. Some special processing is required, as
the BT provided data is (obviously) missing the specific data needed
to open a BT device using libdc code. This processing is not in
this commit, but will follow. This commit is preparation for that.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/downloadfromdcthread.cpp')
-rw-r--r-- | core/downloadfromdcthread.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 43bd1e0b8..64933b5bc 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -242,39 +242,76 @@ device_data_t* DCDeviceData::internalData() return &data; } -int DCDeviceData::getDetectedVendorIndex() +int DCDeviceData::getDetectedVendorIndex(const QString ¤tText) { #if defined(BT_SUPPORT) QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - if (!btDCs.isEmpty()) { - qDebug() << "getDetectedVendorIndex" << btDCs.first().vendorIdx; + QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices(); + + // Pick the vendor of the first confirmed find of a DC (if any), but + // only return a true vendow, and not our virtual one + if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) { + qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx; return btDCs.first().vendorIdx; } + + // When the above fails, just pick the (one and only) virtual vendor + if (!btAllDevices.isEmpty() && currentText == QObject::tr("Paired Bluetooth Devices")) { + qDebug() << "getDetectedVendorIndex" << currentText << btAllDevices.first().vendorIdx; + return btAllDevices.first().vendorIdx; + } #endif return -1; } -int DCDeviceData::getDetectedProductIndex() +int DCDeviceData::getDetectedProductIndex(const QString ¤tVendorText, + const QString ¤tProductText) { #if defined(BT_SUPPORT) QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - if (!btDCs.isEmpty()) { + + // 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 + // BT device + if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) { qDebug() << "getDetectedProductIndex" << btDCs.first().productIdx; return btDCs.first().productIdx; } + + // if the above fails, display the selected paired device + if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) { + qDebug() << "getDetectedProductIndex" << productList[currentVendorText].indexOf(currentProductText); + return productList[currentVendorText].indexOf(currentProductText); + } #endif return -1; } -QString DCDeviceData::getDetectedDeviceAddress() +QString DCDeviceData::getDetectedDeviceAddress(const QString ¤tVendorText, + const QString ¤tProductText) { -#if BT_SUPPORT +#if defined(BT_SUPPORT) QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); - if (!btDCs.isEmpty()) { + QList<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(); qDebug() << "getDetectedDeviceAddress" << btAddr; return btAddr; } + + // if the above fails, pull the BT address from the selected paired device + // 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(); + qDebug() << "getDetectedDeviceAddress" << btAddr; + return btAddr; + } + return QString(); #endif } |