summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bluetooth/bluetooth.cpp25
-rw-r--r--bluetooth/bluetoothmodel.cpp3
2 files changed, 19 insertions, 9 deletions
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index cea89ad..fe1212f 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -228,16 +228,23 @@ void Bluetooth::processDeviceChangesEvent(QJsonObject data)
QString action = data.value("action").toString();
QString id = data.value("device").toString();
- if (action == "added") {
- BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, data);
- m_bluetooth->addDevice(device);
- } else if (action == "changed") {
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- m_bluetooth->updateDeviceProperties(device, data);
- } else if (action == "removed") {
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- m_bluetooth->removeDevice(device);
+ if (id.isEmpty())
+ return;
+
+ BluetoothDevice *device = m_bluetooth->getDevice(id);
+ if (action == "removed") {
+ if (device != nullptr)
+ m_bluetooth->removeDevice(device);
+ return;
+ }
+
+ BluetoothDevice *ndevice = m_bluetooth->updateDeviceProperties(device, data);
+ if (ndevice == nullptr) {
+ qDebug() << "bt - failed to create device object with id: " << id;
+ return;
}
+ if (device == nullptr) //device not previously in model
+ m_bluetooth->addDevice(ndevice);
}
void Bluetooth::processAdapterChangesEvent(QJsonObject data)
diff --git a/bluetooth/bluetoothmodel.cpp b/bluetooth/bluetoothmodel.cpp
index f6c3d09..294b50b 100644
--- a/bluetooth/bluetoothmodel.cpp
+++ b/bluetooth/bluetoothmodel.cpp
@@ -156,6 +156,9 @@ BluetoothDevice *BluetoothModel::updateDeviceProperties(BluetoothDevice *device,
bool paired = properties.value("paired").toBool();
bool connected = properties.value("connected").toBool();
+ if (id.isEmpty())
+ return nullptr;
+
if (device == nullptr)
return new BluetoothDevice(id, address, name, paired, connected);