From 0cf5214c15709844a2b79a7cee029ef93cb76e73 Mon Sep 17 00:00:00 2001 From: Claudiu Olteanu Date: Sat, 18 Jul 2015 20:51:45 +0300 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/btdeviceselectiondialog.cpp | 35 ++++++++++++++++++++++++++++------- qt-ui/btdeviceselectiondialog.h | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp index dfcd64e26..2f5a5d1f9 100644 --- a/qt-ui/btdeviceselectiondialog.cpp +++ b/qt-ui/btdeviceselectiondialog.cpp @@ -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())); +} diff --git a/qt-ui/btdeviceselectiondialog.h b/qt-ui/btdeviceselectiondialog.h index de64c937d..9c040dc68 100644 --- a/qt-ui/btdeviceselectiondialog.h +++ b/qt-ui/btdeviceselectiondialog.h @@ -46,6 +46,7 @@ private: QSharedPointer selectedRemoteDeviceInfo; void updateLocalDeviceInformation(); + void initializeDeviceDiscoveryAgent(); }; #endif // BTDEVICESELECTIONDIALOG_H -- cgit v1.2.3-70-g09d2