From 171a0e2568c639ac40329a9d2ace01344eb395b0 Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Wed, 25 Sep 2013 18:07:20 +0200 Subject: Alter the way type and TNF are treated in the qml API Change-Id: Iff972e1645447a57eb72e3006318a9dd5b2d5c9b Reviewed-by: Alex Blasche --- src/nfc/qdeclarativendefrecord.cpp | 116 ++++++++++++++++++++++++++++--------- src/nfc/qdeclarativendefrecord.h | 23 ++++++-- 2 files changed, 107 insertions(+), 32 deletions(-) (limited to 'src/nfc') 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(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(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(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: -- cgit v1.2.3