summaryrefslogtreecommitdiffstats
path: root/examples/annotatedurl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/annotatedurl')
-rw-r--r--examples/annotatedurl/annotatedurl.cpp119
-rw-r--r--examples/annotatedurl/annotatedurl.h73
-rw-r--r--examples/annotatedurl/annotatedurl.pro18
-rw-r--r--examples/annotatedurl/main.cpp80
-rw-r--r--examples/annotatedurl/mainwindow.cpp72
-rw-r--r--examples/annotatedurl/mainwindow.h70
-rw-r--r--examples/annotatedurl/mainwindow.ui61
7 files changed, 493 insertions, 0 deletions
diff --git a/examples/annotatedurl/annotatedurl.cpp b/examples/annotatedurl/annotatedurl.cpp
new file mode 100644
index 00000000..9b608931
--- /dev/null
+++ b/examples/annotatedurl/annotatedurl.cpp
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "annotatedurl.h"
+
+#include <qnearfieldtarget.h>
+#include <qndefmessage.h>
+#include <qndefrecord.h>
+#include <qndefnfctextrecord.h>
+#include <qndefnfcurirecord.h>
+
+#include <QtCore/QUrl>
+#include <QtCore/QLocale>
+
+#include <QGridLayout>
+#include <QLabel>
+#include <QMouseEvent>
+#include <QDesktopServices>
+
+AnnotatedUrl::AnnotatedUrl(QObject *parent)
+: QObject(parent)
+{
+}
+
+AnnotatedUrl::~AnnotatedUrl()
+{
+}
+
+void AnnotatedUrl::handleMessage(const QNdefMessage &message, QNearFieldTarget *target)
+{
+ Q_UNUSED(target);
+
+ enum {
+ MatchedNone,
+ MatchedFirst,
+ MatchedEnglish,
+ MatchedLanguage,
+ MatchedLanguageAndCountry
+ } bestMatch = MatchedNone;
+
+ QLocale defaultLocale;
+
+ QString title;
+ QUrl url;
+ QPixmap pixmap;
+
+ foreach (const QNdefRecord &record, message) {
+ if (record.isRecordType<QNdefNfcTextRecord>()) {
+ QNdefNfcTextRecord textRecord(record);
+
+ QLocale locale(textRecord.locale());
+
+ // already found best match
+ if (bestMatch == MatchedLanguageAndCountry) {
+ // do nothing
+ } else if (bestMatch <= MatchedLanguage && locale == defaultLocale) {
+ title = textRecord.text();
+ bestMatch = MatchedLanguageAndCountry;
+ } else if (bestMatch <= MatchedEnglish &&
+ locale.language() == defaultLocale.language()) {
+ title = textRecord.text();
+ bestMatch = MatchedLanguage;
+ } else if (bestMatch <= MatchedFirst && locale.language() == QLocale::English) {
+ title = textRecord.text();
+ bestMatch = MatchedEnglish;
+ } else if (bestMatch == MatchedNone) {
+ title = textRecord.text();
+ bestMatch = MatchedFirst;
+ }
+ } else if (record.isRecordType<QNdefNfcUriRecord>()) {
+ QNdefNfcUriRecord uriRecord(record);
+
+ url = uriRecord.uri();
+ } else if (record.typeNameFormat() == QNdefRecord::Mime &&
+ record.type().startsWith("image/")) {
+ pixmap = QPixmap::fromImage(QImage::fromData(record.payload()));
+ }
+ }
+
+ emit annotatedUrl(url, title, pixmap);
+}
+
diff --git a/examples/annotatedurl/annotatedurl.h b/examples/annotatedurl/annotatedurl.h
new file mode 100644
index 00000000..5b050105
--- /dev/null
+++ b/examples/annotatedurl/annotatedurl.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANNOTATEDURL_H
+#define ANNOTATEDURL_H
+
+#include <qnfcglobal.h>
+
+#include <QtCore/QObject>
+
+QT_FORWARD_DECLARE_CLASS(QUrl)
+QT_FORWARD_DECLARE_CLASS(QPixmap)
+
+QTNFC_BEGIN_NAMESPACE
+class QNearFieldTarget;
+class QNdefMessage;
+QTNFC_END_NAMESPACE
+
+QTNFC_USE_NAMESPACE
+
+class AnnotatedUrl : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit AnnotatedUrl(QObject *parent = 0);
+ ~AnnotatedUrl();
+
+signals:
+ void annotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap);
+
+public slots:
+ void handleMessage(const QNdefMessage &message, QNearFieldTarget *target);
+};
+
+#endif // ANNOTATEDURL_H
diff --git a/examples/annotatedurl/annotatedurl.pro b/examples/annotatedurl/annotatedurl.pro
new file mode 100644
index 00000000..c9a22afa
--- /dev/null
+++ b/examples/annotatedurl/annotatedurl.pro
@@ -0,0 +1,18 @@
+QT += nfc widgets
+
+CONFIG += strict_flags
+
+INCLUDEPATH += $$PWD/../../src/connectivity/nfc
+DEPENDPATH += $$PWD/../../src/connectivity/nfc
+
+TARGET = annotatedurl
+
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ annotatedurl.cpp
+
+HEADERS += mainwindow.h \
+ annotatedurl.h
+
+FORMS += mainwindow.ui
+
diff --git a/examples/annotatedurl/main.cpp b/examples/annotatedurl/main.cpp
new file mode 100644
index 00000000..55dc6571
--- /dev/null
+++ b/examples/annotatedurl/main.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "annotatedurl.h"
+#include "mainwindow.h"
+
+#include <qnearfieldmanager.h>
+#include <qndefnfctextrecord.h>
+#include <qndefnfcurirecord.h>
+
+#include <QtCore/QLocale>
+
+#include <QApplication>
+
+
+int main(int argc, char *argv[])
+{
+ //QLocale::setDefault(QLocale(QLocale::Japanese));
+
+ QApplication a(argc, argv);
+ MainWindow mainWindow;
+
+ QNearFieldManager manager;
+ AnnotatedUrl annotatedUrl;
+
+ QNdefFilter filter;
+ filter.setOrderMatch(false);
+ filter.appendRecord<QNdefNfcTextRecord>(1, UINT_MAX);
+ filter.appendRecord<QNdefNfcUriRecord>();
+ manager.registerNdefMessageHandler(filter, &annotatedUrl,
+ SLOT(handleMessage(QNdefMessage,QNearFieldTarget*)));
+
+ QObject::connect(&annotatedUrl, SIGNAL(annotatedUrl(QUrl,QString,QPixmap)),
+ &mainWindow, SLOT(displayAnnotatedUrl(QUrl,QString,QPixmap)));
+
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_6) || defined(Q_WS_MEEGO)
+ mainWindow.showFullScreen();
+#else
+ mainWindow.show();
+#endif
+
+ return a.exec();
+}
diff --git a/examples/annotatedurl/mainwindow.cpp b/examples/annotatedurl/mainwindow.cpp
new file mode 100644
index 00000000..6cd4f00a
--- /dev/null
+++ b/examples/annotatedurl/mainwindow.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QtCore/QUrl>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QDesktopServices>
+
+MainWindow::MainWindow(QWidget *parent)
+: QMainWindow(parent), ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::displayAnnotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap)
+{
+ ui->m_help->setHidden(true);
+
+ ui->m_url->setText(url.toString());
+ ui->m_title->setText(title);
+ ui->m_image->setPixmap(pixmap);
+}
+
+void MainWindow::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (ui->centralWidget->rect().contains(event->pos()))
+ QDesktopServices::openUrl(QUrl(ui->m_url->text()));
+}
diff --git a/examples/annotatedurl/mainwindow.h b/examples/annotatedurl/mainwindow.h
new file mode 100644
index 00000000..d612c13a
--- /dev/null
+++ b/examples/annotatedurl/mainwindow.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNfc module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_FORWARD_DECLARE_CLASS(QUrl)
+
+namespace Ui {
+ class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void displayAnnotatedUrl(const QUrl &url, const QString &title, const QPixmap &pixmap);
+
+protected:
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ Ui::MainWindow *ui;
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/annotatedurl/mainwindow.ui b/examples/annotatedurl/mainwindow.ui
new file mode 100644
index 00000000..26e3b302
--- /dev/null
+++ b/examples/annotatedurl/mainwindow.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>590</width>
+ <height>420</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QGridLayout" name="gridLayout" rowstretch="1,0,1" columnstretch="0,0,0">
+ <item row="0" column="1" colspan="2">
+ <widget class="QLabel" name="m_title">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" rowspan="3">
+ <widget class="QLabel" name="m_image">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="m_help">
+ <property name="text">
+ <string>Touch a tag</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="2">
+ <widget class="QLabel" name="m_url">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>