NetworkManagerQt

wirelessnetwork.cpp
1/*
2 SPDX-FileCopyrightText: 2009, 2011 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "wirelessnetwork.h"
9#include "wirelessnetwork_p.h"
10
11#include "manager.h"
12#include "wirelessdevice.h"
13
14NetworkManager::WirelessNetworkPrivate::WirelessNetworkPrivate(WirelessNetwork *q, WirelessDevice *device)
15 : q_ptr(q)
16 , wirelessNetworkInterface(device)
17{
18 QObject::connect(device, SIGNAL(accessPointAppeared(QString)), q, SLOT(accessPointAppeared(QString)));
19 QObject::connect(device, SIGNAL(accessPointDisappeared(QString)), q, SLOT(accessPointDisappeared(QString)));
20 QObject::connect(device, SIGNAL(activeAccessPointChanged(QString)), q, SLOT(updateStrength()));
21}
22
23NetworkManager::WirelessNetworkPrivate::~WirelessNetworkPrivate()
24{
25}
26
27void NetworkManager::WirelessNetworkPrivate::addAccessPointInternal(const NetworkManager::AccessPoint::Ptr &accessPoint)
28{
29 Q_Q(WirelessNetwork);
30
31 QObject::connect(accessPoint.data(), SIGNAL(signalStrengthChanged(int)), q, SLOT(updateStrength()));
32 aps.insert(accessPoint->uni(), accessPoint);
33 updateStrength();
34}
35
36void NetworkManager::WirelessNetworkPrivate::accessPointAppeared(const QString &uni)
37{
38 if (!aps.contains(uni) && wirelessNetworkInterface) {
39 NetworkManager::AccessPoint::Ptr accessPoint = wirelessNetworkInterface->findAccessPoint(uni);
40 if (accessPoint && accessPoint->ssid() == ssid) {
41 addAccessPointInternal(accessPoint);
42 }
43 }
44}
45
46void NetworkManager::WirelessNetworkPrivate::accessPointDisappeared(const QString &uni)
47{
48 Q_Q(WirelessNetwork);
49 aps.remove(uni);
50 if (aps.isEmpty()) {
51 Q_EMIT q->disappeared(ssid);
52 } else {
53 updateStrength();
54 }
55}
56
57void NetworkManager::WirelessNetworkPrivate::updateStrength()
58{
59 Q_Q(WirelessNetwork);
60
61 int selectedStrength = -1;
63
64 if (!wirelessNetworkInterface) {
65 return;
66 }
67
68 NetworkManager::AccessPoint::Ptr activeAp = wirelessNetworkInterface->activeAccessPoint();
69 if (activeAp && activeAp->ssid() == ssid) {
70 // If the network has an active access point, use it as the referenceAp
71 selectedStrength = activeAp->signalStrength();
72 selectedAp = activeAp;
73 } else {
74 // Otherwise, choose the access point with the strongest signal
75 for (const NetworkManager::AccessPoint::Ptr &iface : std::as_const(aps)) {
76 if (selectedStrength <= iface->signalStrength()) {
77 selectedStrength = iface->signalStrength();
78 selectedAp = iface;
79 }
80 }
81 }
82
83 if (selectedStrength != strength) {
84 strength = selectedStrength;
85 Q_EMIT q->signalStrengthChanged(strength);
86 }
87
88 if (selectedAp && referenceAp != selectedAp) {
89 referenceAp = selectedAp;
90 Q_EMIT q->referenceAccessPointChanged(referenceAp->uni());
91 }
92 // TODO: update the networks delayed
93 // kDebug() << "update strength" << ssid << strength;
94}
95
96NetworkManager::WirelessNetwork::WirelessNetwork(const AccessPoint::Ptr &accessPoint, WirelessDevice *device)
97 : d_ptr(new WirelessNetworkPrivate(this, device))
98{
99 Q_D(WirelessNetwork);
100
101 d->strength = -1;
102 d->ssid = accessPoint->ssid();
103 d->addAccessPointInternal(accessPoint);
104}
105
106NetworkManager::WirelessNetwork::~WirelessNetwork()
107{
108 delete d_ptr;
109}
110
112{
113 Q_D(const WirelessNetwork);
114 return d->ssid;
115}
116
118{
119 Q_D(const WirelessNetwork);
120 return d->strength;
121}
122
128
134
136{
137 Q_D(const WirelessNetwork);
138
139 if (d->wirelessNetworkInterface) {
140 return d->wirelessNetworkInterface->uni();
141 } else {
142 return QString();
143 }
144}
145
146#include "moc_wirelessnetwork.cpp"
This class represents a wireless network, which aggregates all access points with the same SSID.
QString device() const
The uni of device associated with this network.
QString ssid() const
ESSID of the network.
int signalStrength() const
Signal strength of the network.
AccessPoint::List accessPoints() const
List of access points.
AccessPoint::Ptr referenceAccessPoint() const
The uni of the current 'best' (strongest) Access Point.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T * data() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:00:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.