Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qndefnfcsmartposterrecord.cpp
Go to the documentation of this file.
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
6#include <qndefmessage.h>
7
8#include <QtCore/QString>
9#include <QtCore/QStringList>
10#include <QtCore/QUrl>
11
13
70
75 : QNdefRecord(other, QNdefRecord::NfcRtd, "Sp"),
77{
78 // Need to set payload again to create internal structure
79 setPayload(other.payload());
80}
81
89
95{
96 if (this != &other)
97 d = other.d;
98
99 return *this;
100}
101
108
109void QNdefNfcSmartPosterRecord::cleanup()
110{
111 if (d) {
112 // Clean-up existing internal structure
113 d->m_titleList.clear();
114 if (d->m_uri) delete d->m_uri;
115 if (d->m_action) delete d->m_action;
116 d->m_iconList.clear();
117 if (d->m_size) delete d->m_size;
118 if (d->m_type) delete d->m_type;
119 }
120}
121
127{
129
130 cleanup();
131
132 if (!payload.isEmpty()) {
133 // Create new structure
135
136 // Iterate through all the records contained in the payload's message.
137 for (const QNdefRecord& record : message) {
138 // Title
139 if (record.isRecordType<QNdefNfcTextRecord>()) {
140 addTitleInternal(record);
141 }
142
143 // URI
144 else if (record.isRecordType<QNdefNfcUriRecord>()) {
146 }
147
148 // Action
149 else if (record.isRecordType<QNdefNfcActRecord>()) {
151 }
152
153 // Icon
154 else if (record.isRecordType<QNdefNfcIconRecord>()) {
155 addIconInternal(record);
156 }
157
158 // Size
159 else if (record.isRecordType<QNdefNfcSizeRecord>()) {
161 }
162
163 // Type
164 else if (record.isRecordType<QNdefNfcTypeRecord>()) {
166 }
167 }
168 }
169}
170
171void QNdefNfcSmartPosterRecord::convertToPayload()
172{
174
175 // Title
176 for (qsizetype t = 0; t < titleCount(); t++)
177 message.append(titleRecord(t));
178
179 // URI
180 if (d->m_uri)
181 message.append(*(d->m_uri));
182
183 // Action
184 if (d->m_action)
185 message.append(*(d->m_action));
186
187 // Icon
188 for (qsizetype i = 0; i < iconCount(); i++)
189 message.append(iconRecord(i));
190
191 // Size
192 if (d->m_size)
193 message.append(*(d->m_size));
194
195 // Type
196 if (d->m_type)
197 message.append(*(d->m_type));
198
199 QNdefRecord::setPayload(message.toByteArray());
200}
201
209{
210 for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
212
213 if (locale.isEmpty() || text.locale() == locale)
214 return true;
215 }
216
217 return false;
218}
219
225{
226 return d->m_action != nullptr;
227}
228
236{
237 for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
238 const QNdefNfcIconRecord &icon = d->m_iconList[i];
239
240 if (mimetype.isEmpty() || icon.type() == mimetype)
241 return true;
242 }
243
244 return false;
245}
246
252{
253 return d->m_size != nullptr;
254}
255
261{
262 return d->m_type != nullptr;
263}
264
272
279{
280 if (index >= 0 && index < d->m_titleList.size())
281 return d->m_titleList[index];
282
283 return QNdefNfcTextRecord();
284}
285
292{
293 for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
295
296 if (locale.isEmpty() || text.locale() == locale)
297 return text.text();
298 }
299
300 return QString();
301}
302
306QList<QNdefNfcTextRecord> QNdefNfcSmartPosterRecord::titleRecords() const
307{
308 return d->m_titleList;
309}
310
317{
318 const bool status = addTitleInternal(text);
319
320 // Convert to payload if the title is added
321 if (status)
322 convertToPayload();
323
324 return status;
325}
326
327bool QNdefNfcSmartPosterRecord::addTitleInternal(const QNdefNfcTextRecord &text)
328{
329 for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
330 const QNdefNfcTextRecord &rec = d->m_titleList[i];
331
332 if (rec.locale() == text.locale())
333 return false;
334 }
335
337 return true;
338}
339
346{
348 rec.setText(text);
349 rec.setLocale(locale);
350 rec.setEncoding(encoding);
351
352 return addTitle(rec);
353}
354
361{
362 bool status = false;
363
364 for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
365 const QNdefNfcTextRecord &rec = d->m_titleList[i];
366
367 if (rec.text() == text.text() && rec.locale() == text.locale() && rec.encoding() == text.encoding()) {
369 status = true;
370 break;
371 }
372 }
373
374 // Convert to payload if the title list has changed
375 if (status)
376 convertToPayload();
377
378 return status;
379}
380
387{
388 bool status = false;
389
390 for (qsizetype i = 0; i < d->m_titleList.size(); ++i) {
391 const QNdefNfcTextRecord &rec = d->m_titleList[i];
392
393 if (rec.locale() == locale) {
395 status = true;
396 break;
397 }
398 }
399
400 // Convert to payload if the title list has changed
401 if (status)
402 convertToPayload();
403
404 return status;
405}
406
410void QNdefNfcSmartPosterRecord::setTitles(const QList<QNdefNfcTextRecord> &titles)
411{
412 d->m_titleList.clear();
413
414 for (qsizetype i = 0; i < titles.size(); ++i) {
415 d->m_titleList.append(titles[i]);
416 }
417
418 // Convert to payload
419 convertToPayload();
420}
421
426{
427 if (d->m_uri)
428 return d->m_uri->uri();
429
430 return QUrl();
431}
432
437{
438 if (d->m_uri)
439 return *(d->m_uri);
440
441 return QNdefNfcUriRecord();
442}
443
448{
449 if (d->m_uri)
450 delete d->m_uri;
451
452 d->m_uri = new QNdefNfcUriRecord(url);
453
454 // Convert to payload
455 convertToPayload();
456}
457
462{
464 rec.setUri(url);
465
466 setUri(rec);
467}
468
479
484{
485 if (!d->m_action)
486 d->m_action = new QNdefNfcActRecord();
487
488 d->m_action->setAction(act);
489
490 // Convert to payload
491 convertToPayload();
492}
493
501
508{
509 if (index >= 0 && index < d->m_iconList.size())
510 return d->m_iconList[index];
511
512 return QNdefNfcIconRecord();
513}
514
520{
521 for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
522 const QNdefNfcIconRecord &icon = d->m_iconList[i];
523
524 if (mimetype.isEmpty() || icon.type() == mimetype)
525 return icon.data();
526 }
527
528 return QByteArray();
529}
530
534QList<QNdefNfcIconRecord> QNdefNfcSmartPosterRecord::iconRecords() const
535{
536 return d->m_iconList;
537}
538
544{
545 addIconInternal(icon);
546
547 // Convert to payload
548 convertToPayload();
549}
550
551void QNdefNfcSmartPosterRecord::addIconInternal(const QNdefNfcIconRecord &icon)
552{
553 for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
554 const QNdefNfcIconRecord &rec = d->m_iconList[i];
555
556 if (rec.type() == icon.type())
558 }
559
561}
562
568{
570 rec.setType(type);
571 rec.setData(data);
572
573 addIcon(rec);
574}
575
582{
583 bool status = false;
584
585 for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
586 const QNdefNfcIconRecord &rec = d->m_iconList[i];
587
588 if (rec.type() == icon.type() && rec.data() == icon.data()) {
590 status = true;
591 break;
592 }
593 }
594
595 // Convert to payload if the icon list has changed
596 if (status)
597 convertToPayload();
598
599 return status;
600}
601
608{
609 bool status = false;
610
611 for (qsizetype i = 0; i < d->m_iconList.size(); ++i) {
612 const QNdefNfcIconRecord &rec = d->m_iconList[i];
613
614 if (rec.type() == type) {
616 status = true;
617 break;
618 }
619 }
620
621 // Convert to payload if the icon list has changed
622 if (status)
623 convertToPayload();
624
625 return status;
626}
627
634void QNdefNfcSmartPosterRecord::setIcons(const QList<QNdefNfcIconRecord> &icons)
635{
636 d->m_iconList.clear();
637
638 for (qsizetype i = 0; i < icons.size(); ++i) {
639 d->m_iconList.append(icons[i]);
640 }
641
642 // Convert to payload
643 convertToPayload();
644}
645
656{
657 if (d->m_size)
658 return d->m_size->size();
659
660 return 0;
661}
662
670{
671 if (!d->m_size)
672 d->m_size = new QNdefNfcSizeRecord();
673
674 d->m_size->setSize(size);
675
676 // Convert to payload
677 convertToPayload();
678}
679
689{
690 if (d->m_type)
691 return d->m_type->typeInfo();
692
693 return QString();
694}
695
703{
704 if (d->m_type)
705 delete d->m_type;
706
707 d->m_type = new QNdefNfcTypeRecord();
708 d->m_type->setTypeInfo(type);
709
710 // Convert to payload
711 convertToPayload();
712}
713
714void QNdefNfcActRecord::setAction(QNdefNfcSmartPosterRecord::Action action)
715{
717
719}
720
732
736void QNdefNfcIconRecord::setData(const QByteArray &data)
737{
739}
740
745{
746 return payload();
747}
748
749void QNdefNfcSizeRecord::setSize(quint32 size)
750{
751 QByteArray data(4, 0);
752
753 data[0] = (int) ((size & 0xFF000000) >> 24);
754 data[1] = (int) ((size & 0x00FF0000) >> 16);
755 data[2] = (int) ((size & 0x0000FF00) >> 8);
756 data[3] = (int) ((size & 0x000000FF));
757
759}
760
762{
763 const QByteArray p = payload();
764
765 if (p.isEmpty())
766 return 0;
767
768 return ((p[0] << 24) & 0xFF000000) + ((p[1] << 16) & 0x00FF0000)
769 + ((p[2] << 8) & 0x0000FF00) + (p[3] & 0x000000FF);
770}
771
772void QNdefNfcTypeRecord::setTypeInfo(const QString &type)
773{
774 setPayload(type.toUtf8());
775}
776
781
\inmodule QtCore
Definition qbytearray.h:57
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:107
qsizetype size() const noexcept
Definition qlist.h:397
void removeAt(qsizetype i)
Definition qlist.h:590
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
The QNdefMessage class provides an NFC NDEF message.
static Q_NFC_EXPORT QNdefMessage fromByteArray(const QByteArray &message)
Returns an NDEF message parsed from the contents of message.
Q_DECLARE_NDEF_RECORD(QNdefNfcActRecord, QNdefRecord::NfcRtd, "act", QByteArray(0, char(0))) void setAction(QNdefNfcSmartPosterRecord QNdefNfcSmartPosterRecord::Action action() const
The QNdefNfcIconRecord class provides an NFC MIME record to hold an icon.
QByteArray data() const
Returns the icon data as \l QByteArray.
The QNdefNfcSmartPosterRecord class provides an NFC RTD-SmartPoster.
QNdefNfcTextRecord titleRecord(qsizetype index) const
Returns the title record corresponding to the index index inside the smart poster,...
~QNdefNfcSmartPosterRecord()
Destroys the smart poster.
bool hasTitle(const QString &locale=QString()) const
Returns true if the smart poster contains a title record using the locale locale.
QUrl uri() const
Returns the URI from the smart poster's URI record if set.
Action action() const
Returns the action from the action record if available.
void setUri(const QNdefNfcUriRecord &url)
Sets the URI record to url.
QByteArray icon(const QByteArray &mimetype=QByteArray()) const
Returns the associated icon record data if the smart poster contains an icon record with MIME type mi...
QNdefNfcSmartPosterRecord & operator=(const QNdefNfcSmartPosterRecord &other)
Assigns the other smart poster record to this record and returns a reference to this record.
bool hasIcon(const QByteArray &mimetype=QByteArray()) const
Returns true if the smart poster contains an icon record using the type mimetype.
void setSize(quint32 size)
Sets the record size.
bool removeIcon(const QNdefNfcIconRecord &icon)
Attempts to remove the icon record icon from the smart poster.
void setAction(Action act)
Sets the action record to act.
void setTitles(const QList< QNdefNfcTextRecord > &titles)
Adds the title record list titles to the smart poster.
QString typeInfo() const
Returns the MIME type that describes the type of the objects that can be reached via uri().
bool hasTypeInfo() const
Returns true if the smart poster contains a type record, otherwise returns false.
void setTypeInfo(const QString &type)
Sets the type record to type.
QList< QNdefNfcTextRecord > titleRecords() const
Returns a copy of all title records inside the smart poster.
bool removeTitle(const QNdefNfcTextRecord &text)
Attempts to remove the title record text from the smart poster.
void setPayload(const QByteArray &payload)
qsizetype titleCount() const
Returns the number of title records contained inside the smart poster.
bool addTitle(const QNdefNfcTextRecord &text)
Attempts to add a title record text to the smart poster.
bool hasAction() const
Returns true if the smart poster contains an action record, otherwise returns false.
QNdefNfcIconRecord iconRecord(qsizetype index) const
Returns the icon record corresponding to the index index inside the smart poster, where index is a va...
bool hasSize() const
Returns true if the smart poster contains a size record, otherwise returns false.
QNdefNfcSmartPosterRecord()
Constructs a new empty smart poster.
void setIcons(const QList< QNdefNfcIconRecord > &icons)
Adds the icon record list icons to the smart poster.
quint32 size() const
Returns the size from the size record if available; otherwise returns 0.
void addIcon(const QNdefNfcIconRecord &icon)
Adds an icon record icon to the smart poster.
qsizetype iconCount() const
Returns the number of icon records contained inside the smart poster.
Action
This enum describes the course of action that a device should take with the content.
QList< QNdefNfcIconRecord > iconRecords() const
Returns a copy of all icon records inside the smart poster.
QNdefNfcUriRecord uriRecord() const
Returns the smart poster's URI record if set.
QString title(const QString &locale=QString()) const
Returns the title record text associated with locale locale if available.
The QNdefNfcTextRecord class provides an NFC RTD-Text.
void setLocale(const QString &locale)
Sets the locale of the text record to locale.
QString text() const
Returns the contents of the text record as a string.
void setEncoding(Encoding encoding)
Sets the enconding of the contents to encoding.
Encoding
This enum describes the text encoding standard used.
Encoding encoding() const
Returns the encoding of the contents.
void setText(const QString text)
Sets the contents of the text record to text.
The QNdefNfcUriRecord class provides an NFC RTD-URI.
void setUri(const QUrl &uri)
Sets the URI of this URI record to uri.
The QNdefRecord class provides an NFC NDEF record.
Definition qndefrecord.h:16
void setPayload(const QByteArray &payload)
Sets the payload of the NDEF record to payload.
QByteArray type() const
Returns the type of the NDEF record.
QByteArray payload() const
Returns the payload of the NDEF record.
void setType(const QByteArray &type)
Sets the type of the NDEF record to type.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
\inmodule QtCore
Definition qurl.h:94
QString text
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLuint GLsizei const GLchar * message
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
unsigned int quint32
Definition qtypes.h:50
ptrdiff_t qsizetype
Definition qtypes.h:165
QUrl url("example.com")
[constructor-url-reference]
MyRecord record(int row) const
[0]
QSharedPointer< T > other(t)
[5]