summaryrefslogtreecommitdiffstats
path: root/src/bluetoothsettings/discoverymodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetoothsettings/discoverymodel.cpp')
-rw-r--r--src/bluetoothsettings/discoverymodel.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/bluetoothsettings/discoverymodel.cpp b/src/bluetoothsettings/discoverymodel.cpp
index 2f70800..31cf972 100644
--- a/src/bluetoothsettings/discoverymodel.cpp
+++ b/src/bluetoothsettings/discoverymodel.cpp
@@ -163,10 +163,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()
@@ -185,6 +194,9 @@ void DiscoveryModel::scanDevices()
this, SIGNAL(scanFinished()));
}
+ // Reset previous list, devices are already cached by bluez
+ clearDeviceList();
+
m_discoveryAgent->start();
}
@@ -248,4 +260,11 @@ void DiscoveryModel::setConnected(const QString &aAddress, bool connected)
emit dataChanged(index(i, 0), index(i, 0), role);
}
+void DiscoveryModel::clearDeviceList()
+{
+ beginResetModel();
+ m_items.clear();
+ endResetModel();
+}
+
QT_END_NAMESPACE