summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Nurmenniemi <sami.nurmenniemi@qt.io>2017-11-13 09:28:21 +0200
committerSami Nurmenniemi <sami.nurmenniemi@qt.io>2017-11-22 10:42:26 +0000
commit9c9281bb05f785451d276f0d3145029ab6fb8a2f (patch)
treea50888ca629a00ab9e4eb42c400b86ac4de172b5
parent219777455e401139d522c6129c90b7a91588d397 (diff)
Fix bluetooth settings
- Hide "Scanning" text if bluetooth is powered off during scanning - Don't create duplicate entries of devices when scanning again - List devices in alphabetically sorted order - Don't initiate new scan if it's already going on Task-number: QTBUG-60084 Change-Id: I009d66694e3bcfe7419a5f5e01bfd253d7aa4cc8 Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io> Reviewed-by: Teemu Holappa <teemu.holappa@qt.io>
-rw-r--r--src/bluetoothsettings/bluez/bluetoothdevice_p.cpp8
-rw-r--r--src/bluetoothsettings/discoverymodel.cpp27
-rw-r--r--src/bluetoothsettings/discoverymodel.h2
-rw-r--r--src/settingsui/bluetooth/Bluetooth.qml2
4 files changed, 31 insertions, 8 deletions
diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
index 4440277..48e6695 100644
--- a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
+++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
@@ -227,9 +227,11 @@ void BluetoothDevicePrivate::getManagedObjectsFinished(QDBusPendingCallWatcher *
if (m_powered) {
emit q->poweredChanged();
- m_deviceModel->scanDevices();
- m_scanning = true;
- emit q->scanningChanged();
+ if (!m_scanning) {
+ m_deviceModel->scanDevices();
+ m_scanning = true;
+ emit q->scanningChanged();
+ }
}
emit q->availabilityChanged();
diff --git a/src/bluetoothsettings/discoverymodel.cpp b/src/bluetoothsettings/discoverymodel.cpp
index 3cae1df..ad174c7 100644
--- a/src/bluetoothsettings/discoverymodel.cpp
+++ b/src/bluetoothsettings/discoverymodel.cpp
@@ -161,10 +161,19 @@ DiscoveryModel::DiscoveryModel(QObject *parent)
void DiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
- beginInsertRows(QModelIndex(), m_items.count(), m_items.count());
- BtDeviceItem *item = new BtDeviceItem(device);
- m_items.append(item);
- endInsertRows();
+ int index;
+
+ // Insert the device to alphabetically sorted location
+ for (index = 0; index < m_items.count(); index++)
+ {
+ if (device.name() < m_items.at(index)->name())
+ break;
+ }
+
+ beginInsertRows(QModelIndex(), index, index);
+ BtDeviceItem *item = new BtDeviceItem(device);
+ m_items.insert(index, item);
+ endInsertRows();
}
DiscoveryModel::~DiscoveryModel()
@@ -183,6 +192,9 @@ void DiscoveryModel::scanDevices()
this, SIGNAL(scanFinished()));
}
+ // Reset previous list, devices are already cached by bluez
+ clearDeviceList();
+
m_discoveryAgent->start();
}
@@ -245,3 +257,10 @@ void DiscoveryModel::setConnected(const QString &aAddress, bool connected)
if (found)
emit dataChanged(index(i, 0), index(i, 0), role);
}
+
+void DiscoveryModel::clearDeviceList()
+{
+ beginResetModel();
+ m_items.clear();
+ endResetModel();
+}
diff --git a/src/bluetoothsettings/discoverymodel.h b/src/bluetoothsettings/discoverymodel.h
index ba6e1dd..56f8299 100644
--- a/src/bluetoothsettings/discoverymodel.h
+++ b/src/bluetoothsettings/discoverymodel.h
@@ -115,6 +115,8 @@ Q_SIGNALS:
private Q_SLOTS:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
private:
+ void clearDeviceList();
+
QList<BtDeviceItem*> m_items;
QHash<int, QByteArray> m_roleNames;
QBluetoothDeviceDiscoveryAgent *m_discoveryAgent;
diff --git a/src/settingsui/bluetooth/Bluetooth.qml b/src/settingsui/bluetooth/Bluetooth.qml
index e89476f..4c82904 100644
--- a/src/settingsui/bluetooth/Bluetooth.qml
+++ b/src/settingsui/bluetooth/Bluetooth.qml
@@ -68,7 +68,7 @@ Item {
color: "white"
text: "Scanning"
font.family: appFont
- opacity: BtDevice.scanning ? 1.0 : 0.0
+ opacity: (BtDevice.scanning && BtDevice.powered) ? 1.0 : 0.0
visible: opacity > 0
Behavior on opacity {
NumberAnimation {duration: 150}