summaryrefslogtreecommitdiffstats
path: root/src/imports/nfc
diff options
context:
space:
mode:
authorMichael Zanetti <michael.zanetti@nokia.com>2011-11-08 17:05:35 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-16 00:46:54 +0100
commit27ae5800b1f57ac14746279fd62b507bdde026bf (patch)
tree9fdbbca6f59b1765014c465dff9fcd2ffc4d44b5 /src/imports/nfc
parentf0daca9ff8108b15e0ede3ea638393541d2149e0 (diff)
ported bluetooth and nfc declarative plugins from QtMobility to QtConnectivity
Change-Id: I1792d516ca80418af9fc6249e4aa55964fc94b38 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/imports/nfc')
-rw-r--r--src/imports/nfc/nfc.pro32
-rw-r--r--src/imports/nfc/plugin.cpp80
-rw-r--r--src/imports/nfc/qdeclarativendeffilter.cpp147
-rw-r--r--src/imports/nfc/qdeclarativendeffilter_p.h78
-rw-r--r--src/imports/nfc/qdeclarativendefmimerecord.cpp100
-rw-r--r--src/imports/nfc/qdeclarativendefmimerecord_p.h66
-rw-r--r--src/imports/nfc/qdeclarativendeftextrecord.cpp183
-rw-r--r--src/imports/nfc/qdeclarativendeftextrecord_p.h87
-rw-r--r--src/imports/nfc/qdeclarativendefurirecord.cpp99
-rw-r--r--src/imports/nfc/qdeclarativendefurirecord_p.h71
-rw-r--r--src/imports/nfc/qdeclarativenearfield.cpp285
-rw-r--r--src/imports/nfc/qdeclarativenearfield_p.h115
-rw-r--r--src/imports/nfc/qdeclarativenearfieldsocket.cpp383
-rw-r--r--src/imports/nfc/qdeclarativenearfieldsocket_p.h115
-rw-r--r--src/imports/nfc/qmldir1
-rw-r--r--src/imports/nfc/qnfcimport.pri30
16 files changed, 1872 insertions, 0 deletions
diff --git a/src/imports/nfc/nfc.pro b/src/imports/nfc/nfc.pro
new file mode 100644
index 00000000..5ad84d2f
--- /dev/null
+++ b/src/imports/nfc/nfc.pro
@@ -0,0 +1,32 @@
+TARGET = declarative_nfc
+TARGETPATH = QtNfc
+
+include(qnfcimport.pri)
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+DESTDIR = $$QT.nfc.imports/$$TARGETPATH
+INSTALLS += target
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+INSTALLS += qmldir
+
+QT += declarative nfc
+
+# Input
+HEADERS += \
+ qdeclarativenearfieldsocket_p.h \
+ qdeclarativenearfield_p.h \
+ qdeclarativendeffilter_p.h \
+ qdeclarativendeftextrecord_p.h \
+ qdeclarativendefurirecord_p.h \
+ qdeclarativendefmimerecord_p.h
+
+SOURCES += plugin.cpp \
+ qdeclarativenearfieldsocket.cpp \
+ qdeclarativenearfield.cpp \
+ qdeclarativendeffilter.cpp \
+ qdeclarativendeftextrecord.cpp \
+ qdeclarativendefurirecord.cpp \
+ qdeclarativendefmimerecord.cpp
+
+INSTALLS += qmldir
diff --git a/src/imports/nfc/plugin.cpp b/src/imports/nfc/plugin.cpp
new file mode 100644
index 00000000..75a31e6d
--- /dev/null
+++ b/src/imports/nfc/plugin.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
+
+#include <qdeclarativendefrecord.h>
+
+#include "qdeclarativenearfieldsocket_p.h"
+#include "qdeclarativenearfield_p.h"
+#include "qdeclarativendeffilter_p.h"
+#include "qdeclarativendeftextrecord_p.h"
+#include "qdeclarativendefurirecord_p.h"
+#include "qdeclarativendefmimerecord_p.h"
+
+QT_USE_NAMESPACE
+
+class QNfcQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ void registerTypes(const char *uri)
+ {
+ Q_ASSERT(uri == QLatin1String("QtNfc"));
+
+ int major = 5;
+ int minor = 0;
+ qmlRegisterType<QDeclarativeNearFieldSocket>(uri, major, minor, "NearFieldSocket");
+
+ qmlRegisterType<QDeclarativeNearField>(uri, major, minor, "NearField");
+ qmlRegisterType<QDeclarativeNdefFilter>(uri, major, minor, "NdefFilter");
+ qmlRegisterType<QDeclarativeNdefRecord>(uri, major, minor, "NdefRecord");
+ qmlRegisterType<QDeclarativeNdefTextRecord>(uri, major, minor, "NdefTextRecord");
+ qmlRegisterType<QDeclarativeNdefUriRecord>(uri, major, minor, "NdefUriRecord");
+ qmlRegisterType<QDeclarativeNdefMimeRecord>(uri, major, minor, "NdefMimeRecord");
+ }
+};
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qnfcqmlplugin, QNfcQmlPlugin);
diff --git a/src/imports/nfc/qdeclarativendeffilter.cpp b/src/imports/nfc/qdeclarativendeffilter.cpp
new file mode 100644
index 00000000..8625d27b
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendeffilter.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativendeffilter_p.h"
+
+/*!
+ \qmlclass NdefFilter QDeclarativeNdefFilter
+ \brief The NdefFilter element represents a filtering constraint for NDEF message records.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \sa NearField
+ \sa QNdefFilter
+
+ The NdefFilter element is part of the \bold {QtMobility.connectivity 1.2} module.
+
+ The NdefFilter element is used with the NearField element to read NDEF messages from NFC Forum
+ tags that match a given structure.
+
+ \code
+ NearField {
+ filter: [
+ NdefFilter {
+ type: "urn:nfc:wkt:U"
+ minimum: 1
+ maximum: 1
+ }
+ ]
+ }
+ \endcode
+*/
+
+/*!
+ \qmlproperty string NdefFilter::type
+
+ This property holds the NDEF record type that the filter matches. This property must be set to
+ the fully qualified record type, i.e. including the NIS and NSS prefixes. For example set to
+ \i {urn:nfc:wkt:U} to match NFC RTD-URI records.
+*/
+
+/*!
+ \qmlproperty int NdefFilter::minimum
+
+ This property holds the minimum number of records of the given type that must be in the NDEF
+ message for it match.
+
+ To match any number of records set both the minimum and maximum properties to -1.
+
+ \sa maximum
+*/
+
+/*!
+ \qmlproperty int NdefFilter::maximum
+
+ This property holds the maximum number of records of the given type that must be in the NDEF
+ message for it match.
+
+ To match any number of records set both the minimum and maximum properties to -1.
+
+ \sa minimum
+*/
+
+QDeclarativeNdefFilter::QDeclarativeNdefFilter(QObject *parent)
+: QObject(parent), m_minimum(-1), m_maximum(-1)
+{
+}
+
+QString QDeclarativeNdefFilter::type() const
+{
+ return m_type;
+}
+
+void QDeclarativeNdefFilter::setType(const QString &t)
+{
+ if (m_type == t)
+ return;
+
+ m_type = t;
+ emit typeChanged();
+}
+
+int QDeclarativeNdefFilter::minimum() const
+{
+ return m_minimum;
+}
+
+void QDeclarativeNdefFilter::setMinimum(int value)
+{
+ if (m_minimum == value)
+ return;
+
+ m_minimum = value;
+ emit minimumChanged();
+}
+
+int QDeclarativeNdefFilter::maximum() const
+{
+ return m_maximum;
+}
+
+void QDeclarativeNdefFilter::setMaximum(int value)
+{
+ if (m_maximum == value)
+ return;
+
+ m_maximum = value;
+ emit maximumChanged();
+}
diff --git a/src/imports/nfc/qdeclarativendeffilter_p.h b/src/imports/nfc/qdeclarativendeffilter_p.h
new file mode 100644
index 00000000..4edba51a
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendeffilter_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENDEFFILTER_P_H
+#define QDECLARATIVENDEFFILTER_P_H
+
+#include <QtCore/QObject>
+
+class QDeclarativeNdefFilter : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
+ Q_PROPERTY(int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
+
+public:
+ explicit QDeclarativeNdefFilter(QObject *parent = 0);
+
+ QString type() const;
+ void setType(const QString &t);
+
+ int minimum() const;
+ void setMinimum(int value);
+
+ int maximum() const;
+ void setMaximum(int value);
+
+signals:
+ void typeChanged();
+ void minimumChanged();
+ void maximumChanged();
+
+private:
+ QString m_type;
+ int m_minimum;
+ int m_maximum;
+};
+
+#endif // QDECLARATIVENDEFFILTER_P_H
diff --git a/src/imports/nfc/qdeclarativendefmimerecord.cpp b/src/imports/nfc/qdeclarativendefmimerecord.cpp
new file mode 100644
index 00000000..7fe43eb1
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendefmimerecord.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativendefmimerecord_p.h"
+
+/*!
+ \qmlclass NdefMimeRecord QDeclarativeNdefMimeRecord
+ \brief The NdefMimeRecord element represents an NFC MIME record.
+
+ \ingroup connectivity-nfc
+ \inmodule QtConnectivity
+
+ \inherits NdefRecord
+
+ The NdefMimeRecord element is part of the \bold {QtMobility.connectivity 1.2} module.
+
+ The NdefMimeRecord element can contain data with an associated MIME type. The data is
+ accessible from the uri in the \l {NdefMimeRecord::uri}{uri} property.
+*/
+
+/*!
+ \qmlproperty string NdefMimeRecord::uri
+
+ This property hold the URI from which the MIME data can be fetched from. Currently this
+ property returns a data url.
+*/
+
+Q_DECLARE_NDEFRECORD(QDeclarativeNdefMimeRecord, QNdefRecord::Mime, ".*")
+
+static inline QNdefRecord createMimeRecord()
+{
+ QNdefRecord mimeRecord;
+ mimeRecord.setTypeNameFormat(QNdefRecord::Mime);
+ return mimeRecord;
+}
+
+static inline QNdefRecord castToMimeRecord(const QNdefRecord &record)
+{
+ if (record.typeNameFormat() != QNdefRecord::Mime)
+ return createMimeRecord();
+ return record;
+}
+
+QDeclarativeNdefMimeRecord::QDeclarativeNdefMimeRecord(QObject *parent)
+: QDeclarativeNdefRecord(createMimeRecord(), parent)
+{
+}
+
+QDeclarativeNdefMimeRecord::QDeclarativeNdefMimeRecord(const QNdefRecord &record, QObject *parent)
+: QDeclarativeNdefRecord(castToMimeRecord(record), parent)
+{
+}
+
+QDeclarativeNdefMimeRecord::~QDeclarativeNdefMimeRecord()
+{
+}
+
+QString QDeclarativeNdefMimeRecord::uri() const
+{
+ QByteArray dataUri = "data:" + record().type() + ";base64," + record().payload().toBase64();
+ return QString::fromAscii(dataUri.constData(), dataUri.length());
+}
diff --git a/src/imports/nfc/qdeclarativendefmimerecord_p.h b/src/imports/nfc/qdeclarativendefmimerecord_p.h
new file mode 100644
index 00000000..ecbe50f7
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendefmimerecord_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENDEFMIMERECORD_P_H
+#define QDECLARATIVENDEFMIMERECORD_P_H
+
+#include <qdeclarativendefrecord.h>
+
+QTNFC_USE_NAMESPACE
+
+class QDeclarativeNdefMimeRecord : public QDeclarativeNdefRecord
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString uri READ uri NOTIFY uriChanged)
+
+public:
+ explicit QDeclarativeNdefMimeRecord(QObject *parent = 0);
+ Q_INVOKABLE QDeclarativeNdefMimeRecord(const QNdefRecord &record, QObject *parent = 0);
+ ~QDeclarativeNdefMimeRecord();
+
+ QString uri() const;
+
+signals:
+ void uriChanged();
+};
+
+#endif // QDECLARATIVENDEFMIMERECORD_P_H
diff --git a/src/imports/nfc/qdeclarativendeftextrecord.cpp b/src/imports/nfc/qdeclarativendeftextrecord.cpp
new file mode 100644
index 00000000..ae813a0d
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendeftextrecord.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativendeftextrecord_p.h"
+
+#include <QtCore/QLocale>
+
+/*!
+ \qmlclass NdefTextRecord QDeclarativeNdefTextRecord
+ \brief The NdefTextRecord element represents an NFC RTD-Text NDEF record.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \inherits NdefRecord
+
+ \sa QNdefNfcTextRecord
+
+ The NdefTextRecord element is part of the \bold {QtMobility.connectivity 1.2} module.
+
+ The NdefTextRecord element contains a localized piece of text that can be display to the user.
+ An NDEF message may contain many text records for different locales, it is up to the
+ application to select the most appropriate one to display to the user. The localeMatch
+ property can be used to determine if the text record has been matched.
+*/
+
+/*!
+ \qmlproperty string NdefTextRecord::text
+
+ This property holds the text which should be displayed when the current locale matches
+ \l locale.
+*/
+
+/*!
+ \qmlproperty string NdefTextRecord::locale
+
+ This property holds the locale that this text record is for.
+*/
+
+/*!
+ \qmlproperty enumeration NdefTextRecord::localeMatch
+
+ This property holds an enum describing how closely the locale of the text record matches the
+ applications current locale. The application should display only the text record that most
+ closely matches the applications current locale.
+
+ \table
+ \header
+ \o Value
+ \o Description
+ \row
+ \o LocaleMatchedNone
+ \o The text record does not match at all.
+ \row
+ \o LocaleMatchedEnglish
+ \o The language of the text record is English and the language of application's current
+ locale is \bold {not} English. The English language text should be displayed if
+ there is not a more appropriate match.
+ \row
+ \o LocaleMatchedLanguage
+ \o The language of the text record and the language of the applications's current
+ locale are the same.
+ \row
+ \o LocaleMatchedLanguageAndCountry
+ \o The language and country of the text record matches that of the applicatin's current
+ locale.
+ \endtable
+*/
+
+Q_DECLARE_NDEFRECORD(QDeclarativeNdefTextRecord, QNdefRecord::NfcRtd, "T")
+
+QDeclarativeNdefTextRecord::QDeclarativeNdefTextRecord(QObject *parent)
+: QDeclarativeNdefRecord(QNdefNfcTextRecord(), parent)
+{
+}
+
+QDeclarativeNdefTextRecord::QDeclarativeNdefTextRecord(const QNdefRecord &record, QObject *parent)
+: QDeclarativeNdefRecord(QNdefNfcTextRecord(record), parent)
+{
+}
+
+QDeclarativeNdefTextRecord::~QDeclarativeNdefTextRecord()
+{
+}
+
+QString QDeclarativeNdefTextRecord::text() const
+{
+ QNdefNfcTextRecord textRecord(record());
+
+ return textRecord.text();
+}
+
+void QDeclarativeNdefTextRecord::setText(const QString &text)
+{
+ QNdefNfcTextRecord textRecord(record());
+
+ if (textRecord.text() == text)
+ return;
+
+ textRecord.setText(text);
+ setRecord(textRecord);
+ emit textChanged();
+}
+
+QString QDeclarativeNdefTextRecord::locale() const
+{
+ if (!record().isRecordType<QNdefNfcTextRecord>())
+ return QString();
+
+ QNdefNfcTextRecord textRecord(record());
+
+ return textRecord.locale();
+}
+
+void QDeclarativeNdefTextRecord::setLocale(const QString &locale)
+{
+ QNdefNfcTextRecord textRecord(record());
+
+ if (textRecord.locale() == locale)
+ return;
+
+ LocaleMatch previous = localeMatch();
+
+ textRecord.setLocale(locale);
+ setRecord(textRecord);
+ emit localeChanged();
+
+ if (previous != localeMatch())
+ emit localeMatchChanged();
+}
+
+QDeclarativeNdefTextRecord::LocaleMatch QDeclarativeNdefTextRecord::localeMatch() const
+{
+ const QLocale recordLocale(locale());
+ const QLocale defaultLocale;
+
+ if (recordLocale == defaultLocale)
+ return LocaleMatchedLanguageAndCountry;
+ else if (recordLocale.language() == defaultLocale.language())
+ return LocaleMatchedLanguage;
+ else if (recordLocale.language() == QLocale::English)
+ return LocaleMatchedEnglish;
+ else
+ return LocaleMatchedNone;
+}
diff --git a/src/imports/nfc/qdeclarativendeftextrecord_p.h b/src/imports/nfc/qdeclarativendeftextrecord_p.h
new file mode 100644
index 00000000..f8253cdf
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendeftextrecord_p.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENDEFTEXTRECORD_P_H
+#define QDECLARATIVENDEFTEXTRECORD_P_H
+
+#include <qdeclarativendefrecord.h>
+
+#include <qndefnfctextrecord.h>
+
+QTNFC_USE_NAMESPACE
+
+class QDeclarativeNdefTextRecord : public QDeclarativeNdefRecord
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+ Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged)
+ Q_PROPERTY(LocaleMatch localeMatch READ localeMatch NOTIFY localeMatchChanged)
+
+ Q_ENUMS(LocaleMatch)
+
+public:
+ enum LocaleMatch {
+ LocaleMatchedNone,
+ LocaleMatchedEnglish,
+ LocaleMatchedLanguage,
+ LocaleMatchedLanguageAndCountry
+ };
+
+ explicit QDeclarativeNdefTextRecord(QObject *parent = 0);
+ Q_INVOKABLE QDeclarativeNdefTextRecord(const QNdefRecord &record, QObject *parent = 0);
+ ~QDeclarativeNdefTextRecord();
+
+ QString text() const;
+ void setText(const QString &text);
+
+ QString locale() const;
+ void setLocale(const QString &locale);
+
+ LocaleMatch localeMatch() const;
+
+signals:
+ void textChanged();
+ void localeChanged();
+ void localeMatchChanged();
+};
+
+#endif // QDECLARATIVENDEFTEXTRECORD_P_H
diff --git a/src/imports/nfc/qdeclarativendefurirecord.cpp b/src/imports/nfc/qdeclarativendefurirecord.cpp
new file mode 100644
index 00000000..52c4f497
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendefurirecord.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativendefurirecord_p.h"
+
+#include <QtCore/QUrl>
+
+/*!
+ \qmlclass NdefUriRecord QDeclarativeNdefUriRecord
+ \brief The NdefUriRecord element represents an NFC RTD-URI NDEF record.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \inherits NdefRecord
+
+ \sa QNdefNfcUriRecord
+
+ The NdefUriRecord element is part of the \bold {QtMobility.connectivity 1.2} module.
+*/
+
+/*!
+ \qmlproperty string NdefUriRecord::uri
+
+ This property hold the URI stored in this URI record.
+*/
+
+Q_DECLARE_NDEFRECORD(QDeclarativeNdefUriRecord, QNdefRecord::NfcRtd, "U")
+
+QDeclarativeNdefUriRecord::QDeclarativeNdefUriRecord(QObject *parent)
+: QDeclarativeNdefRecord(QNdefNfcUriRecord(), parent)
+{
+}
+
+QDeclarativeNdefUriRecord::QDeclarativeNdefUriRecord(const QNdefRecord &record, QObject *parent)
+: QDeclarativeNdefRecord(QNdefNfcUriRecord(record), parent)
+{
+}
+
+QDeclarativeNdefUriRecord::~QDeclarativeNdefUriRecord()
+{
+}
+
+QString QDeclarativeNdefUriRecord::uri() const
+{
+ QNdefNfcUriRecord uriRecord(record());
+
+ return uriRecord.uri().toString();
+}
+
+void QDeclarativeNdefUriRecord::setUri(const QString &uri)
+{
+ QNdefNfcUriRecord uriRecord(record());
+
+ if (uriRecord.uri() == uri)
+ return;
+
+ uriRecord.setUri(uri);
+ setRecord(uriRecord);
+ emit uriChanged();
+}
diff --git a/src/imports/nfc/qdeclarativendefurirecord_p.h b/src/imports/nfc/qdeclarativendefurirecord_p.h
new file mode 100644
index 00000000..516901f4
--- /dev/null
+++ b/src/imports/nfc/qdeclarativendefurirecord_p.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENDEFURIRECORD_P_H
+#define QDECLARATIVENDEFURIRECORD_P_H
+
+#include <qdeclarativendefrecord.h>
+
+#include <qndefnfcurirecord.h>
+
+#include <QtCore/QMetaType>
+
+QTNFC_USE_NAMESPACE
+
+class QDeclarativeNdefUriRecord : public QDeclarativeNdefRecord
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString uri READ uri WRITE setUri NOTIFY uriChanged)
+
+public:
+ explicit QDeclarativeNdefUriRecord(QObject *parent = 0);
+ Q_INVOKABLE QDeclarativeNdefUriRecord(const QNdefRecord &record, QObject *parent = 0);
+ ~QDeclarativeNdefUriRecord();
+
+ QString uri() const;
+ void setUri(const QString &uri);
+
+signals:
+ void uriChanged();
+};
+
+#endif // QDECLARATIVENDEFURIRECORD_P_H
diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp
new file mode 100644
index 00000000..27ad42ca
--- /dev/null
+++ b/src/imports/nfc/qdeclarativenearfield.cpp
@@ -0,0 +1,285 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativenearfield_p.h"
+#include "qdeclarativendeffilter_p.h"
+#include "qdeclarativendeftextrecord_p.h"
+#include "qdeclarativendefurirecord_p.h"
+#include "qdeclarativendefmimerecord_p.h"
+
+#include <qndefmessage.h>
+#include <qndefnfctextrecord.h>
+#include <qndefnfcurirecord.h>
+
+/*!
+ \qmlclass NearField QDeclarativeNearField
+ \brief The NearField element provides access to NDEF messages stored on NFC Forum tags.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \sa NdefFilter
+ \sa NdefRecord
+
+ \sa QNearFieldManager
+ \sa QNdefMessage
+ \sa QNdefRecord
+
+ The NearField element is part of the \bold {QtNfc 5.0} module.
+
+ The NearField element can be used to read NDEF messages from NFC Forum tags. Set the \l filter
+ and \l orderMatch properties to match the required NDEF messages. Once an NDEF message is
+ successfully read from a tag the \l messageRecords property is updated.
+
+ \code
+ NearField {
+ filter: [ NdefFilter { type: "urn:nfc:wkt:U"; minimum: 1; maximum: 1 } ]
+ orderMatch: false
+
+ onMessageRecordsChanged: displayMessage()
+ }
+ \endcode
+*/
+
+/*!
+ \qmlproperty list<NdefRecord> NearField::messageRecords
+
+ This property contains the list of NDEF records in the last NDEF message read.
+*/
+
+/*!
+ \qmlproperty list<NdefFilter> NearField::filter
+
+ This property holds the NDEF filter constraints. The \l messageRecords property will only be
+ set to NDEF messages which match the filter.
+*/
+
+/*!
+ \qmlproperty bool NearField::orderMatch
+
+ This property indicates whether the order of records should be taken into account when matching
+ messages.
+*/
+
+QDeclarativeNearField::QDeclarativeNearField(QObject *parent)
+: QObject(parent), m_orderMatch(false), m_componentCompleted(false), m_messageUpdating(false),
+ m_manager(0), m_messageHandlerId(-1)
+{
+}
+
+QDeclarativeListProperty<QDeclarativeNdefRecord> QDeclarativeNearField::messageRecords()
+{
+ return QDeclarativeListProperty<QDeclarativeNdefRecord>(this, 0,
+ &QDeclarativeNearField::append_messageRecord,
+ &QDeclarativeNearField::count_messageRecords,
+ &QDeclarativeNearField::at_messageRecord,
+ &QDeclarativeNearField::clear_messageRecords);
+
+}
+
+QDeclarativeListProperty<QDeclarativeNdefFilter> QDeclarativeNearField::filter()
+{
+ return QDeclarativeListProperty<QDeclarativeNdefFilter>(this, 0,
+ &QDeclarativeNearField::append_filter,
+ &QDeclarativeNearField::count_filters,
+ &QDeclarativeNearField::at_filter,
+ &QDeclarativeNearField::clear_filter);
+}
+
+bool QDeclarativeNearField::orderMatch() const
+{
+ return m_orderMatch;
+}
+
+void QDeclarativeNearField::setOrderMatch(bool on)
+{
+ if (m_orderMatch == on)
+ return;
+
+ m_orderMatch = on;
+ emit orderMatchChanged();
+}
+
+void QDeclarativeNearField::componentComplete()
+{
+ m_componentCompleted = true;
+
+ if (!m_filter.isEmpty())
+ registerMessageHandler();
+}
+
+void QDeclarativeNearField::registerMessageHandler()
+{
+ if (!m_manager)
+ m_manager = new QNearFieldManager(this);
+
+ if (m_messageHandlerId != -1)
+ m_manager->unregisterNdefMessageHandler(m_messageHandlerId);
+
+ // no filter abort
+ if (m_filter.isEmpty())
+ return;
+
+ QNdefFilter filter;
+ filter.setOrderMatch(m_orderMatch);
+ foreach (QDeclarativeNdefFilter *f, m_filter) {
+ const QString type = f->type();
+ uint min = f->minimum() < 0 ? UINT_MAX : f->minimum();
+ uint max = f->maximum() < 0 ? UINT_MAX : f->maximum();
+
+ if (type.startsWith(QLatin1String("urn:nfc:wkt:")))
+ filter.appendRecord(QNdefRecord::NfcRtd, type.mid(12).toUtf8(), min, max);
+ else if (type.startsWith(QLatin1String("urn:nfc:ext:")))
+ filter.appendRecord(QNdefRecord::ExternalRtd, type.mid(12).toUtf8(), min, max);
+ else if (type.startsWith(QLatin1String("urn:nfc:mime")))
+ filter.appendRecord(QNdefRecord::Mime, type.mid(13).toUtf8(), min, max);
+ else
+ qWarning("Unknown NDEF record type %s", qPrintable(type));
+ }
+
+ m_messageHandlerId = m_manager->registerNdefMessageHandler(filter, this, SLOT(_q_handleNdefMessage(QNdefMessage)));
+}
+
+void QDeclarativeNearField::_q_handleNdefMessage(const QNdefMessage &message)
+{
+ m_messageUpdating = true;
+
+ QDeclarativeListReference listRef(this, "messageRecords");
+
+ listRef.clear();
+
+ foreach (const QNdefRecord &record, message)
+ listRef.append(qNewDeclarativeNdefRecordForNdefRecord(record));
+
+ m_messageUpdating = false;
+
+ emit messageRecordsChanged();
+}
+
+void QDeclarativeNearField::append_messageRecord(QDeclarativeListProperty<QDeclarativeNdefRecord> *list,
+ QDeclarativeNdefRecord *record)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return;
+
+ record->setParent(nearField);
+ nearField->m_message.append(record);
+ if (!nearField->m_messageUpdating)
+ emit nearField->messageRecordsChanged();
+}
+
+int QDeclarativeNearField::count_messageRecords(QDeclarativeListProperty<QDeclarativeNdefRecord> *list)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return 0;
+
+ return nearField->m_message.count();
+}
+
+QDeclarativeNdefRecord *QDeclarativeNearField::at_messageRecord(QDeclarativeListProperty<QDeclarativeNdefRecord> *list,
+ int index)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return 0;
+
+ return nearField->m_message.at(index);
+}
+
+void QDeclarativeNearField::clear_messageRecords(QDeclarativeListProperty<QDeclarativeNdefRecord> *list)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (nearField) {
+ qDeleteAll(nearField->m_message);
+ nearField->m_message.clear();
+ if (!nearField->m_messageUpdating)
+ emit nearField->messageRecordsChanged();
+ }
+}
+
+void QDeclarativeNearField::append_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list,
+ QDeclarativeNdefFilter *filter)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return;
+
+ filter->setParent(nearField);
+ nearField->m_filter.append(filter);
+ emit nearField->filterChanged();
+
+ if (nearField->m_componentCompleted)
+ nearField->registerMessageHandler();
+}
+
+int QDeclarativeNearField::count_filters(QDeclarativeListProperty<QDeclarativeNdefFilter> *list)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return 0;
+
+ return nearField->m_filter.count();
+}
+
+QDeclarativeNdefFilter *QDeclarativeNearField::at_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list,
+ int index)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return 0;
+
+ return nearField->m_filter.at(index);
+}
+
+void QDeclarativeNearField::clear_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list)
+{
+ QDeclarativeNearField *nearField = qobject_cast<QDeclarativeNearField *>(list->object);
+ if (!nearField)
+ return;
+
+ qDeleteAll(nearField->m_filter);
+ nearField->m_filter.clear();
+ emit nearField->filterChanged();
+ if (nearField->m_componentCompleted)
+ nearField->registerMessageHandler();
+}
diff --git a/src/imports/nfc/qdeclarativenearfield_p.h b/src/imports/nfc/qdeclarativenearfield_p.h
new file mode 100644
index 00000000..323d2a1a
--- /dev/null
+++ b/src/imports/nfc/qdeclarativenearfield_p.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENEARFIELD_P_H
+#define QDECLARATIVENEARFIELD_P_H
+
+#include <QtCore/QObject>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/QDeclarativeParserStatus>
+
+#include <qnearfieldmanager.h>
+#include <qdeclarativendefrecord.h>
+
+class QDeclarativeNdefFilter;
+
+QTNFC_USE_NAMESPACE
+
+class QDeclarativeNearField : public QObject, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QDeclarativeListProperty<QDeclarativeNdefRecord> messageRecords READ messageRecords NOTIFY messageRecordsChanged)
+ Q_PROPERTY(QDeclarativeListProperty<QDeclarativeNdefFilter> filter READ filter NOTIFY filterChanged)
+ Q_PROPERTY(bool orderMatch READ orderMatch WRITE setOrderMatch NOTIFY orderMatchChanged)
+
+ Q_INTERFACES(QDeclarativeParserStatus)
+
+public:
+ explicit QDeclarativeNearField(QObject *parent = 0);
+
+ QDeclarativeListProperty<QDeclarativeNdefRecord> messageRecords();
+
+ QDeclarativeListProperty<QDeclarativeNdefFilter> filter();
+
+ bool orderMatch() const;
+ void setOrderMatch(bool on);
+
+ // From QDeclarativeParserStatus
+ void classBegin() { }
+ void componentComplete();
+
+signals:
+ void messageRecordsChanged();
+ void filterChanged();
+ void orderMatchChanged();
+
+private slots:
+ void _q_handleNdefMessage(const QNdefMessage &message);
+
+private:
+ QList<QDeclarativeNdefRecord *> m_message;
+ QList<QDeclarativeNdefFilter *> m_filter;
+ bool m_orderMatch;
+ bool m_componentCompleted;
+ bool m_messageUpdating;
+
+ QNearFieldManager *m_manager;
+ int m_messageHandlerId;
+
+ void registerMessageHandler();
+
+ static void append_messageRecord(QDeclarativeListProperty<QDeclarativeNdefRecord> *list,
+ QDeclarativeNdefRecord *record);
+ static int count_messageRecords(QDeclarativeListProperty<QDeclarativeNdefRecord> *list);
+ static QDeclarativeNdefRecord *at_messageRecord(QDeclarativeListProperty<QDeclarativeNdefRecord> *list,
+ int index);
+ static void clear_messageRecords(QDeclarativeListProperty<QDeclarativeNdefRecord> *list);
+
+ static void append_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list,
+ QDeclarativeNdefFilter *filter);
+ static int count_filters(QDeclarativeListProperty<QDeclarativeNdefFilter> *list);
+ static QDeclarativeNdefFilter *at_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list,
+ int index);
+ static void clear_filter(QDeclarativeListProperty<QDeclarativeNdefFilter> *list);
+};
+
+#endif // QDECLARATIVENEARFIELD_P_H
diff --git a/src/imports/nfc/qdeclarativenearfieldsocket.cpp b/src/imports/nfc/qdeclarativenearfieldsocket.cpp
new file mode 100644
index 00000000..df230fc4
--- /dev/null
+++ b/src/imports/nfc/qdeclarativenearfieldsocket.cpp
@@ -0,0 +1,383 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativenearfieldsocket_p.h"
+
+#include <qllcpserver.h>
+
+/*!
+ \qmlclass NearFieldSocket QDeclarativeNearFieldSocket
+ \brief The NearFieldSocket element represents an LLCP socket.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \sa QLlcpSocket
+ \sa QLlcpServer
+
+ The NearFieldSocket element is part of the \bold {QtMobility.connectivity 1.2} module.
+
+ The NearFieldSocket element can be used to create a peer-to-peer connection over NFC LLCP
+ sockets. NearfieldSocket can be used for both client and server side sockets.
+*/
+
+/*!
+ \qmlproperty string NearFieldSocket::uri
+
+ This property hold the URI of the socket. The URI uniquely identifies a remote service (for
+ client sockets) or to register a service (for server sockets).
+*/
+
+/*!
+ \qmlproperty bool NearFieldSocket::connected
+
+ This property holds the connected state of the socket.
+*/
+
+/*!
+ \qmlproperty string NearFieldSocket::error
+
+ This property holds the last error that occurred.
+*/
+
+/*!
+ \qmlproperty string NearFieldSocket::state
+
+ This property holds the state of the socket.
+*/
+
+/*!
+ \qmlproperty bool NearFieldSocket::listening
+
+ This property holds whether the socket is listening for incoming connections.
+*/
+
+/*!
+ \qmlproperty string NearFieldSocket::stringData
+
+ This property returns the available string data read from the socket. Seting this property
+ sends the data to the remote socket.
+*/
+
+class QDeclarativeNearFieldSocketPrivate
+{
+ Q_DECLARE_PUBLIC(QDeclarativeNearFieldSocket)
+
+public:
+ QDeclarativeNearFieldSocketPrivate(QDeclarativeNearFieldSocket *q)
+ : q_ptr(q), m_socket(0), m_server(0),
+ m_error(QLatin1String("No Error")),
+ m_state(QLatin1String("No Service Set")),
+ m_componentCompleted(false),
+ m_connected(false), m_listen(false)
+ {
+ }
+
+ ~QDeclarativeNearFieldSocketPrivate()
+ {
+ delete m_socket;
+ }
+
+ void connect()
+ {
+ Q_ASSERT(!uri.isEmpty());
+
+ m_error = QLatin1String("No Error");
+
+ if (m_socket)
+ m_socket->deleteLater();
+
+ m_socket = new QLlcpSocket;
+
+ Q_Q(const QDeclarativeNearFieldSocket);
+
+ QObject::connect(m_socket, SIGNAL(connected()), q, SLOT(socket_connected()));
+ QObject::connect(m_socket, SIGNAL(disconnected()), q, SLOT(socket_disconnected()));
+ QObject::connect(m_socket, SIGNAL(error(QLlcpSocket::SocketError)),
+ q, SLOT(socket_error(QLlcpSocket::SocketError)));
+ QObject::connect(m_socket, SIGNAL(stateChanged(QLlcpSocket::SocketState)),
+ q, SLOT(socket_state(QLlcpSocket::SocketState)));
+ QObject::connect(m_socket, SIGNAL(readyRead()), q, SLOT(socket_readyRead()));
+
+ m_socket->connectToService(0, uri);
+ }
+
+ QDeclarativeNearFieldSocket *q_ptr;
+ QString uri;
+ QLlcpSocket *m_socket;
+ QLlcpServer *m_server;
+ QString m_error;
+ QString m_state;
+ bool m_componentCompleted;
+ bool m_connected;
+ bool m_listen;
+};
+
+QDeclarativeNearFieldSocket::QDeclarativeNearFieldSocket(QObject *parent)
+: QObject(parent), d_ptr(new QDeclarativeNearFieldSocketPrivate(this))
+{
+}
+
+QDeclarativeNearFieldSocket::~QDeclarativeNearFieldSocket()
+{
+ delete d_ptr;
+}
+
+void QDeclarativeNearFieldSocket::componentComplete()
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ d->m_componentCompleted = true;
+
+ if (d->m_connected && !d->uri.isEmpty())
+ d->connect();
+ else if (d->m_listen)
+ setListening(true);
+}
+
+QString QDeclarativeNearFieldSocket::uri() const
+{
+ Q_D(const QDeclarativeNearFieldSocket);
+
+ return d->uri;
+}
+
+void QDeclarativeNearFieldSocket::setUri(const QString &uri)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ d->uri = uri;
+
+ if (!d->m_componentCompleted)
+ return;
+
+ if (d->m_connected)
+ d->connect();
+
+ emit uriChanged();
+}
+
+bool QDeclarativeNearFieldSocket::connected() const
+{
+ Q_D(const QDeclarativeNearFieldSocket);
+
+ if (!d->m_socket)
+ return false;
+
+ return d->m_socket->state() == QLlcpSocket::ConnectedState;
+}
+
+void QDeclarativeNearFieldSocket::setConnected(bool connected)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ d->m_connected = connected;
+ if (connected && d->m_componentCompleted) {
+ if (!d->uri.isEmpty())
+ d->connect();
+ else
+ qWarning() << "NearFieldSocket::setConnected called before a uri was set";
+ }
+
+ if (!connected && d->m_socket)
+ d->m_socket->close();
+}
+
+QString QDeclarativeNearFieldSocket::error() const
+{
+ Q_D(const QDeclarativeNearFieldSocket);
+
+ return d->m_error;
+}
+
+void QDeclarativeNearFieldSocket::socket_connected()
+{
+ emit connectedChanged();
+}
+
+void QDeclarativeNearFieldSocket::socket_disconnected()
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ d->m_socket->deleteLater();
+ d->m_socket = 0;
+ emit connectedChanged();
+}
+
+void QDeclarativeNearFieldSocket::socket_error(QLlcpSocket::SocketError err)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ if (err == QLlcpSocket::RemoteHostClosedError)
+ d->m_error = QLatin1String("Connection Closed by Remote Host");
+ else
+ d->m_error = QLatin1String("Unknown Error");
+
+ emit errorChanged();
+}
+
+void QDeclarativeNearFieldSocket::socket_state(QLlcpSocket::SocketState state)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ switch (state) {
+ case QLlcpSocket::UnconnectedState:
+ d->m_state = QLatin1String("Unconnected");
+ break;
+ case QLlcpSocket::ConnectingState:
+ d->m_state = QLatin1String("Connecting");
+ break;
+ case QLlcpSocket::ConnectedState:
+ d->m_state = QLatin1String("Connected");
+ break;
+ case QLlcpSocket::ClosingState:
+ d->m_state = QLatin1String("Closing");
+ break;
+ case QLlcpSocket::ListeningState:
+ d->m_state = QLatin1String("Listening");
+ break;
+ case QLlcpSocket::BoundState:
+ d->m_state = QLatin1String("Bound");
+ break;
+ }
+
+ emit stateChanged();
+}
+
+QString QDeclarativeNearFieldSocket::state() const
+{
+ Q_D(const QDeclarativeNearFieldSocket);
+
+ return d->m_state;
+}
+
+bool QDeclarativeNearFieldSocket::listening() const
+{
+ Q_D(const QDeclarativeNearFieldSocket);
+
+ if (d->m_server)
+ return true;
+
+ return false;
+}
+
+void QDeclarativeNearFieldSocket::setListening(bool listen)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ if (listen == false && d->m_server) {
+ qWarning() << "Once socket is in listening state, can not be returned to client socket";
+ return;
+ }
+
+ if (!d->m_componentCompleted){
+ d->m_listen = listen;
+ return;
+ }
+
+ if (d->uri.isEmpty()) {
+ qWarning() << "Can not put socket into listening state without an assigned uri";
+ return;
+ }
+
+ d->m_server = new QLlcpServer;
+
+ connect(d->m_server, SIGNAL(newConnection()), this, SLOT(llcp_connection()));
+
+ d->m_server->listen(d->uri);
+
+
+
+ emit listeningChanged();
+}
+
+void QDeclarativeNearFieldSocket::socket_readyRead()
+{
+ emit dataAvailable();
+}
+
+QString QDeclarativeNearFieldSocket::stringData()
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ if (!d->m_socket|| !d->m_socket->bytesAvailable())
+ return QString();
+
+ const QByteArray data = d->m_socket->readAll();
+ return QString::fromUtf8(data.constData(), data.size());
+}
+
+void QDeclarativeNearFieldSocket::sendStringData(const QString &data)
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ if (!d->m_connected || !d->m_socket) {
+ qWarning() << "Writing data to unconnected socket";
+ return;
+ }
+
+ d->m_socket->write(data.toUtf8());
+}
+
+void QDeclarativeNearFieldSocket::llcp_connection()
+{
+ Q_D(QDeclarativeNearFieldSocket);
+
+ QLlcpSocket *socket = d->m_server->nextPendingConnection();
+ if (!socket)
+ return;
+
+ if (d->m_socket) {
+ socket->close();
+ return;
+ }
+
+ d->m_socket = socket;
+
+ connect(socket, SIGNAL(disconnected()), this, SLOT(socket_disconnected()));
+ connect(socket, SIGNAL(error(QLlcpSocket::SocketError)),
+ this, SLOT(socket_error(QLlcpSocket::SocketError)));
+ connect(socket, SIGNAL(stateChanged(QLlcpSocket::SocketState)),
+ this, SLOT(socket_state(QLlcpSocket::SocketState)));
+ connect(socket, SIGNAL(readyRead()), this, SLOT(socket_readyRead()));
+
+ void connectedChanged();
+}
diff --git a/src/imports/nfc/qdeclarativenearfieldsocket_p.h b/src/imports/nfc/qdeclarativenearfieldsocket_p.h
new file mode 100644
index 00000000..e0ed9a6c
--- /dev/null
+++ b/src/imports/nfc/qdeclarativenearfieldsocket_p.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVENEARFIELDSOCKET_P_H
+#define QDECLARATIVENEARFIELDSOCKET_P_H
+
+#include <QtCore/QObject>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/QDeclarativeParserStatus>
+
+#include <qllcpsocket.h>
+
+QTNFC_USE_NAMESPACE
+
+class QDeclarativeNearFieldSocketPrivate;
+
+class QDeclarativeNearFieldSocket : public QObject, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString uri READ uri WRITE setUri NOTIFY uriChanged)
+ Q_PROPERTY(bool connected READ connected WRITE setConnected NOTIFY connectedChanged)
+ Q_PROPERTY(QString error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString state READ state NOTIFY stateChanged)
+ Q_PROPERTY(bool listening READ listening WRITE setListening NOTIFY listeningChanged)
+ Q_PROPERTY(QString stringData READ stringData WRITE sendStringData NOTIFY dataAvailable)
+
+ Q_INTERFACES(QDeclarativeParserStatus)
+
+ Q_DECLARE_PRIVATE(QDeclarativeNearFieldSocket)
+
+public:
+ explicit QDeclarativeNearFieldSocket(QObject *parent = 0);
+ ~QDeclarativeNearFieldSocket();
+
+ QString uri() const;
+ bool connected() const;
+ QString error() const;
+ QString state() const;
+ bool listening() const;
+
+ QString stringData();
+
+ // From QDeclarativeParserStatus
+ void classBegin() {}
+ void componentComplete();
+
+signals:
+ void uriChanged();
+ void connectedChanged();
+ void errorChanged();
+ void stateChanged();
+ void listeningChanged();
+ void dataAvailable();
+
+public slots:
+ void setUri(const QString &service);
+ void setConnected(bool connected);
+ void setListening(bool listen);
+ void sendStringData(const QString &data);
+
+private slots:
+ void socket_connected();
+ void socket_disconnected();
+ void socket_error(QLlcpSocket::SocketError);
+ void socket_state(QLlcpSocket::SocketState);
+ void socket_readyRead();
+
+ void llcp_connection();
+
+private:
+ QDeclarativeNearFieldSocketPrivate *d_ptr;
+};
+
+QML_DECLARE_TYPE(QDeclarativeNearFieldSocket)
+
+#endif // QDECLARATIVENEARFIELDSOCKET_P_H
diff --git a/src/imports/nfc/qmldir b/src/imports/nfc/qmldir
new file mode 100644
index 00000000..40e6a28b
--- /dev/null
+++ b/src/imports/nfc/qmldir
@@ -0,0 +1 @@
+plugin declarative_nfc
diff --git a/src/imports/nfc/qnfcimport.pri b/src/imports/nfc/qnfcimport.pri
new file mode 100644
index 00000000..a46295d8
--- /dev/null
+++ b/src/imports/nfc/qnfcimport.pri
@@ -0,0 +1,30 @@
+load(qt_module)
+
+TEMPLATE = lib
+CONFIG += qt plugin
+
+win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release
+
+isEmpty(TARGETPATH) {
+ error("qimportbase.pri: You must provide a TARGETPATH!")
+}
+
+isEmpty(TARGET) {
+ error("qimportbase.pri: You must provide a TARGET!")
+}
+
+QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir
+copy2build.input = QMLDIRFILE
+copy2build.output = $$QT.nfc.imports/$$TARGETPATH/qmldir
+!contains(TEMPLATE_PREFIX, vc):copy2build.variable_out = PRE_TARGETDEPS
+copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+copy2build.name = COPY ${QMAKE_FILE_IN}
+copy2build.CONFIG += no_link
+# `clean' should leave the build in a runnable state, which means it shouldn't delete qmldir
+copy2build.CONFIG += no_clean
+QMAKE_EXTRA_COMPILERS += copy2build
+
+TARGET = $$qtLibraryTarget($$TARGET)
+contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
+
+load(qt_targets)