From 779292a322874ed958bc4aaabae4d1a0463882ee Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 31 Dec 2017 12:10:37 +0100 Subject: 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 --- core/downloadfromdcthread.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core') 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)); } -- cgit v1.2.3-70-g09d2