summaryrefslogtreecommitdiffstats
path: root/bluetooth/bluetooth.cpp
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-03-20 14:22:57 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-04-04 11:34:09 -0700
commit5ba2e7752c478a386de6c6cf06adb6f9cf7ee79e (patch)
tree678e6edf13d5812a88b6c873b4176927fa0dafe4 /bluetooth/bluetooth.cpp
parent47903065edab76a0278ab160a7cbbc112180f326 (diff)
libqtappfw: bluetooth: add BluetoothModel support
Switch from using single threaded and incorrect QML processing of ListViews to using models provided from libqtappfw Bug-AGL: SPEC-2270 SPEC-2290 Change-Id: I83f02ab104a18ade95dfd172902e32a808c3d897 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'bluetooth/bluetooth.cpp')
-rw-r--r--bluetooth/bluetooth.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index 25ff16e..eb00df4 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -20,15 +20,27 @@
#include "bluetoothmessage.h"
#include "responsemessage.h"
-Bluetooth::Bluetooth (QUrl &url, QObject * parent) :
+Bluetooth::Bluetooth (QUrl &url, QQmlContext *context, QObject * parent) :
QObject(parent),
+ m_context(context),
m_mloop(nullptr)
{
m_mloop = new MessageEngine(url);
+ m_bluetooth = new BluetoothModel();
QObject::connect(m_mloop, &MessageEngine::connected, this, &Bluetooth::onConnected);
QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Bluetooth::onDisconnected);
QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Bluetooth::onMessageReceived);
+ BluetoothModelFilter *m_model = new BluetoothModelFilter();
+ m_model->setSourceModel(m_bluetooth);
+ m_model->setFilterFixedString("true");
+ context->setContextProperty("BluetoothPairedModel", m_model);
+
+ m_model = new BluetoothModelFilter();
+ m_model->setSourceModel(m_bluetooth);
+ m_model->setFilterFixedString("false");
+ context->setContextProperty("BluetoothDiscoveryModel", m_model);
+
uuids.insert("a2dp", "0000110a-0000-1000-8000-00805f9b34fb");
uuids.insert("avrcp", "0000110e-0000-1000-8000-00805f9b34fb");
uuids.insert("hfp", "0000111f-0000-1000-8000-00805f9b34fb");
@@ -192,23 +204,42 @@ void Bluetooth::onDisconnected()
}
}
+void Bluetooth::populateDeviceList(QJsonObject data)
+{
+ QJsonArray devices = data.value("devices").toArray();
+
+ m_bluetooth->removeAllDevices();
+
+ for (auto value : devices) {
+ BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, value.toObject());
+ m_bluetooth->addDevice(device);
+ }
+}
+
void Bluetooth::processDeviceChangesEvent(QJsonObject data)
{
QString action = data.value("action").toString();
+ QString id = data.value("device").toString();
- if (action == "added")
- emit deviceAddedEvent(data);
- else if (action == "changed") {
+ if (action == "added") {
+ BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, data);
+ m_bluetooth->addDevice(device);
+ } else if (action == "changed") {
auto powered = data.find("powered").value();
if (powered.isBool()) {
m_power = powered.toBool();
+ if (!m_power)
+ m_bluetooth->removeAllDevices();
emit powerChanged(m_power);
} else {
- emit deviceUpdatedEvent(data);
+ BluetoothDevice *device = m_bluetooth->getDevice(id);
+ m_bluetooth->updateDeviceProperties(device, data);
}
- } else if (action == "removed")
- emit deviceRemovedEvent(data);
+ } else if (action == "removed") {
+ BluetoothDevice *device = m_bluetooth->getDevice(id);
+ m_bluetooth->removeDevice(device);
+ }
}
void Bluetooth::onMessageReceived(MessageType type, Message *msg)
@@ -226,7 +257,7 @@ void Bluetooth::onMessageReceived(MessageType type, Message *msg)
ResponseMessage *tmsg = qobject_cast<ResponseMessage*>(msg);
if (tmsg->requestVerb() == "managed_objects") {
- emit deviceListEvent(tmsg->replyData());
+ populateDeviceList(tmsg->replyData());
} else if (tmsg->requestVerb() == "adapter_state") {
m_power = tmsg->replyData().value("powered").toBool();
emit powerChanged(m_power);