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>
This commit is contained in:
Berthold Stoeger 2017-12-31 12:10:37 +01:00 committed by Dirk Hohndel
parent 3c022d8673
commit 779292a322

View file

@ -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));
}