diff options
author | Claudiu Olteanu <olteanu.claudiu@ymail.com> | 2015-08-18 20:15:49 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-08-20 22:45:11 -0700 |
commit | a83f59ff0952dd78aee4ddf4207046255889510c (patch) | |
tree | 25e98dfcfec4ff37cdd81d0ded37a6988ced188d | |
parent | 14ca6a4e77ff595135204bc429ec31ad10da0368 (diff) | |
download | subsurface-a83f59ff0952dd78aee4ddf4207046255889510c.tar.gz |
Clear the BTH discovered devices list on each search
Clear the Bluetooth discovered devices list on each search.
In this way we will show only the devices that are in range
and active during the last scannning. Also if we clear the
list before each call we don't need to check anymore if the
discovered device is already in the list.
Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/btdeviceselectiondialog.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp index 3af2501e2..7f537402b 100644 --- a/qt-ui/btdeviceselectiondialog.cpp +++ b/qt-ui/btdeviceselectiondialog.cpp @@ -118,6 +118,7 @@ void BtDeviceSelectionDialog::on_clear_clicked() void BtDeviceSelectionDialog::on_scan_clicked() { ui->dialogStatus->setText("Scanning for remote devices..."); + ui->discoveredDevicesList->clear(); remoteDeviceDiscoveryAgent->start(); ui->scan->setEnabled(false); } @@ -145,28 +146,28 @@ void BtDeviceSelectionDialog::hostModeStateChanged(QBluetoothLocalDevice::HostMo void BtDeviceSelectionDialog::addRemoteDevice(const QBluetoothDeviceInfo &remoteDeviceInfo) { - QString deviceLabel = QString("%1 (%2)").arg(remoteDeviceInfo.name()).arg(remoteDeviceInfo.address().toString()); - QList<QListWidgetItem *> itemsWithSameSignature = ui->discoveredDevicesList->findItems(deviceLabel, Qt::MatchStartsWith); + // By default we use the status label and the color for the UNPAIRED state + QColor pairingColor = QColor(Qt::red); + QString pairingStatusLabel = QString("UNPAIRED"); + QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address()); - // Check if the remote device is already in the list - if (itemsWithSameSignature.empty()) { - QListWidgetItem *item = new QListWidgetItem(deviceLabel); - QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address()); - item->setData(Qt::UserRole, QVariant::fromValue(remoteDeviceInfo)); + if (pairingStatus == QBluetoothLocalDevice::Paired) { + pairingStatusLabel = QString("PAIRED"); + pairingColor = QColor(Qt::gray); + } else if (pairingStatus == QBluetoothLocalDevice::AuthorizedPaired) { + pairingStatusLabel = QString("AUTHORIZED_PAIRED"); + pairingColor = QColor(Qt::blue); + } - if (pairingStatus == QBluetoothLocalDevice::Paired) { - item->setText(QString("%1 [State: PAIRED]").arg(item->text())); - item->setBackgroundColor(QColor(Qt::gray)); - } else if (pairingStatus == QBluetoothLocalDevice::AuthorizedPaired) { - item->setText(QString("%1 [State: AUTHORIZED_PAIRED]").arg(item->text())); - item->setBackgroundColor(QColor(Qt::blue)); - } else { - item->setText(QString("%1 [State: UNPAIRED]").arg(item->text())); - item->setTextColor(QColor(Qt::black)); - } + QString deviceLabel = QString("%1 (%2) [State: %3]").arg(remoteDeviceInfo.name(), + remoteDeviceInfo.address().toString(), + pairingStatusLabel); + QListWidgetItem *item = new QListWidgetItem(deviceLabel); - ui->discoveredDevicesList->addItem(item); - } + item->setData(Qt::UserRole, QVariant::fromValue(remoteDeviceInfo)); + item->setBackgroundColor(pairingColor); + + ui->discoveredDevicesList->addItem(item); } void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item) |