mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
b5ac3a3fa8
commit
0cf5214c15
2 changed files with 29 additions and 7 deletions
|
@ -54,13 +54,9 @@ BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) :
|
||||||
// Update the UI information about the local device
|
// Update the UI information about the local device
|
||||||
updateLocalDeviceInformation();
|
updateLocalDeviceInformation();
|
||||||
|
|
||||||
// Intialize the discovery agent
|
// Initialize the device discovery agent
|
||||||
remoteDeviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent();
|
if (localDevice->isValid())
|
||||||
|
initializeDeviceDiscoveryAgent();
|
||||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
|
|
||||||
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
|
|
||||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
|
|
||||||
this, SLOT(remoteDeviceScanFinished()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BtDeviceSelectionDialog::~BtDeviceSelectionDialog()
|
BtDeviceSelectionDialog::~BtDeviceSelectionDialog()
|
||||||
|
@ -194,6 +190,10 @@ void BtDeviceSelectionDialog::localDeviceChanged(int index)
|
||||||
updateLocalDeviceInformation();
|
updateLocalDeviceInformation();
|
||||||
|
|
||||||
ui->dialogStatus->setText(QString("The local device was changed."));
|
ui->dialogStatus->setText(QString("The local device was changed."));
|
||||||
|
|
||||||
|
// Initialize the device discovery agent
|
||||||
|
if (localDevice->isValid())
|
||||||
|
initializeDeviceDiscoveryAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtDeviceSelectionDialog::displayPairingMenu(const QPoint &pos)
|
void BtDeviceSelectionDialog::displayPairingMenu(const QPoint &pos)
|
||||||
|
@ -316,3 +316,24 @@ void BtDeviceSelectionDialog::updateLocalDeviceInformation()
|
||||||
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
|
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
|
||||||
this, SLOT(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()));
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
QSharedPointer<QBluetoothDeviceInfo> selectedRemoteDeviceInfo;
|
QSharedPointer<QBluetoothDeviceInfo> selectedRemoteDeviceInfo;
|
||||||
|
|
||||||
void updateLocalDeviceInformation();
|
void updateLocalDeviceInformation();
|
||||||
|
void initializeDeviceDiscoveryAgent();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BTDEVICESELECTIONDIALOG_H
|
#endif // BTDEVICESELECTIONDIALOG_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue