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>
This commit is contained in:
Jan Mulder 2017-06-10 10:09:56 +02:00 committed by Dirk Hohndel
parent c7a3509800
commit 790c0dcfc8
5 changed files with 75 additions and 21 deletions

View file

@ -242,39 +242,76 @@ device_data_t* DCDeviceData::internalData()
return &data;
}
int DCDeviceData::getDetectedVendorIndex()
int DCDeviceData::getDetectedVendorIndex(const QString &currentText)
{
#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 &currentVendorText,
const QString &currentProductText)
{
#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 &currentVendorText,
const QString &currentProductText)
{
#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
}