diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2018-07-25 14:42:06 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2018-07-25 14:42:18 +0200 |
commit | 25638b02766ae3109bfc83b3249e6d0dc9e21bdb (patch) | |
tree | 8ac8f0cd544dd39da674657940d6c509ea94721c /src/nfc | |
parent | fc2a206322f6190226ebc1f04062f2c9170f0bac (diff) | |
parent | b19148f9a0f820630bd83432d96117e9598c315d (diff) |
Merge remote-tracking branch 'gerrit/dev' into btlebtle
Change-Id: Id7698ec157a4e06296bcc27d48aaa8325dd3c23a
Diffstat (limited to 'src/nfc')
31 files changed, 306 insertions, 131 deletions
diff --git a/src/nfc/android/androidjninfc.cpp b/src/nfc/android/androidjninfc.cpp index f21d3b08..9a1c5227 100644 --- a/src/nfc/android/androidjninfc.cpp +++ b/src/nfc/android/androidjninfc.cpp @@ -63,6 +63,11 @@ bool isAvailable() return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"isAvailable"); } +bool isSupported() +{ + return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"isSupported"); +} + bool stopDiscovery() { return QAndroidJniObject::callStaticMethod<jboolean>(nfcClassName,"stop"); diff --git a/src/nfc/android/androidjninfc_p.h b/src/nfc/android/androidjninfc_p.h index 746a93ee..60e9a107 100644 --- a/src/nfc/android/androidjninfc_p.h +++ b/src/nfc/android/androidjninfc_p.h @@ -71,6 +71,7 @@ bool startDiscovery(); bool stopDiscovery(); QAndroidJniObject getStartIntent(); bool isAvailable(); +bool isSupported(); bool registerListener(AndroidNfcListenerInterface *listener); bool unregisterListener(AndroidNfcListenerInterface *listener); QAndroidJniObject getTag(const QAndroidJniObject &intent); diff --git a/src/nfc/doc/snippets/doc_src_qtnfc.cpp b/src/nfc/doc/snippets/doc_src_qtnfc.cpp index f4d7f91a..760d65fd 100644 --- a/src/nfc/doc/snippets/doc_src_qtnfc.cpp +++ b/src/nfc/doc/snippets/doc_src_qtnfc.cpp @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/snippets/doc_src_qtnfc.qml b/src/nfc/doc/snippets/doc_src_qtnfc.qml index 65efee56..78f7f83d 100644 --- a/src/nfc/doc/snippets/doc_src_qtnfc.qml +++ b/src/nfc/doc/snippets/doc_src_qtnfc.qml @@ -1,13 +1,23 @@ /**************************************************************************** ** ** Copyright (C) 2013 Aaron McCarthy <mccarthy.aaron@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/snippets/foorecord.cpp b/src/nfc/doc/snippets/foorecord.cpp index 14a83af3..4fecd712 100644 --- a/src/nfc/doc/snippets/foorecord.cpp +++ b/src/nfc/doc/snippets/foorecord.cpp @@ -1,12 +1,22 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/snippets/foorecord.h b/src/nfc/doc/snippets/foorecord.h index e8c130e4..c2501287 100644 --- a/src/nfc/doc/snippets/foorecord.h +++ b/src/nfc/doc/snippets/foorecord.h @@ -1,12 +1,22 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/snippets/main.cpp b/src/nfc/doc/snippets/main.cpp index 09d07b02..6f2bb0d7 100644 --- a/src/nfc/doc/snippets/main.cpp +++ b/src/nfc/doc/snippets/main.cpp @@ -1,12 +1,22 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/snippets/nfc.cpp b/src/nfc/doc/snippets/nfc.cpp index eb7ef989..82297682 100644 --- a/src/nfc/doc/snippets/nfc.cpp +++ b/src/nfc/doc/snippets/nfc.cpp @@ -1,12 +1,22 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are diff --git a/src/nfc/doc/src/nfc-index.qdoc b/src/nfc/doc/src/nfc-index.qdoc index c9acc92b..21f775a6 100644 --- a/src/nfc/doc/src/nfc-index.qdoc +++ b/src/nfc/doc/src/nfc-index.qdoc @@ -60,6 +60,15 @@ import statement in your \c .qml file: \snippet doc_src_qtnfc.qml import +\section1 Licenses + +Qt NFC is available under commercial licenses from \l{The Qt Company}. +In addition, it is available under free software licenses. Since Qt 5.4, +these free software licenses are +\l{GNU Lesser General Public License, version 3}, or +the \l{GNU General Public License, version 2}. +See \l{Qt Licensing} for further details. + \section1 Related Information \section2 Guides diff --git a/src/nfc/doc/src/nfc-qml.qdoc b/src/nfc/doc/src/nfc-qml.qdoc index 48df6d32..bbacb2de 100644 --- a/src/nfc/doc/src/nfc-qml.qdoc +++ b/src/nfc/doc/src/nfc-qml.qdoc @@ -28,7 +28,7 @@ /*! -\qmlmodule QtNfc 5.2 +\qmlmodule QtNfc 5.11 \title Qt NFC QML Types \ingroup qmlmodules \brief Provides QML types for accessing NFC Forum Tags. diff --git a/src/nfc/neard/neard_helper.cpp b/src/nfc/neard/neard_helper.cpp index ef0447a0..9922c1a8 100644 --- a/src/nfc/neard/neard_helper.cpp +++ b/src/nfc/neard/neard_helper.cpp @@ -62,10 +62,10 @@ NeardHelper::NeardHelper(QObject *parent) : return; } - connect(m_dbusObjectManager, SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)), - this, SLOT(interfacesAdded(QDBusObjectPath,InterfaceList))); - connect(m_dbusObjectManager, SIGNAL(InterfacesRemoved(QDBusObjectPath,QStringList)), - this, SLOT(interfacesRemoved(QDBusObjectPath,QStringList))); + connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, + this, &NeardHelper::interfacesAdded); + connect(m_dbusObjectManager, &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved, + this, &NeardHelper::interfacesRemoved); } NeardHelper *NeardHelper::instance() diff --git a/src/nfc/qllcpsocket_android_p.cpp b/src/nfc/qllcpsocket_android_p.cpp index e29634d4..26b50c34 100644 --- a/src/nfc/qllcpsocket_android_p.cpp +++ b/src/nfc/qllcpsocket_android_p.cpp @@ -71,7 +71,7 @@ void QLlcpSocketPrivate::connectToService(QNearFieldTarget *target, const QStrin QNXNFCManager::instance()->registerLLCPConnection(m_conListener, this); qQNXNFCDebug() << "Connecting client socket" << serviceUri << m_conListener; - connect(QNXNFCManager::instance(), SIGNAL(llcpDisconnected()), this, SLOT(disconnectFromService()));*/ + connect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService);*/ } void QLlcpSocketPrivate::disconnectFromService() @@ -83,7 +83,7 @@ void QLlcpSocketPrivate::disconnectFromService() qWarning() << Q_FUNC_INFO << "Error when trying to close LLCP socket"; } QNXNFCManager::instance()->unregisterLLCPConnection(m_conListener); - disconnect(QNXNFCManager::instance(), SIGNAL(llcpDisconnected()), this, SLOT(disconnectFromService())); + disconnect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService); q->disconnected(); m_conListener = 0; @@ -96,7 +96,7 @@ bool QLlcpSocketPrivate::bind(quint8 port) /*m_state = QLlcpSocket::ConnectedState; m_server = true; - connect(QNXNFCManager::instance(), SIGNAL(llcpDisconnected()), this, SLOT(disconnectFromService())); + connect(QNXNFCManager::instance(), &QNXNFCManager::llcpDisconnected, this, &QLlcpSocketPrivate::disconnectFromService); connected(QNXNFCManager::instance()->getLastTarget());*/ return true; diff --git a/src/nfc/qndefnfcsmartposterrecord.cpp b/src/nfc/qndefnfcsmartposterrecord.cpp index 73f2cd21..bc7acfab 100644 --- a/src/nfc/qndefnfcsmartposterrecord.cpp +++ b/src/nfc/qndefnfcsmartposterrecord.cpp @@ -566,7 +566,7 @@ void QNdefNfcSmartPosterRecord::addIcon(const QByteArray &type, const QByteArray rec.setType(type); rec.setData(data); - return addIcon(rec); + addIcon(rec); } /*! diff --git a/src/nfc/qndefnfctextrecord.cpp b/src/nfc/qndefnfctextrecord.cpp index 78736cc0..95fb4c66 100644 --- a/src/nfc/qndefnfctextrecord.cpp +++ b/src/nfc/qndefnfctextrecord.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE /*! \class QNdefNfcTextRecord - \brief The QNdefNfcTextRecord class provides an NFC RTD-Text + \brief The QNdefNfcTextRecord class provides an NFC RTD-Text. \ingroup connectivity-nfc \inmodule QtNfc diff --git a/src/nfc/qndefnfcurirecord.cpp b/src/nfc/qndefnfcurirecord.cpp index 44b17adf..3438d9f2 100644 --- a/src/nfc/qndefnfcurirecord.cpp +++ b/src/nfc/qndefnfcurirecord.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE /*! \class QNdefNfcUriRecord - \brief The QNdefNfcUriRecord class provides an NFC RTD-URI + \brief The QNdefNfcUriRecord class provides an NFC RTD-URI. \ingroup connectivity-nfc \inmodule QtNfc diff --git a/src/nfc/qnearfieldmanager.cpp b/src/nfc/qnearfieldmanager.cpp index 099a070c..02e4d918 100644 --- a/src/nfc/qnearfieldmanager.cpp +++ b/src/nfc/qnearfieldmanager.cpp @@ -119,6 +119,19 @@ QT_BEGIN_NAMESPACE */ /*! + \enum QNearFieldManager::AdapterState + + \since 5.12 + + This enum describes the different states a NFC adapter can have. + + \value Offline The nfc adapter is offline. + \value TurningOn The nfc adapter is turning on. + \value Online The nfc adapter is online. + \value TurningOff The nfc adapter is turning off. +*/ + +/*! \enum QNearFieldManager::TargetAccessMode This enum describes the different access modes an application can have. @@ -133,6 +146,16 @@ QT_BEGIN_NAMESPACE */ /*! + \fn void QNearFieldManager::adapterStateChanged(AdapterState state) + + \since 5.12 + + This signal is emitted whenever the state of the NFC adapter changed. + + \note Currently, this signal is only emitted on Android. +*/ + +/*! \fn void QNearFieldManager::targetDetected(QNearFieldTarget *target) This signal is emitted whenever a target is detected. The \a target parameter represents the @@ -169,10 +192,14 @@ QT_BEGIN_NAMESPACE QNearFieldManager::QNearFieldManager(QObject *parent) : QObject(parent), d_ptr(new QNearFieldManagerPrivateImpl) { - connect(d_ptr, SIGNAL(targetDetected(QNearFieldTarget*)), - this, SIGNAL(targetDetected(QNearFieldTarget*))); - connect(d_ptr, SIGNAL(targetLost(QNearFieldTarget*)), - this, SIGNAL(targetLost(QNearFieldTarget*))); + qRegisterMetaType<AdapterState>(); + + connect(d_ptr, &QNearFieldManagerPrivate::adapterStateChanged, + this, &QNearFieldManager::adapterStateChanged); + connect(d_ptr, &QNearFieldManagerPrivate::targetDetected, + this, &QNearFieldManager::targetDetected); + connect(d_ptr, &QNearFieldManagerPrivate::targetLost, + this, &QNearFieldManager::targetLost); } /*! @@ -186,10 +213,14 @@ QNearFieldManager::QNearFieldManager(QObject *parent) QNearFieldManager::QNearFieldManager(QNearFieldManagerPrivate *backend, QObject *parent) : QObject(parent), d_ptr(backend) { - connect(d_ptr, SIGNAL(targetDetected(QNearFieldTarget*)), - this, SIGNAL(targetDetected(QNearFieldTarget*))); - connect(d_ptr, SIGNAL(targetLost(QNearFieldTarget*)), - this, SIGNAL(targetLost(QNearFieldTarget*))); + qRegisterMetaType<AdapterState>(); + + connect(d_ptr, &QNearFieldManagerPrivate::adapterStateChanged, + this, &QNearFieldManager::adapterStateChanged); + connect(d_ptr, &QNearFieldManagerPrivate::targetDetected, + this, &QNearFieldManager::targetDetected); + connect(d_ptr, &QNearFieldManagerPrivate::targetLost, + this, &QNearFieldManager::targetLost); } /*! @@ -201,7 +232,10 @@ QNearFieldManager::~QNearFieldManager() } /*! - Returns true if NFC functionality is available; otherwise returns false. + Returns \c true if the device has a NFC adapter and + it is turned on; otherwise returns \c false. + + \sa isSupported() */ bool QNearFieldManager::isAvailable() const { @@ -211,6 +245,19 @@ bool QNearFieldManager::isAvailable() const } /*! + \since 5.12 + + Returns \c true if the underlying device has a NFC adapter; otherwise returns \c false. + + \sa isAvailable() +*/ +bool QNearFieldManager::isSupported() const +{ + Q_D(const QNearFieldManager); + + return d->isSupported(); +} +/*! \fn bool QNearFieldManager::startTargetDetection() Starts detecting targets and returns true if target detection is diff --git a/src/nfc/qnearfieldmanager.h b/src/nfc/qnearfieldmanager.h index 9583e01f..500b9631 100644 --- a/src/nfc/qnearfieldmanager.h +++ b/src/nfc/qnearfieldmanager.h @@ -56,6 +56,13 @@ class Q_NFC_EXPORT QNearFieldManager : public QObject Q_DECLARE_PRIVATE(QNearFieldManager) public: + enum class AdapterState { + Offline = 1, + TurningOn = 2, + Online = 3, + TurningOff = 4 + }; + Q_ENUM(AdapterState) enum TargetAccessMode { NoTargetAccess = 0x00, NdefReadTargetAccess = 0x01, @@ -70,6 +77,7 @@ public: ~QNearFieldManager(); bool isAvailable() const; + bool isSupported() const; void setTargetAccessModes(TargetAccessModes accessModes); TargetAccessModes targetAccessModes() const; @@ -91,6 +99,7 @@ public: bool unregisterNdefMessageHandler(int handlerId); Q_SIGNALS: + void adapterStateChanged(AdapterState state); void targetDetected(QNearFieldTarget *target); void targetLost(QNearFieldTarget *target); diff --git a/src/nfc/qnearfieldmanager_android.cpp b/src/nfc/qnearfieldmanager_android.cpp index a5693218..297f8ef8 100644 --- a/src/nfc/qnearfieldmanager_android.cpp +++ b/src/nfc/qnearfieldmanager_android.cpp @@ -48,22 +48,52 @@ #include "qdebug.h" #include "qlist.h" +#include <QScopedPointer> #include <QtCore/QMetaType> #include <QtCore/QMetaMethod> +#include <QtCore/private/qjnihelpers_p.h> QT_BEGIN_NAMESPACE +Q_GLOBAL_STATIC(QAndroidJniObject, broadcastReceiver) +Q_GLOBAL_STATIC(QList<QNearFieldManagerPrivateImpl *>, broadcastListener) + +extern "C" +{ + JNIEXPORT void JNICALL Java_org_qtproject_qt5_android_nfc_QtNfcBroadcastReceiver_jniOnReceive( + JNIEnv */*env*/, jobject /*javaObject*/, jint state) + { + QNearFieldManager::AdapterState adapterState = static_cast<QNearFieldManager::AdapterState>((int) state); + + for (const auto listener : *broadcastListener) { + Q_EMIT listener->adapterStateChanged(adapterState); + } + } +} + QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() : m_detecting(false), m_handlerID(0) { qRegisterMetaType<QAndroidJniObject>("QAndroidJniObject"); qRegisterMetaType<QNdefMessage>("QNdefMessage"); - connect(this, SIGNAL(targetDetected(QNearFieldTarget*)), this, SLOT(handlerTargetDetected(QNearFieldTarget*))); - connect(this, SIGNAL(targetLost(QNearFieldTarget*)), this, SLOT(handlerTargetLost(QNearFieldTarget*))); + + if (!broadcastReceiver->isValid()) { + *broadcastReceiver = QAndroidJniObject("org/qtproject/qt5/android/nfc/QtNfcBroadcastReceiver", + "(Landroid/content/Context;)V", QtAndroidPrivate::context()); + } + broadcastListener->append(this); + + connect(this, &QNearFieldManagerPrivateImpl::targetDetected, this, &QNearFieldManagerPrivateImpl::handlerTargetDetected); + connect(this, &QNearFieldManagerPrivateImpl::targetLost, this, &QNearFieldManagerPrivateImpl::handlerTargetLost); } QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl() { + broadcastListener->removeOne(this); + if (broadcastListener->isEmpty()) { + broadcastReceiver->callMethod<void>("unregisterReceiver"); + *broadcastReceiver = QAndroidJniObject(); + } } void QNearFieldManagerPrivateImpl::handlerTargetDetected(QNearFieldTarget *target) @@ -71,12 +101,12 @@ void QNearFieldManagerPrivateImpl::handlerTargetDetected(QNearFieldTarget *targe if (ndefMessageHandlers.count() == 0 && ndefFilterHandlers.count() == 0) // if no handler is registered return; if (target->hasNdefMessage()) { - connect(target, SIGNAL(ndefMessageRead(const QNdefMessage &, const QNearFieldTarget::RequestId &)), - this, SLOT(handlerNdefMessageRead(const QNdefMessage &, const QNearFieldTarget::RequestId &))); - connect(target, SIGNAL(requestCompleted(const QNearFieldTarget::RequestId &)), - this, SLOT(handlerRequestCompleted(const QNearFieldTarget::RequestId &))); - connect(target, SIGNAL(error(QNearFieldTarget::Error, const QNearFieldTarget::RequestId &)), - this, SLOT(handlerError(QNearFieldTarget::Error, const QNearFieldTarget::RequestId &))); + connect(reinterpret_cast<NearFieldTarget *>(target), &NearFieldTarget::ndefMessageRead, + this, &QNearFieldManagerPrivateImpl::handlerNdefMessageRead); + connect(target, &QNearFieldTarget::requestCompleted, + this, &QNearFieldManagerPrivateImpl::handlerRequestCompleted); + connect(target, &QNearFieldTarget::error, + this, &QNearFieldManagerPrivateImpl::handlerError); QNearFieldTarget::RequestId id = target->readNdefMessages(); m_idToTarget.insert(id, target); @@ -85,12 +115,12 @@ void QNearFieldManagerPrivateImpl::handlerTargetDetected(QNearFieldTarget *targe void QNearFieldManagerPrivateImpl::handlerTargetLost(QNearFieldTarget *target) { - disconnect(target, SIGNAL(ndefMessageRead(const QNdefMessage &, const QNearFieldTarget::RequestId &)), - this, SLOT(handlerNdefMessageRead(const QNdefMessage &, const QNearFieldTarget::RequestId &))); - disconnect(target, SIGNAL(requestCompleted(const QNearFieldTarget::RequestId &)), - this, SLOT(handlerRequestCompleted(const QNearFieldTarget::RequestId &))); - disconnect(target, SIGNAL(error(QNearFieldTarget::Error, const QNearFieldTarget::RequestId &)), - this, SLOT(handlerError(QNearFieldTarget::Error, const QNearFieldTarget::RequestId &))); + disconnect(reinterpret_cast<NearFieldTarget *>(target), &NearFieldTarget::ndefMessageRead, + this, &QNearFieldManagerPrivateImpl::handlerNdefMessageRead); + disconnect(target, &QNearFieldTarget::requestCompleted, + this, &QNearFieldManagerPrivateImpl::handlerRequestCompleted); + disconnect(target, &QNearFieldTarget::error, + this, &QNearFieldManagerPrivateImpl::handlerError); m_idToTarget.remove(m_idToTarget.key(target)); } @@ -176,6 +206,11 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const return AndroidNfc::isAvailable(); } +bool QNearFieldManagerPrivateImpl::isSupported() const +{ + return AndroidNfc::isSupported(); +} + bool QNearFieldManagerPrivateImpl::startTargetDetection() { if (m_detecting) @@ -282,8 +317,8 @@ void QNearFieldManagerPrivateImpl::onTargetDiscovered(QAndroidJniObject intent) target->setIntent(intent); // Updating existing target } else { target = new NearFieldTarget(intent, uid, this); - connect(target, SIGNAL(targetDestroyed(QByteArray)), this, SLOT(onTargetDestroyed(QByteArray))); - connect(target, SIGNAL(targetLost(QNearFieldTarget*)), this, SIGNAL(targetLost(QNearFieldTarget*))); + connect(target, &NearFieldTarget::targetDestroyed, this, &QNearFieldManagerPrivateImpl::onTargetDestroyed); + connect(target, &NearFieldTarget::targetLost, this, &QNearFieldManagerPrivateImpl::targetLost); } emit targetDetected(target); } diff --git a/src/nfc/qnearfieldmanager_android_p.h b/src/nfc/qnearfieldmanager_android_p.h index 69c99709..563d26bc 100644 --- a/src/nfc/qnearfieldmanager_android_p.h +++ b/src/nfc/qnearfieldmanager_android_p.h @@ -76,6 +76,7 @@ public: ~QNearFieldManagerPrivateImpl(); virtual bool isAvailable() const; + bool isSupported() const override; virtual bool startTargetDetection(); virtual void stopTargetDetection(); virtual int registerNdefMessageHandler(QObject *object, const QMetaMethod &method); diff --git a/src/nfc/qnearfieldmanager_emulator.cpp b/src/nfc/qnearfieldmanager_emulator.cpp index 3186bae5..c2c037f6 100644 --- a/src/nfc/qnearfieldmanager_emulator.cpp +++ b/src/nfc/qnearfieldmanager_emulator.cpp @@ -53,8 +53,8 @@ QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() tagActivator->initialize(); - connect(tagActivator, SIGNAL(tagActivated(TagBase*)), this, SLOT(tagActivated(TagBase*))); - connect(tagActivator, SIGNAL(tagDeactivated(TagBase*)), this, SLOT(tagDeactivated(TagBase*))); + connect(tagActivator, &TagActivator::tagActivated, this, &QNearFieldManagerPrivateImpl::tagActivated); + connect(tagActivator, &TagActivator::tagDeactivated, this, &QNearFieldManagerPrivateImpl::tagDeactivated); } QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl() diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp index f1758ae9..7c1c6e05 100644 --- a/src/nfc/qnearfieldmanager_neard.cpp +++ b/src/nfc/qnearfieldmanager_neard.cpp @@ -80,10 +80,10 @@ QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() if (!found) { qCWarning(QT_NFC_NEARD) << "no adapter found, neard daemon running?"; } else { - connect(m_neardHelper, SIGNAL(tagFound(QDBusObjectPath)), - this, SLOT(handleTagFound(QDBusObjectPath))); - connect(m_neardHelper, SIGNAL(tagRemoved(QDBusObjectPath)), - this, SLOT(handleTagRemoved(QDBusObjectPath))); + connect(m_neardHelper, &NeardHelper::tagFound, + this, &QNearFieldManagerPrivateImpl::handleTagFound); + connect(m_neardHelper, &NeardHelper::tagRemoved, + this, &QNearFieldManagerPrivateImpl::handleTagRemoved); } } @@ -114,6 +114,21 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const return false; } +bool QNearFieldManagerPrivateImpl::isSupported() const +{ + if (m_adapterPath.isEmpty()) { + qCWarning(QT_NFC_NEARD) << "no adapter found, neard daemon running?"; + return false; + } + + if (!m_neardHelper->dbusObjectManager()->isValid() || m_adapterPath.isNull()) { + qCWarning(QT_NFC_NEARD) << "dbus object manager invalid or adapter path invalid"; + return false; + } + + return true; +} + bool QNearFieldManagerPrivateImpl::startTargetDetection() { qCDebug(QT_NFC_NEARD) << "starting target detection"; diff --git a/src/nfc/qnearfieldmanager_neard_p.h b/src/nfc/qnearfieldmanager_neard_p.h index b50f947a..cf026982 100644 --- a/src/nfc/qnearfieldmanager_neard_p.h +++ b/src/nfc/qnearfieldmanager_neard_p.h @@ -75,6 +75,8 @@ public: bool isAvailable() const; + bool isSupported() const override; + bool startTargetDetection(); void stopTargetDetection(); diff --git a/src/nfc/qnearfieldmanager_p.h b/src/nfc/qnearfieldmanager_p.h index 7e461da8..351c844a 100644 --- a/src/nfc/qnearfieldmanager_p.h +++ b/src/nfc/qnearfieldmanager_p.h @@ -82,6 +82,11 @@ public: return false; } + virtual bool isSupported() const + { + return false; + } + virtual bool startTargetDetection() { return false; @@ -124,6 +129,7 @@ public: } signals: + void adapterStateChanged(QNearFieldManager::AdapterState state); void targetDetected(QNearFieldTarget *target); void targetLost(QNearFieldTarget *target); diff --git a/src/nfc/qnearfieldsharemanager.cpp b/src/nfc/qnearfieldsharemanager.cpp index 515a9d62..0709f60e 100644 --- a/src/nfc/qnearfieldsharemanager.cpp +++ b/src/nfc/qnearfieldsharemanager.cpp @@ -149,7 +149,7 @@ QNearFieldShareManager::~QNearFieldShareManager() void QNearFieldShareManager::setShareModes(ShareModes mode) { Q_D(QNearFieldShareManager); - return d->setShareModes(mode); + d->setShareModes(mode); } /*! diff --git a/src/nfc/qnearfieldtagtype1.cpp b/src/nfc/qnearfieldtagtype1.cpp index 34f2c8b8..7f27fbe9 100644 --- a/src/nfc/qnearfieldtagtype1.cpp +++ b/src/nfc/qnearfieldtagtype1.cpp @@ -440,9 +440,7 @@ QNearFieldTarget::RequestId QNearFieldTagType1::readNdefMessages() if (d->m_readNdefMessageState == QNearFieldTagType1Private::NotReadingNdefMessage) { d->progressToNextNdefReadMessageState(); } else { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, NdefReadError), - Q_ARG(QNearFieldTarget::RequestId, d->m_readNdefRequestId)); + reportError(QNearFieldTarget::NdefReadError, d->m_readNdefRequestId); } return d->m_readNdefRequestId; @@ -462,9 +460,7 @@ QNearFieldTarget::RequestId QNearFieldTagType1::writeNdefMessages(const QList<QN d->m_ndefWriteMessages = messages; d->progressToNextNdefWriteMessageState(); } else { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, NdefWriteError), - Q_ARG(QNearFieldTarget::RequestId, d->m_readNdefRequestId)); + reportError(QNearFieldTarget::NdefWriteError, d->m_readNdefRequestId); } return d->m_writeNdefRequestId; diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp index e642824b..e9a6fa11 100644 --- a/src/nfc/qnearfieldtarget.cpp +++ b/src/nfc/qnearfieldtarget.cpp @@ -530,4 +530,17 @@ bool QNearFieldTarget::handleResponse(const QNearFieldTarget::RequestId &id, return true; } +/*! + \since 5.12 + + Reports the \a error for the request \a id by appending the signal emission to the event queue. +*/ +void QNearFieldTarget::reportError(QNearFieldTarget::Error error, + const QNearFieldTarget::RequestId &id) +{ + QMetaObject::invokeMethod(this, [this, error, id]() { + Q_EMIT this->error(error, id); + }, Qt::QueuedConnection); +} + QT_END_NAMESPACE diff --git a/src/nfc/qnearfieldtarget.h b/src/nfc/qnearfieldtarget.h index e51960f7..868b52d5 100644 --- a/src/nfc/qnearfieldtarget.h +++ b/src/nfc/qnearfieldtarget.h @@ -153,6 +153,8 @@ protected: Q_INVOKABLE virtual bool handleResponse(const QNearFieldTarget::RequestId &id, const QByteArray &response); + void reportError(QNearFieldTarget::Error error, const QNearFieldTarget::RequestId &id); + Q_SIGNALS: void disconnected(); diff --git a/src/nfc/qnearfieldtarget_android.cpp b/src/nfc/qnearfieldtarget_android.cpp index 50c5c1b3..78da6ac2 100644 --- a/src/nfc/qnearfieldtarget_android.cpp +++ b/src/nfc/qnearfieldtarget_android.cpp @@ -147,25 +147,19 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages() // Making sure that target is still in range QNearFieldTarget::RequestId requestId(new QNearFieldTarget::RequestIdPrivate); if (!m_intent.isValid()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::TargetOutOfRangeError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::TargetOutOfRangeError, requestId); return requestId; } // Getting Ndef technology object if (!setTagTechnology({NDEFTECHNOLOGY})) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::UnsupportedError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::UnsupportedError, requestId); return requestId; } // Connect if (!connect()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::TargetOutOfRangeError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::TargetOutOfRangeError, requestId); return requestId; } @@ -174,9 +168,7 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages() if (catchJavaExceptions()) ndefMessage = QAndroidJniObject(); if (!ndefMessage.isValid()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::NdefReadError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::NdefReadError, requestId); return requestId; } @@ -191,13 +183,17 @@ QNearFieldTarget::RequestId NearFieldTarget::readNdefMessages() // Sending QNdefMessage, requestCompleted and exit. QNdefMessage qNdefMessage = QNdefMessage::fromByteArray(ndefMessageQBA); - QMetaObject::invokeMethod(this, "ndefMessageRead", Qt::QueuedConnection, - Q_ARG(const QNdefMessage&, qNdefMessage)); - QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); - QMetaObject::invokeMethod(this, "ndefMessageRead", Qt::QueuedConnection, - Q_ARG(const QNdefMessage&, qNdefMessage), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + QMetaObject::invokeMethod(this, [this, qNdefMessage]() { + Q_EMIT this->QNearFieldTarget::ndefMessageRead(qNdefMessage); + }, Qt::QueuedConnection); + QMetaObject::invokeMethod(this, [this, requestId]() { + Q_EMIT this->requestCompleted(requestId); + }, Qt::QueuedConnection); + QMetaObject::invokeMethod(this, [this, qNdefMessage, requestId]() { + //TODO This is an Android specific signal in NearFieldTarget. + // We need to check if it is still necessary. + Q_EMIT this->ndefMessageRead(qNdefMessage, requestId); + }, Qt::QueuedConnection); return requestId; } @@ -245,9 +241,7 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma // Connecting QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate()); if (!connect()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::TargetOutOfRangeError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::TargetOutOfRangeError, requestId); return requestId; } @@ -259,9 +253,7 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma // Writing QAndroidJniObject myNewVal = m_tagTech.callObjectMethod("transceive", "([B)[B", jba); if (catchJavaExceptions()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::CommandError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::CommandError, requestId); return requestId; } QByteArray result = jbyteArrayToQByteArray(myNewVal.object<jbyteArray>()); @@ -273,8 +265,9 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma // Closing connection disconnect(); // IOException at this point does not matter anymore. } - QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + QMetaObject::invokeMethod(this, [this, requestId]() { + Q_EMIT this->requestCompleted(requestId); + }, Qt::QueuedConnection); return requestId; } @@ -297,7 +290,6 @@ QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdef QAndroidJniEnvironment env; const char *writeMethod; - QAndroidJniObject tagTechnology; if (!setTagTechnology({NDEFFORMATABLETECHNOLOGY, NDEFTECHNOLOGY})) return QNearFieldTarget::RequestId(); @@ -311,9 +303,7 @@ QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdef // Connecting QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate()); if (!connect()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::TargetOutOfRangeError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::TargetOutOfRangeError, requestId); return requestId; } @@ -324,18 +314,14 @@ QNearFieldTarget::RequestId NearFieldTarget::writeNdefMessages(const QList<QNdef env->SetByteArrayRegion(jba.object<jbyteArray>(), 0, ba.size(), reinterpret_cast<jbyte*>(ba.data())); QAndroidJniObject jmessage = QAndroidJniObject("android/nfc/NdefMessage", "([B)V", jba.object<jbyteArray>()); if (catchJavaExceptions()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::UnknownError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::UnknownError, requestId); return requestId; } // Writing - tagTechnology.callMethod<void>(writeMethod, "(Landroid/nfc/NdefMessage;)V", jmessage.object<jobject>()); + m_tagTech.callMethod<void>(writeMethod, "(Landroid/nfc/NdefMessage;)V", jmessage.object<jobject>()); if (catchJavaExceptions()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::NdefWriteError), - Q_ARG(const QNearFieldTarget::RequestId&, requestId)); + reportError(QNearFieldTarget::NdefWriteError, requestId); return requestId; } diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp index 29b1f74d..030718cc 100644 --- a/src/nfc/qnearfieldtarget_emulator.cpp +++ b/src/nfc/qnearfieldtarget_emulator.cpp @@ -82,9 +82,7 @@ QNearFieldTarget::RequestId TagType1::sendCommand(const QByteArray &command) // tag not in proximity if (!tagMap.value(m_tag)) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, TargetOutOfRangeError), - Q_ARG(QNearFieldTarget::RequestId, id)); + reportError(QNearFieldTarget::TargetOutOfRangeError, id); return id; } @@ -93,17 +91,13 @@ QNearFieldTarget::RequestId TagType1::sendCommand(const QByteArray &command) QByteArray response = m_tag->processCommand(command + char(crc & 0xff) + char(crc >> 8)); if (response.isEmpty()) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, NoResponseError), - Q_ARG(QNearFieldTarget::RequestId, id)); + reportError(QNearFieldTarget::NoResponseError, id); return id; } // check crc if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, ChecksumMismatchError), - Q_ARG(QNearFieldTarget::RequestId, id)); + reportError(QNearFieldTarget::ChecksumMismatchError, id); return id; } @@ -152,9 +146,7 @@ QNearFieldTarget::RequestId TagType2::sendCommand(const QByteArray &command) // tag not in proximity if (!tagMap.value(m_tag)) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, TargetOutOfRangeError), - Q_ARG(QNearFieldTarget::RequestId, id)); + reportError(QNearFieldTarget::TargetOutOfRangeError, id); return id; } @@ -168,9 +160,7 @@ QNearFieldTarget::RequestId TagType2::sendCommand(const QByteArray &command) if (response.length() > 1) { // check crc if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNearFieldTarget::Error, ChecksumMismatchError), - Q_ARG(QNearFieldTarget::RequestId, id)); + reportError(QNearFieldTarget::ChecksumMismatchError, id); return id; } diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h index c84e033f..625cee67 100644 --- a/src/nfc/qnearfieldtarget_neard_p.h +++ b/src/nfc/qnearfieldtarget_neard_p.h @@ -353,14 +353,13 @@ private: if (!newNdefMessage.isEmpty()) { QMetaObject::invokeMethod(this, "ndefMessageRead", Qt::QueuedConnection, - Q_ARG(const QNdefMessage, newNdefMessage)); + Q_ARG(QNdefMessage, newNdefMessage)); // the request id in requestCompleted has to match the one created in readNdefMessages - QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::RequestId, m_currentReadRequestId)); + QMetaObject::invokeMethod(this, [this]() { + Q_EMIT this->requestCompleted(this->m_currentReadRequestId); + }, Qt::QueuedConnection); } else { - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::Error, QNearFieldTarget::UnknownError), - Q_ARG(const QNearFieldTarget::RequestId, m_currentReadRequestId)); + this->reportError(QNearFieldTarget::UnknownError, m_currentReadRequestId); } m_readRequested = false; @@ -388,14 +387,13 @@ private: reply.waitForFinished(); if (reply.isError()) { qCWarning(QT_NFC_NEARD) << "Error writing to NFC tag" << reply.error(); - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::Error, QNearFieldTarget::UnknownError), - Q_ARG(const QNearFieldTarget::RequestId, m_currentWriteRequestId)); + this->reportError(QNearFieldTarget::UnknownError, m_currentWriteRequestId); } QMetaObject::invokeMethod(this, "ndefMessagesWritten", Qt::QueuedConnection); - QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection, - Q_ARG(const QNearFieldTarget::RequestId, m_currentWriteRequestId)); + QMetaObject::invokeMethod(this, [this]() { + Q_EMIT this->requestCompleted(this->m_currentWriteRequestId); + }, Qt::QueuedConnection); } // invalidate current write request diff --git a/src/nfc/qqmlndefrecord.cpp b/src/nfc/qqmlndefrecord.cpp index cd6620cc..a7304f00 100644 --- a/src/nfc/qqmlndefrecord.cpp +++ b/src/nfc/qqmlndefrecord.cpp @@ -228,7 +228,7 @@ QQmlNdefRecord *qNewDeclarativeNdefRecordForNdefRecord(const QNdefRecord &record continue; return static_cast<QQmlNdefRecord *>(metaObject->newInstance( - Q_ARG(QNdefRecord, record), Q_ARG(QObject *, 0))); + Q_ARG(QNdefRecord, record), Q_ARG(QObject*, 0))); } return new QQmlNdefRecord(record); |