diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2018-12-21 14:53:43 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-22 12:57:37 +1300 |
commit | db29fb4e68d20bc6207837bd9e85d897bb6cb8ee (patch) | |
tree | 2e2ee2aab335c2f0123852c86f54dd1965571a11 /mobile-widgets | |
parent | 0f350bef98a49949865bf898396dde7f4a58d1ee (diff) | |
download | subsurface-db29fb4e68d20bc6207837bd9e85d897bb6cb8ee.tar.gz |
Mobile: deal with BT name and address when tapping Download
Instead of trying to update this whenever the connection text changes,
instead deal with it right before it actually gets used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qml/DownloadFromDiveComputer.qml | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index 142465f87..0cd57fae7 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -167,18 +167,6 @@ Kirigami.Page { elide: Text.ElideRight } onCurrentTextChanged: { - // pattern that matches BT addresses - var btAddr = /[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]/ ; - - // On iOS we store UUID instead of device address. - if (Qt.platform.os === 'ios') - btAddr = /\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}/; - - if (btAddr.test(currentText)) - manager.DC_bluetoothMode = true - else - manager.DC_bluetoothMode = false - manager.DC_devName = currentText dc1.enabled = dc2.enabled = dc3.enabled = dc4.enabled = true for (var i = 1; i < 5; i++) { if (comboProduct.currentIndex === -1 && currentText === "FTDI"){ @@ -198,7 +186,6 @@ Kirigami.Page { } } download.text = qsTr("Download") - } } } @@ -277,10 +264,28 @@ Kirigami.Page { comboConnection.currentIndex != -1 onClicked: { text = qsTr("Retry") - // strip any BT Name from the address - var devName = manager.DC_devName - if (devName != qsTr("USB device")) - manager.DC_devName = devName.replace(/^(.*) /, "") + + var connectionString = comboConnection.currentText + // separate BT address and BT name (if applicable) + // pattern that matches BT addresses + var btAddr = "(LE:)?([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}"; + + // On iOS we store UUID instead of device address. + if (Qt.platform.os === 'ios') + btAddr = "(LE:)?\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}"; + + var pattern = new RegExp(btAddr); + var devAddress = ""; + devAddress = pattern.exec(connectionString); + if (devAddress !== null) { + manager.DC_bluetoothMode = true; + manager.DC_devName = devAddress[0]; // exec returns an array with the matched text in element 0 + manager.retrieveBluetoothName(); + manager.appendTextToLog("setting btName to " + manager.DC_devBluetoothName); + } else { + manager.DC_bluetoothMode = false; + manager.DC_devName = connectionString; + } manager.appendTextToLog("DCDownloadThread started for " + manager.DC_vendor + " " + manager.DC_product + " on "+ manager.DC_devName) progressBar.visible = true downloadThread.start() @@ -392,7 +397,7 @@ Kirigami.Page { comboVendor.currentIndex = manager.getDetectedVendorIndex() comboProduct.currentIndex = manager.getDetectedProductIndex(comboVendor.currentText) comboConnection.currentIndex = manager.getMatchingAddress(comboVendor.currentText, comboProduct.currentText) - + } } } |