Reinitialize the BT discovery agent when a new adapter is selected

Reinitialize the Bluetooth device discovery agent when the user
selects a new local Bluetooth adapter using the address
of the selected device.

Before this patch the agent was always using the local default
Bluetooth adapter.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Claudiu Olteanu 2015-07-18 20:51:45 +03:00 committed by Dirk Hohndel
parent b5ac3a3fa8
commit 0cf5214c15
2 changed files with 29 additions and 7 deletions

View file

@ -54,13 +54,9 @@ BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) :
// Update the UI information about the local device
updateLocalDeviceInformation();
// Intialize the discovery agent
remoteDeviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent();
connect(remoteDeviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
this, SLOT(remoteDeviceScanFinished()));
// Initialize the device discovery agent
if (localDevice->isValid())
initializeDeviceDiscoveryAgent();
}
BtDeviceSelectionDialog::~BtDeviceSelectionDialog()
@ -194,6 +190,10 @@ void BtDeviceSelectionDialog::localDeviceChanged(int index)
updateLocalDeviceInformation();
ui->dialogStatus->setText(QString("The local device was changed."));
// Initialize the device discovery agent
if (localDevice->isValid())
initializeDeviceDiscoveryAgent();
}
void BtDeviceSelectionDialog::displayPairingMenu(const QPoint &pos)
@ -316,3 +316,24 @@ void BtDeviceSelectionDialog::updateLocalDeviceInformation()
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
this, SLOT(error(QBluetoothLocalDevice::Error)));
}
void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
{
// Intialize the discovery agent
remoteDeviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(localDevice->address());
// Test if the discovery agent was successfully created
if (remoteDeviceDiscoveryAgent->error() == QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError) {
ui->dialogStatus->setText(QString("The device discovery agent was not created because the %1 address does not "
"match the physical adapter address of any local Bluetooth device.")
.arg(localDevice->address().toString()));
ui->scan->setEnabled(false);
ui->clear->setEnabled(false);
return;
}
connect(remoteDeviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
this, SLOT(remoteDeviceScanFinished()));
}

View file

@ -46,6 +46,7 @@ private:
QSharedPointer<QBluetoothDeviceInfo> selectedRemoteDeviceInfo;
void updateLocalDeviceInformation();
void initializeDeviceDiscoveryAgent();
};
#endif // BTDEVICESELECTIONDIALOG_H