summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/imports/bluetooth/bluetooth.pro29
-rw-r--r--src/imports/bluetooth/bluetooth.qrc5
-rw-r--r--src/imports/bluetooth/default.svg24
-rw-r--r--src/imports/bluetooth/plugin.cpp76
-rw-r--r--src/imports/bluetooth/qbluetoothimport.pri30
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp306
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h115
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothimageprovider.cpp97
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothimageprovider_p.h61
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice.cpp491
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice_p.h120
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothsocket.cpp375
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothsocket_p.h116
-rw-r--r--src/imports/bluetooth/qmldir1
-rw-r--r--src/imports/imports.pro2
-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
-rw-r--r--src/src.pro2
32 files changed, 3721 insertions, 1 deletions
diff --git a/src/imports/bluetooth/bluetooth.pro b/src/imports/bluetooth/bluetooth.pro
new file mode 100644
index 00000000..323c9f00
--- /dev/null
+++ b/src/imports/bluetooth/bluetooth.pro
@@ -0,0 +1,29 @@
+TARGET = declarative_bluetooth
+TARGETPATH = QtBluetooth
+
+include(qbluetoothimport.pri)
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+DESTDIR = $$QT.bluetooth.imports/$$TARGETPATH
+INSTALLS += target
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+INSTALLS += qmldir
+
+QT += declarative bluetooth network
+
+# Input
+HEADERS += \
+ qdeclarativebluetoothservice_p.h \
+ qdeclarativebluetoothsocket_p.h \
+ qdeclarativebluetoothimageprovider_p.h \
+ qdeclarativebluetoothdiscoverymodel_p.h
+
+SOURCES += plugin.cpp \
+ qdeclarativebluetoothservice.cpp \
+ qdeclarativebluetoothsocket.cpp \
+ qdeclarativebluetoothdiscoverymodel.cpp \
+ qdeclarativebluetoothimageprovider.cpp
+
+RESOURCES += bluetooth.qrc
+
diff --git a/src/imports/bluetooth/bluetooth.qrc b/src/imports/bluetooth/bluetooth.qrc
new file mode 100644
index 00000000..1677bebb
--- /dev/null
+++ b/src/imports/bluetooth/bluetooth.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>default.svg</file>
+ </qresource>
+</RCC>
diff --git a/src/imports/bluetooth/default.svg b/src/imports/bluetooth/default.svg
new file mode 100644
index 00000000..0453ae53
--- /dev/null
+++ b/src/imports/bluetooth/default.svg
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 12.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 51448) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY ns_svg "http://www.w3.org/2000/svg">
+ <!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
+]>
+<svg version="1.1" id="&#x56FE;&#x5C42;_1" xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" width="21.792" height="21.819"
+ viewBox="0 0 21.792 21.819" overflow="visible" enable-background="new 0 0 21.792 21.819" xml:space="preserve">
+<linearGradient id="XMLID_2_" gradientUnits="userSpaceOnUse" x1="11.0322" y1="2.8701" x2="11.0322" y2="21.2133">
+ <stop offset="0" style="stop-color:#95D1DB"/>
+ <stop offset="0.0684" style="stop-color:#7FBAE0"/>
+ <stop offset="0.2073" style="stop-color:#5892EA"/>
+ <stop offset="0.3506" style="stop-color:#3871F1"/>
+ <stop offset="0.4971" style="stop-color:#2058F7"/>
+ <stop offset="0.648" style="stop-color:#0E45FC"/>
+ <stop offset="0.8061" style="stop-color:#033BFE"/>
+ <stop offset="0.9831" style="stop-color:#0037FF"/>
+</linearGradient>
+<path fill="url(#XMLID_2_)" stroke="#4D4D4D" stroke-width="0.5" stroke-linejoin="round" d="M10.496,10.931l5.303-4.672
+ L9.172,0.292l-0.05,9.427L9.109,9.708v0.029L7.304,8.168L6.266,9.364l1.802,1.567l-1.802,1.567l1.038,1.195l1.806-1.569v0.029
+ l0.013-0.012l0.05,9.428l6.627-5.966L10.496,10.931z M10.672,3.993l2.502,2.252l-2.525,2.225L10.672,3.993z M13.174,15.617
+ l-2.502,2.252l-0.023-4.477L13.174,15.617z"/>
+<rect opacity="0" fill="#FFFFFF" width="21.792" height="21.792"/>
+</svg>
diff --git a/src/imports/bluetooth/plugin.cpp b/src/imports/bluetooth/plugin.cpp
new file mode 100644
index 00000000..f50ecca0
--- /dev/null
+++ b/src/imports/bluetooth/plugin.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 "qdeclarativebluetoothdiscoverymodel_p.h"
+#include "qdeclarativebluetoothimageprovider_p.h"
+#include "qdeclarativebluetoothservice_p.h"
+#include "qdeclarativebluetoothsocket_p.h"
+
+QT_USE_NAMESPACE
+
+class QBluetoothQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ void registerTypes(const char *uri)
+ {
+ Q_ASSERT(uri == QLatin1String("QtBluetooth"));
+
+ int major = 5;
+ int minor = 0;
+ qmlRegisterType<QDeclarativeBluetoothDiscoveryModel>(uri, major, minor, "BluetoothDiscoveryModel");
+ qmlRegisterType<QDeclarativeBluetoothService>(uri, major, minor, "BluetoothService");
+ qmlRegisterType<QDeclarativeBluetoothSocket>(uri, major, minor, "BluetoothSocket");
+ }
+
+ void initializeEngine(QDeclarativeEngine *engine, const char *uri) {
+ Q_UNUSED(uri);
+ engine->addImageProvider("bluetoothicons", new BluetoothThumbnailImageProvider);
+ }
+};
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qbluetoothqmlplugin, QBluetoothQmlPlugin);
diff --git a/src/imports/bluetooth/qbluetoothimport.pri b/src/imports/bluetooth/qbluetoothimport.pri
new file mode 100644
index 00000000..26bf54e4
--- /dev/null
+++ b/src/imports/bluetooth/qbluetoothimport.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.bluetooth.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)
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
new file mode 100644
index 00000000..311a2311
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -0,0 +1,306 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 "qdeclarativebluetoothdiscoverymodel_p.h"
+
+#include <QPixmap>
+
+#include <qbluetoothdeviceinfo.h>
+#include <qbluetoothaddress.h>
+
+#include "qdeclarativebluetoothservice_p.h"
+
+/*!
+ \qmlclass BluetoothDiscoveryModel QDeclarativeBluetoothDiscoveryModel
+ \brief The BluetoothDisoceryModel element provides access device and service scanning
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ This element is part of the \bold{QtConnectivity} module.
+
+ BluetoothDiscoveryModel provides a model of connectable services. The
+ contents of the model can be filtered by UUID allowing discovery to be
+ limited to a single service such as a game.
+
+ The model roles provided by BluetoothDiscoveryModel are display, decoration and \c Service.
+ Through the \c Service role the BluetoothService maybe accessed for more details.
+
+ \sa QBluetoothServiceDiscoveryAgent
+
+*/
+
+class QDeclarativeBluetoothDiscoveryModelPrivate
+{
+public:
+ QDeclarativeBluetoothDiscoveryModelPrivate()
+ :m_agent(0),
+ m_error(QBluetoothServiceDiscoveryAgent::NoError),
+ m_minimal(true),
+ m_working(false),
+ m_componentCompleted(false),
+ m_discovery(true)
+ {
+ }
+ ~QDeclarativeBluetoothDiscoveryModelPrivate()
+ {
+ if (m_agent)
+ delete m_agent;
+ }
+
+ QBluetoothServiceDiscoveryAgent *m_agent;
+
+ QBluetoothServiceDiscoveryAgent::Error m_error;
+// QList<QBluetoothServiceInfo> m_services;
+ QList<QDeclarativeBluetoothService *> m_services;
+ bool m_minimal;
+ bool m_working;
+ bool m_componentCompleted;
+ QString m_uuid;
+ bool m_discovery;
+};
+
+QDeclarativeBluetoothDiscoveryModel::QDeclarativeBluetoothDiscoveryModel(QObject *parent) :
+ QAbstractListModel(parent),
+ d(new QDeclarativeBluetoothDiscoveryModelPrivate)
+{
+
+ QHash<int, QByteArray> roleNames;
+ roleNames = QAbstractItemModel::roleNames();
+ roleNames.insert(Qt::DisplayRole, "name");
+ roleNames.insert(Qt::DecorationRole, "icon");
+ roleNames.insert(ServiceRole, "service");
+ setRoleNames(roleNames);
+
+ d->m_agent = new QBluetoothServiceDiscoveryAgent(this);
+ connect(d->m_agent, SIGNAL(serviceDiscovered(const QBluetoothServiceInfo&)), this, SLOT(serviceDiscovered(const QBluetoothServiceInfo&)));
+ connect(d->m_agent, SIGNAL(finished()), this, SLOT(finishedDiscovery()));
+ connect(d->m_agent, SIGNAL(canceled()), this, SLOT(finishedDiscovery()));
+ connect(d->m_agent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this, SLOT(errorDiscovery(QBluetoothServiceDiscoveryAgent::Error)));
+
+}
+void QDeclarativeBluetoothDiscoveryModel::componentComplete()
+{
+ d->m_componentCompleted = true;
+ setDiscovery(d->m_discovery);
+}
+
+/*!
+ \qmlproperty bool BluetoothSocket::discovery
+
+ This property starts or stops discovery.
+
+ */
+
+void QDeclarativeBluetoothDiscoveryModel::setDiscovery(bool discovery_)
+{
+ d->m_discovery = discovery_;
+
+ if (!d->m_componentCompleted)
+ return;
+
+ d->m_working = false;
+
+ d->m_agent->stop();
+
+ if (!discovery_) {
+ emit discoveryChanged();
+ return;
+ }
+
+ if (!d->m_uuid.isEmpty())
+ d->m_agent->setUuidFilter(QBluetoothUuid(d->m_uuid));
+
+ d->m_working = true;
+
+ if (d->m_minimal) {
+ qDebug() << "Doing minimal";
+ d->m_agent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery);
+ }
+ else
+ d->m_agent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
+
+ emit discoveryChanged();
+}
+
+void QDeclarativeBluetoothDiscoveryModel::errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error)
+{
+ d->m_error = error;
+ emit errorChanged();
+}
+
+/*!
+ \qmlproperty string BluetoothDiscoveryModel::error
+
+ This property holds the last error reported by discovery.
+
+ This property is read only.
+ */
+QString QDeclarativeBluetoothDiscoveryModel::error() const
+{
+ switch (d->m_error){
+ case QBluetoothServiceDiscoveryAgent::NoError:
+ break;
+ default:
+ return QLatin1String("UnknownError");
+ }
+ return QLatin1String("NoError");
+
+}
+
+int QDeclarativeBluetoothDiscoveryModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return d->m_services.count();
+}
+
+QVariant QDeclarativeBluetoothDiscoveryModel::data(const QModelIndex &index, int role) const
+{
+ QDeclarativeBluetoothService *service = d->m_services.value(index.row());
+ QBluetoothServiceInfo *info = service->serviceInfo();
+
+ switch (role) {
+ case Qt::DisplayRole:
+ {
+ QString label = info->device().name();
+ if (label.isEmpty())
+ label += info->device().address().toString();
+ label += " " + info->serviceName();
+ return label;
+ }
+ case Qt::DecorationRole:
+ return QLatin1String("image://bluetoothicons/default");
+ case ServiceRole:
+ {
+ return QVariant::fromValue(service);
+ }
+ }
+ return QVariant();
+}
+
+/*!
+ \qmlsignal BluetoothDiscoveryModel::newServiceDiscovered()
+
+ This handler is called when a new service is discovered.
+ */
+
+void QDeclarativeBluetoothDiscoveryModel::serviceDiscovered(const QBluetoothServiceInfo &service)
+{
+ QDeclarativeBluetoothService *bs = new QDeclarativeBluetoothService(service, this);
+
+ for (int i = 0; i < d->m_services.count(); i++) {
+ if (bs->deviceAddress() == d->m_services.at(i)->deviceAddress()) {
+ delete bs;
+ return;
+ }
+ }
+
+ beginResetModel(); // beginInsertRows(...) doesn't work for full discovery...
+ d->m_services.append(bs);
+ endResetModel();
+ emit newServiceDiscovered(bs);
+}
+
+/*!
+ \qmlsignal BluetoothDiscoveryModel::discoveryChanged()
+
+ This handler is called when discovery has completed and no
+ further results will be generated.
+*/
+
+void QDeclarativeBluetoothDiscoveryModel::finishedDiscovery()
+{
+ qDebug() << "Done!";
+ d->m_working = false;
+ emit discoveryChanged();
+}
+
+/*!
+ \qmlproperty bool BluetoothDiscoveryModel::minimalDiscovery
+
+ This property controls minimalDiscovery, which is faster than full discocvery but it
+ only guarantees the device and UUID information to be correct.
+
+ */
+
+bool QDeclarativeBluetoothDiscoveryModel::minimalDiscovery()
+{
+ return d->m_minimal;
+}
+
+void QDeclarativeBluetoothDiscoveryModel::setMinimalDiscovery(bool minimalDiscovery_)
+{
+ d->m_minimal = minimalDiscovery_;
+ emit minimalDiscoveryChanged();
+}
+
+bool QDeclarativeBluetoothDiscoveryModel::discovery()
+{
+ return d->m_working;
+}
+
+/*!
+ \qmlproperty string BluetoothDiscoveryModel::uuidFilter
+
+ This property holds an optional UUID filter. A UUID can be used to return only
+ matching services. 16 bit, 32 bit or 128 bit UUIDs maybe used. The string format
+ is the same format as QUuid.
+
+ \sa QBluetoothUuid
+ \sa QUuid
+ */
+
+
+QString QDeclarativeBluetoothDiscoveryModel::uuidFilter() const
+{
+ return d->m_uuid;
+}
+
+void QDeclarativeBluetoothDiscoveryModel::setUuidFilter(QString uuid)
+{
+ QBluetoothUuid qbuuid(uuid);
+ if (qbuuid.isNull()) {
+ qWarning() << "Invalid UUID providded " << uuid;
+ return;
+ }
+ d->m_uuid = uuid;
+ emit uuidFilterChanged();
+}
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
new file mode 100644
index 00000000..5247a227
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 QDECLARATIVECONTACTMODEL_P_H
+#define QDECLARATIVECONTACTMODEL_P_H
+
+#include <QAbstractListModel>
+#include <QDeclarativeParserStatus>
+#include <QDeclarativeListProperty>
+#include <QDeclarativeParserStatus>
+
+#include <qbluetoothserviceinfo.h>
+#include <qbluetoothservicediscoveryagent.h>
+
+#include <qbluetoothglobal.h>
+
+#include "qdeclarativebluetoothservice_p.h"
+
+QTBLUETOOTH_USE_NAMESPACE
+
+class QDeclarativeBluetoothDiscoveryModelPrivate;
+class QDeclarativeBluetoothDiscoveryModel : public QAbstractListModel, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QString error READ error NOTIFY errorChanged)
+ Q_PROPERTY(bool minimalDiscovery READ minimalDiscovery WRITE setMinimalDiscovery NOTIFY minimalDiscoveryChanged)
+ Q_PROPERTY(bool discovery READ discovery WRITE setDiscovery NOTIFY discoveryChanged)
+ Q_PROPERTY(QString uuidFilter READ uuidFilter WRITE setUuidFilter NOTIFY uuidFilterChanged)
+ Q_INTERFACES(QDeclarativeParserStatus)
+public:
+ explicit QDeclarativeBluetoothDiscoveryModel(QObject *parent = 0);
+
+ enum {
+ ServiceRole = Qt::UserRole + 500,
+ AddressRole,
+ NameRole
+ };
+
+ QString error() const;
+
+ // From QDeclarativeParserStatus
+ virtual void classBegin() {}
+
+ virtual void componentComplete();
+
+ // From QAbstractListModel
+ int rowCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+
+ bool minimalDiscovery();
+ void setMinimalDiscovery(bool minimalDiscovery_);
+
+ bool discovery();
+
+ QString uuidFilter() const;
+ void setUuidFilter(QString uuid);
+
+signals:
+ void errorChanged();
+ void minimalDiscoveryChanged();
+ void newServiceDiscovered(QDeclarativeBluetoothService *service);
+ void discoveryChanged();
+ void uuidFilterChanged();
+
+public slots:
+ void setDiscovery(bool discovery_);
+
+private slots:
+
+ void serviceDiscovered(const QBluetoothServiceInfo &service);
+ void finishedDiscovery();
+ void errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error);
+
+private:
+ QDeclarativeBluetoothDiscoveryModelPrivate* d;
+};
+
+#endif // QDECLARATIVECONTACTMODEL_P_H
diff --git a/src/imports/bluetooth/qdeclarativebluetoothimageprovider.cpp b/src/imports/bluetooth/qdeclarativebluetoothimageprovider.cpp
new file mode 100644
index 00000000..ac918e33
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothimageprovider.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 <QDebug>
+#include <qdeclarativeextensionplugin.h>
+
+#include <qdeclarativeengine.h>
+#include <qdeclarative.h>
+#include "qdeclarativebluetoothimageprovider_p.h"
+
+
+QTBLUETOOTH_USE_NAMESPACE
+
+// This is run in a low priority thread.
+QImage BluetoothThumbnailImageProvider::requestImage(const QString &id, QSize *size, const QSize &req_size)
+{
+ if (m_thumbnails.contains(id)) {
+ if (size)
+ *size = req_size;
+ return m_thumbnails.value(id).scaled(req_size);
+ }
+
+ /* url format:
+ image://bluetoothicons/{hosttype}
+ */
+
+
+ QImage image(
+ req_size.width() > 0 ? req_size.width() : 100,
+ req_size.height() > 0 ? req_size.height() : 50,
+ QImage::Format_RGB32);
+
+ QString imageUrl;
+
+ if (id == "default")
+ imageUrl = QLatin1String(":/default.svg");
+
+ imageUrl = imageUrl.isEmpty() ? QLatin1String(":/default.svg") : imageUrl;
+ image.load(imageUrl);
+
+ if (size)
+ *size = image.size();
+
+ m_thumbnails.insert(id, image);
+
+ return image;
+}
+
+BluetoothThumbnailImageProvider::BluetoothThumbnailImageProvider()
+ :QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
+{
+
+}
+
+BluetoothThumbnailImageProvider::~BluetoothThumbnailImageProvider()
+{
+}
+
+
diff --git a/src/imports/bluetooth/qdeclarativebluetoothimageprovider_p.h b/src/imports/bluetooth/qdeclarativebluetoothimageprovider_p.h
new file mode 100644
index 00000000..ada2174a
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothimageprovider_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 <qdeclarativeimageprovider.h>
+#include <QMap>
+
+#include <qbluetoothserviceinfo.h>
+
+QTBLUETOOTH_USE_NAMESPACE
+
+
+class BluetoothThumbnailImageProvider : public QDeclarativeImageProvider
+{
+public:
+ // This is run in a low priority thread.
+ QImage requestImage(const QString &id, QSize *size, const QSize &req_size);
+ BluetoothThumbnailImageProvider();
+ ~BluetoothThumbnailImageProvider();
+
+private:
+ QMap<QString, QImage> m_thumbnails;
+};
+
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
new file mode 100644
index 00000000..d5462ba6
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
@@ -0,0 +1,491 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 "qdeclarativebluetoothservice_p.h"
+
+#include <qbluetoothdeviceinfo.h>
+#include <qbluetoothsocket.h>
+#include <qbluetoothaddress.h>
+#include <ql2capserver.h>
+#include <qrfcommserver.h>
+
+#include <QObject>
+
+/* ==================== QDeclarativeBluetoothService ======================= */
+
+/*!
+ \qmlclass BluetoothService QDeclarativeBluetoothService
+ \brief The BluetoothService element contains all the information available for a single bluetooth service.\.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \sa QBluetoothAddress
+ \sa QBluetoothSocket
+
+ The BluetoothService element is part of the \bold{QtMobility.connectivity 1.2} module.
+
+ It allows a QML project to get information about a remote service, or describe a service
+ for a BluetoothSocket to connect to.
+ */
+
+
+class QDeclarativeBluetoothServicePrivate
+{
+public:
+ QDeclarativeBluetoothServicePrivate()
+ : m_componentComplete(false),
+ m_service(0), m_port(0),
+ m_needsRegistration(false),
+ m_listen(0)
+ {
+
+ }
+
+ ~QDeclarativeBluetoothServicePrivate()
+ {
+ delete m_service;
+ }
+
+ int listen();
+
+ bool m_componentComplete;
+ QBluetoothServiceInfo *m_service;
+ QString m_protocol;
+ qint32 m_port;
+ QString m_description;
+ QString m_name;
+ QString m_uuid;
+ bool m_needsRegistration;
+ QObject *m_listen;
+
+};
+
+QDeclarativeBluetoothService::QDeclarativeBluetoothService(QObject *parent) :
+ QObject(parent)
+{
+ d = new QDeclarativeBluetoothServicePrivate;
+}
+
+QDeclarativeBluetoothService::QDeclarativeBluetoothService(const QBluetoothServiceInfo &service, QObject *parent)
+ : QObject(parent)
+{
+ d = new QDeclarativeBluetoothServicePrivate;
+ d->m_service = new QBluetoothServiceInfo(service);
+}
+
+QDeclarativeBluetoothService::~QDeclarativeBluetoothService()
+{
+ delete d;
+}
+
+void QDeclarativeBluetoothService::componentComplete()
+{
+ d->m_componentComplete = true;
+
+ if (d->m_needsRegistration)
+ setRegistered(true);
+}
+
+
+/*!
+ \qmlproperty string BluetoothService::deviceName
+
+ This property holds the name of the remote device.
+ */
+
+QString QDeclarativeBluetoothService::deviceName() const
+{
+ if (!d->m_service)
+ return QString();
+
+ return d->m_service->device().name();
+}
+
+/*!
+ \qmlproperty string BluetoothService::deviceAddress
+
+ This property holds the remote device MAc address. Must be valid if you to
+ connect to a remote device with a BluetoothSocket.
+ */
+
+QString QDeclarativeBluetoothService::deviceAddress() const
+{
+ if (!d->m_service)
+ return QString();
+
+ return d->m_service->device().address().toString();
+}
+
+void QDeclarativeBluetoothService::setDeviceAddress(QString address)
+{
+ if (!d->m_service)
+ d->m_service = new QBluetoothServiceInfo();
+
+ QBluetoothAddress a(address);
+ QBluetoothDeviceInfo device(a, QString(), QBluetoothDeviceInfo::ComputerDevice);
+ d->m_service->setDevice(device);
+}
+
+/*!
+ \qmlproperty string BluetoothService::serviceName
+
+ This property holds the name of the remote service if available.
+ */
+
+QString QDeclarativeBluetoothService::serviceName() const
+{
+ if (!d->m_service)
+ return QString();
+
+ if (!d->m_name.isEmpty())
+ return d->m_name;
+
+ return d->m_service->serviceName();
+}
+
+void QDeclarativeBluetoothService::setServiceName(QString name)
+{
+ d->m_name = name;
+}
+
+
+/*!
+ \qmlproperty string BluetoothService::serviceDescription
+
+ This property holds the description provided by the remote service.
+ */
+QString QDeclarativeBluetoothService::serviceDescription() const
+{
+ if (!d->m_service)
+ return QString();
+
+ if (!d->m_description.isEmpty())
+ return d->m_name;
+
+ return d->m_service->serviceDescription();
+}
+
+void QDeclarativeBluetoothService::setServiceDescription(QString description)
+{
+ d->m_description = description;
+ emit detailsChanged();
+}
+
+/*!
+ \qmlproperty string BluetoothService::serviceProtocol
+
+ This property holds the protocol used for the service. Can be the string
+ "l2cap" or "rfcomm"
+ */
+
+QString QDeclarativeBluetoothService::serviceProtocol() const
+{
+ if (!d->m_protocol.isEmpty())
+ return d->m_protocol;
+
+ if (!d->m_service)
+ return QString();
+
+ if (d->m_service->socketProtocol() == QBluetoothServiceInfo::L2capProtocol)
+ return QLatin1String("l2cap");
+ if (d->m_service->socketProtocol() == QBluetoothServiceInfo::RfcommProtocol)
+ return QLatin1String("rfcomm");
+
+ return QLatin1String("unknown");
+}
+
+void QDeclarativeBluetoothService::setServiceProtocol(QString protocol)
+{
+ if (protocol != "rfcomm" && protocol != "l2cap")
+ qWarning() << "Invalid protocol" << protocol;
+
+ d->m_protocol = protocol;
+ emit detailsChanged();
+}
+
+/*!
+ \qmlproperty string BluetoothService::serviceUuid
+
+ This property holds the UUID of the remote service. Service UUID or port, as
+ well as the address must be set to connect to a remote service. If UUID and
+ port are set, the port is used. The UUID takes longer to connect since
+ service discovery must be initiated to discover the port value.
+ */
+
+QString QDeclarativeBluetoothService::serviceUuid() const
+{
+ if (!d->m_uuid.isEmpty())
+ return d->m_uuid;
+
+ if (!d->m_service)
+ return QString();
+
+ return d->m_service->attribute(QBluetoothServiceInfo::ServiceId).toString();
+}
+
+void QDeclarativeBluetoothService::setServiceUuid(QString uuid)
+{
+ d->m_uuid = uuid;
+ if (!d->m_service)
+ d->m_service = new QBluetoothServiceInfo();
+ d->m_service->setAttribute(QBluetoothServiceInfo::ServiceId, QBluetoothUuid(uuid));
+
+ emit detailsChanged();
+}
+
+/*!
+ \qmlproperty int BluetoothService::servicePort
+
+ This property holds the port value for the remote service. Bluetooth does not
+ use well defined port values, so port values should not be stored and used
+ later without care. Connecting via UUID is much more consistent.
+ */
+qint32 QDeclarativeBluetoothService::servicePort() const
+{
+ if (d->m_port > 0)
+ return d->m_port;
+
+ if (!d->m_service)
+ return -1;
+
+ if (d->m_service->serverChannel() > 0)
+ return d->m_service->serverChannel();
+ if (d->m_service->protocolServiceMultiplexer() > 0)
+ return d->m_service->protocolServiceMultiplexer();
+
+ return -1;
+}
+
+void QDeclarativeBluetoothService::setServicePort(qint32 port)
+{
+ if (d->m_port != port){
+ d->m_port = port;
+ if (isRegistered())
+ setRegistered(true);
+ emit detailsChanged();
+ }
+}
+
+/*!
+ \qmlproperty string BluetoothService::registered
+
+ This property holds the registration/publication status of the service. If true the service
+ is published via service discovery. Not implemented in 1.2.
+ */
+
+bool QDeclarativeBluetoothService::isRegistered() const
+{
+ if (!d->m_service)
+ return false;
+
+ return d->m_service->isRegistered();
+}
+
+
+int QDeclarativeBluetoothServicePrivate::listen() {
+
+ if (m_protocol == "l2cap") {
+ QL2capServer *server = new QL2capServer();
+
+ server->setMaxPendingConnections(1);
+ server->listen(QBluetoothAddress(), m_port);
+ m_port = server->serverPort();
+ m_listen = server;
+ }
+ else if (m_protocol == "rfcomm") {
+ QRfcommServer *server = new QRfcommServer();
+
+ server->setMaxPendingConnections(1);
+ server->listen(QBluetoothAddress(), m_port);
+ m_port = server->serverPort();
+ m_listen = server;
+ }
+ else {
+ qDebug() << "Unknown protocol, can't make service" << m_protocol;
+ }
+
+ return m_port;
+
+}
+
+void QDeclarativeBluetoothService::setRegistered(bool registered)
+{
+
+ d->m_needsRegistration = registered;
+
+ if (!d->m_componentComplete) {
+ return;
+ }
+
+ if (!registered) {
+ if (!d->m_service)
+ return;
+ d->m_service->unregisterService();
+ emit registeredChanged();
+ }
+
+ if (!d->m_service) {
+ d->m_service = new QBluetoothServiceInfo();
+ }
+
+
+ delete d->m_listen;
+ d->m_listen = 0;
+
+ d->listen();
+ connect(d->m_listen, SIGNAL(newConnection()), this, SLOT(new_connection()));
+
+
+ d->m_service->setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010);
+
+// QBluetoothServiceInfo::Sequence classId;
+//// classId << QVariant::fromVhttp://theunderstatement.com/alue(QBluetoothUuid(serviceUuid));
+// classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
+// d->m_service->setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
+
+ d->m_service->setAttribute(QBluetoothServiceInfo::ServiceName, d->m_name);
+ d->m_service->setAttribute(QBluetoothServiceInfo::ServiceDescription,
+ d->m_description);
+
+ d->m_service->setServiceUuid(QBluetoothUuid(d->m_uuid));
+
+ qDebug() << "name/uuid" << d->m_name << d->m_uuid << d->m_port;
+
+ d->m_service->setAttribute(QBluetoothServiceInfo::BrowseGroupList,
+ QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
+
+ QBluetoothServiceInfo::Sequence protocolDescriptorList;
+ QBluetoothServiceInfo::Sequence protocol;
+
+ qDebug() << "Port" << d->m_port;
+
+ if (d->m_protocol == "l2cap") {
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap))
+ << QVariant::fromValue(quint16(d->m_port));
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ }
+ else if (d->m_protocol == "rfcomm") {
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
+ << QVariant::fromValue(quint8(d->m_port));
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ }
+ else {
+ qWarning() << "No protocol specified for bluetooth service";
+ }
+ d->m_service->setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
+ protocolDescriptorList);
+
+ if (d->m_service->registerService()) {
+ qDebug() << "registered";
+ emit registeredChanged();
+ }
+ else {
+ qDebug() << "Failed";
+ }
+}
+
+QBluetoothServiceInfo *QDeclarativeBluetoothService::serviceInfo() const
+{
+ return d->m_service;
+}
+
+void QDeclarativeBluetoothService::new_connection()
+{
+ emit newClient();
+}
+
+QDeclarativeBluetoothSocket *QDeclarativeBluetoothService::nextClient()
+{
+ QL2capServer *server = qobject_cast<QL2capServer *>(d->m_listen);
+ if (server) {
+ if (server->hasPendingConnections()) {
+ QBluetoothSocket *socket = server->nextPendingConnection();
+ return new QDeclarativeBluetoothSocket(socket, this, 0x0);
+ }
+ else {
+ qDebug() << "Socket has no pending connection, failing";
+ return 0x0;
+ }
+ }
+ QRfcommServer *rserver = qobject_cast<QRfcommServer *>(d->m_listen);
+ if (rserver) {
+ if (rserver->hasPendingConnections()) {
+ QBluetoothSocket *socket = rserver->nextPendingConnection();
+ return new QDeclarativeBluetoothSocket(socket, this, 0x0);;
+ }
+ else {
+ qDebug() << "Socket has no pending connection, failing";
+ return 0x0;
+ }
+ }
+ return 0x0;
+}
+
+void QDeclarativeBluetoothService::assignNextClient(QDeclarativeBluetoothSocket *dbs)
+{
+ QL2capServer *server = qobject_cast<QL2capServer *>(d->m_listen);
+ if (server) {
+ if (server->hasPendingConnections()) {
+ QBluetoothSocket *socket = server->nextPendingConnection();
+ dbs->newSocket(socket, this);
+ return;
+ }
+ else {
+ qDebug() << "Socket has no pending connection, failing";
+ return;
+ }
+ }
+ QRfcommServer *rserver = qobject_cast<QRfcommServer *>(d->m_listen);
+ if (rserver) {
+ if (rserver->hasPendingConnections()) {
+ QBluetoothSocket *socket = rserver->nextPendingConnection();
+ dbs->newSocket(socket, this);
+ return;
+ }
+ else {
+ qDebug() << "Socket has no pending connection, failing";
+ return;
+ }
+ }
+ return;
+}
+
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
new file mode 100644
index 00000000..bb968fd6
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 QDECLARATIVEBLUETOOTHSERVICE_P_H
+#define QDECLARATIVEBLUETOOTHSERVICE_P_H
+
+#include <QObject>
+#include <qdeclarative.h>
+#include <qbluetoothserviceinfo.h>
+#include <qdeclarativebluetoothsocket_p.h>
+
+class QDeclarativeBluetoothSocket;
+
+QTBLUETOOTH_USE_NAMESPACE
+
+class QDeclarativeBluetoothServicePrivate;
+
+class QDeclarativeBluetoothService : public QObject, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QString deviceName READ deviceName NOTIFY detailsChanged)
+ Q_PROPERTY(QString deviceAddress READ deviceAddress WRITE setDeviceAddress NOTIFY detailsChanged)
+ Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY detailsChanged)
+ Q_PROPERTY(QString serviceDescription READ serviceDescription WRITE setServiceDescription NOTIFY detailsChanged)
+ Q_PROPERTY(QString serviceUuid READ serviceUuid WRITE setServiceUuid NOTIFY detailsChanged)
+ Q_PROPERTY(QString serviceProtocol READ serviceProtocol WRITE setServiceProtocol NOTIFY detailsChanged)
+ Q_PROPERTY(qint32 servicePort READ servicePort WRITE setServicePort NOTIFY detailsChanged)
+ Q_PROPERTY(bool registered READ isRegistered WRITE setRegistered NOTIFY registeredChanged)
+
+ Q_INTERFACES(QDeclarativeParserStatus)
+
+public:
+ explicit QDeclarativeBluetoothService(QObject *parent = 0);
+ explicit QDeclarativeBluetoothService(const QBluetoothServiceInfo &service,
+ QObject *parent = 0);
+ ~QDeclarativeBluetoothService();
+
+ QString deviceName() const;
+ QString deviceAddress() const;
+ QString serviceName() const;
+ QString serviceDescription() const;
+ QString serviceUuid() const;
+ QString serviceProtocol() const;
+ qint32 servicePort() const;
+ bool isRegistered() const;
+
+ QBluetoothServiceInfo *serviceInfo() const;
+
+ Q_INVOKABLE QDeclarativeBluetoothSocket *nextClient();
+ Q_INVOKABLE void assignNextClient(QDeclarativeBluetoothSocket *dbs);
+
+ // From QDeclarativeParserStatus
+ void classBegin() {}
+ void componentComplete();
+
+signals:
+ void detailsChanged();
+ void registeredChanged();
+ void newClient();
+
+public slots:
+ void setServiceName(QString name);
+ void setDeviceAddress(QString address);
+ void setServiceDescription(QString description);
+ void setServiceUuid(QString uuid);
+ void setServiceProtocol(QString protocol);
+ void setServicePort(qint32 port);
+ void setRegistered(bool registered);
+
+
+private slots:
+ void new_connection();
+
+private:
+ QDeclarativeBluetoothServicePrivate* d;
+ friend class QDeclarativeBluetoothServicePrivate;
+
+};
+
+QML_DECLARE_TYPE(QDeclarativeBluetoothService)
+
+#endif // QDECLARATIVEBLUETOOTHSERVICE_P_H
diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp
new file mode 100644
index 00000000..70015be7
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 "qdeclarativebluetoothsocket_p.h"
+
+#include <QPointer>
+#include <QStringList>
+#include <QDataStream>
+#include <QByteArray>
+
+
+#include <qbluetoothdeviceinfo.h>
+#include <qbluetoothaddress.h>
+#include <qbluetoothsocket.h>
+#include <ql2capserver.h>
+#include <qrfcommserver.h>
+
+/* ==================== QDeclarativeBluetoothSocket ======================= */
+
+/*!
+ \qmlclass BluetoothSocket QDeclarativeBluetoothSocket
+ \brief The BluetoothSocket element represents a single bluetooth client socket.
+
+ \ingroup connectivity-qml
+ \inmodule QtConnectivity
+
+ \sa QBluetoothSocket
+ \sa QDataStream
+
+ The BluetoothSocket element is part of the \bold{QtConnectivity} module.
+
+ It allows a QML class easily connect to another bluetooth device and send
+ and received QString's from the device. Data is sent and received via a
+ QDataStream allowing type safe transfer of string data. QDataStream is a well known
+ format and maybe decoded by non-Qt applications.
+
+ Connections to remove devices can be over rfcomm or l2cap. Either the remote port
+ or service UUID is required. This is specified by creating a BluetoothService,
+ or passing in the service return from BluetoothDiscoveryModel.
+ */
+
+class QDeclarativeBluetoothSocketPrivate
+{
+public:
+ QDeclarativeBluetoothSocketPrivate(QDeclarativeBluetoothSocket *bs)
+ : m_dbs(bs), m_service(0), m_socket(0),
+ m_error(QLatin1String("No Error")),
+ m_state(QLatin1String("No Service Set")),
+ m_componentCompleted(false),
+ m_connected(false)
+ {
+
+ }
+
+ ~QDeclarativeBluetoothSocketPrivate()
+ {
+ delete m_socket;
+ }
+
+ void connect()
+ {
+ Q_ASSERT(m_service);
+ qDebug() << "Connecting to: " << m_service->serviceInfo()->device().address().toString();
+ m_error = QLatin1String("No Error");
+
+ if (m_socket)
+ m_socket->deleteLater();
+
+// delete m_socket;
+ m_socket = new QBluetoothSocket();
+ m_socket->connectToService(*m_service->serviceInfo());
+ QObject::connect(m_socket, SIGNAL(connected()), m_dbs, SLOT(socket_connected()));
+ QObject::connect(m_socket, SIGNAL(disconnected()), m_dbs, SLOT(socket_disconnected()));
+ QObject::connect(m_socket, SIGNAL(error(QBluetoothSocket::SocketError)), m_dbs, SLOT(socket_error(QBluetoothSocket::SocketError)));
+ QObject::connect(m_socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), m_dbs, SLOT(socket_state(QBluetoothSocket::SocketState)));
+ QObject::connect(m_socket, SIGNAL(readyRead()), m_dbs, SLOT(socket_readyRead()));
+
+ m_stream = new QDataStream(m_socket);
+ }
+
+ QDeclarativeBluetoothSocket *m_dbs;
+ QDeclarativeBluetoothService *m_service;
+ QBluetoothSocket *m_socket;
+ QString m_error;
+ QString m_state;
+ bool m_componentCompleted;
+ bool m_connected;
+ QDataStream *m_stream;
+
+};
+
+QDeclarativeBluetoothSocket::QDeclarativeBluetoothSocket(QObject *parent) :
+ QObject(parent)
+{
+ d = new QDeclarativeBluetoothSocketPrivate(this);
+}
+
+QDeclarativeBluetoothSocket::QDeclarativeBluetoothSocket(QDeclarativeBluetoothService *service, QObject *parent)
+ : QObject(parent)
+{
+ d = new QDeclarativeBluetoothSocketPrivate(this);
+ d->m_service = service;
+}
+
+QDeclarativeBluetoothSocket::QDeclarativeBluetoothSocket(QBluetoothSocket *socket, QDeclarativeBluetoothService *service, QObject *parent)
+ : QObject(parent)
+{
+ d = new QDeclarativeBluetoothSocketPrivate(this);
+ d->m_service = service;
+ d->m_socket = socket;
+ d->m_connected = true;
+ d->m_componentCompleted = true;
+
+ QObject::connect(socket, SIGNAL(connected()), this, SLOT(socket_connected()));
+ QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socket_disconnected()));
+ QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socket_error(QBluetoothSocket::SocketError)));
+ QObject::connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socket_state(QBluetoothSocket::SocketState)));
+ QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(socket_readyRead()));
+
+ d->m_stream = new QDataStream(socket);
+
+}
+
+
+QDeclarativeBluetoothSocket::~QDeclarativeBluetoothSocket()
+{
+ delete d;
+}
+
+void QDeclarativeBluetoothSocket::componentComplete()
+{
+ d->m_componentCompleted = true;
+
+ if (d->m_connected && d->m_service)
+ d->connect();
+}
+
+/*!
+ \qmlproperty BluetoothService BluetoothSocket::service
+
+ This property holds the details of the remote service to connect too. It can be
+ set to a static BluetoothService with a fixed description, or a service returned
+ by service discovery.
+ */
+
+
+QDeclarativeBluetoothService *QDeclarativeBluetoothSocket::service()
+{
+ return d->m_service;
+}
+
+void QDeclarativeBluetoothSocket::setService(QDeclarativeBluetoothService *service)
+{
+ d->m_service = service;
+
+ if (!d->m_componentCompleted)
+ return;
+
+ if (d->m_connected)
+ d->connect();
+ emit serviceChanged();
+}
+
+/*!
+ \qmlproperty bool BluetoothSocket::connected
+
+ This property holds the connection state of the socket. If the socket is
+ connected to peer it returns true. It can be set true of false to control the
+ connection. When set true the property will not return true until the
+ connection is established.
+
+ */
+
+
+bool QDeclarativeBluetoothSocket::connected()
+{
+ if (!d->m_socket)
+ return false;
+
+ return d->m_socket->state() == QBluetoothSocket::ConnectedState;
+}
+
+void QDeclarativeBluetoothSocket::setConnected(bool connected)
+{
+ d->m_connected = connected;
+ if (connected && d->m_componentCompleted) {
+ if (d->m_service) {
+ d->connect();
+ }
+ else {
+ qWarning() << "BluetoothSocket::setConnected called before a service was set";
+ }
+ }
+
+ if (!connected && d->m_socket){
+ d->m_socket->close();
+ }
+}
+
+/*!
+ \qmlproperty string BluetoothSocket::error
+
+ This property holds the string for the last reported error
+ This property is read only.
+ */
+
+
+QString QDeclarativeBluetoothSocket::error()
+{
+ return d->m_error;
+}
+
+void QDeclarativeBluetoothSocket::socket_connected()
+{
+ emit connectedChanged();
+}
+
+void QDeclarativeBluetoothSocket::socket_disconnected()
+{
+ d->m_socket->deleteLater();
+ d->m_socket = 0;
+ emit connectedChanged();
+}
+
+void QDeclarativeBluetoothSocket::socket_error(QBluetoothSocket::SocketError err)
+{
+ if (err == QBluetoothSocket::ConnectionRefusedError)
+ d->m_error = QLatin1String("Connection Refused");
+ else if (err == QBluetoothSocket::RemoteHostClosedError)
+ d->m_error = QLatin1String("Connection Closed by Remote Host");
+ else if (err == QBluetoothSocket::HostNotFoundError)
+ d->m_error = QLatin1String("Host Not Found");
+ else if (err == QBluetoothSocket::ServiceNotFoundError)
+ d->m_error = QLatin1String("Could not find service at remote host");
+ else
+ d->m_error = QLatin1String("Unknown Error");
+
+ emit errorChanged();
+}
+
+void QDeclarativeBluetoothSocket::socket_state(QBluetoothSocket::SocketState state)
+{
+ switch (state) {
+ case QBluetoothSocket::UnconnectedState:
+ d->m_state = QLatin1String("Unconnected");
+ break;
+ case QBluetoothSocket::ServiceLookupState:
+ d->m_state = QLatin1String("Service Lookup");
+ break;
+ case QBluetoothSocket::ConnectingState:
+ d->m_state = QLatin1String("Connecting");
+ break;
+ case QBluetoothSocket::ConnectedState:
+ d->m_state = QLatin1String("Connected");
+ break;
+ case QBluetoothSocket::ClosingState:
+ d->m_state = QLatin1String("Closing");
+ break;
+ case QBluetoothSocket::ListeningState:
+ d->m_state = QLatin1String("Listening");
+ break;
+ case QBluetoothSocket::BoundState:
+ d->m_state = QLatin1String("Bound");
+ break;
+ }
+
+ emit stateChanged();
+}
+
+QString QDeclarativeBluetoothSocket::state()
+{
+ return d->m_state;
+}
+
+void QDeclarativeBluetoothSocket::socket_readyRead()
+{
+ emit dataAvailable();
+}
+
+/*!
+ \qmlproperty string BluetoothSocket::stringData
+
+ This property receives or sends data to remote bluetooth device. Arrival of
+ data is signaled through the dataAvailable signal and can be read by
+ stringData. Calling sendStringData will transmit the string to the far side.
+ If excessive amounts of data are sent the function may block. Reading will
+ never block.
+ */
+
+
+QString QDeclarativeBluetoothSocket::stringData()
+{
+ if (!d->m_socket|| !d->m_socket->bytesAvailable())
+ return QString();
+
+ QString data;
+ *d->m_stream >> data;
+ return data;
+}
+
+void QDeclarativeBluetoothSocket::sendStringData(QString data)
+{
+ if (!d->m_connected || !d->m_socket){
+ qWarning() << "Writing data to unconnected socket";
+ return;
+ }
+
+ QByteArray b;
+ QDataStream s(&b, QIODevice::WriteOnly);
+ s << data;
+ d->m_socket->write(b);
+}
+
+void QDeclarativeBluetoothSocket::newSocket(QBluetoothSocket *socket, QDeclarativeBluetoothService *service)
+{
+ if (d->m_socket){
+ delete d->m_socket;
+ }
+
+ d->m_service = service;
+ d->m_socket = socket;
+ d->m_connected = true;
+ d->m_componentCompleted = true;
+ d->m_error = QLatin1String("No Error");
+
+ QObject::connect(socket, SIGNAL(connected()), this, SLOT(socket_connected()));
+ QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socket_disconnected()));
+ QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socket_error(QBluetoothSocket::SocketError)));
+ QObject::connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socket_state(QBluetoothSocket::SocketState)));
+ QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(socket_readyRead()));
+
+ d->m_stream = new QDataStream(socket);
+
+ socket_state(socket->state());
+
+ emit connectedChanged();
+}
diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h
new file mode 100644
index 00000000..17947b4e
--- /dev/null
+++ b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtBluetooth 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 QDECLARATIVEBLUETOOTHSOCKET_P_H
+#define QDECLARATIVEBLUETOOTHSOCKET_P_H
+
+#include <QObject>
+#include <qdeclarative.h>
+#include <QDeclarativeParserStatus>
+
+#include <qbluetoothsocket.h>
+
+#include "qdeclarativebluetoothservice_p.h"
+
+QTBLUETOOTH_USE_NAMESPACE
+
+class QDeclarativeBluetoothSocketPrivate;
+class QDeclarativeBluetoothService;
+
+class QDeclarativeBluetoothSocket : public QObject, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QDeclarativeBluetoothService *service READ service WRITE setService NOTIFY serviceChanged)
+ 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(QString stringData READ stringData WRITE sendStringData NOTIFY dataAvailable)
+ Q_INTERFACES(QDeclarativeParserStatus)
+
+public:
+ explicit QDeclarativeBluetoothSocket(QObject *parent = 0);
+ explicit QDeclarativeBluetoothSocket(QDeclarativeBluetoothService *service,
+ QObject *parent = 0);
+ explicit QDeclarativeBluetoothSocket(QBluetoothSocket *socket, QDeclarativeBluetoothService *service,
+ QObject *paprent = 0);
+ ~QDeclarativeBluetoothSocket();
+
+ QDeclarativeBluetoothService *service();
+ bool connected();
+ QString error();
+ QString state();
+
+ QString stringData();
+
+ // From QDeclarativeParserStatus
+ void classBegin() {}
+ void componentComplete();
+
+ void newSocket(QBluetoothSocket *socket, QDeclarativeBluetoothService *service);
+
+signals:
+ void serviceChanged();
+ void connectedChanged();
+ void errorChanged();
+ void stateChanged();
+ void dataAvailable();
+
+public slots:
+ void setService(QDeclarativeBluetoothService *service);
+ void setConnected(bool connected);
+ void sendStringData(QString data);
+
+private slots:
+ void socket_connected();
+ void socket_disconnected();
+ void socket_error(QBluetoothSocket::SocketError);
+ void socket_state(QBluetoothSocket::SocketState);
+ void socket_readyRead();
+
+private:
+ QDeclarativeBluetoothSocketPrivate* d;
+ friend class QDeclarativeBluetoothSocketPrivate;
+
+};
+
+QML_DECLARE_TYPE(QDeclarativeBluetoothSocket)
+
+#endif // QDECLARATIVEBLUETOOTHSOCKET_P_H
diff --git a/src/imports/bluetooth/qmldir b/src/imports/bluetooth/qmldir
new file mode 100644
index 00000000..c03f0ab1
--- /dev/null
+++ b/src/imports/bluetooth/qmldir
@@ -0,0 +1 @@
+plugin declarative_bluetooth
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
new file mode 100644
index 00000000..f1072841
--- /dev/null
+++ b/src/imports/imports.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += bluetooth nfc
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)
diff --git a/src/src.pro b/src/src.pro
index b39b5650..040da1fd 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
CONFIG += ordered
-SUBDIRS = bluetooth nfc
+SUBDIRS = bluetooth nfc imports