| 1 | /*************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 BlackBerry Limited. All rights reserved. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtNfc 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 "qnearfieldsharemanager.h" |
| 41 | #include "qnearfieldsharemanager_p.h" |
| 42 | |
| 43 | #include "qnearfieldsharemanagerimpl_p.h" |
| 44 | |
| 45 | #include "qnearfieldsharetarget.h" |
| 46 | |
| 47 | QT_BEGIN_NAMESPACE |
| 48 | |
| 49 | /*! |
| 50 | \class QNearFieldShareManager |
| 51 | \brief The QNearFieldShareManager class manages all interactions related to sharing files and data over NFC. |
| 52 | |
| 53 | \ingroup connectivity-nfc |
| 54 | \inmodule QtNfc |
| 55 | \since 5.3 |
| 56 | |
| 57 | Applications can share NDEF data or file content using NFC technology by tapping two NFC-enabled devices |
| 58 | together. The QNearFieldShareManager provides a high level entry point to access this functionality. |
| 59 | |
| 60 | The class allows both NDEF data and/or files to be shared between two devices by calling the setShareModes() |
| 61 | method. This method specifies either an NDEF Data and/or a File transfer. The targetDetected() signal is emitted |
| 62 | each time a share target is detected. A QNearFieldShareTarget pointer is passed with the signal, which can |
| 63 | be used to share either an NDEF message or one or more files. |
| 64 | |
| 65 | The process of sharing files via NFC involves other underlying communication transports such as Bluetooth or Wi-Fi Direct. |
| 66 | It is implementation specific how and what type of transports are used to perform file transfer. The overall time taken to |
| 67 | transfer content depends on the maximum speed of the transport used. Note that the process of sharing NDEF message/data |
| 68 | does not require the use of other transports outside NFC. |
| 69 | |
| 70 | If an error occurs, shareError() returns the error type. |
| 71 | |
| 72 | Platforms that do not support both NDEF data and file content sharing modes can return the supported subset in the |
| 73 | supportedShareModes() method. Applications that call setShareModes() with an unsupported mode will receive an error |
| 74 | signal with a UnsupportedShareModeError. |
| 75 | |
| 76 | Since sharing data over NFC is effectively a data pipe between two processes (one on the sender and one of |
| 77 | the receiver), the application developer should only create a single instance of QNearFieldShareManager per |
| 78 | application. This avoids the possibility that different parts of the same application attempt to all consume |
| 79 | data transferred over NFC. |
| 80 | */ |
| 81 | |
| 82 | /*! |
| 83 | \enum QNearFieldShareManager::ShareError |
| 84 | |
| 85 | This enum specifies the share error type. |
| 86 | |
| 87 | \value NoError No error. |
| 88 | \value UnknownError Unknown or internal error occurred. |
| 89 | \value InvalidShareContentError Invalid content was provided for sharing. |
| 90 | \value ShareCanceledError Data or file sharing is canceled on the local or remote device. |
| 91 | \value ShareInterruptedError Data or file sharing is interrupted due to an I/O error. |
| 92 | \value ShareRejectedError Data or file sharing is rejected by the remote device. |
| 93 | \value UnsupportedShareModeError Data or file sharing is not supported by the share target. |
| 94 | \value ShareAlreadyInProgressError Data or file sharing is already in progress. |
| 95 | \value SharePermissionDeniedError File sharing is denied due to insufficient permission. |
| 96 | */ |
| 97 | |
| 98 | /*! |
| 99 | \enum QNearFieldShareManager::ShareMode |
| 100 | |
| 101 | This enum specifies the content type to be shared. |
| 102 | |
| 103 | \value NoShare No content is currently set to be shared. |
| 104 | \value NdefShare Share NDEF message with target. |
| 105 | \value FileShare Share file with target. |
| 106 | */ |
| 107 | |
| 108 | /*! |
| 109 | \fn void QNearFieldShareManager::targetDetected(QNearFieldShareTarget* shareTarget) |
| 110 | |
| 111 | This signal is emitted whenever a \a shareTarget is detected. The \a shareTarget |
| 112 | instance is owned by QNearFieldShareManager and must not be deleted by the application. |
| 113 | */ |
| 114 | |
| 115 | /*! |
| 116 | \fn void QNearFieldShareManager::shareModesChanged(ShareModes modes) |
| 117 | |
| 118 | This signal is emitted whenever the share \a modes are changed. |
| 119 | */ |
| 120 | |
| 121 | /*! |
| 122 | \fn void QNearFieldShareManager::error(ShareError error) |
| 123 | |
| 124 | This signal is emitted whenever an \a error occurs related to a share request. |
| 125 | */ |
| 126 | |
| 127 | /*! |
| 128 | Constructs a new near field share manager with \a parent. |
| 129 | */ |
| 130 | QNearFieldShareManager::QNearFieldShareManager(QObject *parent) |
| 131 | : QObject(parent), d_ptr(new QNearFieldShareManagerPrivateImpl(this)) |
| 132 | { |
| 133 | } |
| 134 | |
| 135 | /*! |
| 136 | Destroys the near field share manager. |
| 137 | */ |
| 138 | QNearFieldShareManager::~QNearFieldShareManager() |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | /*! |
| 143 | Initializes the NFC share \a mode to detect a QNearFieldShareTarget for data and/or file sharing. |
| 144 | Calls to this method will overwrite previous share modes. |
| 145 | |
| 146 | A shareModesChanged() signal will be emitted when share modes are different from previous modes. |
| 147 | A targetDetected() signal will be emitted if a share target is detected. |
| 148 | */ |
| 149 | void QNearFieldShareManager::setShareModes(ShareModes mode) |
| 150 | { |
| 151 | Q_D(QNearFieldShareManager); |
| 152 | d->setShareModes(mode); |
| 153 | } |
| 154 | |
| 155 | /*! |
| 156 | Returns the shared modes supported by NFC. |
| 157 | */ |
| 158 | QNearFieldShareManager::ShareModes QNearFieldShareManager::supportedShareModes() |
| 159 | { |
| 160 | return QNearFieldShareManagerPrivateImpl::supportedShareModes(); |
| 161 | } |
| 162 | |
| 163 | /*! |
| 164 | Returns which shared modes are set. |
| 165 | */ |
| 166 | QNearFieldShareManager::ShareModes QNearFieldShareManager::shareModes() const |
| 167 | { |
| 168 | Q_D(const QNearFieldShareManager); |
| 169 | return d->shareModes(); |
| 170 | } |
| 171 | |
| 172 | /*! |
| 173 | Returns the error code of the error that occurred. |
| 174 | */ |
| 175 | QNearFieldShareManager::ShareError QNearFieldShareManager::shareError() const |
| 176 | { |
| 177 | Q_D(const QNearFieldShareManager); |
| 178 | return d->shareError(); |
| 179 | } |
| 180 | |
| 181 | QT_END_NAMESPACE |
| 182 | |