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

@ -66,6 +66,7 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
this_d.address = device.address(); this_d.address = device.address();
this_d.name = device.name(); this_d.name = device.name();
btPairedDevices.append(this_d); btPairedDevices.append(this_d);
struct btVendorProduct btVP;
QString newDevice = device.name(); QString newDevice = device.name();
@ -77,20 +78,27 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
addBtUuid(id); addBtUuid(id);
qDebug() << id.toByteArray(); qDebug() << id.toByteArray();
} }
qDebug() << "Found new device " + newDevice + " (" + device.address().toString() + ")"; qDebug() << "Found new device:" << newDevice << device.address();
QString vendor, product; QString vendor;
foreach (vendor, productList.keys()) { foreach (vendor, productList.keys()) {
if (productList[vendor].contains(newDevice)) { if (productList[vendor].contains(newDevice)) {
qDebug() << "this could be a " + vendor + " " + qDebug() << "this could be a " + vendor + " " +
(newDevice == "OSTC 3" ? "OSTC family" : newDevice); (newDevice == "OSTC 3" ? "OSTC family" : newDevice);
struct btVendorProduct btVP;
btVP.btdi = device; btVP.btdi = device;
btVP.vendorIdx = vendorList.indexOf(vendor); btVP.vendorIdx = vendorList.indexOf(vendor);
btVP.productIdx = productList[vendor].indexOf(newDevice); btVP.productIdx = productList[vendor].indexOf(newDevice);
qDebug() << "adding new btDCs entry" << newDevice << btVP.vendorIdx << btVP.productIdx; qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();;
btDCs << btVP; btDCs << btVP;
break;
} }
} }
productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name);
btVP.btdi = device;
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();
btAllDevices << btVP;
} }
QList <struct btVendorProduct> BTDiscovery::getBtDcs() QList <struct btVendorProduct> BTDiscovery::getBtDcs()
@ -98,6 +106,10 @@ QList <struct btVendorProduct> BTDiscovery::getBtDcs()
return btDCs; return btDCs;
} }
QList <struct btVendorProduct> BTDiscovery::getBtAllDevices()
{
return btAllDevices;
}
// Android: As Qt is not able to pull the pairing data from a device, i // 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 // a lengthy discovery process is needed to see what devices are paired. On

View file

@ -40,11 +40,13 @@ public:
void getBluetoothDevices(); void getBluetoothDevices();
#endif #endif
QList<struct btVendorProduct> getBtDcs(); QList<struct btVendorProduct> getBtDcs();
QList<struct btVendorProduct> getBtAllDevices();
#endif #endif
private: private:
static BTDiscovery *m_instance; static BTDiscovery *m_instance;
#if defined(BT_SUPPORT) #if defined(BT_SUPPORT)
QList<struct btVendorProduct> btDCs; QList<struct btVendorProduct> btDCs; // recognized DCs
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff
#endif #endif
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
bool checkException(const char* method, const QAndroidJniObject* obj); bool checkException(const char* method, const QAndroidJniObject* obj);

View file

@ -242,39 +242,76 @@ device_data_t* DCDeviceData::internalData()
return &data; return &data;
} }
int DCDeviceData::getDetectedVendorIndex() int DCDeviceData::getDetectedVendorIndex(const QString &currentText)
{ {
#if defined(BT_SUPPORT) #if defined(BT_SUPPORT)
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
if (!btDCs.isEmpty()) { QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
qDebug() << "getDetectedVendorIndex" << btDCs.first().vendorIdx;
// 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; 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 #endif
return -1; return -1;
} }
int DCDeviceData::getDetectedProductIndex() int DCDeviceData::getDetectedProductIndex(const QString &currentVendorText,
const QString &currentProductText)
{ {
#if defined(BT_SUPPORT) #if defined(BT_SUPPORT)
QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs(); 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; qDebug() << "getDetectedProductIndex" << btDCs.first().productIdx;
return 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 #endif
return -1; 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(); 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(); QString btAddr = btDCs.first().btdi.address().toString();
qDebug() << "getDetectedDeviceAddress" << btAddr; qDebug() << "getDetectedDeviceAddress" << btAddr;
return 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(); return QString();
#endif #endif
} }

View file

@ -45,9 +45,11 @@ public:
device_data_t* internalData(); device_data_t* internalData();
Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor); Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor);
Q_INVOKABLE int getDetectedVendorIndex(); Q_INVOKABLE int getDetectedVendorIndex(const QString &currentText);
Q_INVOKABLE int getDetectedProductIndex(); Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText,
Q_INVOKABLE QString getDetectedDeviceAddress(); const QString &currentProductText);
Q_INVOKABLE QString getDetectedDeviceAddress(const QString &currentVendorText,
const QString &currentProductText);
public slots: public slots:
void setVendor(const QString& vendor); void setVendor(const QString& vendor);

View file

@ -57,11 +57,11 @@ Kirigami.Page {
id: comboVendor id: comboVendor
Layout.fillWidth: true Layout.fillWidth: true
model: vendorList model: vendorList
currentIndex: downloadThread.data().getDetectedVendorIndex() currentIndex: downloadThread.data().getDetectedVendorIndex(currentText)
onCurrentTextChanged: { onCurrentTextChanged: {
comboProduct.model = downloadThread.data().getProductListFromVendor(comboVendor.currentText) comboProduct.model = downloadThread.data().getProductListFromVendor(comboVendor.currentText)
if (currentIndex == downloadThread.data().getDetectedVendorIndex()) if (currentIndex == downloadThread.data().getDetectedVendorIndex(currentText))
comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex() comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex(currentText, comboProduct.currentText)
} }
} }
Kirigami.Label { text: qsTr(" Dive Computer:") } Kirigami.Label { text: qsTr(" Dive Computer:") }
@ -74,7 +74,7 @@ Kirigami.Page {
Kirigami.Label { text: qsTr("Bluetooth download:") } Kirigami.Label { text: qsTr("Bluetooth download:") }
CheckBox { CheckBox {
id: isBluetooth id: isBluetooth
checked: downloadThread.data().getDetectedVendorIndex() != -1 checked: downloadThread.data().getDetectedVendorIndex(ComboBox.currentText) != -1
} }
} }
@ -89,7 +89,8 @@ Kirigami.Page {
onClicked: { onClicked: {
text: qsTr("Retry") text: qsTr("Retry")
if (downloadThread.deviceData.bluetoothMode) { if (downloadThread.deviceData.bluetoothMode) {
var addr = downloadThread.data().getDetectedDeviceAddress() var addr = downloadThread.data().getDetectedDeviceAddress(comboVendor.currentText,
comboProduct.currentText)
if (addr !== "") if (addr !== "")
downloadThread.deviceData.devName = addr downloadThread.deviceData.devName = addr
} }