summaryrefslogtreecommitdiffstats
path: root/examples/nfc/annotatedurl/annotatedurl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nfc/annotatedurl/annotatedurl.cpp')
-rw-r--r--examples/nfc/annotatedurl/annotatedurl.cpp56
1 files changed, 52 insertions, 4 deletions
diff --git a/examples/nfc/annotatedurl/annotatedurl.cpp b/examples/nfc/annotatedurl/annotatedurl.cpp
index f29045b6..cd35c4ef 100644
--- a/examples/nfc/annotatedurl/annotatedurl.cpp
+++ b/examples/nfc/annotatedurl/annotatedurl.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtNfc module.
**
@@ -17,8 +17,8 @@
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
-** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
-** of its contributors may be used to endorse or promote products derived
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
@@ -40,6 +40,7 @@
#include "annotatedurl.h"
+#include <qnearfieldmanager.h>
#include <qnearfieldtarget.h>
#include <qndefmessage.h>
#include <qndefrecord.h>
@@ -53,14 +54,61 @@
#include <QLabel>
#include <QMouseEvent>
#include <QDesktopServices>
+#include <QDebug>
AnnotatedUrl::AnnotatedUrl(QObject *parent)
: QObject(parent)
{
+ //! [QNearFieldManager register handler]
+ manager = new QNearFieldManager(this);
+ if (!manager->isAvailable()) {
+ qWarning() << "NFC not available";
+ return;
+ }
+
+ QNdefFilter filter;
+ filter.setOrderMatch(false);
+ filter.appendRecord<QNdefNfcTextRecord>(1, UINT_MAX);
+ filter.appendRecord<QNdefNfcUriRecord>();
+ int result = manager->registerNdefMessageHandler(filter, this,
+ SLOT(handleMessage(QNdefMessage,QNearFieldTarget*)));
+ //! [QNearFieldManager register handler]
+
+ if (result != -1)
+ return;
+
+ manager->startTargetDetection();
+ connect(manager, SIGNAL(targetDetected(QNearFieldTarget*)),
+ this, SLOT(targetDetected(QNearFieldTarget*)));
+ connect(manager, SIGNAL(targetLost(QNearFieldTarget*)),
+ this, SLOT(targetLost(QNearFieldTarget*)));
}
AnnotatedUrl::~AnnotatedUrl()
{
+
+}
+
+void AnnotatedUrl::targetDetected(QNearFieldTarget *target)
+{
+ if (!target)
+ return;
+
+ connect(target, SIGNAL(ndefMessageRead(QNdefMessage)),
+ this, SLOT(handlePolledNdefMessage(QNdefMessage)));
+ target->readNdefMessages();
+}
+
+void AnnotatedUrl::targetLost(QNearFieldTarget *target)
+{
+ if (target)
+ target->deleteLater();
+}
+
+void AnnotatedUrl::handlePolledNdefMessage(QNdefMessage message)
+{
+ QNearFieldTarget *target = qobject_cast<QNearFieldTarget *>(sender());
+ handleMessage(message, target);
}
//! [handleMessage 1]