diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2017-12-31 12:10:37 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-31 07:56:33 -0800 |
commit | 779292a322874ed958bc4aaabae4d1a0463882ee (patch) | |
tree | 03d32fa16a901e7ce9e82a0fc93c877922b312a3 /core | |
parent | 3c022d8673934ebacd618072e1534fa671346499 (diff) | |
download | subsurface-779292a322874ed958bc4aaabae4d1a0463882ee.tar.gz |
Workaround for invalid bluetooth device names
Owing to bug #1002 invalid bluetooth device addresses of the form
"devicename (deviceaddress)" or "deviceaddress (devicename)" may
have found their way into the preferences. Recognize such names
and extract the correct address.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/downloadfromdcthread.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index ede307ce0..dda7d2289 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -291,6 +291,22 @@ void DCDeviceData::setProduct(const QString& product) void DCDeviceData::setDevName(const QString& devName) { + // This is a workaround for bug #1002. A string of the form "devicename (deviceaddress)" + // or "deviceaddress (devicename)" may have found its way into the preferences. + // Try to fetch the address from such a string + // TODO: Remove this code in due course + if (data.bluetooth_mode) { + int idx1 = devName.indexOf('('); + int idx2 = devName.lastIndexOf(')'); + if (idx1 >= 0 && idx2 >= 0 && idx2 > idx1) { + QString front = devName.left(idx1).trimmed(); + QString back = devName.mid(idx1 + 1, idx2 - idx1 - 1); + QString newDevName = back.indexOf(':') >= 0 ? back : front; + qWarning() << "Found invalid bluetooth device" << devName << "corrected to" << newDevName << "."; + data.devname = strdup(qPrintable(newDevName)); + return; + } + } data.devname = strdup(qPrintable(devName)); } |