diff options
author | Fabian Bumberger <fbumberger@rim.com> | 2013-08-01 18:15:07 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-06 13:10:31 +0200 |
commit | d7ab00bac1d94bfdca412fab47a0d125f70bcb3a (patch) | |
tree | 6dd4accde959f920c9a5de5296f176070f1dfaa5 | |
parent | eacbe014db7a502b1045e848dc7ca40a2bb9e635 (diff) |
QNX: Emit pairing finished signal
Pairing finished signal is emitted after pairing was requested.
Also fixes a typo and a bug where the q Pointer was not saved.
Task-number: QTBUG-32247
Change-Id: Ia2d32fdafd9510908f278edda927071199326f5d
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp | 4 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice.cpp | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_p.h | 4 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_qnx.cpp | 75 | ||||
-rw-r--r-- | src/bluetooth/qnx/ppshelpers.cpp | 3 | ||||
-rw-r--r-- | src/bluetooth/qnx/ppshelpers_p.h | 2 |
6 files changed, 74 insertions, 15 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp index 58d5783a..35a7c6d8 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp @@ -59,8 +59,8 @@ QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate() if (pendingStart) stop(); - ppsUnreguisterForEvent(QStringLiteral("device_added"), this); - ppsUnreguisterForEvent(QStringLiteral("device_search"), this); + ppsUnregisterForEvent(QStringLiteral("device_added"), this); + ppsUnregisterForEvent(QStringLiteral("device_search"), this); } bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp index 68659d8a..22d3986a 100644 --- a/src/bluetooth/qbluetoothlocaldevice.cpp +++ b/src/bluetooth/qbluetoothlocaldevice.cpp @@ -220,6 +220,7 @@ bool QBluetoothLocalDevice::isValid() const \fn QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) Set the \a pairing status with \a address. The results are returned by the signal, pairingFinished(). + On BlackBerry AuthorizedPaired is not possible and will have the same behavior as Paired. Caution: creating a pairing may take minutes, and may require the user to acknowledge. */ diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h index 4fa7f3f0..6a7e4ac8 100644 --- a/src/bluetooth/qbluetoothlocaldevice_p.h +++ b/src/bluetooth/qbluetoothlocaldevice_p.h @@ -119,7 +119,7 @@ class QBluetoothLocalDevicePrivate : public QObject Q_OBJECT Q_DECLARE_PUBLIC(QBluetoothLocalDevice) public: - QBluetoothLocalDevicePrivate(); + QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *); ~QBluetoothLocalDevicePrivate(); static QString name(); @@ -131,6 +131,8 @@ public: void setHostMode(QBluetoothLocalDevice::HostMode mode); QBluetoothLocalDevice::HostMode hostMode() const; + void requestPairing(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing); + void setAccess(int); Q_INVOKABLE void controlReply(ppsResult res); diff --git a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp index 4bf00082..a75347c4 100644 --- a/src/bluetooth/qbluetoothlocaldevice_qnx.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_qnx.cpp @@ -49,14 +49,14 @@ QT_BEGIN_NAMESPACE_BLUETOOTH QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent) : QObject(parent) { - this->d_ptr = new QBluetoothLocalDevicePrivate(); + this->d_ptr = new QBluetoothLocalDevicePrivate(this); this->d_ptr->isValidDevice = true; //assume single local device on QNX } QBluetoothLocalDevice::QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent) : QObject(parent) { - this->d_ptr = new QBluetoothLocalDevicePrivate(); + this->d_ptr = new QBluetoothLocalDevicePrivate(this); //works since we assume a single local device on QNX this->d_ptr->isValidDevice = (QBluetoothLocalDevicePrivate::address() == address); @@ -104,9 +104,19 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) { - Q_UNUSED(pairing); - if (isValid()) - ppsSendControlMessage("initiate_pairing", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), 0); + if (address.isNull()) { + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); + return; + } + + const Pairing current_pairing = pairingStatus(address); + if (current_pairing == pairing) { + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, pairing)); + return; + } + d_ptr->requestPairing(address, pairing); } QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const @@ -125,16 +135,21 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation) Q_UNUSED(confirmation); } -QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate() +QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q) + : q_ptr(q) { ppsRegisterControl(); ppsRegisterForEvent(QStringLiteral("access_changed"), this); + ppsRegisterForEvent(QStringLiteral("pairing_complete"), this); + ppsRegisterForEvent(QStringLiteral("device_deleted"), this); } QBluetoothLocalDevicePrivate::~QBluetoothLocalDevicePrivate() { ppsUnregisterControl(this); - ppsUnreguisterForEvent(QStringLiteral("access_changed"), this); + ppsUnregisterForEvent(QStringLiteral("access_changed"), this); + ppsUnregisterForEvent(QStringLiteral("pairing_complete"), this); + ppsUnregisterForEvent(QStringLiteral("device_deleted"), this); } bool QBluetoothLocalDevicePrivate::isValid() const @@ -192,6 +207,19 @@ void QBluetoothLocalDevicePrivate::setHostMode(QBluetoothLocalDevice::HostMode m setAccess(2); } } + +void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &address, + QBluetoothLocalDevice::Pairing pairing) +{ + if (pairing == QBluetoothLocalDevice::Paired || pairing == QBluetoothLocalDevice::AuthorizedPaired) { + ppsSendControlMessage("initiate_pairing", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), + this); + } else { + ppsSendControlMessage("remove_device", QStringLiteral("{\"addr\":\"%1\"}").arg(address.toString()), + this); + } +} + QBluetoothLocalDevice::HostMode QBluetoothLocalDevicePrivate::hostMode() const { if (!isValid()) @@ -229,17 +257,44 @@ void QBluetoothLocalDevicePrivate::controlReply(ppsResult result) qBBBluetoothDebug() << Q_FUNC_INFO << result.msg << result.dat; if (!result.errorMsg.isEmpty()) { qWarning() << Q_FUNC_INFO << result.errorMsg; - q_ptr->error(QBluetoothLocalDevice::UnknownError); + if (result.msg == QStringLiteral("initiate_pairing")) + q_ptr->error(QBluetoothLocalDevice::PairingError); + else + q_ptr->error(QBluetoothLocalDevice::UnknownError); } } void QBluetoothLocalDevicePrivate::controlEvent(ppsResult result) { + qBBBluetoothDebug() << Q_FUNC_INFO << "Control Event" << result.msg; if (result.msg == QStringLiteral("access_changed")) { if (__newHostMode == -1 && result.dat.size() > 1 && result.dat.first() == QStringLiteral("level")) { - qBBBluetoothDebug() << "New Host mode" << hostMode(); - Q_EMIT q_ptr->hostModeStateChanged(hostMode()); + QBluetoothLocalDevice::HostMode newHostMode = hostMode(); + qBBBluetoothDebug() << "New Host mode" << newHostMode; + Q_EMIT q_ptr->hostModeStateChanged(newHostMode); + } + } else if (result.msg == QStringLiteral("pairing_complete")) { + qBBBluetoothDebug() << "pairing completed"; + if (result.dat.contains(QStringLiteral("addr"))) { + const QBluetoothAddress address = QBluetoothAddress( + result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1)); + + QBluetoothLocalDevice::Pairing pairingStatus = QBluetoothLocalDevice::Paired; + + if (result.dat.contains(QStringLiteral("trusted")) && + result.dat.at(result.dat.indexOf(QStringLiteral("trusted")) + 1) == QStringLiteral("true")) { + pairingStatus = QBluetoothLocalDevice::AuthorizedPaired; + } + qBBBluetoothDebug() << "pairing completed" << address.toString(); + Q_EMIT q_ptr->pairingFinished(address, pairingStatus); + } + } else if (result.msg == QStringLiteral("device_deleted")) { + qBBBluetoothDebug() << "device deleted"; + if (result.dat.contains(QStringLiteral("addr"))) { + const QBluetoothAddress address = QBluetoothAddress( + result.dat.at(result.dat.indexOf(QStringLiteral("addr")) + 1)); + Q_EMIT q_ptr->pairingFinished(address, QBluetoothLocalDevice::Unpaired); } } } diff --git a/src/bluetooth/qnx/ppshelpers.cpp b/src/bluetooth/qnx/ppshelpers.cpp index 6225ef0d..eb7f4f31 100644 --- a/src/bluetooth/qnx/ppshelpers.cpp +++ b/src/bluetooth/qnx/ppshelpers.cpp @@ -261,6 +261,7 @@ void ppsDecodeControlResponse() if (wMessage.second != 0) wMessage.second->metaObject()->invokeMethod(wMessage.second, "controlReply", Q_ARG(ppsResult, result)); } else if (resType == EVENT) { + qBBBluetoothDebug() << "Distributing event" << result.msg; for (int i=0; i < evtRegistration.size(); i++) { if (result.msg == evtRegistration.at(i).first) evtRegistration.at(i).second->metaObject()->invokeMethod(evtRegistration.at(i).second, "controlEvent", Q_ARG(ppsResult, result)); @@ -421,7 +422,7 @@ void ppsRegisterForEvent(const QString &evt, QObject *obj) evtRegistration.append(QPair<QString, QObject*>(evt,obj)); } -void ppsUnreguisterForEvent(const QString &str, QObject *obj) +void ppsUnregisterForEvent(const QString &str, QObject *obj) { for (int i=evtRegistration.size()-1; i >= 0; --i) { if (evtRegistration.at(i).first == str && evtRegistration.at(i).second == obj) diff --git a/src/bluetooth/qnx/ppshelpers_p.h b/src/bluetooth/qnx/ppshelpers_p.h index 2809cb28..d09768a3 100644 --- a/src/bluetooth/qnx/ppshelpers_p.h +++ b/src/bluetooth/qnx/ppshelpers_p.h @@ -128,7 +128,7 @@ bool ppsReadRemoteDevice(int fd, pps_decoder_t *decoder, QBluetoothAddress *btAd void ppsRegisterForEvent(const QString &evt, QObject *obj); -void ppsUnreguisterForEvent(const QString &evt, QObject *obj); +void ppsUnregisterForEvent(const QString &evt, QObject *obj); QT_END_NAMESPACE_BLUETOOTH |