diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-05-14 17:37:45 -0700 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2020-05-15 04:05:06 +0300 |
commit | 34ebaf6599775da18495cda7717a3f6e495f7079 (patch) | |
tree | c8ef213a42cf0e93d2c2b50181610322a0732b69 /core/connectionlistmodel.cpp | |
parent | a1a51e5d89013f0423675dfe607cc136f82f727f (diff) | |
download | subsurface-34ebaf6599775da18495cda7717a3f6e495f7079.tar.gz |
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>
Diffstat (limited to 'core/connectionlistmodel.cpp')
-rw-r--r-- | core/connectionlistmodel.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/core/connectionlistmodel.cpp b/core/connectionlistmodel.cpp index d97d4722c..6966802e3 100644 --- a/core/connectionlistmodel.cpp +++ b/core/connectionlistmodel.cpp @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include "core/connectionlistmodel.h" +#if defined(BT_SUPPORT) +#include "core/btdiscovery.h" +#endif ConnectionListModel::ConnectionListModel(QObject *parent) : QAbstractListModel(parent) @@ -31,8 +34,18 @@ int ConnectionListModel::rowCount(const QModelIndex&) const void ConnectionListModel::addAddress(const QString &address) { if (!m_addresses.contains(address)) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_addresses.append(address); + int idx = rowCount(); +#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(); } } |