1 /* This file is part of the KDE project
2 Copyright (C) 2006 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2007 Kevin Ottens <ervin@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "wirelessnetworkinterface.h"
22 #include "wirelessnetworkinterface_p.h"
24 #include "soliddefs_p.h"
25 #include "wirelessaccesspoint.h"
26 #include "ifaces/wirelessaccesspoint.h"
27 #include "ifaces/wirelessnetworkinterface.h"
29 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(QObject
*backendObject
)
30 : NetworkInterface(*new WirelessNetworkInterfacePrivate(this), backendObject
)
32 Q_D(WirelessNetworkInterface
);
33 d
->setBackendObject(backendObject
);
34 makeConnections( backendObject
);
35 d
->readAccessPoints();
38 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(const WirelessNetworkInterface
&networkinterface
)
39 : NetworkInterface(*new WirelessNetworkInterfacePrivate(this), networkinterface
)
41 Q_D(WirelessNetworkInterface
);
42 d
->setBackendObject(networkinterface
.d_ptr
->backendObject());
43 makeConnections( networkinterface
.d_ptr
->backendObject() );
44 d
->readAccessPoints();
47 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(WirelessNetworkInterfacePrivate
&dd
, QObject
*backendObject
)
48 : NetworkInterface(dd
, backendObject
)
50 Q_D(WirelessNetworkInterface
);
51 makeConnections( backendObject
);
52 d
->readAccessPoints();
55 Solid::Control::WirelessNetworkInterface::WirelessNetworkInterface(WirelessNetworkInterfacePrivate
&dd
, const WirelessNetworkInterface
&networkinterface
)
56 : NetworkInterface(dd
, networkinterface
.d_ptr
->backendObject())
58 Q_D(WirelessNetworkInterface
);
59 makeConnections( networkinterface
.d_ptr
->backendObject() );
60 d
->readAccessPoints();
63 Solid::Control::WirelessNetworkInterface::~WirelessNetworkInterface()
68 Solid::Control::NetworkInterface::Type
Solid::Control::WirelessNetworkInterface::type() const
73 void Solid::Control::WirelessNetworkInterface::makeConnections(QObject
* source
)
75 connect(source
, SIGNAL(accessPointAppeared(const QString
&)),
76 this, SLOT(_k_accessPointAdded(const QString
&)));
77 connect(source
, SIGNAL(accessPointDisappeared(const QString
&)),
78 this, SLOT(_k_accessPointRemoved(const QString
&)));
79 connect(source
, SIGNAL(bitRateChanged(int)),
80 this, SIGNAL(bitRateChanged(int)));
81 connect(source
, SIGNAL(activeAccessPointChanged(const QString
&)),
82 this, SIGNAL(activeAccessPointChanged(const QString
&)));
83 connect(source
, SIGNAL(modeChanged(Solid::Control::WirelessNetworkInterface::OperationMode
)),
84 this, SIGNAL(modeChanged(Solid::Control::WirelessNetworkInterface::OperationMode
)));
87 QString
Solid::Control::WirelessNetworkInterface::hardwareAddress() const
89 Q_D(const WirelessNetworkInterface
);
90 return_SOLID_CALL(Ifaces::WirelessNetworkInterface
*, d
->backendObject(), QString(), hardwareAddress());
93 QString
Solid::Control::WirelessNetworkInterface::activeAccessPoint() const
95 Q_D(const WirelessNetworkInterface
);
96 return_SOLID_CALL(Ifaces::WirelessNetworkInterface
*, d
->backendObject(), QString(), activeAccessPoint());
99 int Solid::Control::WirelessNetworkInterface::bitRate() const
101 Q_D(const WirelessNetworkInterface
);
102 return_SOLID_CALL(Ifaces::WirelessNetworkInterface
*, d
->backendObject(), 0, bitRate());
105 Solid::Control::WirelessNetworkInterface::OperationMode
Solid::Control::WirelessNetworkInterface::mode() const
107 Q_D(const WirelessNetworkInterface
);
108 return_SOLID_CALL(Ifaces::WirelessNetworkInterface
*, d
->backendObject(), (Solid::Control::WirelessNetworkInterface::OperationMode
)0, mode());
111 Solid::Control::WirelessNetworkInterface::Capabilities
Solid::Control::WirelessNetworkInterface::wirelessCapabilities() const
113 Q_D(const WirelessNetworkInterface
);
114 return_SOLID_CALL(Ifaces::WirelessNetworkInterface
*, d
->backendObject(), (Solid::Control::WirelessNetworkInterface::Capabilities
)0, wirelessCapabilities());
117 Solid::Control::AccessPoint
* Solid::Control::WirelessNetworkInterface::findAccessPoint(const QString
& uni
) const
119 const AccessPointPair pair
= findRegisteredAccessPoint(uni
);
123 void Solid::Control::WirelessNetworkInterfacePrivate::setBackendObject(QObject
*object
)
125 NetworkInterfacePrivate::setBackendObject(object
);
131 Solid::Control::AccessPointList
Solid::Control::WirelessNetworkInterface::accessPoints() const
133 Q_D(const WirelessNetworkInterface
);
134 return d
->apMap
.keys();
137 void Solid::Control::WirelessNetworkInterface::_k_accessPointAdded(const QString
& uni
)
139 Q_D(WirelessNetworkInterface
);
140 AccessPointMap::Iterator mapIt
= d
->apMap
.find(uni
);
142 if (mapIt
!= d
->apMap
.end())
144 // Oops, I'm not sure it should happen...
145 // But for an unknown reason it does
146 // We were deleting the existing items here, which caused problems later
147 // when the client calls find AccessPoint and gets a frontend object with a
148 // null private object - dangling pointer
150 mapIt
= d
->apMap
.insert(uni
, AccessPointPair(0, 0));
153 emit
accessPointAppeared(uni
);
156 void Solid::Control::WirelessNetworkInterface::_k_accessPointRemoved(const QString
& uni
)
158 Q_D(WirelessNetworkInterface
);
159 AccessPointPair pair
= d
->apMap
.take(uni
);
167 emit
accessPointDisappeared(uni
);
170 void Solid::Control::WirelessNetworkInterface::_k_destroyed(QObject
*object
)
172 Q_D(WirelessNetworkInterface
);
173 Ifaces::AccessPoint
*ap
= qobject_cast
<Ifaces::AccessPoint
*>(object
);
177 QString uni
= ap
->uni();
178 AccessPointPair pair
= d
->apMap
.take(uni
);
183 Solid::Control::AccessPointPair
184 Solid::Control::WirelessNetworkInterface::findRegisteredAccessPoint(const QString
&uni
) const
186 Q_D(const WirelessNetworkInterface
);
188 AccessPointMap::ConstIterator mapIt
= d
->apMap
.constFind(uni
);
189 if (mapIt
!= d
->apMap
.constEnd() && mapIt
.value().second
) {
190 return mapIt
.value();
192 AccessPointPair pair
= d
->createAP(uni
);
193 if (pair
.first
&& pair
.second
) {
194 d
->apMap
[uni
] = pair
;
199 return AccessPointPair(0, 0);
202 void Solid::Control::WirelessNetworkInterfacePrivate::readAccessPoints()
204 Ifaces::WirelessNetworkInterface
* t
= qobject_cast
<Ifaces::WirelessNetworkInterface
*>(backendObject());
207 const MacAddressList unis
= t
->accessPoints();
208 Q_FOREACH (const QString
& uni
, unis
) {
209 apMap
[uni
] = AccessPointPair(0, 0);
214 Solid::Control::AccessPointPair
215 Solid::Control::WirelessNetworkInterfacePrivate::createAP(const QString
&uni
) const
217 Ifaces::WirelessNetworkInterface
*device
= qobject_cast
<Ifaces::WirelessNetworkInterface
*>(backendObject());
221 Ifaces::AccessPoint
*iface
= qobject_cast
<Ifaces::AccessPoint
*>(device
->createAccessPoint(uni
));
223 if (qobject_cast
<Ifaces::AccessPoint
*>(iface
)!=0) {
224 ap
= new AccessPoint(iface
);
228 AccessPointPair
pair(ap
, iface
);
229 QObject::connect(iface
, SIGNAL(destroyed(QObject
*)),
230 parent(), SLOT(_k_destroyed(QObject
*)));
235 return AccessPointPair(0, 0);
238 #include "wirelessnetworkinterface.moc"