summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bluetoothsettings/bluetoothdevice.cpp117
-rw-r--r--src/bluetoothsettings/bluetoothdevice.h35
-rw-r--r--src/bluetoothsettings/bluez/bluetoothdevice_p.cpp219
-rw-r--r--src/bluetoothsettings/bluez/bluetoothdevice_p.h46
-rw-r--r--src/bluetoothsettings/bluez/bluez.pri4
-rw-r--r--src/bluetoothsettings/discoverymodel.cpp25
-rw-r--r--src/bluetoothsettings/discoverymodel.h1
-rw-r--r--src/settingsui/bluetooth/Bluetooth.qml14
-rw-r--r--src/settingsui/bluetooth/Discovery.qml2
9 files changed, 302 insertions, 161 deletions
diff --git a/src/bluetoothsettings/bluetoothdevice.cpp b/src/bluetoothsettings/bluetoothdevice.cpp
index 932d8f6..0facf27 100644
--- a/src/bluetoothsettings/bluetoothdevice.cpp
+++ b/src/bluetoothsettings/bluetoothdevice.cpp
@@ -28,135 +28,64 @@
****************************************************************************/
#include <discoverymodel.h>
#include "bluetoothdevice.h"
-#include "bluez/bluetoothdevice_p.h"
+#include "bluetoothdevice_p.h"
BluetoothDevice::BluetoothDevice(QObject *parent) : QObject(parent)
- ,m_localDevice(new QBluetoothLocalDevice(this))
- ,m_deviceModel(new DiscoveryModel(this))
- ,m_powered(false)
- ,m_scanning(true)
+ ,d_ptr(new BluetoothDevicePrivate(this))
{
- m_powered = m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff;
-
- connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDevice::deviceStateChanged);
- connect(m_localDevice, &QBluetoothLocalDevice::deviceConnected, this, &BluetoothDevice::deviceConnected);
- connect(m_localDevice, &QBluetoothLocalDevice::deviceDisconnected, this, &BluetoothDevice::deviceDisconnected);
- connect(m_deviceModel, &DiscoveryModel::scanFinished, this, &BluetoothDevice::scanFinished);
-
- if (m_powered) {
- m_deviceModel->scanDevices();
- }
-
-}
-
-void BluetoothDevice::deviceStateChanged(QBluetoothLocalDevice::HostMode state)
-{
- m_powered = state != QBluetoothLocalDevice::HostPoweredOff;
- emit poweredChanged();
}
bool BluetoothDevice::powered() const
{
- return m_powered;
+ Q_D(const BluetoothDevice);
+ return d->powered();
}
void BluetoothDevice::setPowered(const bool& aPowered)
{
- if (aPowered) {
- m_localDevice->powerOn();
- }
- else {
- m_localDevice->setHostMode(QBluetoothLocalDevice::HostPoweredOff);
- }
+ Q_D(BluetoothDevice);
+ d->setPowered(aPowered);
}
-QObject* BluetoothDevice::deviceModel() const
-{
- return static_cast<QObject*>(m_deviceModel);
-}
-void BluetoothDevice::scanFinished()
+DiscoveryModel* BluetoothDevice::deviceModel() const
{
- m_scanning = false;
- emit scanningChanged();
- updateConnectionStatuses();
+ Q_D(const BluetoothDevice);
+ return d->m_deviceModel;
}
bool BluetoothDevice::scanning() const
{
- return m_scanning;
+ Q_D(const BluetoothDevice);
+ return d->scanning();
}
void BluetoothDevice::setScanning(const bool& aScan)
{
- if (m_scanning && !aScan) {
- //TODO m_deviceModel->cancel();
- }
- else if (aScan && !m_scanning) {
- m_deviceModel->scanDevices();
- m_scanning = true;
- emit scanningChanged();
- }
-}
-
-void BluetoothDevice::updateConnectionStatuses()
-{
- QList<QBluetoothAddress> connectedDevices =
- m_localDevice->connectedDevices();
-
- foreach (QBluetoothAddress addr, connectedDevices) {
- m_deviceModel->setConnected(addr.toString(), true);
- }
+ Q_D(BluetoothDevice);
+ d->setScanning(aScan);
}
void BluetoothDevice::requestPairing(const QString& address)
{
- QBluetoothAddress addr(address);
- m_localDevice->requestPairing(addr, QBluetoothLocalDevice::Paired);
- connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BluetoothDevice::pairingDisplayConfirmation);
-
- connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BluetoothDevice::pairingDisplayPinCode);
-
- connect(m_localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BluetoothDevice::pairingFinished);
+ Q_D(BluetoothDevice);
+ d->requestPairing(address);
}
-void BluetoothDevice::requestConnect(const QString &address)
+void BluetoothDevice::requestConnect(const QString& address)
{
- QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address));
- connectionHandler->connectDevice();
+ Q_D(BluetoothDevice);
+ d->requestConnect(address);
}
void BluetoothDevice::requestDisconnect(const QString& address)
{
- QScopedPointer<BluetoothDevicePrivate> connectionHandler(new BluetoothDevicePrivate(address));
- connectionHandler->disconnectDevice();
-}
-
-void BluetoothDevice::pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin)
-{
- Q_UNUSED(address);
- Q_UNUSED(pin);
-}
-
-void BluetoothDevice::pairingDisplayPinCode(const QBluetoothAddress & address, QString pin)
-{
- Q_UNUSED(address);
- Q_UNUSED(pin);
-}
-
-void BluetoothDevice::pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing)
-{
- if (pairing == QBluetoothLocalDevice::Paired) {
- requestConnect(address.toString());
- }
-}
-
-void BluetoothDevice::deviceConnected(const QBluetoothAddress & address)
-{
- m_deviceModel->setConnected(address.toString(), true);
+ Q_D(BluetoothDevice);
+ d->requestDisconnect(address);
}
-void BluetoothDevice::deviceDisconnected(const QBluetoothAddress & address)
+bool BluetoothDevice::available() const
{
- m_deviceModel->setConnected(address.toString(), false);
+ Q_D(const BluetoothDevice);
+ return d->available();
}
diff --git a/src/bluetoothsettings/bluetoothdevice.h b/src/bluetoothsettings/bluetoothdevice.h
index 219154f..03ea961 100644
--- a/src/bluetoothsettings/bluetoothdevice.h
+++ b/src/bluetoothsettings/bluetoothdevice.h
@@ -30,51 +30,40 @@
#define BLUETOOTHDEVICE_H
#include <QObject>
-#include <QBluetoothLocalDevice>
+#include "discoverymodel.h"
QT_BEGIN_NAMESPACE
-class DiscoveryModel;
+QT_FORWARD_DECLARE_CLASS(DiscoveryModel)
+QT_FORWARD_DECLARE_CLASS(BluetoothDevicePrivate)
class Q_DECL_EXPORT BluetoothDevice : public QObject
{
Q_OBJECT
Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged)
Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged)
- Q_PROPERTY(QObject* deviceModel READ deviceModel CONSTANT)
+ Q_PROPERTY(bool available READ available NOTIFY availabilityChanged)
+ Q_PROPERTY(DiscoveryModel* deviceModel READ deviceModel CONSTANT)
public:
explicit BluetoothDevice(QObject *parent = Q_NULLPTR);
bool powered() const;
void setPowered(const bool& aPowered);
- QObject* deviceModel() const;
+ DiscoveryModel *deviceModel() const;
bool scanning() const;
void setScanning(const bool& aScan);
+ bool available() const;
Q_INVOKABLE void requestPairing(const QString& address);
Q_INVOKABLE void requestConnect(const QString& address);
Q_INVOKABLE void requestDisconnect(const QString& address);
Q_SIGNALS:
void poweredChanged();
void scanningChanged();
-
-public Q_SLOTS:
- void deviceStateChanged(QBluetoothLocalDevice::HostMode state);
- void scanFinished();
- //These are not yet signaled
- //See bug https://bugreports.qt.io/browse/QTBUG-38401
- void pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin);
- void pairingDisplayPinCode(const QBluetoothAddress & address, QString pin);
- void pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing);
- void deviceConnected(const QBluetoothAddress & address);
- void deviceDisconnected(const QBluetoothAddress & address);
-
-private:
- void updateConnectionStatuses();
-
+ void availabilityChanged();
+protected:
+ BluetoothDevicePrivate *d_ptr;
private:
- QBluetoothLocalDevice* m_localDevice;
- DiscoveryModel *m_deviceModel;
- bool m_powered;
- bool m_scanning;
+Q_DISABLE_COPY(BluetoothDevice)
+Q_DECLARE_PRIVATE(BluetoothDevice)
};
QT_END_NAMESPACE
diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
index d5e6288..28ed605 100644
--- a/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
+++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.cpp
@@ -26,26 +26,209 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include "discoverymodel.h"
#include "bluetoothdevice_p.h"
#include "datatypes.h"
#include "objectmanager_interface.cpp"
#include "moc_objectmanager_interface.cpp"
#include "device1_interface.h"
+BluetoothDevicePrivate::BluetoothDevicePrivate(BluetoothDevice *parent) : QObject(parent)
+ ,q_ptr(parent)
+ ,m_localDevice(Q_NULLPTR)
+ ,m_powered(false)
+ ,m_scanning(false)
+ ,m_adapter(QStringLiteral(""))
+ ,m_deviceModel(new DiscoveryModel(this))
+{
+ qDBusRegisterMetaType<InterfaceList>();
+ qDBusRegisterMetaType<ManagedObjectList>();
+
+ m_manager = new OrgFreedesktopDBusObjectManagerInterface(QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus(), this);
+ QDBusPendingReply<ManagedObjectList> reply = m_manager->GetManagedObjects();
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
+ connect(watcher, &QDBusPendingCallWatcher::finished,
+ this, &BluetoothDevicePrivate::getManagedObjectsFinished, Qt::QueuedConnection);
+}
-BluetoothDevicePrivate::BluetoothDevicePrivate(const QString& address, QObject *parent)
- :QObject(parent)
- ,m_address(address)
+void BluetoothDevicePrivate::deviceStateChanged(QBluetoothLocalDevice::HostMode state)
{
+ Q_Q(BluetoothDevice);
+ m_powered = state != QBluetoothLocalDevice::HostPoweredOff;
+ emit q->poweredChanged();
+}
+bool BluetoothDevicePrivate::powered() const
+{
+ return m_powered;
}
-OrgBluezDevice1Interface* BluetoothDevicePrivate::findDevice()
+void BluetoothDevicePrivate::setPowered(const bool& aPowered)
{
- OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
- QStringLiteral("/"),
- QDBusConnection::systemBus());
- QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
+ if (aPowered) {
+ m_localDevice->powerOn();
+ }
+ else {
+ m_localDevice->setHostMode(QBluetoothLocalDevice::HostPoweredOff);
+ }
+}
+
+DiscoveryModel* BluetoothDevicePrivate::deviceModel() const
+{
+ return m_deviceModel;
+}
+
+void BluetoothDevicePrivate::scanFinished()
+{
+ Q_Q(BluetoothDevice);
+ m_scanning = false;
+ emit q->scanningChanged();
+ updateConnectionStatuses();
+}
+
+bool BluetoothDevicePrivate::scanning() const
+{
+ return m_scanning;
+}
+
+void BluetoothDevicePrivate::setScanning(const bool& aScan)
+{
+ Q_Q(BluetoothDevice);
+ if (m_scanning && !aScan) {
+ m_deviceModel->stopScanning();
+ }
+ else if (aScan && !m_scanning) {
+ m_deviceModel->scanDevices();
+ }
+ m_scanning = aScan;
+ emit q->scanningChanged();
+}
+
+bool BluetoothDevicePrivate::available() const
+{
+ return (!m_adapter.isEmpty());
+}
+
+void BluetoothDevicePrivate::updateConnectionStatuses()
+{
+ QList<QBluetoothAddress> connectedDevices =
+ m_localDevice->connectedDevices();
+
+ foreach (QBluetoothAddress addr, connectedDevices) {
+ m_deviceModel->setConnected(addr.toString(), true);
+ }
+}
+
+void BluetoothDevicePrivate::requestPairing(const QString& address)
+{
+ QBluetoothAddress addr(address);
+ if (m_localDevice) {
+ m_localDevice->requestPairing(addr, QBluetoothLocalDevice::Paired);
+ connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BluetoothDevicePrivate::pairingDisplayConfirmation);
+
+ connect(m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BluetoothDevicePrivate::pairingDisplayPinCode);
+
+ connect(m_localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BluetoothDevicePrivate::pairingFinished);
+ }
+}
+
+void BluetoothDevicePrivate::requestConnect(const QString &address)
+{
+ OrgBluezDevice1Interface *dev = findPeerDevice(address);
+ if (dev) {
+ dev->Connect();
+ dev->deleteLater();
+ }
+}
+
+void BluetoothDevicePrivate::requestDisconnect(const QString& address)
+{
+ OrgBluezDevice1Interface *dev = findPeerDevice(address);
+ if (dev) {
+ dev->Disconnect();
+ dev->deleteLater();
+ }
+}
+
+void BluetoothDevicePrivate::pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin)
+{
+ Q_UNUSED(address);
+ Q_UNUSED(pin);
+}
+
+void BluetoothDevicePrivate::pairingDisplayPinCode(const QBluetoothAddress & address, QString pin)
+{
+ Q_UNUSED(address);
+ Q_UNUSED(pin);
+}
+
+void BluetoothDevicePrivate::pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing)
+{
+ if (pairing == QBluetoothLocalDevice::Paired) {
+ requestConnect(address.toString());
+ }
+}
+
+void BluetoothDevicePrivate::deviceConnected(const QBluetoothAddress & address)
+{
+ m_deviceModel->setConnected(address.toString(), true);
+}
+
+void BluetoothDevicePrivate::deviceDisconnected(const QBluetoothAddress & address)
+{
+ m_deviceModel->setConnected(address.toString(), false);
+}
+
+void BluetoothDevicePrivate::getManagedObjectsFinished(QDBusPendingCallWatcher *watcher)
+{
+ Q_Q(BluetoothDevice);
+
+ QDBusPendingReply<ManagedObjectList> reply = *watcher;
+ watcher->deleteLater();
+ if (reply.isError()) {
+ return;
+ }
+
+ //Find adapter
+ ManagedObjectList managedObjectList = reply.value();
+ for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) {
+ const InterfaceList &ifaceList = it.value();
+ for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) {
+ const QString &iface = jt.key();
+ const QVariantMap &ifaceValues = jt.value();
+
+ if (iface == QStringLiteral("org.bluez.Adapter1")) {
+ m_adapter = ifaceValues[QStringLiteral("Address")].toString();
+ break;
+ }
+ }
+ }
+
+ if (!m_adapter.isEmpty()) {
+ m_localDevice = new QBluetoothLocalDevice(this);
+ m_powered = m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff;
+
+ connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDevicePrivate::deviceStateChanged);
+ connect(m_localDevice, &QBluetoothLocalDevice::deviceConnected, this, &BluetoothDevicePrivate::deviceConnected);
+ connect(m_localDevice, &QBluetoothLocalDevice::deviceDisconnected, this, &BluetoothDevicePrivate::deviceDisconnected);
+ connect(m_deviceModel, &DiscoveryModel::scanFinished, this, &BluetoothDevicePrivate::scanFinished);
+
+ if (m_powered) {
+ emit q->poweredChanged();
+ m_deviceModel->scanDevices();
+ m_scanning = true;
+ emit q->scanningChanged();
+ }
+
+ emit q->availabilityChanged();
+ }
+}
+
+OrgBluezDevice1Interface* BluetoothDevicePrivate::findPeerDevice(const QString &address)
+{
+ QDBusPendingReply<ManagedObjectList> reply = m_manager->GetManagedObjects();
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "Failed to get objects";
@@ -61,7 +244,7 @@ OrgBluezDevice1Interface* BluetoothDevicePrivate::findDevice()
const QString &iface = jt.key();
const QVariantMap &ifaceValues = jt.value();
if (iface == QStringLiteral("org.bluez.Device1")) {
- if (ifaceValues[QStringLiteral("Address")] == m_address) {
+ if (ifaceValues[QStringLiteral("Address")] == address) {
OrgBluezDevice1Interface *devIf = new OrgBluezDevice1Interface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus());
return devIf;
}
@@ -70,21 +253,3 @@ OrgBluezDevice1Interface* BluetoothDevicePrivate::findDevice()
}
return NULL;
}
-
-void BluetoothDevicePrivate::connectDevice()
-{
- OrgBluezDevice1Interface *dev = findDevice();
- if (dev) {
- dev->Connect();
- dev->deleteLater();
- }
-}
-
-void BluetoothDevicePrivate::disconnectDevice()
-{
- OrgBluezDevice1Interface *dev = findDevice();
- if (dev) {
- dev->Disconnect();
- dev->deleteLater();
- }
-}
diff --git a/src/bluetoothsettings/bluez/bluetoothdevice_p.h b/src/bluetoothsettings/bluez/bluetoothdevice_p.h
index f6892e3..432a7e7 100644
--- a/src/bluetoothsettings/bluez/bluetoothdevice_p.h
+++ b/src/bluetoothsettings/bluez/bluetoothdevice_p.h
@@ -41,19 +41,55 @@
//
#include <QObject>
+#include <QBluetoothLocalDevice>
+#include <QtDBus>
+#include "bluetoothdevice.h"
class OrgBluezDevice1Interface;
+class OrgFreedesktopDBusObjectManagerInterface;
class BluetoothDevicePrivate : public QObject
{
+ Q_OBJECT
+ Q_DECLARE_PUBLIC(BluetoothDevice)
public:
- explicit BluetoothDevicePrivate(const QString& address, QObject *parent = Q_NULLPTR);
- void connectDevice();
- void disconnectDevice();
+ BluetoothDevice *q_ptr;
+ BluetoothDevicePrivate(BluetoothDevice *parent);
+ bool powered() const;
+ void setPowered(const bool& aPowered);
+ bool scanning() const;
+ bool available() const;
+ void setScanning(const bool& aScan);
+ void requestPairing(const QString& address);
+ void requestConnect(const QString& address);
+ void requestDisconnect(const QString& address);
+ DiscoveryModel* deviceModel() const;
+
+public Q_SLOTS:
+ void deviceStateChanged(QBluetoothLocalDevice::HostMode state);
+ void scanFinished();
+ //These are not yet signaled
+ //See bug https://bugreports.qt.io/browse/QTBUG-38401
+ void pairingDisplayConfirmation(const QBluetoothAddress & address, QString pin);
+ void pairingDisplayPinCode(const QBluetoothAddress & address, QString pin);
+ void pairingFinished(const QBluetoothAddress & address, QBluetoothLocalDevice::Pairing pairing);
+ void deviceConnected(const QBluetoothAddress & address);
+ void deviceDisconnected(const QBluetoothAddress & address);
+ void getManagedObjectsFinished(QDBusPendingCallWatcher *watcher);
+
+private:
+ void updateConnectionStatuses();
+ OrgBluezDevice1Interface* findPeerDevice(const QString& address);
private:
- OrgBluezDevice1Interface* findDevice();
- QString m_address;
+ QBluetoothLocalDevice* m_localDevice;
+ bool m_powered;
+ bool m_scanning;
+ QString m_adapter;
+ DiscoveryModel *m_deviceModel;
+ OrgFreedesktopDBusObjectManagerInterface *m_manager;
};
+
+
#endif // BLUETOOTHDEVICE__P_H
diff --git a/src/bluetoothsettings/bluez/bluez.pri b/src/bluetoothsettings/bluez/bluez.pri
index ea4929c..b8d39fd 100644
--- a/src/bluetoothsettings/bluez/bluez.pri
+++ b/src/bluetoothsettings/bluez/bluez.pri
@@ -5,11 +5,11 @@ INCLUDEPATH += $${PWD}/bluez
DBUS_INTERFACES = \
$${PWD}/objectmanager.xml \
- $${PWD}/device1.xml \
+ $${PWD}/device1.xml
HEADERS += \
$$PWD/bluetoothdevice_p.h \
- $$PWD/datatypes.h
+ $$PWD/datatypes.h \
SOURCES += \
$$PWD/bluetoothdevice_p.cpp
diff --git a/src/bluetoothsettings/discoverymodel.cpp b/src/bluetoothsettings/discoverymodel.cpp
index 00dbb0c..3cae1df 100644
--- a/src/bluetoothsettings/discoverymodel.cpp
+++ b/src/bluetoothsettings/discoverymodel.cpp
@@ -150,20 +150,13 @@ BtDeviceItem::DeviceType BtDeviceItem::getPhoneDeviceType(const quint8 minor) co
DiscoveryModel::DiscoveryModel(QObject *parent)
: QAbstractListModel(parent)
- ,m_discoveryAgent(new QBluetoothDeviceDiscoveryAgent(this))
+ ,m_discoveryAgent(Q_NULLPTR)
{
m_roleNames.insert(Qt::UserRole, "modelData");
m_roleNames.insert(Address, "address");
m_roleNames.insert(Name, "name");
m_roleNames.insert(Type, "type");
m_roleNames.insert(Connected, "connected");
-
- connect(m_discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
- this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
-
- connect(m_discoveryAgent, SIGNAL(finished()),
- this, SIGNAL(scanFinished()));
-
}
void DiscoveryModel::deviceDiscovered(const QBluetoothDeviceInfo &device)
@@ -181,9 +174,25 @@ DiscoveryModel::~DiscoveryModel()
void DiscoveryModel::scanDevices()
{
+ if (!m_discoveryAgent) {
+ m_discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
+ connect(m_discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
+ this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
+
+ connect(m_discoveryAgent, SIGNAL(finished()),
+ this, SIGNAL(scanFinished()));
+ }
+
m_discoveryAgent->start();
}
+void DiscoveryModel::stopScanning()
+{
+ if (m_discoveryAgent) {
+ m_discoveryAgent->stop();
+ }
+}
+
QHash<int, QByteArray> DiscoveryModel::roleNames() const
{
return m_roleNames;
diff --git a/src/bluetoothsettings/discoverymodel.h b/src/bluetoothsettings/discoverymodel.h
index 75d93bc..ba6e1dd 100644
--- a/src/bluetoothsettings/discoverymodel.h
+++ b/src/bluetoothsettings/discoverymodel.h
@@ -100,6 +100,7 @@ public:
QHash<int, QByteArray> roleNames() const;
void setConnected(const QString& aAddress, bool connected);
void scanDevices();
+ void stopScanning();
enum Roles {
Name = Qt::UserRole,
diff --git a/src/settingsui/bluetooth/Bluetooth.qml b/src/settingsui/bluetooth/Bluetooth.qml
index 309f978..72b4ae6 100644
--- a/src/settingsui/bluetooth/Bluetooth.qml
+++ b/src/settingsui/bluetooth/Bluetooth.qml
@@ -47,6 +47,7 @@ Item {
title: qsTr("Bluetooth status")
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
+ enabled: BtDevice.available
RowLayout {
spacing: 10
@@ -56,8 +57,19 @@ Item {
}
Switch {
checked: BtDevice.powered
- onCheckedChanged: BtDevice.powered = checked
+ onCheckedChanged: {
+ BtDevice.powered = checked
+ }
}
+
+ Connections {
+ target: BtDevice
+ onPoweredChanged: {
+ if (BtDevice.powered)
+ BtDevice.scanning = true
+ }
+ }
+
Label {
text: qsTr("On")
}
diff --git a/src/settingsui/bluetooth/Discovery.qml b/src/settingsui/bluetooth/Discovery.qml
index 4daa469..1b3184a 100644
--- a/src/settingsui/bluetooth/Discovery.qml
+++ b/src/settingsui/bluetooth/Discovery.qml
@@ -82,7 +82,7 @@ Item {
anchors.left: parent.left
anchors.top: parent.top
anchors.topMargin: 4
- source: mainList.getIcon(deviceType)
+ source: mainList.getIcon(type)
}
Column {
id: column