Cleanup: Use QString as parameter for [get|save]BtDeviceInfo()

Each callsite of saveBtDeviceInfo() has a QString, which is converted
to a C-string, passed and immediately converted back. Remove these
conversions by taking a reference to QString directly.

getBtDeviceInfo() is not as clear. Here, the callsite has a C-string
handed down from libdivecomputer. Nevertheless, pass a reference of
QString here as well. Firstly, for reasons of symmetry. Secondly,
to avoid multiple conversions in the getBtDeviceInfo() functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-02-25 00:17:33 +01:00 committed by Jan Mulder
parent d9c0df0142
commit 7bd860f2b7
4 changed files with 7 additions and 7 deletions

View file

@ -169,7 +169,7 @@ void BTDiscovery::btDeviceDiscovered(const QBluetoothDeviceInfo &device)
// On mobile (iOS) the current ConnectionListModel does not support // On mobile (iOS) the current ConnectionListModel does not support
// additional data, so just save all discovered devices. // additional data, so just save all discovered devices.
saveBtDeviceInfo(btDeviceAddress(&device, false).toUtf8().constData(), device); saveBtDeviceInfo(btDeviceAddress(&device, false), device);
#endif #endif
btDeviceDiscoveredMain(this_d); btDeviceDiscoveredMain(this_d);
@ -287,12 +287,12 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob
QHash<QString, QBluetoothDeviceInfo> btDeviceInfo; QHash<QString, QBluetoothDeviceInfo> btDeviceInfo;
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo) void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo)
{ {
btDeviceInfo[devaddr] = deviceInfo; btDeviceInfo[devaddr] = deviceInfo;
} }
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr) QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr)
{ {
if (btDeviceInfo.contains(devaddr)) if (btDeviceInfo.contains(devaddr))
return btDeviceInfo[devaddr]; return btDeviceInfo[devaddr];

View file

@ -16,8 +16,8 @@
#include <QAndroidJniEnvironment> #include <QAndroidJniEnvironment>
#endif #endif
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo); void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo);
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr); QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr);
class BTDiscovery : public QObject { class BTDiscovery : public QObject {
Q_OBJECT Q_OBJECT

View file

@ -298,7 +298,7 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d
qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1"); qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1");
#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(devaddr); QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(QString(devaddr));
QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice); QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice);
#else #else
// this is deprecated but given that we don't use Qt to scan for // this is deprecated but given that we don't use Qt to scan for

View file

@ -155,7 +155,7 @@ void BtDeviceSelectionDialog::on_save_clicked()
selectedRemoteDeviceInfo.reset(new QBluetoothDeviceInfo(remoteDeviceInfo)); selectedRemoteDeviceInfo.reset(new QBluetoothDeviceInfo(remoteDeviceInfo));
QString address = remoteDeviceInfo.address().isNull() ? remoteDeviceInfo.deviceUuid().toString() : QString address = remoteDeviceInfo.address().isNull() ? remoteDeviceInfo.deviceUuid().toString() :
remoteDeviceInfo.address().toString(); remoteDeviceInfo.address().toString();
saveBtDeviceInfo(address.toUtf8().constData(), remoteDeviceInfo); saveBtDeviceInfo(address, remoteDeviceInfo);
if (remoteDeviceDiscoveryAgent->isActive()) { if (remoteDeviceDiscoveryAgent->isActive()) {
// Stop the SDP agent if the clear button is pressed and enable the Scan button // Stop the SDP agent if the clear button is pressed and enable the Scan button
remoteDeviceDiscoveryAgent->stop(); remoteDeviceDiscoveryAgent->stop();