1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qbluetoothtransferrequest.h"
41#include "qbluetoothaddress.h"
42#include "qbluetoothtransferrequest_p.h"
43
44
45QT_BEGIN_NAMESPACE
46
47/*!
48 \class QBluetoothTransferRequest
49 \inmodule QtBluetooth
50 \brief The QBluetoothTransferRequest class stores information about a
51 data transfer request.
52
53 \since 5.2
54
55 QBluetoothTransferRequest is part of the Bluetooth Transfer API and is the class holding the
56 information necessary to initiate a transfer over Bluetooth.
57
58 \sa QBluetoothTransferReply, QBluetoothTransferManager
59*/
60
61/*!
62 \enum QBluetoothTransferRequest::Attribute
63
64 Attribute codes for QBluetoothTransferRequest and QBluetoothTransferReply.
65
66 \value DescriptionAttribute A textual description of the object being transferred.
67 May be displayed in the UI of the remote device.
68 \value TimeAttribute Time attribute of the object being transferred.
69 \value TypeAttribute MIME type of the object being transferred.
70 \value LengthAttribute Length in bytes of the object being transferred.
71 \value NameAttribute Name of the object being transferred. May be displayed in the UI of
72 the remote device.
73*/
74
75/*!
76 Constructs a new Bluetooth transfer request to the device with \a address.
77*/
78QBluetoothTransferRequest::QBluetoothTransferRequest(const QBluetoothAddress &address)
79:d_ptr(new QBluetoothTransferRequestPrivate)
80{
81 Q_D(QBluetoothTransferRequest);
82
83 d->m_address = address;
84}
85
86/*!
87 Constructs a new Bluetooth transfer request that is a copy of \a other.
88*/
89QBluetoothTransferRequest::QBluetoothTransferRequest(const QBluetoothTransferRequest &other)
90:d_ptr(new QBluetoothTransferRequestPrivate)
91{
92 *this = other;
93}
94
95/*!
96 Destorys the Bluetooth transfer request.
97*/
98QBluetoothTransferRequest::~QBluetoothTransferRequest()
99{
100 delete d_ptr;
101}
102
103/*!
104 Returns the attribute associated with \a code. If the attribute has not been set, it
105 returns \a defaultValue.
106
107 \sa setAttribute(), QBluetoothTransferRequest::Attribute
108*/
109QVariant QBluetoothTransferRequest::attribute(Attribute code, const QVariant &defaultValue) const
110{
111 Q_D(const QBluetoothTransferRequest);
112
113 if (d->m_parameters.contains(akey: (int)code)) {
114 return d->m_parameters.value(akey: (int)code);
115 } else {
116 return defaultValue;
117 }
118}
119
120/*!
121 Sets the attribute associated with \a code to \a value. If the attribute is
122 already set, the previous value is discarded. If \a value is an invalid QVariant, the attribute
123 is unset.
124
125 \sa attribute(), QBluetoothTransferRequest::Attribute
126*/
127void QBluetoothTransferRequest::setAttribute(Attribute code, const QVariant &value)
128{
129 Q_D(QBluetoothTransferRequest);
130
131 d->m_parameters.insert(akey: (int)code, avalue: value);
132}
133
134/*!
135 Returns the address associated with the Bluetooth transfer request.
136*/
137QBluetoothAddress QBluetoothTransferRequest::address() const
138{
139 Q_D(const QBluetoothTransferRequest);
140
141 return d->m_address;
142}
143
144
145/*!
146 Returns true if this object is not the same as \a other.
147
148 \sa operator==()
149*/
150bool QBluetoothTransferRequest::operator!=(const QBluetoothTransferRequest &other) const
151{
152 return !(*this == other);
153}
154
155/*!
156 Creates a copy of \a other.
157*/
158QBluetoothTransferRequest &QBluetoothTransferRequest::operator=(const QBluetoothTransferRequest &other)
159{
160 Q_D(QBluetoothTransferRequest);
161
162 d->m_address = other.d_func()->m_address;
163 d->m_parameters = other.d_func()->m_parameters;
164
165 return *this;
166}
167
168/*!
169 Returns true if this object is the same as \a other.
170*/
171bool QBluetoothTransferRequest::operator==(const QBluetoothTransferRequest &other) const
172{
173 Q_D(const QBluetoothTransferRequest);
174 if (d->m_address == other.d_func()->m_address && d->m_parameters == other.d_func()->m_parameters) {
175 return true;
176 }
177 return false;
178}
179
180QBluetoothTransferRequestPrivate::QBluetoothTransferRequestPrivate()
181{
182}
183
184QT_END_NAMESPACE
185

source code of qtconnectivity/src/bluetooth/qbluetoothtransferrequest.cpp