QML UI: remove the Paired Bluetooth Devices virtual vendor

We now actually handle connections in a sane manner and don't need
that workaround anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-07-17 07:43:31 -07:00
parent cec3c256e7
commit 025efc12d4
3 changed files with 10 additions and 85 deletions

View file

@ -324,12 +324,9 @@ int DCDeviceData::getDetectedVendorIndex(const QString &currentText)
#if defined(BT_SUPPORT)
QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
// Pick the vendor of the first confirmed find of a DC (if any), but
// only return a true vendor, and not our virtual one
if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) {
qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx;
// Pick the vendor of the first confirmed find of a DC (if any)
if (!btDCs.isEmpty())
return btDCs.first().vendorIdx;
}
#endif
return -1;
}
@ -342,17 +339,9 @@ int DCDeviceData::getDetectedProductIndex(const QString &currentVendorText,
// 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;
// BT device)
if (!btDCs.isEmpty())
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;
}
@ -361,19 +350,9 @@ QString DCDeviceData::getDetectedDeviceAddress(const QString &currentVendorText,
const QString &currentProductText)
{
#if defined(BT_SUPPORT)
if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
// simply get the address from the product text
QRegularExpression extractAddr(".*\\(([0-9A-FL:]*)\\)");
QRegularExpressionMatch m = extractAddr.match(currentProductText);
if (m.hasMatch()) {
qDebug() << "matched" << m.captured(1);
return m.captured(1);
}
}
// Otherwise, pull the vendor from the found devices that are possible real dive computers
// Pull the vendor from the found devices that are possible real dive computers
// HACK: this assumes that dive computer names are unique across vendors
// and will only give you the first of multiple identically named dive computers - use
// the Paired Bluetooth Devices vendor in cases like that
// and will only give you the first of multiple identically named dive computers
QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
BTDiscovery::btVendorProduct btDC;
Q_FOREACH(btDC, btDCs) {
@ -383,43 +362,3 @@ QString DCDeviceData::getDetectedDeviceAddress(const QString &currentVendorText,
#endif
return QStringLiteral("cannot determine address of dive computer");
}
QString DCDeviceData::getDeviceDescriptorVendor(const QString &currentVendorText,
const QString &currentProductText)
{
#if defined(BT_SUPPORT)
if (currentVendorText != QObject::tr("Paired Bluetooth Devices"))
return currentVendorText;
QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
// Pull the vendor from the found devices that are possible real dive computers
// HACK: this assumes that dive computer names are unique across vendors
BTDiscovery::btVendorProduct btDC;
Q_FOREACH(btDC, btDCs) {
if (currentProductText.startsWith(dc_descriptor_get_product(btDC.dcDescriptor)))
return dc_descriptor_get_vendor(btDC.dcDescriptor);
}
#endif
return QStringLiteral("failed to detect vendor");
}
QString DCDeviceData::getDeviceDescriptorProduct(const QString &currentVendorText,
const QString &currentProductText)
{
#if defined(BT_SUPPORT)
if (currentVendorText != QObject::tr("Paired Bluetooth Devices"))
return currentProductText;
QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
// Pull the canonical product from the found devices that are possible real dive computers
// HACK: this assumes that dive computer names are unique across vendors
BTDiscovery::btVendorProduct btDC;
Q_FOREACH(btDC, btDCs) {
if (currentProductText.startsWith(dc_descriptor_get_product(btDC.dcDescriptor)))
return dc_descriptor_get_product(btDC.dcDescriptor);
}
#endif
return QStringLiteral("failed to detect product");
}

View file

@ -52,10 +52,6 @@ public:
const QString &currentProductText);
Q_INVOKABLE QString getDetectedDeviceAddress(const QString &currentVendorText,
const QString &currentProductText);
Q_INVOKABLE QString getDeviceDescriptorVendor(const QString &currentVendorText,
const QString &currentProductText);
Q_INVOKABLE QString getDeviceDescriptorProduct(const QString &currentVendorText,
const QString &currentProductText);
public slots:
void setVendor(const QString& vendor);

View file

@ -157,20 +157,10 @@ Kirigami.Page {
}
onClicked: {
text = qsTr("Retry")
if (downloadThread.deviceData.bluetoothMode) {
var addr = downloadThread.data().getDetectedDeviceAddress(comboVendor.currentText,
comboProduct.currentText)
if (addr !== "")
downloadThread.deviceData.devName = addr
var vendor = downloadThread.deviceData.getDeviceDescriptorVendor(comboVendor.currentText,
comboProduct.currentText)
downloadThread.deviceData.vendor = vendor;
var product = downloadThread.deviceData.getDeviceDescriptorProduct(comboVendor.currentText,
comboProduct.currentText)
downloadThread.deviceData.product = product;
}
manager.appendTextToLog("DCDownloadThread started for " + downloadThread.deviceData.devName)
// strip any BT Name from the address
var devName = downloadThread.deviceData.devName
downloadThread.deviceData.devName = devName.replace(/ (.*)$/, "")
manager.appendTextToLog("DCDownloadThread started for " + downloadThread.deviceData.product + " on "+ downloadThread.deviceData.devName)
progressBar.visible = true
downloadThread.start()
}