summaryrefslogtreecommitdiffstats
path: root/src/nfc/qnearfieldtarget_neard_p.h
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2014-06-26 15:33:11 +0200
committerFabian Bumberger <fbumberger@rim.com>2014-07-02 14:41:42 +0200
commitfdc3a1702218657a965a0b820fdf8756d37919c8 (patch)
tree491ac83a23c0f02b3efb0f5d5913ee216132062b /src/nfc/qnearfieldtarget_neard_p.h
parent5eec86183c1d2b593be7485b8a301882d29b2600 (diff)
Add neard ndef record parsing
This patch adds the neard dbus interface and provides logic to parse data from this interface. Change-Id: Id9a5df88d75c71cf6f2b320afed644a38d03c38d Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/nfc/qnearfieldtarget_neard_p.h')
-rw-r--r--src/nfc/qnearfieldtarget_neard_p.h85
1 files changed, 77 insertions, 8 deletions
diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h
index 4ed596a0..f11f7158 100644
--- a/src/nfc/qnearfieldtarget_neard_p.h
+++ b/src/nfc/qnearfieldtarget_neard_p.h
@@ -51,6 +51,11 @@
#include <qndefmessage.h>
#include "neard/tag_p.h"
+#include "neard/record_p.h"
+
+#include <qndefnfctextrecord.h>
+#include <qndefnfcsmartposterrecord.h>
+#include <qndefnfcurirecord.h>
QT_BEGIN_NAMESPACE
@@ -66,13 +71,23 @@ public:
{
m_tagInterface = new OrgNeardTagInterface(QStringLiteral("org.neard"),
interfacePath.path(),
- QDBusConnection::systemBus());
+ QDBusConnection::systemBus(), this);
- if (!isValid())
+ if (!isValid()) {
+ qCWarning(QT_NFC_NEARD) << "Could not connect to org.neard.Tag dbus interface"
+ << interfacePath.path();
return;
+ }
+
+ QDBusPendingReply<QVariantMap> reply = m_tagInterface->GetProperties();
+ reply.waitForFinished();
+ if (reply.isError()) {
+ qCWarning(QT_NFC_NEARD) << "Could not get properties of org.neard.Tag dbus interface"
+ << interfacePath.path();
+ return;
+ }
- QVariantMap properties = m_tagInterface->GetProperties();
- QString type = properties.value(QStringLiteral("Type")).toString();
+ const QString &type = reply.value().value(QStringLiteral("Type")).toString();
m_type = QNearFieldTarget::ProprietaryTag;
if (type == QStringLiteral("Type 1"))
@@ -89,7 +104,6 @@ public:
~NearFieldTarget()
{
- delete m_tagInterface;
}
bool isValid()
@@ -174,10 +188,65 @@ public:
}
private:
- QNdefRecord readRecord(QDBusObjectPath path)
+ QNdefRecord readRecord(const QDBusObjectPath &path)
{
- Q_UNUSED(path);
- // TODO
+ OrgNeardRecordInterface recordInterface(QStringLiteral("org.neard"),
+ path.path(),
+ QDBusConnection::systemBus());
+ if (!recordInterface.isValid())
+ return QNdefRecord();
+
+ QDBusPendingReply<QVariantMap> reply = recordInterface.GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ return QNdefRecord();
+
+ const QString &value = reply.value().value(QStringLiteral("Representation")).toString();
+ const QString &locale = reply.value().value(QStringLiteral("Language")).toString();
+ const QString &encoding = reply.value().value(QStringLiteral("Encoding")).toString();
+ const QString &uri = reply.value().value(QStringLiteral("URI")).toString();
+// const QString &mimetype = reply.value().value(QStringLiteral("MIMEType")).toString();
+// const QString &mime = reply.value().value(QStringLiteral("MIME")).toString();
+// const QString &arr = reply.value().value(QStringLiteral("ARR")).toString();
+// const QString &size = reply.value().value(QStringLiteral("Size")).toString();
+
+ const QString type = reply.value().value(QStringLiteral("Type")).toString();
+ if (type == QStringLiteral("Text")) {
+ QNdefNfcTextRecord textRecord;
+ textRecord.setText(value);
+ textRecord.setLocale(locale);
+ textRecord.setEncoding((encoding == QStringLiteral("UTF-8")) ? QNdefNfcTextRecord::Utf8
+ : QNdefNfcTextRecord::Utf16);
+ return textRecord;
+ } else if (type == QStringLiteral("SmartPoster")) {
+ QNdefNfcSmartPosterRecord spRecord;
+ if (!value.isEmpty()) {
+ spRecord.addTitle(value, locale, (encoding == QStringLiteral("UTF-8"))
+ ? QNdefNfcTextRecord::Utf8
+ : QNdefNfcTextRecord::Utf16);
+ }
+
+ if (!uri.isEmpty())
+ spRecord.setUri(QUrl(uri));
+
+// const QString &actionString = reply.value().value(QStringLiteral("Action")).toString();
+// if (!action.isEmpty()) {
+// QNdefNfcSmartPosterRecord::Action action;
+
+// spRecord.setAction(acti);
+// }
+
+ return spRecord;
+ } else if (type == QStringLiteral("URI")) {
+ QNdefNfcUriRecord uriRecord;
+ uriRecord.setUri(QUrl(uri));
+ return uriRecord;
+ } else if (type == QStringLiteral("MIME")) {
+
+ } else if (type == QStringLiteral("AAR")) {
+
+ }
+
return QNdefRecord();
}