summaryrefslogtreecommitdiffstats
path: root/qt-ui/btdeviceselectiondialog.cpp
diff options
context:
space:
mode:
authorGravatar Claudiu Olteanu <olteanu.claudiu@ymail.com>2015-07-18 20:51:45 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-20 05:39:43 -0700
commit0cf5214c15709844a2b79a7cee029ef93cb76e73 (patch)
tree44c6feca989d7b77584bdfa17598c1488f6b0030 /qt-ui/btdeviceselectiondialog.cpp
parentb5ac3a3fa8168bd6bf38ecb1985f37c7d683e411 (diff)
downloadsubsurface-0cf5214c15709844a2b79a7cee029ef93cb76e73.tar.gz
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>
Diffstat (limited to 'qt-ui/btdeviceselectiondialog.cpp')
-rw-r--r--qt-ui/btdeviceselectiondialog.cpp35
1 files changed, 28 insertions, 7 deletions
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()));
+}