summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@nokia.com>2011-05-16 09:15:02 +0200
committerRainer Keller <rainer.keller@nokia.com>2011-05-17 09:21:12 +0200
commite04dd17419c571e8e2f098c8dbe1550ee26b0200 (patch)
treed6db1461aa8fa744f989bf308039a8b11c221fec
parent7ba61af09678127861e33931e741ebbf9b002385 (diff)
Add NFC tag editor
Reviewed-by: ckamm
-rw-r--r--src/nfctargetgenerator/ndefeditor.cpp326
-rw-r--r--src/nfctargetgenerator/ndefeditor.h83
-rw-r--r--src/nfctargetgenerator/ndefeditor.ui227
-rw-r--r--src/nfctargetgenerator/nfctargetgenerator.cpp185
-rw-r--r--src/nfctargetgenerator/nfctargetgenerator.h70
-rw-r--r--src/nfctargetgenerator/nfctargetgenerator.pri28
-rw-r--r--src/nfctargetgenerator/nfctargetgenerator.ui93
-rw-r--r--src/nfctargetgenerator/tageditor.h52
-rw-r--r--src/nfctargetgenerator/tagtype1.cpp286
-rw-r--r--src/nfctargetgenerator/tagtype1.h62
-rw-r--r--src/nfctargetgenerator/tagtype1.ui414
-rw-r--r--src/nfctargetgenerator/tagtype2.cpp272
-rw-r--r--src/nfctargetgenerator/tagtype2.h59
-rw-r--r--src/nfctargetgenerator/tagtype2.ui356
-rw-r--r--src/nfctargetgenerator/tlveditor.cpp346
-rw-r--r--src/nfctargetgenerator/tlveditor.h79
-rw-r--r--src/nfctargetgenerator/tlveditor.ui581
-rw-r--r--src/src.pri1
-rw-r--r--src/ui/nfcui.cpp51
-rw-r--r--src/ui/nfcui.h4
20 files changed, 3549 insertions, 26 deletions
diff --git a/src/nfctargetgenerator/ndefeditor.cpp b/src/nfctargetgenerator/ndefeditor.cpp
new file mode 100644
index 0000000..3056742
--- /dev/null
+++ b/src/nfctargetgenerator/ndefeditor.cpp
@@ -0,0 +1,326 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "ndefeditor.h"
+#include "ui_ndefeditor.h"
+
+#include <qndefrecord.h>
+#include <qndefnfctextrecord.h>
+#include <qndefnfcurirecord.h>
+#include <qndefmessage.h>
+
+#include <QtCore/QUrl>
+#include <QtCore/QBuffer>
+
+#include <QtGui/QMenu>
+#include <QtGui/QListWidgetItem>
+#include <QtGui/QFileDialog>
+#include <QtGui/QImageReader>
+
+QTM_USE_NAMESPACE
+
+static QString imageFormatToMimeType(const QByteArray &format)
+{
+ if (format == "bmp")
+ return QLatin1String("image/bmp");
+ else if (format == "gif")
+ return QLatin1String("image/gif");
+ else if (format == "jpg" || format == "jpeg")
+ return QLatin1String("image/jpeg");
+ else if (format == "mng")
+ return QLatin1String("video/x-mng");
+ else if (format == "png")
+ return QLatin1String("image/png");
+ else if (format == "pbm")
+ return QLatin1String("image/x-portable-bitmap");
+ else if (format == "pgm")
+ return QLatin1String("image/x-portable-graymap");
+ else if (format == "ppm")
+ return QLatin1String("image/x-portable-pixmap");
+ else if (format == "tiff")
+ return QLatin1String("image/tiff");
+ else if (format == "xbm")
+ return QLatin1String("image/x-xbitmap");
+ else if (format == "xpm")
+ return QLatin1String("image/x-xpixmap");
+ else if (format == "svg")
+ return QLatin1String("image/svg+xml");
+ else
+ return QString();
+}
+
+class RecordItem : public QListWidgetItem
+{
+public:
+ RecordItem(const QNdefRecord &record);
+ ~RecordItem();
+
+ void setRecord(const QNdefRecord &record);
+ QNdefRecord record() const;
+
+ QVariant data(int role) const;
+
+private:
+ QNdefRecord m_record;
+};
+
+RecordItem::RecordItem(const QNdefRecord &record)
+: m_record(record)
+{
+}
+
+RecordItem::~RecordItem()
+{
+}
+
+void RecordItem::setRecord(const QNdefRecord &record)
+{
+ m_record = record;
+}
+
+QNdefRecord RecordItem::record() const
+{
+ return m_record;
+}
+
+QVariant RecordItem::data(int role) const
+{
+ if (role == Qt::DisplayRole) {
+ if (m_record.isRecordType<QNdefNfcTextRecord>())
+ return NdefEditor::tr("NFC Text");
+ else if (m_record.isRecordType<QNdefNfcUriRecord>())
+ return NdefEditor::tr("NFC URI");
+ else if (m_record.typeNameFormat() == QNdefRecord::Mime)
+ return NdefEditor::tr("MIME: <%1>").arg(QString::fromAscii(m_record.type().constData()));
+ else
+ return NdefEditor::tr("Unknown Record");
+ }
+
+ return QListWidgetItem::data(role);
+}
+
+NdefEditor::NdefEditor(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NdefEditor)
+{
+ ui->setupUi(this);
+
+ addMenu = new QMenu(this);
+ addMenu->addAction(tr("NFC Text Record"), this, SLOT(addNfcTextRecord()));
+ addMenu->addAction(tr("NFC URI Record"), this, SLOT(addNfcUriRecord()));
+ addMenu->addAction(tr("MIME Image Record"), this, SLOT(addMimeRecord()));
+
+ ui->addRecord->setMenu(addMenu);
+
+ on_recordList_currentRowChanged(ui->recordList->currentRow());
+
+ connect(ui->textData, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
+ connect(ui->textLocale, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
+ connect(ui->uriData, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
+}
+
+NdefEditor::~NdefEditor()
+{
+ delete ui;
+}
+
+void NdefEditor::setNdefMessage(const QNdefMessage &message)
+{
+ while (ui->recordList->count())
+ delete ui->recordList->takeItem(0);
+
+ foreach (const QNdefRecord &record, message) {
+ RecordItem *item = new RecordItem(record);
+ ui->recordList->addItem(item);
+ }
+}
+
+QNdefMessage NdefEditor::ndefMessage() const
+{
+ QNdefMessage message;
+
+ for (int i = 0; i < ui->recordList->count(); ++i) {
+ RecordItem *item = static_cast<RecordItem *>(ui->recordList->item(i));
+ if (!item)
+ continue;
+
+ message.append(item->record());
+ }
+
+ return message;
+}
+
+void NdefEditor::on_recordList_currentRowChanged(int currentRow)
+{
+ ui->removeRecord->setEnabled(currentRow != -1);
+
+ RecordItem *item = static_cast<RecordItem *>(ui->recordList->item(currentRow));
+ if (!item) {
+ ui->recordEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QNdefRecord record = item->record();
+ if (record.isRecordType<QNdefNfcTextRecord>()) {
+ QNdefNfcTextRecord textRecord(record);
+
+ ui->recordEditor->setCurrentIndex(1);
+
+ ui->textLocale->setText(textRecord.locale());
+ ui->textData->setText(textRecord.text());
+ } else if (record.isRecordType<QNdefNfcUriRecord>()) {
+ QNdefNfcUriRecord uriRecord(record);
+
+ ui->recordEditor->setCurrentIndex(2);
+
+ ui->uriData->setText(uriRecord.uri().toString());
+ } else if (record.typeNameFormat() == QNdefRecord::Mime) {
+ if (record.type().startsWith("image/")) {
+ ui->recordEditor->setCurrentIndex(3);
+
+ QByteArray data = record.payload();
+ QBuffer buffer(&data);
+ buffer.open(QIODevice::ReadOnly);
+
+ QImageReader reader(&buffer);
+
+ ui->mimeImageType->setText(imageFormatToMimeType(reader.format()));
+
+ ui->mimeImageImage->setPixmap(QPixmap::fromImageReader(&reader));
+ }
+ } else {
+ ui->recordEditor->setCurrentIndex(0);
+ }
+}
+
+void NdefEditor::addNfcTextRecord()
+{
+ QNdefNfcTextRecord record;
+
+ RecordItem *item = new RecordItem(record);
+
+ ui->recordList->addItem(item);
+}
+
+void NdefEditor::addNfcUriRecord()
+{
+ QNdefNfcUriRecord record;
+
+ RecordItem *item = new RecordItem(record);
+
+ ui->recordList->addItem(item);
+}
+
+void NdefEditor::addMimeRecord()
+{
+ QNdefRecord record;
+ record.setTypeNameFormat(QNdefRecord::Mime);
+ record.setType("image/jpeg");
+
+ record.setType("image/png");
+
+ RecordItem *item = new RecordItem(record);
+
+ ui->recordList->addItem(item);
+}
+
+void NdefEditor::textRecordEditingFinished()
+{
+ RecordItem *item = static_cast<RecordItem *>(ui->recordList->currentItem());
+ if (!item) {
+ ui->recordEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QNdefNfcTextRecord record = item->record();
+ record.setText(ui->textData->text());
+ record.setLocale(ui->textLocale->text());
+
+ item->setRecord(record);
+}
+
+void NdefEditor::uriRecordEditingFinished()
+{
+ RecordItem *item = static_cast<RecordItem *>(ui->recordList->currentItem());
+ if (!item) {
+ ui->recordEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QNdefNfcUriRecord record = item->record();
+ record.setUri(QUrl(ui->uriData->text()));
+
+ item->setRecord(record);
+}
+
+void NdefEditor::on_removeRecord_clicked()
+{
+ delete ui->recordList->takeItem(ui->recordList->currentRow());
+}
+
+void NdefEditor::on_mimeImageOpen_clicked()
+{
+ QString mimeDataFile = QFileDialog::getOpenFileName(this, tr("Select Image File"));
+ if (mimeDataFile.isEmpty())
+ return;
+
+ QFile imageFile(mimeDataFile);
+ if (!imageFile.open(QIODevice::ReadOnly))
+ ui->mimeImageImage->clear();
+
+ QByteArray imageData = imageFile.readAll();
+
+ QBuffer buffer(&imageData);
+ buffer.open(QIODevice::ReadOnly);
+
+ QImageReader reader(&buffer);
+ QString mimeType = imageFormatToMimeType(reader.format());
+ ui->mimeImageType->setText(mimeType);
+
+ QImage image = reader.read();
+
+ ui->mimeImageImage->setPixmap(QPixmap::fromImage(image));
+
+ RecordItem *item = static_cast<RecordItem *>(ui->recordList->currentItem());
+ if (!item) {
+ ui->recordEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QNdefRecord record = item->record();
+
+ record.setType(mimeType.toAscii());
+ record.setPayload(imageData);
+
+ item->setRecord(record);
+ emit editingFinished();
+}
diff --git a/src/nfctargetgenerator/ndefeditor.h b/src/nfctargetgenerator/ndefeditor.h
new file mode 100644
index 0000000..fba227b
--- /dev/null
+++ b/src/nfctargetgenerator/ndefeditor.h
@@ -0,0 +1,83 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef NDEFEDITOR_H
+#define NDEFEDITOR_H
+
+#include <qmobilityglobal.h>
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class NdefEditor;
+}
+
+class QMenu;
+
+QTM_BEGIN_NAMESPACE
+class QNdefMessage;
+QTM_END_NAMESPACE
+
+QTM_USE_NAMESPACE
+
+class NdefEditor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NdefEditor(QWidget *parent = 0);
+ ~NdefEditor();
+
+ QNdefMessage ndefMessage() const;
+ void setNdefMessage(const QNdefMessage &message);
+
+signals:
+ void editingFinished();
+
+private slots:
+ void on_mimeImageOpen_clicked();
+ void on_removeRecord_clicked();
+ void on_recordList_currentRowChanged(int currentRow);
+
+ void textRecordEditingFinished();
+ void uriRecordEditingFinished();
+
+ void addNfcTextRecord();
+ void addNfcUriRecord();
+ void addMimeRecord();
+
+private:
+ Ui::NdefEditor *ui;
+ QMenu *addMenu;
+};
+
+#endif // NDEFEDITOR_H
diff --git a/src/nfctargetgenerator/ndefeditor.ui b/src/nfctargetgenerator/ndefeditor.ui
new file mode 100644
index 0000000..ec10208
--- /dev/null
+++ b/src/nfctargetgenerator/ndefeditor.ui
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NdefEditor</class>
+ <widget class="QWidget" name="NdefEditor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>377</width>
+ <height>231</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" rowspan="3">
+ <widget class="QListWidget" name="recordList"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QToolButton" name="addRecord">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Add</string>
+ </property>
+ <property name="popupMode">
+ <enum>QToolButton::InstantPopup</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="removeRecord">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QStackedWidget" name="recordEditor">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="currentIndex">
+ <number>3</number>
+ </property>
+ <widget class="QWidget" name="unknownRecord">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Unknown NDEF Record</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="nfcTextRecord">
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>NFC Text Record</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Text:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="textData"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Locale:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="textLocale"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="nfcUriRecord">
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>NFC URI Record</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Uri:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="uriData"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="mimeImageRecord">
+ <layout class="QFormLayout" name="formLayout_3">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>MIME Record &lt;image/*&gt;</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="mimeImageType">
+ <property name="text">
+ <string>image/</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QToolButton" name="mimeImageOpen">
+ <property name="text">
+ <string>Load Image</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QLabel" name="mimeImageImage">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>textData</sender>
+ <signal>editingFinished()</signal>
+ <receiver>NdefEditor</receiver>
+ <slot>textRecordEditingFinished()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>94</x>
+ <y>161</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>88</x>
+ <y>268</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>textLocale</sender>
+ <signal>editingFinished()</signal>
+ <receiver>NdefEditor</receiver>
+ <slot>textRecordEditingFinished()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>154</x>
+ <y>194</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>169</x>
+ <y>268</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>uriData</sender>
+ <signal>editingFinished()</signal>
+ <receiver>NdefEditor</receiver>
+ <slot>uriRecordEditingFinished()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>183</x>
+ <y>155</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>138</x>
+ <y>269</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+ <slots>
+ <signal>editingFinished()</signal>
+ <slot>textRecordEditingFinished()</slot>
+ <slot>uriRecordEditingFinished()</slot>
+ <slot>mimeRecordEditingFinished()</slot>
+ </slots>
+</ui>
diff --git a/src/nfctargetgenerator/nfctargetgenerator.cpp b/src/nfctargetgenerator/nfctargetgenerator.cpp
new file mode 100644
index 0000000..a0f4bef
--- /dev/null
+++ b/src/nfctargetgenerator/nfctargetgenerator.cpp
@@ -0,0 +1,185 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "nfctargetgenerator.h"
+#include "ui_nfctargetgenerator.h"
+
+#include "tagtype1.h"
+#include "tagtype2.h"
+
+#include <QtCore/QSettings>
+
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
+
+#include <QtCore/QDebug>
+#include <QtGui/QPushButton>
+
+NfcTargetGenerator::NfcTargetGenerator(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::NfcTargetGenerator), tagEditor(0)
+{
+ QPushButton *button = 0;
+
+ ui->setupUi(this);
+
+ button = ui->buttonBox->addButton("New", QDialogButtonBox::ActionRole);
+ button->setIcon(QIcon::fromTheme("document-new"));
+ connect(button, SIGNAL(clicked()), this, SLOT(action_new()));
+
+ button = ui->buttonBox->addButton("Open", QDialogButtonBox::ActionRole);
+ button->setIcon(QIcon::fromTheme("document-open"));
+ connect(button, SIGNAL(clicked()), this, SLOT(open_triggered()));
+
+ button = ui->buttonBox->addButton("Save", QDialogButtonBox::ActionRole);
+ button->setIcon(QIcon::fromTheme("document-save"));
+ connect(button, SIGNAL(clicked()), this, SLOT(save_triggered()));
+
+ button = ui->buttonBox->addButton("Save As", QDialogButtonBox::ActionRole);
+ button->setIcon(QIcon::fromTheme("document-save-as"));
+ connect(button, SIGNAL(clicked()), this, SLOT(save_As_triggered()));
+
+ button = ui->buttonBox->addButton("Close", QDialogButtonBox::ActionRole);
+ button->setIcon(QIcon::fromTheme("document-close"));
+ connect(button, SIGNAL(clicked()), this, SLOT(reject()));
+
+ on_targetType_currentIndexChanged(0);
+}
+
+NfcTargetGenerator::~NfcTargetGenerator()
+{
+ delete ui;
+}
+
+void NfcTargetGenerator::save(const QString &filename)
+{
+ if (ui->name->text().isEmpty()) {
+ QMessageBox::critical(this, "Name is Empty", "Tag name field is empty.");
+ return;
+ }
+
+ QSettings target(filename, QSettings::IniFormat);
+
+ target.beginGroup(QLatin1String("Target"));
+ target.setValue(QLatin1String("Name"), ui->name->text());
+
+ switch (ui->targetType->currentIndex()) {
+ case 0:
+ target.setValue(QLatin1String("Type"), QLatin1String("TagType1"));
+ break;
+ case 1:
+ target.setValue(QLatin1String("Type"), QLatin1String("TagType2"));
+ break;
+ default:
+ target.setValue(QLatin1String("Type"), QLatin1String("Unknown"));
+ }
+
+ target.endGroup();
+
+ tagEditor->save(&target);
+}
+
+void NfcTargetGenerator::on_targetType_currentIndexChanged(int index)
+{
+ if (tagEditor)
+ delete tagEditor;
+
+ switch (index) {
+ case 0:
+ tagEditor = new TagType1(this);
+ break;
+ case 1:
+ tagEditor = new TagType2(this);
+ break;
+ default:
+ tagEditor = 0;
+ }
+
+ if (tagEditor)
+ ui->tagEditor->addWidget(tagEditor);
+}
+
+void NfcTargetGenerator::load(const QString &filename)
+{
+ QSettings target(filename, QSettings::IniFormat);
+
+ target.beginGroup(QLatin1String("Target"));
+ ui->name->setText(target.value(QLatin1String("Name")).toString());
+
+ const QString tagType = target.value(QLatin1String("Type")).toString();
+ if (tagType == QLatin1String("TagType1"))
+ ui->targetType->setCurrentIndex(0);
+ else if (tagType == QLatin1String("TagType2"))
+ ui->targetType->setCurrentIndex(1);
+
+ target.endGroup();
+
+ tagEditor->load(&target);
+}
+
+static QString nfcDataPath()
+{
+ return QCoreApplication::applicationDirPath()+"/stubdata/nfctargets";
+}
+
+void NfcTargetGenerator::save_triggered()
+{
+ if (m_filename.isEmpty())
+ save_As_triggered();
+ else
+ save(m_filename);
+}
+
+void NfcTargetGenerator::save_As_triggered()
+{
+ m_filename = QFileDialog::getSaveFileName(this, tr("Save File As"), nfcDataPath(),
+ QLatin1String("*.nfc"));
+
+ if (!m_filename.isEmpty())
+ save(m_filename);
+}
+
+void NfcTargetGenerator::open_triggered()
+{
+ m_filename = QFileDialog::getOpenFileName(this, tr("Open File"), nfcDataPath(),
+ QLatin1String("*.nfc"));
+
+ if (!m_filename.isEmpty())
+ load(m_filename);
+}
+
+void NfcTargetGenerator::action_new()
+{
+ on_targetType_currentIndexChanged(ui->targetType->currentIndex());
+ m_filename.clear();
+ ui->name->clear();
+}
diff --git a/src/nfctargetgenerator/nfctargetgenerator.h b/src/nfctargetgenerator/nfctargetgenerator.h
new file mode 100644
index 0000000..9fc090d
--- /dev/null
+++ b/src/nfctargetgenerator/nfctargetgenerator.h
@@ -0,0 +1,70 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef NFCTARGETGENERATOR_H
+#define NFCTARGETGENERATOR_H
+
+#include <QtGui/QDialog>
+
+namespace Ui {
+ class NfcTargetGenerator;
+}
+
+class TagEditor;
+class QAbstractButton;
+
+class NfcTargetGenerator : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit NfcTargetGenerator(QWidget *parent = 0);
+ ~NfcTargetGenerator();
+
+private:
+ void save(const QString &filename);
+ void load(const QString &filename);
+
+private slots:
+ void action_new();
+ void on_targetType_currentIndexChanged(int index);
+ void open_triggered();
+ void save_As_triggered();
+ void save_triggered();
+
+private:
+ Ui::NfcTargetGenerator *ui;
+ QString m_filename;
+ TagEditor *tagEditor;
+};
+
+#endif // NFCTARGETGENERATOR_H
diff --git a/src/nfctargetgenerator/nfctargetgenerator.pri b/src/nfctargetgenerator/nfctargetgenerator.pri
new file mode 100644
index 0000000..c9866a0
--- /dev/null
+++ b/src/nfctargetgenerator/nfctargetgenerator.pri
@@ -0,0 +1,28 @@
+QT *= core gui
+CONFIG *= mobility
+MOBILITY *= connectivity
+INCLUDEPATH += src/nfctargetgenerator
+DEPENDPATH += src/nfctargetgenerator
+
+SOURCES += \
+ nfctargetgenerator.cpp \
+ tagtype1.cpp \
+ tagtype2.cpp \
+ ndefeditor.cpp \
+ tlveditor.cpp \
+ $$QT_MOBILITY_SOURCE_PATH/src/connectivity/nfc/qtlv.cpp \
+
+HEADERS += nfctargetgenerator.h \
+ tagtype1.h \
+ tagtype2.h \
+ ndefeditor.h \
+ tlveditor.h \
+ tageditor.h \
+ $$QT_MOBILITY_SOURCE_PATH/src/connectivity/nfc/qtlv_p.h \
+
+FORMS += nfctargetgenerator.ui \
+ tagtype1.ui \
+ tagtype2.ui \
+ ndefeditor.ui \
+ tlveditor.ui \
+
diff --git a/src/nfctargetgenerator/nfctargetgenerator.ui b/src/nfctargetgenerator/nfctargetgenerator.ui
new file mode 100644
index 0000000..5935754
--- /dev/null
+++ b/src/nfctargetgenerator/nfctargetgenerator.ui
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NfcTargetGenerator</class>
+ <widget class="QDialog" name="NfcTargetGenerator">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>479</width>
+ <height>163</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>NFC Target Generator</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="name"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="targetType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>NFC Tag Type 1</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>NFC Tag Type 2</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <layout class="QVBoxLayout" name="tagEditor"/>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::NoButton</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>NfcTargetGenerator</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>239</x>
+ <y>140</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>239</x>
+ <y>81</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/nfctargetgenerator/tageditor.h b/src/nfctargetgenerator/tageditor.h
new file mode 100644
index 0000000..c6d9ee7
--- /dev/null
+++ b/src/nfctargetgenerator/tageditor.h
@@ -0,0 +1,52 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef TAGEDITOR_H
+#define TAGEDITOR_H
+
+#include <QtGui/QWidget>
+
+class QSettings;
+
+class TagEditor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TagEditor(QWidget *parent) : QWidget(parent) { }
+ ~TagEditor() { }
+
+ virtual void save(QSettings *settings) const = 0;
+ virtual void load(QSettings *settings) = 0;
+};
+
+#endif // TAGEDITOR_H
diff --git a/src/nfctargetgenerator/tagtype1.cpp b/src/nfctargetgenerator/tagtype1.cpp
new file mode 100644
index 0000000..302f59f
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype1.cpp
@@ -0,0 +1,286 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "tagtype1.h"
+#include "ui_tagtype1.h"
+#include "../../src/connectivity/nfc/qtlv_p.h"
+
+#include <math.h>
+
+#include <QtCore/QSettings>
+#include <QDebug>
+
+QTM_USE_NAMESPACE
+
+static inline quint8 blockByteToAddress(quint8 block, quint8 byte)
+{
+ return ((block & 0x0f) << 3) | (byte & 0x07);
+}
+
+TagType1::TagType1(QWidget *parent)
+: TagEditor(parent), ui(new Ui::TagType1)
+{
+ ui->setupUi(this);
+}
+
+TagType1::~TagType1()
+{
+ delete ui;
+}
+
+void TagType1::save(QSettings *settings) const
+{
+ settings->beginGroup(QLatin1String("TagType1"));
+
+ quint8 hr0 = ui->hr0->value();
+
+ settings->setValue(QLatin1String("HR0"), hr0);
+
+ settings->setValue(QLatin1String("HR1"), ui->hr1->value());
+
+ quint8 nmn = ui->ndefMessage->isChecked() ? 0xe1 : 0;
+
+ double version = ui->nfcVersion->value();
+ quint8 vno = (quint8(floor(version)) << 4) | quint8(10 * (version - floor(version)));
+
+ quint8 tms = (ui->memorySize->value() / 8) - 1;
+
+ quint8 ra;
+ switch (ui->readAccess->currentIndex()) {
+ case 0:
+ ra = 0x00;
+ break;
+ default:
+ ra = 0x00;
+ }
+
+ quint8 wa;
+ switch (ui->writeAccess->currentIndex()) {
+ case 0:
+ wa = 0x00;
+ break;
+ case 1:
+ wa = 0x0f;
+ break;
+ default:
+ wa = 0x00;
+ }
+
+ quint8 rwa = (ra << 4) | wa;
+
+ quint16 lock = 0;
+ if (ui->lock0->isChecked())
+ lock |= 0x01 << 0;
+ if (ui->lock1->isChecked())
+ lock |= 0x01 << 1;
+ if (ui->lock2->isChecked())
+ lock |= 0x01 << 2;
+ if (ui->lock3->isChecked())
+ lock |= 0x01 << 3;
+ if (ui->lock4->isChecked())
+ lock |= 0x01 << 4;
+ if (ui->lock5->isChecked())
+ lock |= 0x01 << 5;
+ if (ui->lock6->isChecked())
+ lock |= 0x01 << 6;
+ if (ui->lock7->isChecked())
+ lock |= 0x01 << 7;
+ if (ui->lock8->isChecked())
+ lock |= 0x01 << 8;
+ if (ui->lock9->isChecked())
+ lock |= 0x01 << 9;
+ if (ui->lock10->isChecked())
+ lock |= 0x01 << 10;
+ if (ui->lock11->isChecked())
+ lock |= 0x01 << 11;
+ if (ui->lock12->isChecked())
+ lock |= 0x01 << 12;
+ if (ui->lock13->isChecked())
+ lock |= 0x01 << 13;
+ if (ui->lock14->isChecked())
+ lock |= 0x01 << 14;
+
+ QByteArray data;
+
+ // uid
+ data.append(QByteArray::fromHex(ui->uid->text().remove(QChar(':')).toAscii()));
+ data.append('\0');
+ Q_ASSERT(data.length() == 8);
+
+ // capability
+ data.append(nmn);
+ data.append(vno);
+ data.append(tms);
+ data.append(rwa);
+
+ Q_ASSERT(data.length() == 12);
+
+ data.reserve(ui->memorySize->value());
+ for (int i = data.length(); i < ui->memorySize->value(); ++i)
+ data[i] = '\0';
+
+ //qDebug() << "Data length = " << data.length();
+
+ // lock bytes
+ data[blockByteToAddress(0x0e, 0)] = lock & 0x0f;
+ data[blockByteToAddress(0x0e, 1)] = lock >> 8;
+
+ QTlvWriter writer(&data);
+ writer.addReservedMemory(0, 12); // skip uid, cc
+ writer.addReservedMemory(104, 16); // skip reserved block D, lock block E
+ writer.addReservedMemory(120, 8); // skip reserved block F
+
+ for (int i = 0; i < ui->tlvEditor->tlvItemCount(); ++i) {
+ QPair<quint8, QByteArray> tlv = ui->tlvEditor->tlvItemAt(i);
+ writer.writeTlv(tlv.first, tlv.second);
+ }
+
+ if (data.length() != ui->memorySize->value()) {
+ qDebug() << "Data length:" << data.length();
+ }
+
+ settings->setValue(QLatin1String("Data"), data);
+
+ //qDebug() << data.toHex();
+
+ settings->endGroup();
+}
+
+void TagType1::load(QSettings *settings)
+{
+ settings->beginGroup(QLatin1String("TagType1"));
+
+ quint8 hr0 = settings->value(QLatin1String("HR0"), 0x11).toUInt();
+
+ ui->hr0->setValue(hr0);
+ if (hr0 == 0x11)
+ ui->memoryStructure->setCurrentIndex(0);
+ else if (hr0 >= 0x10 && hr0 <= 0x1f)
+ ui->memoryStructure->setCurrentIndex(1);
+ else
+ ui->memoryStructure->setCurrentIndex(2);
+
+ quint8 hr1 = settings->value(QLatin1String("HR1"), 0x00).toUInt();
+ ui->hr1->setValue(hr1);
+
+ QByteArray data = settings->value(QLatin1String("Data")).toByteArray();
+
+ QByteArray uid = data.mid(0, 7).toHex();
+ ui->uid->setText(uid);
+
+ quint8 nmn = data.at(8);
+ ui->ndefMessage->setChecked(nmn == 0xe1);
+
+ quint8 vno = data.at(9);
+ ui->nfcVersion->setValue((vno >> 4) + 0.1 *(vno & 0x0f));
+
+ quint8 tms = data.at(10);
+ ui->memorySize->setValue(8 * (tms + 1));
+
+ quint8 rwa = data.at(11);
+ switch (rwa >> 4) {
+ case 0:
+ ui->readAccess->setCurrentIndex(0);
+ break;
+ default:
+ ui->readAccess->setCurrentIndex(0);
+ }
+
+ switch (rwa & 0x0f) {
+ case 0:
+ ui->writeAccess->setCurrentIndex(0);
+ break;
+ case 0x0f:
+ ui->writeAccess->setCurrentIndex(1);
+ break;
+ default:
+ ui->writeAccess->setCurrentIndex(0);
+ }
+
+ quint16 lock = (quint8(data[blockByteToAddress(0x0e, 1)]) << 8) |
+ quint8(data[blockByteToAddress(0x0e, 0)]);
+
+ ui->lock0->setChecked(lock & 0x0001);
+ ui->lock1->setChecked(lock & 0x0002);
+ ui->lock2->setChecked(lock & 0x0004);
+ ui->lock3->setChecked(lock & 0x0008);
+ ui->lock4->setChecked(lock & 0x0010);
+ ui->lock5->setChecked(lock & 0x0020);
+ ui->lock6->setChecked(lock & 0x0040);
+ ui->lock7->setChecked(lock & 0x0080);
+ ui->lock8->setChecked(lock & 0x0100);
+ ui->lock9->setChecked(lock & 0x0200);
+ ui->lock10->setChecked(lock & 0x0400);
+ ui->lock11->setChecked(lock & 0x0800);
+ ui->lock12->setChecked(lock & 0x1000);
+ ui->lock13->setChecked(lock & 0x2000);
+ ui->lock14->setChecked(lock & 0x4000);
+
+ //qDebug() << data.toHex();
+
+ ui->tlvEditor->clear();
+
+ QTlvReader reader(data);
+ reader.addReservedMemory(0, 12); // skip uid, cc
+ reader.addReservedMemory(104, 16); // skip reserved block D, lock block E
+ reader.addReservedMemory(120, 8); // skip reserved block F
+
+ while (!reader.atEnd()) {
+ if (!reader.readNext())
+ break;
+
+ ui->tlvEditor->addTlvItem(reader.tag(), reader.data());
+ }
+
+ settings->endGroup();
+}
+
+void TagType1::on_memoryStructure_currentIndexChanged(int index)
+{
+ switch (index) {
+ case 0: // static
+ ui->hr0->setRange(0x11, 0x11);
+ ui->hr0->setEnabled(false);
+ break;
+ case 1: // dynamic
+ ui->hr0->setRange(0x10, 0x1f);
+ ui->hr0->setEnabled(true);
+ break;
+ case 2: // proprietary
+ ui->hr0->setRange(0x00, 0xff);
+ ui->hr0->setEnabled(true);
+ break;
+ default:
+ ;
+ }
+}
+
diff --git a/src/nfctargetgenerator/tagtype1.h b/src/nfctargetgenerator/tagtype1.h
new file mode 100644
index 0000000..821a698
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype1.h
@@ -0,0 +1,62 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef TAGTYPE1_H
+#define TAGTYPE1_H
+
+#include "tageditor.h"
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class TagType1;
+}
+
+class TagType1 : public TagEditor
+{
+ Q_OBJECT
+
+public:
+ explicit TagType1(QWidget *parent = 0);
+ ~TagType1();
+
+ void save(QSettings *settings) const;
+ void load(QSettings *settings);
+
+private:
+ Ui::TagType1 *ui;
+
+private slots:
+ void on_memoryStructure_currentIndexChanged(int index);
+};
+
+#endif // TAGTYPE1_H
diff --git a/src/nfctargetgenerator/tagtype1.ui b/src/nfctargetgenerator/tagtype1.ui
new file mode 100644
index 0000000..751f2b4
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype1.ui
@@ -0,0 +1,414 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TagType1</class>
+ <widget class="QWidget" name="TagType1">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>352</width>
+ <height>379</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Memory Structure:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="memoryStructure">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Static</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Dynamic</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Proprietary</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>NFC Version:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QDoubleSpinBox" name="nfcVersion">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="decimals">
+ <number>1</number>
+ </property>
+ <property name="minimum">
+ <double>1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Memory Size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QSpinBox" name="memorySize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> bytes</string>
+ </property>
+ <property name="minimum">
+ <number>8</number>
+ </property>
+ <property name="maximum">
+ <number>2048</number>
+ </property>
+ <property name="singleStep">
+ <number>8</number>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Locked Blocks:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="lock0">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="lock4">
+ <property name="text">
+ <string>4</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="lock8">
+ <property name="text">
+ <string>8</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="lock9">
+ <property name="text">
+ <string>9</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QCheckBox" name="lock12">
+ <property name="text">
+ <string>C</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="lock5">
+ <property name="text">
+ <string>5</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QCheckBox" name="lock6">
+ <property name="text">
+ <string>6</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QCheckBox" name="lock7">
+ <property name="text">
+ <string>7</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QCheckBox" name="lock10">
+ <property name="text">
+ <string>A</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QCheckBox" name="lock1">
+ <property name="text">
+ <string>1</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QCheckBox" name="lock2">
+ <property name="text">
+ <string>2</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QCheckBox" name="lock3">
+ <property name="text">
+ <string>3</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
+ <widget class="QCheckBox" name="lock11">
+ <property name="text">
+ <string>B</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QCheckBox" name="lock13">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>D</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QCheckBox" name="lock14">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>E</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="10" column="0" colspan="2">
+ <widget class="QFrame" name="frame">
+ <property name="minimumSize">
+ <size>
+ <width>10</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="TlvEditor" name="tlvEditor" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Read Access:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Write Access:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1">
+ <widget class="QComboBox" name="readAccess">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Read Access without security</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="QComboBox" name="writeAccess">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Write Access without security</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>No Write Access</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>HR1:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QCheckBox" name="ndefMessage">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>NDEF Message</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="hr1">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="prefix">
+ <string/>
+ </property>
+ <property name="maximum">
+ <number>255</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>UID:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="uid">
+ <property name="inputMask">
+ <string>HH:HH:HH:HH:HH:HH:HH; </string>
+ </property>
+ <property name="text">
+ <string>00:00:00:00:00:00:00</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="hr0">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>HR0:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>TlvEditor</class>
+ <extends>QWidget</extends>
+ <header>tlveditor.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/nfctargetgenerator/tagtype2.cpp b/src/nfctargetgenerator/tagtype2.cpp
new file mode 100644
index 0000000..55c650d
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype2.cpp
@@ -0,0 +1,272 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "tagtype2.h"
+#include "ui_tagtype2.h"
+#include "../../src/connectivity/nfc/qtlv_p.h"
+
+#include <math.h>
+
+#include <QtCore/QSettings>
+#include <QDebug>
+
+QTM_USE_NAMESPACE
+
+static inline quint8 blockByteToAddress(quint8 block, quint8 byte)
+{
+ return ((block & 0x0f) << 3) | (byte & 0x07);
+}
+
+TagType2::TagType2(QWidget *parent)
+: TagEditor(parent), ui(new Ui::TagType2)
+{
+ ui->setupUi(this);
+}
+
+TagType2::~TagType2()
+{
+ delete ui;
+}
+
+void TagType2::save(QSettings *settings) const
+{
+ settings->beginGroup(QLatin1String("TagType2"));
+
+ quint8 nmn = ui->ndefMessage->isChecked() ? 0xe1 : 0;
+
+ double version = ui->nfcVersion->value();
+ quint8 vno = (quint8(floor(version)) << 4) | quint8(10 * (version - floor(version)));
+
+ quint8 tms = ui->memorySize->value() / 8;
+
+ quint8 ra;
+ switch (ui->readAccess->currentIndex()) {
+ case 0:
+ ra = 0x00;
+ break;
+ case 1:
+ ra = 0x08;
+ break;
+ case 2:
+ ra = 0x0e;
+ break;
+ default:
+ ra = 0x00;
+ }
+
+ quint8 wa;
+ switch (ui->writeAccess->currentIndex()) {
+ case 0:
+ wa = 0x00;
+ break;
+ case 1:
+ wa = 0x08;
+ break;
+ case 2:
+ wa = 0x0e;
+ break;
+ case 3:
+ wa = 0x0f;
+ break;
+ default:
+ wa = 0x00;
+ }
+
+ quint8 rwa = (ra << 4) | wa;
+
+ quint16 lock = 0;
+ if (ui->lock0->isChecked())
+ lock |= 0x01 << 0;
+ if (ui->lock1->isChecked())
+ lock |= 0x01 << 1;
+ if (ui->lock2->isChecked())
+ lock |= 0x01 << 2;
+ if (ui->lock3->isChecked())
+ lock |= 0x01 << 3;
+ if (ui->lock4->isChecked())
+ lock |= 0x01 << 4;
+ if (ui->lock5->isChecked())
+ lock |= 0x01 << 5;
+ if (ui->lock6->isChecked())
+ lock |= 0x01 << 6;
+ if (ui->lock7->isChecked())
+ lock |= 0x01 << 7;
+ if (ui->lock8->isChecked())
+ lock |= 0x01 << 8;
+ if (ui->lock9->isChecked())
+ lock |= 0x01 << 9;
+ if (ui->lock10->isChecked())
+ lock |= 0x01 << 10;
+ if (ui->lock11->isChecked())
+ lock |= 0x01 << 11;
+ if (ui->lock12->isChecked())
+ lock |= 0x01 << 12;
+ if (ui->lock13->isChecked())
+ lock |= 0x01 << 13;
+ if (ui->lock14->isChecked())
+ lock |= 0x01 << 14;
+
+ QByteArray data;
+
+ // uid
+ const QByteArray uid = QByteArray::fromHex(ui->uid->text().remove(QChar(':')).toAscii());
+ data.append(uid.left(3));
+ data.append('\0'); // internal0
+ data.append(uid.mid(3, 4));
+ Q_ASSERT(data.length() == 8);
+
+ // internal
+ data.append('\0'); // internal1
+ data.append('\0'); // internal2
+
+ // lock bytes
+ data.append(lock & 0x0f);
+ data.append(lock >> 8);
+
+ // capability
+ data.append(nmn);
+ data.append(vno);
+ data.append(tms);
+ data.append(rwa);
+
+ Q_ASSERT(data.length() == 16);
+
+ data.reserve(16 + ui->memorySize->value());
+ for (int i = data.length(); i < ui->memorySize->value(); ++i)
+ data[i] = '\0';
+
+ //qDebug() << "Data length = " << data.length();
+
+ QTlvWriter writer(&data);
+ writer.addReservedMemory(0, 16); // skip uid, lock, cc
+
+ for (int i = 0; i < ui->tlvEditor->tlvItemCount(); ++i) {
+ QPair<quint8, QByteArray> tlv = ui->tlvEditor->tlvItemAt(i);
+ writer.writeTlv(tlv.first, tlv.second);
+ }
+
+ if (data.length() != ui->memorySize->value()) {
+ qDebug() << "Data length:" << data.length();
+ }
+
+ settings->setValue(QLatin1String("Data"), data);
+
+ //qDebug() << data.toHex();
+
+ settings->endGroup();
+}
+
+void TagType2::load(QSettings *settings)
+{
+ settings->beginGroup(QLatin1String("TagType2"));
+
+ QByteArray data = settings->value(QLatin1String("Data")).toByteArray();
+
+ QByteArray uid = data.mid(0, 3).toHex() + data.mid(4, 4);
+ ui->uid->setText(uid);
+
+ quint16 lock = (quint8(data.at(10)) << 8) | quint8(data.at(11));
+
+ ui->lock0->setChecked(lock & 0x0001);
+ ui->lock1->setChecked(lock & 0x0002);
+ ui->lock2->setChecked(lock & 0x0004);
+ ui->lock3->setChecked(lock & 0x0008);
+ ui->lock4->setChecked(lock & 0x0010);
+ ui->lock5->setChecked(lock & 0x0020);
+ ui->lock6->setChecked(lock & 0x0040);
+ ui->lock7->setChecked(lock & 0x0080);
+ ui->lock8->setChecked(lock & 0x0100);
+ ui->lock9->setChecked(lock & 0x0200);
+ ui->lock10->setChecked(lock & 0x0400);
+ ui->lock11->setChecked(lock & 0x0800);
+ ui->lock12->setChecked(lock & 0x1000);
+ ui->lock13->setChecked(lock & 0x2000);
+ ui->lock14->setChecked(lock & 0x4000);
+
+ quint8 nmn = data.at(12);
+ ui->ndefMessage->setChecked(nmn == 0xe1);
+
+ quint8 vno = data.at(13);
+ ui->nfcVersion->setValue((vno >> 4) + 0.1 *(vno & 0x0f));
+
+ quint8 tms = data.at(14);
+ ui->memorySize->setValue(8 * tms);
+
+ quint8 rwa = data.at(15);
+ switch (rwa >> 4) {
+ case 0x00:
+ ui->readAccess->setCurrentIndex(0);
+ break;
+ case 0x08:
+ ui->readAccess->setCurrentIndex(1);
+ break;
+ case 0x0e:
+ ui->readAccess->setCurrentIndex(2);
+ break;
+ default:
+ ui->readAccess->setCurrentIndex(0);
+ }
+
+ switch (rwa & 0x0f) {
+ case 0x00:
+ ui->writeAccess->setCurrentIndex(0);
+ break;
+ case 0x08:
+ ui->writeAccess->setCurrentIndex(1);
+ break;
+ case 0x0e:
+ ui->writeAccess->setCurrentIndex(2);
+ break;
+ case 0x0f:
+ ui->writeAccess->setCurrentIndex(3);
+ break;
+ default:
+ ui->writeAccess->setCurrentIndex(0);
+ }
+
+ //qDebug() << data.toHex();
+
+ ui->tlvEditor->clear();
+
+ QTlvReader reader(data);
+ reader.addReservedMemory(0, 16); // skip uid, lock, cc
+
+ while (!reader.atEnd()) {
+ if (!reader.readNext())
+ break;
+
+ ui->tlvEditor->addTlvItem(reader.tag(), reader.data());
+ }
+
+ settings->endGroup();
+}
+
diff --git a/src/nfctargetgenerator/tagtype2.h b/src/nfctargetgenerator/tagtype2.h
new file mode 100644
index 0000000..928d47e
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype2.h
@@ -0,0 +1,59 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef TAGTYPE2_H
+#define TAGTYPE2_H
+
+#include "tageditor.h"
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class TagType2;
+}
+
+class TagType2 : public TagEditor
+{
+ Q_OBJECT
+
+public:
+ explicit TagType2(QWidget *parent = 0);
+ ~TagType2();
+
+ void save(QSettings *settings) const;
+ void load(QSettings *settings);
+
+private:
+ Ui::TagType2 *ui;
+};
+
+#endif // TAGTYPE2_H
diff --git a/src/nfctargetgenerator/tagtype2.ui b/src/nfctargetgenerator/tagtype2.ui
new file mode 100644
index 0000000..232a8a0
--- /dev/null
+++ b/src/nfctargetgenerator/tagtype2.ui
@@ -0,0 +1,356 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TagType2</class>
+ <widget class="QWidget" name="TagType2">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>352</width>
+ <height>379</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>UID:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="uid">
+ <property name="inputMask">
+ <string>HH:HH:HH:HH:HH:HH:HH; </string>
+ </property>
+ <property name="text">
+ <string>00:00:00:00:00:00:00</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="ndefMessage">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>NDEF Message</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>NFC Version:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="nfcVersion">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="decimals">
+ <number>1</number>
+ </property>
+ <property name="minimum">
+ <double>1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Memory Size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="memorySize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> bytes</string>
+ </property>
+ <property name="minimum">
+ <number>8</number>
+ </property>
+ <property name="maximum">
+ <number>2048</number>
+ </property>
+ <property name="singleStep">
+ <number>8</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Read Access:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QComboBox" name="readAccess">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Read Access without security</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Proprietary (0x08)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Proprietary (0x0E)</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Write Access:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QComboBox" name="writeAccess">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Write Access without security</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Proprietary (0x08)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Proprietary (0x0E)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>No Write Access</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Locked Blocks:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="lock0">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="lock4">
+ <property name="text">
+ <string>4</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="lock8">
+ <property name="text">
+ <string>8</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="lock9">
+ <property name="text">
+ <string>9</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QCheckBox" name="lock12">
+ <property name="text">
+ <string>C</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="lock5">
+ <property name="text">
+ <string>5</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QCheckBox" name="lock6">
+ <property name="text">
+ <string>6</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QCheckBox" name="lock7">
+ <property name="text">
+ <string>7</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QCheckBox" name="lock10">
+ <property name="text">
+ <string>A</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QCheckBox" name="lock1">
+ <property name="text">
+ <string>1</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QCheckBox" name="lock2">
+ <property name="text">
+ <string>2</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QCheckBox" name="lock3">
+ <property name="text">
+ <string>3</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
+ <widget class="QCheckBox" name="lock11">
+ <property name="text">
+ <string>B</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QCheckBox" name="lock13">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>D</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QCheckBox" name="lock14">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>E</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="7" column="0" colspan="2">
+ <widget class="QFrame" name="frame">
+ <property name="minimumSize">
+ <size>
+ <width>10</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="TlvEditor" name="tlvEditor" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>TlvEditor</class>
+ <extends>QWidget</extends>
+ <header>tlveditor.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/nfctargetgenerator/tlveditor.cpp b/src/nfctargetgenerator/tlveditor.cpp
new file mode 100644
index 0000000..c09869e
--- /dev/null
+++ b/src/nfctargetgenerator/tlveditor.cpp
@@ -0,0 +1,346 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#include "tlveditor.h"
+#include "ui_tlveditor.h"
+
+#include <qndefmessage.h>
+
+#include <QtGui/QMenu>
+
+QTM_USE_NAMESPACE
+
+class TlvItem : public QListWidgetItem
+{
+public:
+ TlvItem(quint8 tag, const QByteArray &value);
+ ~TlvItem();
+
+ quint8 tagType() const;
+
+ QByteArray value() const;
+ void setValue(const QByteArray &value);
+
+ QVariant data(int role) const;
+
+private:
+ quint8 m_tagType;
+ QByteArray m_value;
+};
+
+TlvItem::TlvItem(quint8 tag, const QByteArray &value)
+: m_tagType(tag), m_value(value)
+{
+}
+
+TlvItem::~TlvItem()
+{
+}
+
+QVariant TlvItem::data(int role) const
+{
+ if (role == Qt::DisplayRole) {
+ switch (m_tagType) {
+ case 0x00:
+ return TlvEditor::tr("Null");
+ case 0x01:
+ return TlvEditor::tr("Locked Memory");
+ case 0x02:
+ return TlvEditor::tr("Reserved Memory");
+ case 0x03:
+ return TlvEditor::tr("NDEF Message");
+ case 0xfe:
+ return TlvEditor::tr("Terminator");
+ }
+ }
+
+ return QListWidgetItem::data(role);
+}
+
+quint8 TlvItem::tagType() const
+{
+ return m_tagType;
+}
+
+QByteArray TlvItem::value() const
+{
+ return m_value;
+}
+
+void TlvItem::setValue(const QByteArray &value)
+{
+ m_value = value;
+}
+
+TlvEditor::TlvEditor(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::TlvEditor)
+{
+ ui->setupUi(this);
+
+ addMenu = new QMenu(this);
+ addMenu->addAction(tr("NDEF Message"), this, SLOT(addNdefMessage()));
+ addMenu->addAction(tr("NULL"), this, SLOT(addNull()));
+ addMenu->addAction(tr("Terminator"), this, SLOT(addTerminator()));
+ addMenu->addAction(tr("Reserved Memory"), this, SLOT(addReservedMemory()));
+ addMenu->addAction(tr("Locked Memory"), this, SLOT(addLockedMemory()));
+
+ ui->add->setMenu(addMenu);
+
+ on_tlvList_currentRowChanged(ui->tlvList->currentRow());
+
+ connect(ui->ndefEditor, SIGNAL(editingFinished()), this, SLOT(ndefMessageSaved()));
+
+ connect(ui->pageAddress, SIGNAL(valueChanged(int)), this, SLOT(updateReservedMemory()));
+ connect(ui->pageSize, SIGNAL(currentIndexChanged(int)), this, SLOT(updateReservedMemory()));
+ connect(ui->byteOffset, SIGNAL(valueChanged(int)), this, SLOT(updateReservedMemory()));
+ connect(ui->size, SIGNAL(valueChanged(int)), this, SLOT(updateReservedMemory()));
+
+ connect(ui->lockPageAddress, SIGNAL(valueChanged(int)), this, SLOT(updateLockedMemory()));
+ connect(ui->lockPageSize, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLockedMemory()));
+ connect(ui->lockByteOffset, SIGNAL(valueChanged(int)), this, SLOT(updateLockedMemory()));
+ connect(ui->lockSize, SIGNAL(valueChanged(int)), this, SLOT(updateLockedMemory()));
+ connect(ui->lockBytesPerBit, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(updateLockedMemory()));
+}
+
+TlvEditor::~TlvEditor()
+{
+ delete ui;
+}
+
+void TlvEditor::clear()
+{
+ while (ui->tlvList->count())
+ delete ui->tlvList->takeItem(0);
+}
+
+void TlvEditor::addTlvItem(quint8 tag, const QByteArray &value)
+{
+ ui->tlvList->addItem(new TlvItem(tag, value));
+}
+
+QPair<quint8, QByteArray> TlvEditor::tlvItemAt(int i) const
+{
+ TlvItem *item = static_cast<TlvItem *>(ui->tlvList->item(i));
+ if (!item)
+ return qMakePair(quint8(0), QByteArray());
+
+ return qMakePair(item->tagType(), item->value());
+}
+
+int TlvEditor::tlvItemCount() const
+{
+ return ui->tlvList->count();
+}
+
+void TlvEditor::addNdefMessage()
+{
+ TlvItem *item = new TlvItem(0x03, QByteArray());
+
+ ui->tlvList->addItem(item);
+}
+
+void TlvEditor::addNull()
+{
+ TlvItem *item = new TlvItem(0x00, QByteArray());
+
+ ui->tlvList->addItem(item);
+}
+
+void TlvEditor::addTerminator()
+{
+ TlvItem *item = new TlvItem(0xfe, QByteArray());
+
+ ui->tlvList->addItem(item);
+}
+
+void TlvEditor::addReservedMemory()
+{
+ TlvItem *item = new TlvItem(0x02, QByteArray(3, '\0'));
+
+ ui->tlvList->addItem(item);
+}
+
+void TlvEditor::addLockedMemory()
+{
+ TlvItem *item = new TlvItem(0x01, QByteArray(3, '\0'));
+
+ ui->tlvList->addItem(item);
+}
+
+void TlvEditor::on_tlvList_currentRowChanged(int currentRow)
+{
+ ui->remove->setEnabled(currentRow != -1);
+
+ TlvItem *item = static_cast<TlvItem *>(ui->tlvList->item(currentRow));
+ if (!item) {
+ ui->tlvEditor->setCurrentIndex(0);
+ return;
+ }
+
+ switch (item->tagType()) {
+ case 0x01:
+ ui->tlvEditor->setCurrentIndex(3);
+ setLockedMemory(item->value());
+ break;
+ case 0x02:
+ ui->tlvEditor->setCurrentIndex(2);
+ setReservedMemory(item->value());
+ break;
+ case 0x03:
+ ui->tlvEditor->setCurrentIndex(1);
+ ui->ndefEditor->setNdefMessage(QNdefMessage::fromByteArray(item->value()));
+ break;
+ default:
+ ui->tlvEditor->setCurrentIndex(0);
+ }
+}
+
+void TlvEditor::ndefMessageSaved()
+{
+ TlvItem *item = static_cast<TlvItem *>(ui->tlvList->currentItem());
+ if (!item) {
+ ui->tlvEditor->setCurrentIndex(0);
+ return;
+ }
+
+ //qDebug() << "Saving ndef message tlv";
+
+ QNdefMessage message = ui->ndefEditor->ndefMessage();
+ item->setValue(message.toByteArray());
+}
+
+void TlvEditor::on_remove_clicked()
+{
+ delete ui->tlvList->takeItem(ui->tlvList->currentRow());
+}
+
+void TlvEditor::setReservedMemory(const QByteArray &value)
+{
+ quint8 position = value.at(0);
+ int pageAddress = position >> 4;
+ int byteOffset = position & 0x0f;
+
+ int size = quint8(value.at(1));
+ if (size == 0)
+ size = 256;
+
+ quint8 pageControl = value.at(2);
+ int bytesPerPageN = pageControl & 0x0f;
+
+ int byteAddress = bytesPerPageN ? pageAddress * (1 << bytesPerPageN) + byteOffset : 0;
+
+ ui->pageAddress->setValue(pageAddress);
+ ui->pageSize->setCurrentIndex(bytesPerPageN - 1);
+ ui->byteOffset->setValue(byteOffset);
+ ui->size->setValue(size);
+
+ ui->byteAddress->setText(QString::number(byteAddress));
+}
+
+void TlvEditor::updateReservedMemory()
+{
+ int pageAddress = ui->pageAddress->value();
+ int bytesPerPageN = ui->pageSize->currentIndex() + 1;
+ int byteOffset = ui->byteOffset->value();
+ int size = ui->size->value();
+
+ int byteAddress = pageAddress * (1 << bytesPerPageN) + byteOffset;
+
+ ui->byteAddress->setText(QString::number(byteAddress));
+
+ TlvItem *item = static_cast<TlvItem *>(ui->tlvList->currentItem());
+ if (!item) {
+ ui->tlvEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QByteArray value;
+ value.append((quint8(pageAddress) << 4) | (quint8(byteOffset) & 0x0f));
+ value.append(quint8(size == 256 ? 0 : size));
+ value.append(quint8(bytesPerPageN));
+
+ item->setValue(value);
+}
+
+void TlvEditor::setLockedMemory(const QByteArray &value)
+{
+ quint8 position = value.at(0);
+ int pageAddress = position >> 4;
+ int byteOffset = position & 0x0f;
+
+ int size = quint8(value.at(1));
+ if (size == 0)
+ size = 256;
+
+ quint8 pageControl = value.at(2);
+ int bytesPerPageN = pageControl & 0x0f;
+ int bytesPerBitN = pageControl >> 4;
+
+ int byteAddress = bytesPerPageN ? pageAddress * (1 << bytesPerPageN) + byteOffset : 0;
+
+ ui->lockPageAddress->setValue(pageAddress);
+ ui->lockPageSize->setCurrentIndex(bytesPerPageN - 1);
+ ui->lockByteOffset->setValue(byteOffset);
+ ui->lockSize->setValue(size);
+ ui->lockBytesPerBit->setCurrentIndex(bytesPerBitN - 1);
+
+ ui->byteAddress->setText(QString::number(byteAddress));
+}
+
+void TlvEditor::updateLockedMemory()
+{
+ int pageAddress = ui->lockPageAddress->value();
+ int bytesPerPageN = ui->lockPageSize->currentIndex() + 1;
+ int byteOffset = ui->lockByteOffset->value();
+ int size = ui->lockSize->value();
+ int bytesPerBitN = ui->lockBytesPerBit->currentIndex() + 1;
+
+ int byteAddress = pageAddress * (1 << bytesPerPageN) + byteOffset;
+
+ ui->lockByteAddress->setText(QString::number(byteAddress));
+
+ TlvItem *item = static_cast<TlvItem *>(ui->tlvList->currentItem());
+ if (!item) {
+ ui->tlvEditor->setCurrentIndex(0);
+ return;
+ }
+
+ QByteArray value;
+ value.append((quint8(pageAddress) << 4) | (quint8(byteOffset) & 0x0f));
+ value.append(quint8(size == 256 ? 0 : size));
+ value.append(quint8(bytesPerBitN) << 4 | quint8(bytesPerPageN));
+
+ item->setValue(value);
+}
+
diff --git a/src/nfctargetgenerator/tlveditor.h b/src/nfctargetgenerator/tlveditor.h
new file mode 100644
index 0000000..9c97e9a
--- /dev/null
+++ b/src/nfctargetgenerator/tlveditor.h
@@ -0,0 +1,79 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** 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.
+**
+** 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at info@qt.nokia.com.
+**
+**************************************************************************/
+
+#ifndef TLVEDITOR_H
+#define TLVEDITOR_H
+
+#include <QtGui/QWidget>
+
+namespace Ui {
+ class TlvEditor;
+}
+
+class QMenu;
+
+class TlvEditor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit TlvEditor(QWidget *parent = 0);
+ ~TlvEditor();
+
+ void clear();
+ void addTlvItem(quint8 tag, const QByteArray &value);
+ QPair<quint8, QByteArray> tlvItemAt(int i) const;
+ int tlvItemCount() const;
+
+private slots:
+ void on_remove_clicked();
+ void on_tlvList_currentRowChanged(int currentRow);
+ void addNdefMessage();
+ void addNull();
+ void addTerminator();
+ void addReservedMemory();
+ void addLockedMemory();
+
+ void setReservedMemory(const QByteArray &value);
+ void updateReservedMemory();
+
+ void setLockedMemory(const QByteArray &value);
+ void updateLockedMemory();
+
+ void ndefMessageSaved();
+
+private:
+ Ui::TlvEditor *ui;
+ QMenu *addMenu;
+};
+
+#endif // TLVEDITOR_H
diff --git a/src/nfctargetgenerator/tlveditor.ui b/src/nfctargetgenerator/tlveditor.ui
new file mode 100644
index 0000000..9bc16d0
--- /dev/null
+++ b/src/nfctargetgenerator/tlveditor.ui
@@ -0,0 +1,581 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TlvEditor</class>
+ <widget class="QWidget" name="TlvEditor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>501</width>
+ <height>481</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" rowspan="3">
+ <widget class="QListWidget" name="tlvList"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QToolButton" name="add">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Add</string>
+ </property>
+ <property name="popupMode">
+ <enum>QToolButton::InstantPopup</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="remove">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QStackedWidget" name="tlvEditor">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="currentIndex">
+ <number>3</number>
+ </property>
+ <widget class="QWidget" name="unknownTlv">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Unknown TLV</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="ndefMessageTlv">
+ <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>NDEF Message</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="NdefEditor" name="ndefEditor" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page">
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Reserved Memory</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Page address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="pageAddress">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum">
+ <number>15</number>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Page size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Byte offset:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="byteOffset">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum">
+ <number>15</number>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QSpinBox" name="size">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> bytes</string>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>256</number>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Byte address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLabel" name="byteAddress">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="pageSize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>2 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>64 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>128 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>256 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>512 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>1024 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>2048 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4096 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8192 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16384 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32768 bytes</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page_2">
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Page address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="lockPageAddress">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum">
+ <number>15</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label_13">
+ <property name="text">
+ <string>Locked Memory</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>Page size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="lockPageSize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>2 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>64 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>128 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>256 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>512 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>1024 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>2048 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4096 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8192 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16384 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32768 bytes</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>Byte offset:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QSpinBox" name="lockByteOffset">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum">
+ <number>15</number>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_14">
+ <property name="text">
+ <string>Size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QSpinBox" name="lockSize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="suffix">
+ <string> bits</string>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>256</number>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="label_15">
+ <property name="text">
+ <string>Bytes locked per bit:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1">
+ <widget class="QComboBox" name="lockBytesPerBit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>2 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>64 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>128 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>256 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>512 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>1024 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>2048 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>4096 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>8192 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>16384 bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>32768 bytes</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="8" column="0">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Byte address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="QLabel" name="lockByteAddress">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>NdefEditor</class>
+ <extends>QWidget</extends>
+ <header>ndefeditor.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/src.pri b/src/src.pri
index 3458f7f..3ad96be 100644
--- a/src/src.pri
+++ b/src/src.pri
@@ -4,6 +4,7 @@ include(ui/ui.pri)
include(modeltest/modeltest.pri)
include(shared/qtlockedfile/qtlockedfile.pri)
include(shared/qtsingleapplication/qtsingleapplication.pri)
+include(nfctargetgenerator/nfctargetgenerator.pri)
DEFINES += SIMULATOR_APPLICATION
diff --git a/src/ui/nfcui.cpp b/src/ui/nfcui.cpp
index 6fd05ad..d4f09a2 100644
--- a/src/ui/nfcui.cpp
+++ b/src/ui/nfcui.cpp
@@ -42,8 +42,10 @@
#include <QtGui/QListWidget>
#include <QtGui/QPushButton>
+#include <QtGui/QHBoxLayout>
#include <QtCore/QDebug>
+#include "nfctargetgenerator.h"
class NfcTargetItem : public QListWidgetItem
{
@@ -109,6 +111,27 @@ NfcUi::NfcUi(QWidget *parent)
mTargets->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
connect(mTargets, SIGNAL(activated(QModelIndex)), SLOT(targetActivated(QModelIndex)));
+ optionsList << new OptionsItem(tr("Targets"), mTargets);
+
+ QPushButton *editButton = new QPushButton(tr("Start Editor"), this);
+ connect(editButton, SIGNAL(clicked()), this, SLOT(startEditor()));
+ OptionsItem *item = new OptionsItem("", editButton, true);
+ optionsList << item;
+
+ setTitle(tr("NFC"));
+ setOptions(optionsList);
+
+ loadTagList();
+}
+
+NfcUi::~NfcUi()
+{
+}
+
+void NfcUi::loadTagList()
+{
+ mTargets->clear();
+
QDirIterator nfcTargets("stubdata/nfctargets", QStringList(QLatin1String("*.nfc")),
QDir::Files);
while (nfcTargets.hasNext()) {
@@ -137,21 +160,6 @@ NfcUi::NfcUi(QWidget *parent)
mTargets->addItem(targetItem);
}
-
- optionsList << new OptionsItem(tr("Targets"), mTargets);
-
- mReset = new QPushButton(tr("Reset Target"));
- mReset->setToolTip(tr("Resets the selected target factory defaults."));
- connect(mReset, SIGNAL(clicked()), this, SLOT(resetTarget()));
-
- optionsList <<new OptionsItem(QString(), mReset, true);
-
- setTitle(tr("NFC"));
- setOptions(optionsList);
-}
-
-NfcUi::~NfcUi()
-{
}
QByteArray NfcUi::processCommand(const QByteArray &command)
@@ -200,14 +208,9 @@ void NfcUi::targetActivated(const QModelIndex &index)
}
}
-void NfcUi::resetTarget()
+void NfcUi::startEditor()
{
- NfcTargetItem *targetItem = static_cast<NfcTargetItem *>(mTargets->currentItem());
- if (targetItem) {
- if (targetItem->data(NfcTargetItem::InProximity).toBool())
- targetItem->setData(NfcTargetItem::InProximity, false);
-
- qDebug() << "Need to reset" << targetItem->data(NfcTargetItem::NameRole).toString();
- }
+ NfcTargetGenerator dialog(this);
+ dialog.exec();
+ loadTagList();
}
-
diff --git a/src/ui/nfcui.h b/src/ui/nfcui.h
index d0180f8..f1e27ac 100644
--- a/src/ui/nfcui.h
+++ b/src/ui/nfcui.h
@@ -56,11 +56,11 @@ signals:
private slots:
void targetActivated(const QModelIndex &index);
- void resetTarget();
+ void startEditor();
+ void loadTagList();
private:
QListWidget *mTargets;
- QPushButton *mReset;
};
#endif // NFCUI_H