| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Copyright (C) 2016 BlackBerry Limited. All rights reserved. | 
| 5 | ** Contact: https://www.qt.io/licensing/ | 
| 6 | ** | 
| 7 | ** This file is part of the QtBluetooth module of the Qt Toolkit. | 
| 8 | ** | 
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 10 | ** Commercial License Usage | 
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 12 | ** accordance with the commercial license agreement provided with the | 
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 17 | ** | 
| 18 | ** GNU Lesser General Public License Usage | 
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 20 | ** General Public License version 3 as published by the Free Software | 
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 22 | ** packaging of this file. Please review the following information to | 
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 25 | ** | 
| 26 | ** GNU General Public License Usage | 
| 27 | ** Alternatively, this file may be used under the terms of the GNU | 
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 29 | ** Public license version 3 or any later version approved by the KDE Free | 
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 32 | ** included in the packaging of this file. Please review the following | 
| 33 | ** information to ensure the GNU General Public License requirements will | 
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 36 | ** | 
| 37 | ** $QT_END_LICENSE$ | 
| 38 | ** | 
| 39 | ****************************************************************************/ | 
| 40 | #ifndef QDECLARATIVECONTACTMODEL_P_H | 
| 41 | #define QDECLARATIVECONTACTMODEL_P_H | 
| 42 |  | 
| 43 | // | 
| 44 | //  W A R N I N G | 
| 45 | //  ------------- | 
| 46 | // | 
| 47 | // This file is not part of the Qt API.  It exists purely as an | 
| 48 | // implementation detail.  This header file may change from version to | 
| 49 | // version without notice, or even be removed. | 
| 50 | // | 
| 51 | // We mean it. | 
| 52 | // | 
| 53 |  | 
| 54 | #include <QAbstractListModel> | 
| 55 | #include <QQmlParserStatus> | 
| 56 | #include <QQmlListProperty> | 
| 57 | #include <QQmlParserStatus> | 
| 58 |  | 
| 59 | #include <qbluetoothserviceinfo.h> | 
| 60 | #include <qbluetoothservicediscoveryagent.h> | 
| 61 | #include <qbluetoothdevicediscoveryagent.h> | 
| 62 |  | 
| 63 | #include <qtbluetoothglobal.h> | 
| 64 |  | 
| 65 | #include "qdeclarativebluetoothservice_p.h" | 
| 66 |  | 
| 67 | QT_USE_NAMESPACE | 
| 68 |  | 
| 69 | class QDeclarativeBluetoothDiscoveryModelPrivate; | 
| 70 | class QDeclarativeBluetoothDiscoveryModel : public QAbstractListModel, public QQmlParserStatus | 
| 71 | { | 
| 72 |     Q_OBJECT | 
| 73 |     Q_PROPERTY(Error error READ error NOTIFY errorChanged) | 
| 74 |     Q_PROPERTY(DiscoveryMode discoveryMode READ discoveryMode WRITE setDiscoveryMode NOTIFY discoveryModeChanged) | 
| 75 |     Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) | 
| 76 |     Q_PROPERTY(QString uuidFilter READ uuidFilter WRITE setUuidFilter NOTIFY uuidFilterChanged) | 
| 77 |     Q_PROPERTY(QString remoteAddress READ remoteAddress WRITE setRemoteAddress NOTIFY remoteAddressChanged) | 
| 78 |     Q_INTERFACES(QQmlParserStatus) | 
| 79 | public: | 
| 80 |     explicit QDeclarativeBluetoothDiscoveryModel(QObject *parent = 0); | 
| 81 |     virtual ~QDeclarativeBluetoothDiscoveryModel(); | 
| 82 |  | 
| 83 |     enum { | 
| 84 |         Name = Qt::UserRole + 1, | 
| 85 |         ServiceRole, | 
| 86 |         DeviceName, | 
| 87 |         RemoteAddress | 
| 88 |     }; | 
| 89 |  | 
| 90 |     enum DiscoveryMode { | 
| 91 |         MinimalServiceDiscovery, | 
| 92 |         FullServiceDiscovery, | 
| 93 |         DeviceDiscovery | 
| 94 |     }; | 
| 95 |     Q_ENUM(DiscoveryMode) | 
| 96 |  | 
| 97 |     enum Error | 
| 98 |     { | 
| 99 |         NoError, | 
| 100 |         InputOutputError, | 
| 101 |         PoweredOffError, | 
| 102 |         UnknownError, | 
| 103 |         InvalidBluetoothAdapterError | 
| 104 |     }; | 
| 105 |     Q_ENUM(Error) | 
| 106 |  | 
| 107 |     Error error() const; | 
| 108 |  | 
| 109 |     void componentComplete() override; | 
| 110 |  | 
| 111 |     void classBegin() override { } | 
| 112 |  | 
| 113 |     // From QAbstractListModel | 
| 114 |     int rowCount(const QModelIndex &parent) const  override; | 
| 115 |     QVariant data(const QModelIndex &index, int role) const override; | 
| 116 |  | 
| 117 |     QHash<int,QByteArray> roleNames() const override; | 
| 118 |  | 
| 119 |     DiscoveryMode discoveryMode() const; | 
| 120 |     void setDiscoveryMode(DiscoveryMode discovery); | 
| 121 |  | 
| 122 |     // TODO Qt 6 This property behaves synchronously but should really be | 
| 123 |     // asynchronous. The agents start/stop/restart is not immediate. | 
| 124 |     bool running() const; | 
| 125 |     void setRunning(bool running); | 
| 126 |  | 
| 127 |     QString uuidFilter() const; | 
| 128 |     void setUuidFilter(QString uuid); | 
| 129 |  | 
| 130 |     QString remoteAddress(); | 
| 131 |     void setRemoteAddress(QString); | 
| 132 |  | 
| 133 | signals: | 
| 134 |     void errorChanged(); | 
| 135 |     void discoveryModeChanged(); | 
| 136 |     void serviceDiscovered(QDeclarativeBluetoothService *service); | 
| 137 |     void deviceDiscovered(const QString& device); | 
| 138 |     void runningChanged(); | 
| 139 |     void uuidFilterChanged(); | 
| 140 |     void remoteAddressChanged(); | 
| 141 |  | 
| 142 | private slots: | 
| 143 |     void serviceDiscovered(const QBluetoothServiceInfo &service); | 
| 144 |     void deviceDiscovered(const QBluetoothDeviceInfo &device); | 
| 145 |     void finishedDiscovery(); | 
| 146 |     void errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error); | 
| 147 |     void errorDeviceDiscovery(QBluetoothDeviceDiscoveryAgent::Error); | 
| 148 |  | 
| 149 | private: | 
| 150 |     void clearModel(); | 
| 151 |  | 
| 152 |     enum Action { | 
| 153 |         IdleAction = 0, | 
| 154 |         StopAction, | 
| 155 |         DeviceDiscoveryAction, | 
| 156 |         MinimalServiceDiscoveryAction, | 
| 157 |         FullServiceDiscoveryAction | 
| 158 |     }; | 
| 159 |  | 
| 160 |     bool toggleStartStop(Action action); | 
| 161 |     void updateNextAction(Action action); | 
| 162 |     void transitionToNextAction(); | 
| 163 |  | 
| 164 | private: | 
| 165 |     QDeclarativeBluetoothDiscoveryModelPrivate* d; | 
| 166 |     friend class QDeclarativeBluetoothDiscoveryModelPrivate; | 
| 167 |  | 
| 168 | }; | 
| 169 |  | 
| 170 | #endif // QDECLARATIVECONTACTMODEL_P_H | 
| 171 |  |