Index: sources/view/VBluetooth.cpp =================================================================== diff -u -rc3a1e077ddeba65709084f9af5dd756741db8b4f -r5696b8db4628ee3143d93952c5dbdf511fa985b1 --- sources/view/VBluetooth.cpp (.../VBluetooth.cpp) (revision c3a1e077ddeba65709084f9af5dd756741db8b4f) +++ sources/view/VBluetooth.cpp (.../VBluetooth.cpp) (revision 5696b8db4628ee3143d93952c5dbdf511fa985b1) @@ -28,6 +28,9 @@ connect(&_BLEScanner, SIGNAL(didConnectToDevice(QBluetoothDeviceInfo)), this, SLOT(onConnectedToDevice(QBluetoothDeviceInfo))); + connect(&_BLEScanner, SIGNAL(didDisconnectFromDevice(QBluetoothDeviceInfo)), + this, SLOT(onDisconnectedFromDevice(QBluetoothDeviceInfo))); + // outgoing connect(this, SIGNAL(didSelectDevice(const QString)), &_BLEScanner, SLOT(doSelectDevice(const QString))); @@ -158,7 +161,7 @@ return tr("No Error."); break; case QLowEnergyController::UnknownError: - return tr("Unknown Error."); + return tr("Unknown Error. Is device turned off?"); break; case QLowEnergyController::UnknownRemoteDeviceError: return tr("Unknown Remote Device Error."); @@ -205,20 +208,19 @@ */ bool VBluetooth::isDeviceAlreadyPaired(const QBluetoothDeviceInfo &deviceInfo) { - bool alreadyPaired = false; for (QObject *device : pairedDevices) { VBluetoothDeviceInfo *pairedDevice = static_cast(device); if (pairedDevice->getAddress() == deviceInfo.address().toString()) - alreadyPaired = true; + return true; } - return alreadyPaired; + return false; } /*! * \brief VBluetooth::removeFromDevices * Removes a device from the non-paired bluetooth devices list * Adds that devices to the non-paired bluetooth devices blacklist - * \param info - the bluetooth device info object to remove + * \param info - (VBluetoothDeviceInfo*) the bluetooth device info object to remove */ void VBluetooth::removeFromDevices(const VBluetoothDeviceInfo *info) { @@ -241,18 +243,58 @@ * \brief VBluetooth::onConnectedToDevice * Slot called when BLEScanner connects to a device. Moves a device * from the devices list to the my devices list - * \param deviceInfo - the device connected to + * \param deviceInfo - (QBluetoothDeviceInfo) the device connected to */ void VBluetooth::onConnectedToDevice(const QBluetoothDeviceInfo &deviceInfo) { VBluetoothDeviceInfo *info = new VBluetoothDeviceInfo(deviceInfo); + info->setConnected(true); bool alreadyPaired = isDeviceAlreadyPaired(deviceInfo); - if (!alreadyPaired) - { + if (alreadyPaired) { + setDeviceConnected(deviceInfo, true); + } else { pairedDevices.append(info); emit didPairedDevicesChanged(); removeFromDevices(info); } - onUpdateStatus(tr("Connected.")); + onUpdateStatus(tr("Paired, Connected.")); } + +/*! + * \brief VBluetooth::setDeviceConnected + * Ensures the device displays as connected + * \param deviceInfo - (QBluetoothDeviceInfo) contains the device information + * \param connected - (bool) true to set connected, false to set not connected + */ +void VBluetooth::setDeviceConnected(const QBluetoothDeviceInfo &deviceInfo, const bool &connected) +{ + if (isDeviceAlreadyPaired(deviceInfo)) { + for (QList::iterator iter = pairedDevices.begin(); iter != pairedDevices.end(); ++iter) + { + if (deviceInfo.address().toString() == ((VBluetoothDeviceInfo*)(*iter))->getAddress()) + ((VBluetoothDeviceInfo*)(*iter))->setConnected(connected); + } + emit didPairedDevicesChanged(); + } else { + for (QList::iterator iter = bleDevices.begin(); iter != bleDevices.end(); ++iter) + { + if (deviceInfo.address().toString() == ((VBluetoothDeviceInfo*)(*iter))->getAddress()) + ((VBluetoothDeviceInfo*)(*iter))->setConnected(connected); + } + emit didDevicesChanged(); + } +} + +/*! + * \brief VBluetooth::onDisconnectedFromDevice + * Slot called when the BLEScanner detects that a device disconnected. Updates + * the status of the device to Not Connected if is has already been paired + * \param deviceInfo - (QBluetoothDeviceInfo) contains the device information + */ +void VBluetooth::onDisconnectedFromDevice(const QBluetoothDeviceInfo &deviceInfo) +{ + setDeviceConnected(deviceInfo, false); + emit didPairedDevicesChanged(); + onUpdateStatus(tr("Paired, Not Connected.")); +}