summaryrefslogtreecommitdiffstats
path: root/src/networksettings/qnetworksettings.cpp
blob: 79ec2d43992cbf3aeaa85e0befed88bcfd468a5b (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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Device Utilities module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qnetworksettings.h"

QT_BEGIN_NAMESPACE

/*!
    \module QtNetworkSettings
    \qtvariable networksettings
    \ingroup qtdevice-utilities-cpp-modules
    \ingroup modules
    \title Qt Network Settings C++ Classes
    \brief Provides functionality for controlling network settings.

    To use classes from this module, add this directive into the C++ files:

    \code
    #include <QtNetworkSettings>
    \endcode

    To link against the corresponding C++ libraries when using CMake to build you application,
    add the following to your CMakeLists.txt file:

    \code
    find_package(Qt6 COMPONENTS NetworkSettings REQUIRED)
    target_link_libraries(mytarget Qt6::NetworkSettings)
    \endcode

    Or if you are using qmake to build your application, add the following line to your qmake .pro project file:

    \code
    QT += networksettings
    \endcode
*/

/*!
    \class QNetworkSettingsState
    \inmodule QtNetworkSettings

    \brief The QNetworkSettingsState class represents the network interface
    state.

    \sa QNetworkSettingsManager
*/

/*!
    \enum QNetworkSettingsState::States

    This enum type holds the state of the network interface.

    \value  Idle
    \value  Failure
            Failed to connect.
    \value  Association
            Authentication in progress.
    \value  Configuration
            Configuration in progress.
    \value  Ready
            Connected to a network.
    \value  Disconnect
            Disconnected from a network.
    \value  Online
            Acquired an IP address.
    \value  Undefined
            Undefined state.
*/

/*!
    \property QNetworkSettingsState::state
    \brief The state of the network interface.

    \sa QNetworkSettingsState::States
*/

/*!
    \fn QNetworkSettingsState::stateChanged()
    This signal is emitted when the state of the network interface changes.

    \sa QNetworkSettingsState::States
*/

/*!
    Creates a new network interface state object with the state \a state and the
    parent \a parent.
*/
QNetworkSettingsState::QNetworkSettingsState(States state, QObject *parent)
    : QObject(parent)
    , m_state(state)
{
}

/*!
    Creates a new network interface state object with the parent \a parent.
*/
QNetworkSettingsState::QNetworkSettingsState(QObject *parent)
    : QObject(parent)
    , m_state(Undefined)
{
}

/*!
    Returns the network interface state.
*/
QNetworkSettingsState::States QNetworkSettingsState::state() const {
    return m_state;
}

/*!
    Sets the network interface state to \a state.
*/
void QNetworkSettingsState::setState(const States state) {
    m_state = state;
    emit stateChanged();
}

/*!
    \class QNetworkSettingsType
    \inmodule QtNetworkSettings

    \brief The QNetworkSettingsType class represents the network interface
    type.

    \sa QNetworkSettingsManager
*/

/*!
    \enum QNetworkSettingsType::Types

    This enum type holds the type of the network interface.

    \value  Wired
            Wired network
    \value  Wifi
            Wifi network
    \value  Bluetooth
            Bluetooth network
    \value  Unknown
            Unknown network type
*/

/*!
    \property QNetworkSettingsType::type
    \brief The type of the network interface.

    \sa QNetworkSettingsType::Types
*/

/*!
    \fn QNetworkSettingsType::typeChanged()
    This signal is emitted when the type of the network interface changes.

    \sa QNetworkSettingsType::Types
*/

/*!
    Creates a new network interface type object with the type \a type and
    parent \a parent.
*/
QNetworkSettingsType::QNetworkSettingsType(Types type, QObject *parent)
    : QObject(parent)
    , m_type(type)
{
    m_type = type;
}

/*!
    Creates a new network interface type object with the parent \a parent.
*/
QNetworkSettingsType::QNetworkSettingsType(QObject *parent)
    : QObject(parent)
{
    m_type = Unknown;
}

/*!
    Returns the network interface type.
*/
QNetworkSettingsType::Types QNetworkSettingsType::type() const {
    return m_type;
}

/*!
    Sets the network interface type to \a type.
*/
void QNetworkSettingsType::setType(const Types type) {
    m_type = type;
    emit typeChanged();
}

/*!
    \class QNetworkSettingsIPv4
    \inmodule QtNetworkSettings

    \brief The QNetworkSettingsIPv4 class encapsulates IPv4 network
    configuration.
*/

/*!
    \enum QNetworkSettingsIPv4::MethodType

    This enum type holds the method used for IPv4 configuration.

    \value  Dhcp
            The DHCP protocol is used for the network configuration.
    \value  Manual
            The network is configured manually.
    \value  Off
            The network is not configured.
*/

/*!
    \property QNetworkSettingsIPv4::address
    \brief Holds the IPv4 address.
*/

/*!
    \property QNetworkSettingsIPv4::gateway
    \brief Holds the IPv4 gateway address.
*/

/*!
    \property QNetworkSettingsIPv4::method
    \brief Holds the method of IPv4 configuration.

    \sa QNetworkSettingsIPv4::MethodType
*/

/*!
    \property QNetworkSettingsIPv4::mask
    \brief Holds the IPv4 network mask.
*/

/*!
    Creates a new IPv4 network configuration with the parent \a parent.
*/
QNetworkSettingsIPv4::QNetworkSettingsIPv4(QObject *parent)
    : QObject(parent)
{
}

QString QNetworkSettingsIPv4::address() const {
    return m_address;
}

void QNetworkSettingsIPv4::setAddress(const QString& address) {
    m_address = address;
    emit addressChanged();
}

QString QNetworkSettingsIPv4::gateway() const {
    return m_gateway;
}

void QNetworkSettingsIPv4::setGateway(const QString& gateway) {
    m_gateway = gateway;
    emit gatewayChanged();
}

QNetworkSettingsIPv4::MethodType QNetworkSettingsIPv4::method() const {
    return m_method;
}

void QNetworkSettingsIPv4::setMethod(const MethodType method) {
    m_method = method;
    emit methodChanged();
}

QString QNetworkSettingsIPv4::mask() const {
    return m_mask;
}

void QNetworkSettingsIPv4::setMask(const QString& mask) {
    m_mask = mask;
    emit maskChanged();
}

/*!
    \class QNetworkSettingsIPv6
    \inmodule QtNetworkSettings

    \brief The QNetworkSettingsIPv6 class encapsulates IPv6 network
    configuration.
*/

/*!
    \enum QNetworkSettingsIPv6::MethodType

    This enum type holds the method used for IPv6 configuration.

    \value  Auto
            The network is configured automatically.
    \value  Manual
            The network is configured manually.
    \value  Off
            The network is not configured.
*/

/*!
    \enum QNetworkSettingsIPv6::PrivacyType
    \brief Holds the method of applying the privacy extensions in IPv6.

    \value  Disabled
            Disables privacy extensions in IPv6
    \value  Enabled
            Enables \l {https://tools.ietf.org/html/rfc4941}
            {Privacy Extensions for Stateless Address Autoconfiguration in IPv6}.
    \value  Preferred
            Enables privacy extensions and gives preference to the use of
            temporary addresses, even when a public address is available
*/

/*!
    \property QNetworkSettingsIPv6::address
    \brief Holds the IPv6 address.
*/

/*!
    \property QNetworkSettingsIPv6::gateway
    \brief Holds the IPv6 gateway address.
*/

/*!
    \property QNetworkSettingsIPv6::method
    \brief Holds the method of IPv6 configuration.

    \sa QNetworkSettingsIPv6::MethodType
*/

/*!
    \property QNetworkSettingsIPv6::privacy
    \brief Holds the method of applying privacy extensions for IPv6.

    \sa QNetworkSettingsIPv6::PrivacyType
*/

/*!
    \property QNetworkSettingsIPv6::prefixLength
    \brief Holds the IPv6 network prefix length in bits.
*/


/*!
    Creates a new IPv6 network configuration with the parent \a parent.
*/
QNetworkSettingsIPv6::QNetworkSettingsIPv6(QObject *parent)
    : QObject(parent)
{
}

QString QNetworkSettingsIPv6::address() const {
    return m_address;
}

void QNetworkSettingsIPv6::setAddress(const QString& address) {
    m_address = address;
    emit addressChanged();
}

QString QNetworkSettingsIPv6::gateway() const {
    return m_gateway;
}

void QNetworkSettingsIPv6::setGateway(const QString& gateway) {
    m_gateway = gateway;
    emit gatewayChanged();
}

QNetworkSettingsIPv6::MethodType QNetworkSettingsIPv6::method() const {
    return m_method;
}

void QNetworkSettingsIPv6::setMethod(const MethodType method) {
    m_method = method;
    emit methodChanged();
}

QNetworkSettingsIPv6::PrivacyType QNetworkSettingsIPv6::privacy() const {
    return m_privacy;
}

void QNetworkSettingsIPv6::setPrivacy(const PrivacyType privacy) {
    m_privacy = privacy;
    emit privacyChanged();
}

int QNetworkSettingsIPv6::prefixLength() const {
    return m_prefixLength;
}

void QNetworkSettingsIPv6::setPrefixLength(const int& prefixLength) {
    m_prefixLength = prefixLength;
    emit prefixLengthChanged();
}


/*!
    \class QNetworkSettingsProxy
    \inmodule QtNetworkSettings
    \brief The QNetworkSettingsProxy class encapsulates network proxy
    configuration.
*/

/*!
    \enum QNetworkSettingsProxy::MethodType
    \brief Holds the network proxy configuration method.

    \value  Direct
            Direct network connection, no proxy in use
    \value  Auto
            Automatic proxy configuration
    \value  Manual
            Manual proxy configuration

    \sa url
*/

/*!
    \property QNetworkSettingsProxy::method
    \brief Holds the network proxy configuration method.

    \sa MethodType
*/

/*!
    \property QNetworkSettingsProxy::url
    \brief Holds the proxy URL.

    For manual proxy configuration, this property holds the proxy server
    address. For automatic configuration, it holds the proxy auto-config URL.

    \sa MethodType
*/

/*!
    \property QNetworkSettingsProxy::excludes
    \readonly
    \brief The model containing the proxy exclusion list.

    The addresses in the proxy exclusion list are accessed directly,
    instead of forwarding the requests to a proxy.

    This property can be used as a model for a view
    that lists the proxy exclusion addresses.

    \sa QNetworkSettingsAddressModel
*/

/*!
    \property QNetworkSettingsProxy::servers
    \readonly
    \brief The model containing the proxy exclusion list.

    This property holds the list of proxy server names.
*/

/*!
    Creates a new proxy configuration with the parent \a parent.
*/
QNetworkSettingsProxy::QNetworkSettingsProxy(QObject *parent)
    : QObject(parent)
{

}

QUrl QNetworkSettingsProxy::url() const {
    return m_url;
}

void QNetworkSettingsProxy::setUrl(const QUrl& url) {
    m_url = url;
    emit urlChanged();
}

QAbstractItemModel* QNetworkSettingsProxy::servers(void) {
    return &m_servers;
}

/*!
    Sets the proxy server list.
    \a servers lists the server names.

    The QNetworkSettingsProxy::serversChanged signal is emitted when the server list
    is set.
*/
void QNetworkSettingsProxy::setServers(const QStringList& servers) {
    m_servers.setStringList(servers);
    emit serversChanged();
}

QStringList QNetworkSettingsProxy::servers() const {
    return m_servers.stringList();
}

QAbstractItemModel* QNetworkSettingsProxy::excludes(void) {
    return &m_excludes;
}

QStringList QNetworkSettingsProxy::excludes() const {
    return m_excludes.stringList();
}

/*!
    Sets the proxy exclusion list.
    \a excludes lists the addresses on the exclustion list.

    The QNetworkSettingsProxy::excludesChanged signal is emitted when the proxy
    exclusion list is set.
*/
void QNetworkSettingsProxy::setExcludes(const QStringList& excludes) {
    m_excludes.setStringList(excludes);
    emit excludesChanged();
}

QNetworkSettingsProxy::MethodType QNetworkSettingsProxy::method(void) const {
    return m_method;
}

void QNetworkSettingsProxy::setMethod(const MethodType& method) {
    m_method = method;
    emit methodChanged();
}

/*!
    \class QNetworkSettingsWireless
    \inmodule QtNetworkSettings
    \brief The QNetworkSettingsWireless class encapsulates the configuration
    for a Wifi network service.
*/

/*!
    \enum QNetworkSettingsWireless::SecurityFlags
    \brief This enum type holds the wireless security protocol used to
    protect the connection.

    \value  None
            Not protected
    \value  WEP
            Wired Equivalent Privacy (WEP)
    \value  WPA
            Wi-Fi Protected Access (WPA)
    \value  WPA2
            Wi-Fi Protected Access, version 2 (WPA2)
*/

/*!
    \property QNetworkSettingsWireless::signalStrength
    \brief Holds the Wifi signal strength, in the range from 0 to 100.
*/

/*!
    \property QNetworkSettingsWireless::hidden
    \readonly
    \brief Holds whether the wireless SSID is hidden.
*/

/*!
    \property QNetworkSettingsWireless::isOutOfRange
    \brief Holds whether the Wifi access point is out of range.
*/

/*!
    \fn void QNetworkSettingsWireless::passwordChanged()

    This signal is sent when the password has changed.
*/

/*!
    Creates a new Wifi network configuration with the parent \a parent.
*/
QNetworkSettingsWireless::QNetworkSettingsWireless(QObject* parent)
  : QObject(parent) {
}

/*!
    Returns whether the Wifi network supports the wireless security
    protocols specified in \a security.

    \sa QNetworkSettingsWireless::SecurityFlags
*/
bool QNetworkSettingsWireless::supportsSecurity(SecurityFlags security) {
    if (m_securityFlags & security) {
        return true;
    }
    return false;
}

bool QNetworkSettingsWireless::hidden() const {
    return m_hidden;
}

/*!
    Sets \a hidden status.

    The QNetworkSettingsWireless::hiddenChanged signal is emitted when the
    hidden status is changed.
*/
void QNetworkSettingsWireless::setHidden(const bool hidden) {
    m_hidden = hidden;
    emit hiddenChanged();
}

int QNetworkSettingsWireless::signalStrength() const {
    return m_signalStrength;
}

void QNetworkSettingsWireless::setSignalStrength(const int signalStrength) {
    m_signalStrength = signalStrength;
    emit signalStrengthChanged();
}

/*!
    Sets \a security flags.
*/
void QNetworkSettingsWireless::setSecurity(const SecurityFlags security) {
    if (security == None) {
        m_securityFlags = None;
    } else {
        m_securityFlags |= security;
    }
}

void QNetworkSettingsWireless::setOutOfRange(const bool aOutOfRange) {
    m_isOutOfRange = aOutOfRange;
    emit outOfRangeChanged();
}

bool QNetworkSettingsWireless::outOfRange() const {
    return m_isOutOfRange;
}

QT_END_NAMESPACE