forked from andijakl/nfcinteractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnfcndefparser.h
129 lines (106 loc) · 4.23 KB
/
nfcndefparser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Andreas Jakl ([email protected])
**
** Released under Nokia Example Code License.
** See license.txt in the main project folder.
**
****************************************************************************/
#ifndef NFCNDEFPARSER_H
#define NFCNDEFPARSER_H
#include <QObject>
#include <QDebug>
#include "nfcrecordmodel.h"
// Clipboard
#include <QApplication>
#include <QClipboard>
// NDEF
#include <QNdefMessage>
#include <QNdefRecord>
#include <QNdefNfcUriRecord>
#include <QNdefNfcTextRecord>
#include "ndefnfcrecords/ndefnfcmimeimagerecord.h"
#include "ndefnfcrecords/ndefnfcsprecord.h"
#include "ndefnfcrecords/ndefnfcmimevcardrecord.h"
#include "ndefnfcrecords/ndefnfcandroidapprecord.h"
// Image handling
#include <QImage>
#include "tagimagecache.h"
// VCard reading
#include <QContact>
#include <QContactDetail>
#include <QVariantMap>
#include <QContactThumbnail>
// Logging tags/images to files
#include <QDir>
#include <QFile>
#include <QDateTime>
QTM_USE_NAMESPACE
/*!
\brief Parse the contents of an NDEF message and return the contents
of known records in human-readable textual form.
The output contains information about all the records contained
in the message. More details are reported for records of type:
Uri, Text, Smart Poster, Image and Mime/vCard.
The NfcTargetAnalyzer has a similar task, but returns the general
tag information in textual form.
*/
class NfcNdefParser : public QObject
{
Q_OBJECT
public:
explicit NfcNdefParser(NfcRecordModel *nfcRecordModel, QObject *parent = 0);
void setImageCache(TagImageCache* tagImageCache);
void setAppSettings(AppSettings* appSettings);
signals:
/*! \brief The tag contained an image.
The parameter contains the image id that can be used
to fetch it from the tag image cache class. */
void nfcTagImage(const int nfcImgId);
public:
/*! \brief Parse the NDEF message and return its contents
as human-readable text. */
QString parseNdefMessage(const QNdefMessage &message);
void setParseToModel(bool parseToModel);
private:
QString parseUriRecord(const QNdefNfcUriRecord &record);
QString parseTextRecord(const QNdefNfcTextRecord &record);
QString textRecordToString(const QNdefNfcTextRecord &textRecord);
QString parseSpRecord(const NdefNfcSpRecord &record);
QString parseImageRecord(const NdefNfcMimeImageRecord &record);
QString parseVcardRecord(NdefNfcMimeVcardRecord &record);
QString parseLaunchAppRecord(const NdefNfcLaunchAppRecord &record);
QString parseAndroidAppRecord(const NdefNfcAndroidAppRecord &record);
bool addContactDetailToModel(const QString &detailName, const QString &detailValue);
QString parseCustomRecord(const QNdefRecord &record);
QString convertRecordTypeNameToString(const QNdefRecord::TypeNameFormat typeName);
private:
void storeImageToFileForModel(const NdefNfcMimeImageRecord &imgRecord, const bool removeVisible);
void storeClipboard(const QString &text, const QString &locale);
void storeClipboard(const QUrl &uri);
void setStoredClipboard();
private:
/*! Used for storing images found on the tags. */
TagImageCache* m_imgCache; // Not owned by this class
bool m_parseToModel;
/*! Stores the editable records of the compose tag view.
Not owned by this class.*/
NfcRecordModel* m_nfcRecordModel;
/*! Content that's currently stored in m_clipboardText.
Used to prioritize what's going to be written to the clipboard,
in the following priority order:
Uri > Text (English) > Text (any other language). */
enum ClipboardContents {
ClipboardEmpty,
ClipboardUri,
ClipboardText,
ClipboardTextEn // Give preference to English text for storing on the clipboard
};
ClipboardContents m_clipboardContents;
QString m_clipboardText;
/*! Persistent storageof application settings. Not owned by this class. */
AppSettings* m_appSettings;
};
#endif // NFCNDEFPARSER_H