Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qndefnfcurirecord.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qndefnfcurirecord.h"
5
6
#
include
<
QtCore
/
QString
>
7
#
include
<
QtCore
/
QUrl
>
8
9
#
include
<
QtCore
/
QDebug
>
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\class QNdefNfcUriRecord
15
\brief The QNdefNfcUriRecord class provides an NFC RTD-URI.
16
17
\ingroup connectivity-nfc
18
\inmodule QtNfc
19
\since 5.2
20
21
RTD-URI encapsulates a URI.
22
*/
23
24
/*!
25
\fn QNdefNfcUriRecord::QNdefNfcUriRecord()
26
27
Constructs an empty NFC uri record.
28
*/
29
30
/*!
31
\fn QNdefNfcUriRecord::QNdefNfcUriRecord(const QNdefRecord& other)
32
33
Constructs a new NFC uri record that is a copy of \a other.
34
*/
35
static
const
char
*
const
abbreviations[] = {
36
0,
37
"http://www."
,
38
"https://www."
,
39
"http://"
,
40
"https://"
,
41
"tel:"
,
42
"mailto:"
,
43
"ftp://anonymous:anonymous@"
,
44
"ftp://ftp."
,
45
"ftps://"
,
46
"sftp://"
,
47
"smb://"
,
48
"nfs://"
,
49
"ftp://"
,
50
"dav://"
,
51
"news:"
,
52
"telnet://"
,
53
"imap:"
,
54
"rtsp://"
,
55
"urn:"
,
56
"pop:"
,
57
"sip:"
,
58
"sips:"
,
59
"tftp:"
,
60
"btspp://"
,
61
"btl2cap://"
,
62
"btgoep://"
,
63
"tcpobex://"
,
64
"irdaobex://"
,
65
"file://"
,
66
"urn:epc:id:"
,
67
"urn:epc:tag:"
,
68
"urn:epc:pat:"
,
69
"urn:epc:raw:"
,
70
"urn:epc:"
,
71
"urn:nfc:"
,
72
};
73
74
/*!
75
Returns the URI of this URI record.
76
77
\warning Application developers are advised to validate the returned
78
URI before acting on it. See \l{Qt NFC Security Considerations} for guidance.
79
*/
80
QUrl QNdefNfcUriRecord::uri()
const
81
{
82
QByteArray p = payload();
83
84
if
(p.isEmpty())
85
return
QUrl();
86
87
quint8 code = p.at(0);
88
if
(code >=
sizeof
(abbreviations) /
sizeof
(*abbreviations))
89
code = 0;
90
p.remove(0, 1);
91
if
(
const
char
*abbreviation = abbreviations[code])
92
p.insert(0, abbreviation);
93
return
QUrl(QString::fromUtf8(p));
94
}
95
96
/*!
97
Sets the URI of this URI record to \a uri.
98
*/
99
void
QNdefNfcUriRecord::setUri(
const
QUrl &uri)
100
{
101
int
abbrevs =
sizeof
(abbreviations) /
sizeof
(*abbreviations);
102
103
for
(
int
i = 1; i < abbrevs; ++i) {
104
if
(uri.toString().startsWith(QLatin1String(abbreviations[i]))) {
105
QByteArray p(1, i);
106
107
p += uri.toString().mid(qstrlen(abbreviations[i])).toUtf8();
108
109
setPayload(p);
110
111
return
;
112
}
113
}
114
115
QByteArray p(1, 0);
116
p += uri.toString().toUtf8();
117
118
setPayload(p);
119
}
120
121
QT_END_NAMESPACE
qtconnectivity
src
nfc
qndefnfcurirecord.cpp
Generated on
for Qt by
1.18.0