summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-09-25 18:07:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-30 15:00:59 +0200
commit171a0e2568c639ac40329a9d2ace01344eb395b0 (patch)
treecafc0d50acadf9b0fd5edeb6a05f3b47dd8956d6 /src
parent2ef02cb4d0474dce51658d381743de96204dce72 (diff)
Alter the way type and TNF are treated in the qml API
Change-Id: Iff972e1645447a57eb72e3006318a9dd5b2d5c9b Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/nfc/qdeclarativendeffilter.cpp14
-rw-r--r--src/imports/nfc/qdeclarativendeffilter_p.h8
-rw-r--r--src/imports/nfc/qdeclarativenearfield.cpp41
-rw-r--r--src/imports/nfc/qdeclarativenearfield_p.h2
-rw-r--r--src/nfc/qdeclarativendefrecord.cpp116
-rw-r--r--src/nfc/qdeclarativendefrecord.h23
6 files changed, 146 insertions, 58 deletions
diff --git a/src/imports/nfc/qdeclarativendeffilter.cpp b/src/imports/nfc/qdeclarativendeffilter.cpp
index cdb99461..ae551774 100644
--- a/src/imports/nfc/qdeclarativendeffilter.cpp
+++ b/src/imports/nfc/qdeclarativendeffilter.cpp
@@ -119,6 +119,20 @@ void QDeclarativeNdefFilter::setType(const QString &t)
emit typeChanged();
}
+QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefFilter::typeNameFormat() const
+{
+ return m_typeNameFormat;
+}
+
+void QDeclarativeNdefFilter::setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat format)
+{
+ if (m_typeNameFormat == format)
+ return;
+
+ m_typeNameFormat = format;
+ Q_EMIT(typeNameFormatChanged());
+}
+
int QDeclarativeNdefFilter::minimum() const
{
return m_minimum;
diff --git a/src/imports/nfc/qdeclarativendeffilter_p.h b/src/imports/nfc/qdeclarativendeffilter_p.h
index d64db531..8622aece 100644
--- a/src/imports/nfc/qdeclarativendeffilter_p.h
+++ b/src/imports/nfc/qdeclarativendeffilter_p.h
@@ -43,21 +43,25 @@
#define QDECLARATIVENDEFFILTER_P_H
#include <QtCore/QObject>
+#include <qdeclarativendefrecord.h>
class QDeclarativeNdefFilter : public QObject
{
Q_OBJECT
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(QDeclarativeNdefRecord::TypeNameFormat typeNameFormat READ typeNameFormat WRITE setTypeNameFormat NOTIFY typeNameFormatChanged)
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);
+ QDeclarativeNdefRecord::TypeNameFormat typeNameFormat() const;
+ void setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat format);
+
int minimum() const;
void setMinimum(int value);
@@ -68,11 +72,13 @@ signals:
void typeChanged();
void minimumChanged();
void maximumChanged();
+ void typeNameFormatChanged();
private:
QString m_type;
int m_minimum;
int m_maximum;
+ QDeclarativeNdefRecord::TypeNameFormat m_typeNameFormat;
};
#endif // QDECLARATIVENDEFFILTER_P_H
diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp
index 681e2e9e..81a27730 100644
--- a/src/imports/nfc/qdeclarativenearfield.cpp
+++ b/src/imports/nfc/qdeclarativenearfield.cpp
@@ -72,7 +72,7 @@
\code
NearField {
- filter: [ NdefFilter { type: "urn:nfc:wkt:U"; minimum: 1; maximum: 1 } ]
+ filter: [ NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; minimum: 1; maximum: 1 } ]
orderMatch: false
onMessageRecordsChanged: displayMessage()
@@ -143,7 +143,7 @@ void QDeclarativeNearField::componentComplete()
{
m_componentCompleted = true;
- if (!m_filter.isEmpty())
+ if (!m_filterList.isEmpty())
registerMessageHandler();
}
@@ -156,27 +156,20 @@ void QDeclarativeNearField::registerMessageHandler()
m_manager->unregisterNdefMessageHandler(m_messageHandlerId);
// no filter abort
- if (m_filter.isEmpty())
+ if (m_filterList.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));
+ QNdefFilter ndefFilter;
+ ndefFilter.setOrderMatch(m_orderMatch);
+ foreach (const QDeclarativeNdefFilter *filter, m_filterList) {
+ const QString type = filter->type();
+ uint min = filter->minimum() < 0 ? UINT_MAX : filter->minimum();
+ uint max = filter->maximum() < 0 ? UINT_MAX : filter->maximum();
+
+ ndefFilter.appendRecord(static_cast<QNdefRecord::TypeNameFormat>(filter->typeNameFormat()), type.toUtf8(), min, max);
}
- m_messageHandlerId = m_manager->registerNdefMessageHandler(filter, this, SLOT(_q_handleNdefMessage(QNdefMessage)));
+ m_messageHandlerId = m_manager->registerNdefMessageHandler(ndefFilter, this, SLOT(_q_handleNdefMessage(QNdefMessage)));
}
void QDeclarativeNearField::_q_handleNdefMessage(const QNdefMessage &message)
@@ -246,7 +239,7 @@ void QDeclarativeNearField::append_filter(QQmlListProperty<QDeclarativeNdefFilte
return;
filter->setParent(nearField);
- nearField->m_filter.append(filter);
+ nearField->m_filterList.append(filter);
emit nearField->filterChanged();
if (nearField->m_componentCompleted)
@@ -259,7 +252,7 @@ int QDeclarativeNearField::count_filters(QQmlListProperty<QDeclarativeNdefFilter
if (!nearField)
return 0;
- return nearField->m_filter.count();
+ return nearField->m_filterList.count();
}
QDeclarativeNdefFilter *QDeclarativeNearField::at_filter(QQmlListProperty<QDeclarativeNdefFilter> *list,
@@ -269,7 +262,7 @@ QDeclarativeNdefFilter *QDeclarativeNearField::at_filter(QQmlListProperty<QDecla
if (!nearField)
return 0;
- return nearField->m_filter.at(index);
+ return nearField->m_filterList.at(index);
}
void QDeclarativeNearField::clear_filter(QQmlListProperty<QDeclarativeNdefFilter> *list)
@@ -278,8 +271,8 @@ void QDeclarativeNearField::clear_filter(QQmlListProperty<QDeclarativeNdefFilter
if (!nearField)
return;
- qDeleteAll(nearField->m_filter);
- nearField->m_filter.clear();
+ qDeleteAll(nearField->m_filterList);
+ nearField->m_filterList.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
index d3f4b50f..ad551308 100644
--- a/src/imports/nfc/qdeclarativenearfield_p.h
+++ b/src/imports/nfc/qdeclarativenearfield_p.h
@@ -87,7 +87,7 @@ private slots:
private:
QList<QDeclarativeNdefRecord *> m_message;
- QList<QDeclarativeNdefFilter *> m_filter;
+ QList<QDeclarativeNdefFilter *> m_filterList;
bool m_orderMatch;
bool m_componentCompleted;
bool m_messageUpdating;
diff --git a/src/nfc/qdeclarativendefrecord.cpp b/src/nfc/qdeclarativendefrecord.cpp
index 4d560500..edec632e 100644
--- a/src/nfc/qdeclarativendefrecord.cpp
+++ b/src/nfc/qdeclarativendefrecord.cpp
@@ -106,10 +106,32 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty string NdefRecord::recordType
+ \qmlproperty string NdefRecord::type
- This property holds the fully qualified record type of the NDEF record. The fully qualified
- record type includes the NIS and NSS prefixes.
+ This property holds the type of the NDEF record.
+*/
+
+/*!
+ \qmlproperty enumeration NdefRecord::typeNameFormat
+
+ This property holds the TNF of the NDEF record.
+
+ \table
+ \header \li Property \li Description
+ \row \li \c NdefRecord.Empty
+ \li An empty NDEF record, the record does not contain a payload.
+ \row \li \c NdefRecord.NfcRtd
+ \li The NDEF record type is defined by an NFC RTD Specification.
+ \row \li \c NdefRecord.Mime
+ \li The NDEF record type follows the construct described in RFC 2046.
+ \row \li \c NdefRecord.Uri
+ \li The NDEF record type follows the construct described in RFC 3986.
+ \row \li \c NdefRecord.ExternalRtd
+ \li The NDEF record type follows the construct for external type names
+ described the NFC RTD Specification.
+ \endtable
+
+ \sa QNdefRecord::typeNameFormat()
*/
/*!
@@ -119,7 +141,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QDeclarativeNdefRecord::recordTypeChanged()
+ \fn void QDeclarativeNdefRecord::typeChanged()
This signal is emitted when the record type changes.
*/
@@ -131,9 +153,15 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \property QDeclarativeNdefRecord::recordType
+ \property QDeclarativeNdefRecord::type
+
+ This property hold the type of the NDEF record.
+*/
+
+/*!
+ \property QDeclarativeNdefRecord::typeNameFormat
- This property hold the record type of the NDEF record that this class represents.
+ This property hold the TNF of the NDEF record.
*/
/*!
@@ -223,44 +251,76 @@ QDeclarativeNdefRecord::QDeclarativeNdefRecord(const QNdefRecord &record, QObjec
}
/*!
- Returns the fully qualified record type of the record. The fully qualified record type
- includes both the NIS and NSS prefixes.
+ \enum QDeclarativeNdefRecord::TypeNameFormat
+
+ This enum describes the type name format of an NDEF record. The values of this enum are according to
+ \l QNdefRecord::TypeNameFormat
+
+ \value Empty An empty NDEF record, the record does not contain a payload.
+ \value NfcRtd The NDEF record type is defined by an NFC RTD Specification.
+ \value Mime The NDEF record type follows the construct described in RFC 2046.
+ \value Uri The NDEF record type follows the construct described in RFC 3986.
+ \value ExternalRtd The NDEF record type follows the construct for external type names
+ described the NFC RTD Specification.
*/
-QString QDeclarativeNdefRecord::recordType() const
+
+/*!
+ Returns the type of the record.
+
+ \sa QNdefRecord::setType(), QNdefRecord::type()
+*/
+QString QDeclarativeNdefRecord::type() const
{
Q_D(const QDeclarativeNdefRecord);
- if (d->record.typeNameFormat() == QNdefRecord::Empty)
- return QString();
-
- return urnForRecordType(d->record.typeNameFormat(), d->record.type());
+ return QLatin1String(d->record.type());
}
/*!
Sets the record type to \a type if it is not currently equal to \a type; otherwise does
- nothing. If the record type is set the recordTypeChanged() signal will be emitted.
+ nothing. If the record type is set the typeChanged() signal will be emitted.
+
+ \sa QNdefRecord::setType(), QNdefRecord::type()
*/
-void QDeclarativeNdefRecord::setRecordType(const QString &type)
+void QDeclarativeNdefRecord::setType(const QString &newtype)
{
- if (type == recordType())
+ if (newtype == type())
return;
Q_D(QDeclarativeNdefRecord);
+ d->record.setType(newtype.toUtf8());
+
+ emit typeChanged();
+}
- if (type.startsWith(QLatin1String("urn:nfc:wkt:"))) {
- d->record.setTypeNameFormat(QNdefRecord::NfcRtd);
- d->record.setType(type.mid(12).toUtf8());
- } else if (type.startsWith(QLatin1String("urn:nfc:ext:"))) {
- d->record.setTypeNameFormat(QNdefRecord::ExternalRtd);
- d->record.setType(type.mid(12).toUtf8());
- } else if (type.startsWith(QLatin1String("urn:nfc:mime:"))) {
- d->record.setTypeNameFormat(QNdefRecord::Mime);
- d->record.setType(type.mid(13).toUtf8());
- } else {
- qWarning("Don't know how to decode NDEF type %s\n", qPrintable(type));
+/*!
+ Sets the type name format of the NDEF record to \a typeNameFormat.
+*/
+void QDeclarativeNdefRecord::setTypeNameFormat(QDeclarativeNdefRecord::TypeNameFormat typeNameFormat)
+{
+ Q_D(QDeclarativeNdefRecord);
+ bool emitChanged = true;
+ if (static_cast<QDeclarativeNdefRecord::TypeNameFormat>(d->record.typeNameFormat()) == typeNameFormat) {
+ emitChanged = false;
}
- emit recordTypeChanged();
+ //We always have to set the tnf, otherwise we run into problems when tnf is empty. Then
+ //the QNdefRecordPrivate is not created
+ d->record.setTypeNameFormat(static_cast<QNdefRecord::TypeNameFormat>(typeNameFormat));
+
+ if (emitChanged)
+ Q_EMIT(typeNameFormatChanged());
+}
+
+/*!
+ \fn QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefRecord::typeNameFormat() const
+
+ Returns the type name format of the NDEF record.
+*/
+QDeclarativeNdefRecord::TypeNameFormat QDeclarativeNdefRecord::typeNameFormat() const
+{
+ Q_D(const QDeclarativeNdefRecord);
+ return static_cast<QDeclarativeNdefRecord::TypeNameFormat>(d->record.typeNameFormat());
}
/*!
diff --git a/src/nfc/qdeclarativendefrecord.h b/src/nfc/qdeclarativendefrecord.h
index ab7031f4..52c436fe 100644
--- a/src/nfc/qdeclarativendefrecord.h
+++ b/src/nfc/qdeclarativendefrecord.h
@@ -56,21 +56,36 @@ class Q_NFC_EXPORT QDeclarativeNdefRecord : public QObject
Q_DECLARE_PRIVATE(QDeclarativeNdefRecord)
- Q_PROPERTY(QString recordType READ recordType WRITE setRecordType NOTIFY recordTypeChanged)
+ Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
+ Q_PROPERTY(TypeNameFormat typeNameFormat READ typeNameFormat WRITE setTypeNameFormat NOTIFY typeNameFormatChanged)
Q_PROPERTY(QNdefRecord record READ record WRITE setRecord NOTIFY recordChanged)
+ Q_ENUMS(TypeNameFormat)
public:
+ enum TypeNameFormat {
+ Empty = QNdefRecord::Empty,
+ NfcRtd = QNdefRecord::NfcRtd,
+ Mime = QNdefRecord::Mime,
+ Uri = QNdefRecord::Uri,
+ ExternalRtd = QNdefRecord::ExternalRtd,
+ Unknown = QNdefRecord::Unknown
+ };
+
explicit QDeclarativeNdefRecord(QObject *parent = 0);
explicit QDeclarativeNdefRecord(const QNdefRecord &record, QObject *parent = 0);
- QString recordType() const;
- void setRecordType(const QString &t);
+ QString type() const;
+ void setType(const QString &t);
+
+ void setTypeNameFormat(TypeNameFormat typeNameFormat);
+ TypeNameFormat typeNameFormat() const;
QNdefRecord record() const;
void setRecord(const QNdefRecord &record);
Q_SIGNALS:
- void recordTypeChanged();
+ void typeChanged();
+ void typeNameFormatChanged();
void recordChanged();
private: