1 | // Copyright (C) 2016 - 2012 Research In Motion |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QNDEFNFCSMARTPOSTERRECORD_H |
5 | #define QNDEFNFCSMARTPOSTERRECORD_H |
6 | |
7 | #include <QtCore/QList> |
8 | #include <QtCore/QString> |
9 | #include <QtNfc/qtnfcglobal.h> |
10 | #include <QtNfc/QNdefRecord> |
11 | #include <QtNfc/qndefnfctextrecord.h> |
12 | #include <QtNfc/qndefnfcurirecord.h> |
13 | |
14 | QT_FORWARD_DECLARE_CLASS(QUrl) |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class QNdefNfcSmartPosterRecordPrivate; |
19 | |
20 | #define Q_DECLARE_ISRECORDTYPE_FOR_MIME_NDEF_RECORD(className) \ |
21 | QT_BEGIN_NAMESPACE \ |
22 | template<> inline bool QNdefRecord::isRecordType<className>() const\ |
23 | { \ |
24 | return (typeNameFormat() == QNdefRecord::Mime); \ |
25 | } \ |
26 | QT_END_NAMESPACE |
27 | |
28 | #define Q_DECLARE_MIME_NDEF_RECORD(className, initialPayload) \ |
29 | className() : QNdefRecord(QNdefRecord::Mime, "") { setPayload(initialPayload); } \ |
30 | className(const QNdefRecord &other) : QNdefRecord(other, QNdefRecord::Mime) { } |
31 | |
32 | class Q_NFC_EXPORT QNdefNfcIconRecord : public QNdefRecord |
33 | { |
34 | public: |
35 | Q_DECLARE_MIME_NDEF_RECORD(QNdefNfcIconRecord, QByteArray(0, char(0))) |
36 | |
37 | void setData(const QByteArray &data); |
38 | QByteArray data() const; |
39 | }; |
40 | |
41 | class Q_NFC_EXPORT QNdefNfcSmartPosterRecord : public QNdefRecord |
42 | { |
43 | public: |
44 | enum Action { |
45 | UnspecifiedAction = -1, |
46 | DoAction = 0, |
47 | SaveAction = 1, |
48 | EditAction = 2 |
49 | }; |
50 | |
51 | QNdefNfcSmartPosterRecord(); |
52 | QNdefNfcSmartPosterRecord(const QNdefRecord &other); |
53 | QNdefNfcSmartPosterRecord(const QNdefNfcSmartPosterRecord &other); |
54 | QNdefNfcSmartPosterRecord &operator=(const QNdefNfcSmartPosterRecord &other); |
55 | ~QNdefNfcSmartPosterRecord(); |
56 | |
57 | void setPayload(const QByteArray &payload); |
58 | |
59 | bool hasTitle(const QString &locale = QString()) const; |
60 | bool hasAction() const; |
61 | bool hasIcon(const QByteArray &mimetype = QByteArray()) const; |
62 | bool hasSize() const; |
63 | bool hasTypeInfo() const; |
64 | |
65 | qsizetype titleCount() const; |
66 | QNdefNfcTextRecord titleRecord(qsizetype index) const; |
67 | QString title(const QString &locale = QString()) const; |
68 | QList<QNdefNfcTextRecord> titleRecords() const; |
69 | |
70 | bool addTitle(const QNdefNfcTextRecord &text); |
71 | bool addTitle(const QString &text, const QString &locale, QNdefNfcTextRecord::Encoding encoding); |
72 | bool removeTitle(const QNdefNfcTextRecord &text); |
73 | bool removeTitle(const QString &locale); |
74 | void setTitles(const QList<QNdefNfcTextRecord> &titles); |
75 | |
76 | QUrl uri() const; |
77 | QNdefNfcUriRecord uriRecord() const; |
78 | void setUri(const QNdefNfcUriRecord &url); |
79 | void setUri(const QUrl &url); |
80 | |
81 | Action action() const; |
82 | void setAction(Action act); |
83 | |
84 | qsizetype iconCount() const; |
85 | QNdefNfcIconRecord iconRecord(qsizetype index) const; |
86 | QByteArray icon(const QByteArray& mimetype = QByteArray()) const; |
87 | |
88 | QList<QNdefNfcIconRecord> iconRecords() const; |
89 | |
90 | void addIcon(const QNdefNfcIconRecord &icon); |
91 | void addIcon(const QByteArray &type, const QByteArray &data); |
92 | bool removeIcon(const QNdefNfcIconRecord &icon); |
93 | bool removeIcon(const QByteArray &type); |
94 | void setIcons(const QList<QNdefNfcIconRecord> &icons); |
95 | |
96 | quint32 size() const; |
97 | void setSize(quint32 size); |
98 | |
99 | QString typeInfo() const; |
100 | void setTypeInfo(const QString &type); |
101 | |
102 | private: |
103 | QSharedDataPointer<QNdefNfcSmartPosterRecordPrivate> d; |
104 | |
105 | void cleanup(); |
106 | void convertToPayload(); |
107 | |
108 | bool addTitleInternal(const QNdefNfcTextRecord &text); |
109 | void addIconInternal(const QNdefNfcIconRecord &icon); |
110 | }; |
111 | |
112 | QT_END_NAMESPACE |
113 | |
114 | Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD(QNdefNfcSmartPosterRecord, QNdefRecord::NfcRtd, "Sp" ) |
115 | Q_DECLARE_ISRECORDTYPE_FOR_MIME_NDEF_RECORD(QNdefNfcIconRecord) |
116 | |
117 | #endif // QNDEFNFCSMARTPOSTERRECORD_H |
118 | |