summaryrefslogtreecommitdiffstats
path: root/src/imports/wifi/pluginmain.cpp
blob: b498b6672d6d2b9cb3b9901522511b3c593a6c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use the contact form at
** http://www.qt.io
**
** This file is part of Qt Enterprise Embedded.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** the contact form at http://www.qt.io
**
****************************************************************************/
#include <B2QtWifi/QWifiManager>
#include <B2QtWifi/QWifiDevice>
#include <B2QtWifi/QWifiConfiguration>

#include <QtQml>

QT_BEGIN_NAMESPACE

/*!
    \qmlmodule B2Qt.Wifi 1.0
    \title B2Qt Wifi QML Module
    \ingroup qtee-qmlmodules
    \brief A module for managing wireless network connectivity.

*/

/*!
    \page b2qt-addon-wifi.html
    \title B2Qt Wifi Module
    \ingroup qtee-modules
    \brief A module for managing wireless network connectivity.

    B2Qt.Wifi provides QML types and C++ classes for:

    \list
    \li Wifi backend handling
    \li Retrieval of information from Wifi network access points
    \li Wifi connection handling
    \li System's network interface configuration
    \li Other tasks that allow the device to access network
    \endlist

    \section1 Writing the Code

    Depending on what fits best with the application, you can choose to use
    either C++ or QML for accessing Wifi functionality. If the majority of the
    user interface is written in QML, it is recommended that you use the QML
    types, which provide a simpler and declarative way to handle Wifi networks.

    \list
    \li \l{Getting Started with B2Qt.Wifi in QML}
    \li \l{Getting Started with B2Qt.Wifi in C++}
    \endlist

    \section1 API Reference

    \section2 QML Types

    \annotatedlist wifi-qmltypes

    \section2 C++ Classes

    \annotatedlist wifi-cppclasses
*/

/*!
    \module B2Qt.Wifi.Cpp 1.0
    \title B2Qt Wifi C++ Module
    \ingroup qtee-cppmodules
    \brief A module for managing wireless network connectivity.
*/

/*!
    \qmltype WifiManager
    \inqmlmodule B2Qt.Wifi
    \ingroup wifi-qmltypes
    \brief Main interface to the Wifi functionality.

    WifiManager is a singleton type that is a central point for handling Wifi functionality
    related tasks. You can use WifiManager's API to control the Wifi backend, scan surroundings for
    Wifi access points and connect a device to a wireless network.

    When scanning for networks, WifiManager packs the results in a list-based data model which can
    be used with Qt's Model/View classes. Information about the Wifi networks is supplied via the model's
    interface, accessed with the following roles:

    \list
    \li \e ssid - informal (human) name of a Wifi network (string)
    \li \e bssid - basic service set identification of a network, used to uniquely identify BSS (string)
    \li \e signalStrength - strength of a Wifi signal represented as percentage (0-100) (int)
    \li \e supportsWPA - holds whether network access point supports WPA security protocol (bool)
    \li \e supportsWPA2 - holds whether network access point supports WPA2 security protocol (bool)
    \li \e supportsWEP - holds whether network access point supports WEP security protocol (bool)
    \li \e supportsWPS - holds whether network access point supports WPS security protocol (bool)
    \endlist
 */

/*!
    \qmlproperty enumeration WifiManager::NetworkState
    \readonly

    This property holds the current state of the network connection.

    \list
    \li \e WifiManager.Disconnected - Not connected to any network
    \li \e WifiManager.Authenticating - Verifying password with the network provider
    \li \e WifiManager.HandshakeFailed - Incorrect password provided
    \li \e WifiManager.ObtainingIPAddress - Requesting IP address from DHCP server
    \li \e WifiManager.DhcpRequestFailed - Could not retrieve IP address
    \li \e WifiManager.Connected - Ready to process network requests
    \endlist
*/

/*!
    \qmlproperty enumeration WifiManager::BackendState
    \readonly

    This property holds the current state of the Wifi backend.

    \list
    \li \e WifiManager.Initializing - Wireless supplicant is starting up
    \li \e WifiManager.Running - Supplicant is initialized and ready to process commands
    \li \e WifiManager.Terminating - Shutting down wireless supplicant
    \li \e WifiManager.NotRunning - Wireless supplicant process is not running
    \endlist
*/

/*!
    \qmlsignal WifiManager::networkStateChanged(NetworkState networkState)

    This signal is emitted whenever changes in a network state occur. The network name for
    which the NetworkState change events are send can be obtained from currentSSID.

    \sa NetworkState, currentSSID
*/

/*!
    \qmlsignal WifiManager::backendStateChanged(BackendState backendState)

    This signal is emitted whenever changes in a backend state occur.

    \sa start, stop
*/

/*!
    \qmlsignal WifiManager::currentSSIDChanged(string currentSSID)

    This signal is emitted when switching between different Wifi networks.

    \sa start, stop
*/

/*!
    \qmlsignal WifiManager::scanningChanged(bool scanning)

    This signal is emitted when device starts or stops to scan for available Wifi networks.

    \sa scanning
*/

/*!
    \qmlsignal WifiManager::lastErrorChanged(string error)

    This signal is emitted if some internal process has failed, \a error contains
    a message on what has failed.

    \sa connect
*/

/*!
    \qmlproperty model WifiManager::networks
    \readonly

    This property holds a list-based data model of networks that can be sensed by a device.
    Model can be used with Qt's Model/View classes like ListView. Data in the model is updated
    every 5 seconds if scanning is enabled.

    \sa scanning
*/

/*!
    \qmlproperty string WifiManager::currentSSID
    \readonly

    This property holds a network name of last selected network, the network for
    which the NetworkState change events are sent. Property can contain an empty
    string when no active network connection exists.
*/

/*!
    \qmlmethod WifiManager::start()

    Start the Wifi backend. This function returns immediately, the BackendState
    change events are delivered asynchronously.

    \sa stop, BackendState
*/

/*!
    \qmlmethod WifiManager::stop()

    Stop the Wifi backend and if connected to any network shut down the network connection.
    This function returns immediately, the BackendState change events are delivered asynchronously.

    \sa start, BackendState
*/

/*!
    \qmlproperty bool WifiManager::scanning

    This property holds whether or not the backend is scanning for Wifi networks. To
    preserve battery energy, set this property to false when scanning is not required.
    When enabled, new readings are taken every 5 seconds.

    For scanning to work, first you need to initialize the Wifi backend.

    \sa start
*/

/*!
    \qmlproperty string WifiManager::lastError
    \readonly

    This property holds an error message if some internal process has failed.

    \sa connect
*/

/*!
    \qmlmethod bool WifiManager::connect(WifiConfiguration config)

    Connect a device to a network using the \a config network configuration.
    This method returns \a true if the network with provoded configuration could be
    successfully added by the backend or \a false on failure, to obtain an error message
    read lastError property.

    \sa disconnect, NetworkState, lastError
*/

/*!
    \qmlmethod WifiManager::disconnect()

    Disconnect from currently connected network connection.

    \sa connect, NetworkState
*/

/*!
    \qmltype WifiDevice
    \inqmlmodule B2Qt.Wifi
    \ingroup wifi-qmltypes
    \brief Represents a physical device.

    Use this element to query if a device is Wifi capable, before attempting
    to use the functionality of WifiManager.

    \qml
    import B2Qt.Wifi 1.0

    GroupBox {
        id: wifiOptions
        title: "Wifi"
        visible: false

        Component.onCompleted: {
            if (WifiDevice.wifiSupported()) {
                var component = Qt.createComponent("WifiGroupBoxContent.qml")
                var wifi = component.createObject(wifiOptions.contentItem)
                if (wifi)
                    wifiOptions.visible = true
            } else {
                print("Wifi functionality not available on this device.")
            }
        }
    }
    \endqml
*/

/*!
    \qmlmethod bool WifiDevice::wifiSupported()

    Returns \a true if a device is Wifi capable - Wifi driver and firmware has been
    successfully loaded by the system, otherwise returns \a false.
*/

/*!
    \qmltype WifiConfiguration
    \inqmlmodule B2Qt.Wifi
    \ingroup wifi-qmltypes
    \brief Used to define a network configuration.

    WifiConfiguration object represents a single network configuration. Use this object
    to configure a properties of your network, for example what passphrase and security
    protocol to use. WifiManager's connect() function takes this object and connects a
    device to a network that matches the provided configuration.
*/

/*!
    \qmlproperty string WifiConfiguration::ssid

    This property holds informal (human) name of a Wifi network.
*/

/*!
    \qmlproperty string WifiConfiguration::passphrase

    This property holds the passphrase to use for authenticating with a network.
*/

/*!
    \qmlproperty string WifiConfiguration::protocol

    This property holds the security protocols to use for Wifi connection.
    WPA is used by default if property is not set, supported values are: WPA, WPA2, WEP, WPS.
*/

/*!
    \qmlproperty bool WifiConfiguration::ssidHidden

    If a Wifi access point does not broadcast its SSID, setting this property
    to \c true ensures that the Wifi backend can detect the specified network.

    By default this property is set to \c false.
*/

static QObject *globalWifiDevice(QQmlEngine *, QJSEngine *)
{
    return new QWifiDevice;
}

static QObject *globalWifiManager(QQmlEngine *, QJSEngine *)
{
    return QWifiManager::instance();
}

class QWifiPlugin : public QQmlExtensionPlugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")

public:
    virtual void registerTypes(const char *uri)
    {
        Q_ASSERT(QLatin1String(uri) == QLatin1String("B2Qt.Wifi"));

        qmlRegisterType<QAbstractListModel>();
        qmlRegisterSingletonType<QWifiManager>(uri, 1, 0, "WifiManager", globalWifiManager);
        qmlRegisterSingletonType<QWifiDevice>(uri, 1, 0, "WifiDevice", globalWifiDevice);
        qmlRegisterType<QWifiConfiguration>(uri, 1, 0, "WifiConfiguration");
    }
};

QT_END_NAMESPACE

#include "pluginmain.moc"