mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Reimplement pairingFinished method
The old implementation didn't use the correct deviceLabel pattern. When the pairing status of a device was changed the name of the device was missing from the new label. With the new implementation when the pairing status is changed we replace the old state with the new one and maintain the device information from the old label. Also we set the same pairing background colors used in the addRemoteDevice callback. In this way the label's state is consistent and the UX is improved. Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a83f59ff09
commit
69c81ed8e4
1 changed files with 39 additions and 32 deletions
|
@ -242,46 +242,53 @@ void BtDeviceSelectionDialog::displayPairingMenu(const QPoint &pos)
|
||||||
|
|
||||||
void BtDeviceSelectionDialog::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
|
void BtDeviceSelectionDialog::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
|
||||||
{
|
{
|
||||||
|
// Determine the color, the new pairing status and the log message. By default we assume that the devices are UNPAIRED.
|
||||||
QString remoteDeviceStringAddress = address.toString();
|
QString remoteDeviceStringAddress = address.toString();
|
||||||
|
QColor pairingColor = QColor(Qt::red);
|
||||||
|
QString pairingStatusLabel = QString("UNPAIRED");
|
||||||
|
QString dialogStatusMessage = QString("Device %1 was unpaired.").arg(remoteDeviceStringAddress);
|
||||||
|
bool enableSaveButton = false;
|
||||||
|
|
||||||
|
if (pairing == QBluetoothLocalDevice::Paired) {
|
||||||
|
pairingStatusLabel = QString("PAIRED");
|
||||||
|
pairingColor = QColor(Qt::gray);
|
||||||
|
enableSaveButton = true;
|
||||||
|
dialogStatusMessage = QString("Device %1 was paired.").arg(remoteDeviceStringAddress);
|
||||||
|
} else if (pairing == QBluetoothLocalDevice::AuthorizedPaired) {
|
||||||
|
pairingStatusLabel = QString("AUTHORIZED_PAIRED");
|
||||||
|
pairingColor = QColor(Qt::blue);
|
||||||
|
enableSaveButton = true;
|
||||||
|
dialogStatusMessage = QString("Device %1 was authorized paired.").arg(remoteDeviceStringAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the items which represent the BTH device and update their state
|
||||||
QList<QListWidgetItem *> items = ui->discoveredDevicesList->findItems(remoteDeviceStringAddress, Qt::MatchContains);
|
QList<QListWidgetItem *> items = ui->discoveredDevicesList->findItems(remoteDeviceStringAddress, Qt::MatchContains);
|
||||||
|
|
||||||
if (pairing == QBluetoothLocalDevice::Paired || pairing == QBluetoothLocalDevice::Paired ) {
|
for (int i = 0; i < items.count(); ++i) {
|
||||||
ui->dialogStatus->setText(QString("Device %1 was paired.")
|
QListWidgetItem *item = items.at(i);
|
||||||
.arg(remoteDeviceStringAddress));
|
QString updatedDeviceLabel = item->text().replace(QRegularExpression("PAIRED|AUTHORIZED_PAIRED|UNPAIRED"),
|
||||||
|
pairingStatusLabel);
|
||||||
|
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
item->setText(updatedDeviceLabel);
|
||||||
QListWidgetItem *item = items.at(i);
|
item->setBackgroundColor(pairingColor);
|
||||||
|
}
|
||||||
|
|
||||||
item->setText(QString("%1 [State: PAIRED]").arg(remoteDeviceStringAddress));
|
// Check if the updated device is the selected one from the list and inform the user that it can/cannot start the download mode
|
||||||
item->setBackgroundColor(QColor(Qt::gray));
|
QListWidgetItem *currentItem = ui->discoveredDevicesList->currentItem();
|
||||||
}
|
|
||||||
|
|
||||||
QListWidgetItem *currentItem = ui->discoveredDevicesList->currentItem();
|
if (currentItem != NULL && currentItem->text().contains(remoteDeviceStringAddress, Qt::CaseInsensitive)) {
|
||||||
|
if (pairing == QBluetoothLocalDevice::Unpaired) {
|
||||||
if (currentItem != NULL && currentItem->text().contains(remoteDeviceStringAddress, Qt::CaseInsensitive)) {
|
dialogStatusMessage = QString("The device %1 must be paired in order to be used. Please use the context menu for pairing options.")
|
||||||
ui->dialogStatus->setText(QString("The device %1 can now be used for connection. You can press the Save button.")
|
.arg(remoteDeviceStringAddress);
|
||||||
.arg(remoteDeviceStringAddress));
|
} else {
|
||||||
ui->save->setEnabled(true);
|
dialogStatusMessage = QString("The device %1 can now be used for connection. You can press the Save button.")
|
||||||
}
|
.arg(remoteDeviceStringAddress);
|
||||||
} else {
|
|
||||||
ui->dialogStatus->setText(QString("Device %1 was unpaired.")
|
|
||||||
.arg(remoteDeviceStringAddress));
|
|
||||||
|
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
|
||||||
QListWidgetItem *item = items.at(i);
|
|
||||||
|
|
||||||
item->setText(QString("%1 [State: UNPAIRED]").arg(remoteDeviceStringAddress));
|
|
||||||
item->setBackgroundColor(QColor(Qt::white));
|
|
||||||
}
|
|
||||||
|
|
||||||
QListWidgetItem *currentItem = ui->discoveredDevicesList->currentItem();
|
|
||||||
|
|
||||||
if (currentItem != NULL && currentItem->text().contains(remoteDeviceStringAddress, Qt::CaseInsensitive)) {
|
|
||||||
ui->dialogStatus->setText(QString("The device %1 must be paired in order to be used. Please use the context menu for pairing options.")
|
|
||||||
.arg(remoteDeviceStringAddress));
|
|
||||||
ui->save->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the save button and the dialog status message
|
||||||
|
ui->save->setEnabled(enableSaveButton);
|
||||||
|
ui->dialogStatus->setText(dialogStatusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtDeviceSelectionDialog::error(QBluetoothLocalDevice::Error error)
|
void BtDeviceSelectionDialog::error(QBluetoothLocalDevice::Error error)
|
||||||
|
|
Loading…
Reference in a new issue