Compare commits

...

2 Commits

Author SHA1 Message Date
Dirk Hohndel
e7bdd5a019 core/bt: ensure that BT/BLE addresses with name sort first
We don't order the list of addresses alphabetically, but we want to ensure
that devices that offer us a name are listed before those that don't. This
should only be relevant if the user selects the option to show all BT/BLE
devices, not just recognized dive computer, because if we recognize a computer
we always have the product name prepended to the address.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-14 17:37:45 -07:00
Dirk Hohndel
d4665f92ea core/bt: always add bt name for devices
If the user asks to have all BT/BLE devices shown, we should behave
consistently to the case of a recognized dive computer and always show the
device name. In almost all cases the BT/BLE address (and even worse on
iOS/macOS the weird uuids) are completely meaningless.

If there isn't a name, don't add a leading space in order to make it easy to
detect if we have an address without a name (which almost certainly isn't a
dive computer, so it should be towards the end of the list of addresses - which
will be handled in a later commit).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-14 17:37:24 -07:00
3 changed files with 22 additions and 5 deletions

View File

@ -1,4 +1,5 @@
Mobile: fix failure to recognize several Aqualung BLE dive computers Core: always include BT/BLE name, even for devices no recognized as dive computer
Core: fix failure to recognize several Aqualung BLE dive computers
Mobile: show dive tags on dive details page Mobile: show dive tags on dive details page
Desktop: update SAC fields and other statistics when editing cylinders Desktop: update SAC fields and other statistics when editing cylinders
Desktop: Reconnect the variations checkbox in planner Desktop: Reconnect the variations checkbox in planner

View File

@ -274,8 +274,11 @@ void BTDiscovery::btDeviceDiscoveredMain(const btPairedDevice &device)
return; return;
} }
// Do we want only devices we recognize as dive computers? // Do we want only devices we recognize as dive computers?
if (m_showNonDiveComputers) if (m_showNonDiveComputers) {
connectionListModel.addAddress(device.address); if (!newDevice.isEmpty())
newDevice += " ";
connectionListModel.addAddress(newDevice + device.address);
}
qDebug() << "Not recognized as dive computer"; qDebug() << "Not recognized as dive computer";
} }

View File

@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "core/connectionlistmodel.h" #include "core/connectionlistmodel.h"
#if defined(BT_SUPPORT)
#include "core/btdiscovery.h"
#endif
ConnectionListModel::ConnectionListModel(QObject *parent) : ConnectionListModel::ConnectionListModel(QObject *parent) :
QAbstractListModel(parent) QAbstractListModel(parent)
@ -31,8 +34,18 @@ int ConnectionListModel::rowCount(const QModelIndex&) const
void ConnectionListModel::addAddress(const QString &address) void ConnectionListModel::addAddress(const QString &address)
{ {
if (!m_addresses.contains(address)) { if (!m_addresses.contains(address)) {
beginInsertRows(QModelIndex(), rowCount(), rowCount()); int idx = rowCount();
m_addresses.append(address); #if defined(BT_SUPPORT)
// make sure that addresses that are just a BT/BLE address without name stay at the end of the list
if (address != extractBluetoothAddress(address)) {
for (idx = 0; idx < rowCount(); idx++)
if (m_addresses[idx] == extractBluetoothAddress(m_addresses[idx]))
// found the first name-less BT/BLE address, insert before that
break;
}
#endif
beginInsertRows(QModelIndex(), idx, idx);
m_addresses.insert(idx, address);
endInsertRows(); endInsertRows();
} }
} }