~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to solid/networkmanager-0.7/wirelessnetworkinterface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
 
3
 
 
4
This program is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU General Public License as
 
6
published by the Free Software Foundation; either version 2 of
 
7
the License or (at your option) version 3 or any later version
 
8
accepted by the membership of KDE e.V. (or its successor approved
 
9
by the membership of KDE e.V.), which shall act as a proxy
 
10
defined in Section 14 of version 3 of the license.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
/* Modes of operation */
 
22
#define NM_802_11_MODE_UNKNOWN 0 /* Mode is unknown. */
 
23
#define NM_802_11_MODE_ADHOC   1 /* Uncoordinated network without central infrastructure. */
 
24
#define NM_802_11_MODE_INFRA   2 /* Coordinated network with one or more central controllers. */
 
25
 
 
26
#include "wirelessnetworkinterface.h"
 
27
#include "wirelessnetworkinterface_p.h"
 
28
 
 
29
#include <KDebug>
 
30
 
 
31
#include "accesspoint.h"
 
32
#include "manager.h"
 
33
 
 
34
NMWirelessNetworkInterfacePrivate::NMWirelessNetworkInterfacePrivate(const QString & path, QObject * owner)
 
35
    : NMNetworkInterfacePrivate(path, owner), wirelessIface(NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus())
 
36
      , bitRate(0)
 
37
{
 
38
 
 
39
}
 
40
 
 
41
NMWirelessNetworkInterface::NMWirelessNetworkInterface(const QString & path, NMNetworkManager * manager, QObject * parent)
 
42
    : NMNetworkInterface(*new NMWirelessNetworkInterfacePrivate(path, this), manager, parent)
 
43
{
 
44
    Q_D(NMWirelessNetworkInterface);
 
45
    d->hardwareAddress = d->wirelessIface.hwAddress();
 
46
    d->mode = convertOperationMode(d->wirelessIface.mode());
 
47
    d->bitRate = d->wirelessIface.bitrate();
 
48
    d->activeAccessPoint = d->wirelessIface.activeAccessPoint().path();
 
49
    d->wirelessCapabilities = convertCapabilities(d->wirelessIface.wirelessCapabilities());
 
50
 
 
51
    connect( &d->wirelessIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
 
52
                this, SLOT(wirelessPropertiesChanged(const QVariantMap &)));
 
53
    connect( &d->wirelessIface, SIGNAL(AccessPointAdded(const QDBusObjectPath &)),
 
54
                this, SLOT(accessPointAdded(const QDBusObjectPath &)));
 
55
    connect( &d->wirelessIface, SIGNAL(AccessPointRemoved(const QDBusObjectPath &)),
 
56
                this, SLOT(accessPointRemoved(const QDBusObjectPath &)));
 
57
 
 
58
 
 
59
    qDBusRegisterMetaType<QList<QDBusObjectPath> >();
 
60
    QDBusReply< QList <QDBusObjectPath> > apPathList = d->wirelessIface.GetAccessPoints();
 
61
    if (apPathList.isValid())
 
62
    {
 
63
        //kDebug(1441) << "Got device list";
 
64
        QList <QDBusObjectPath> aps = apPathList.value();
 
65
        foreach (const QDBusObjectPath &op, aps)
 
66
        {
 
67
            d->accessPoints.append(op.path());
 
68
            //kDebug(1441) << "  " << op.path();
 
69
        }
 
70
    }
 
71
    else
 
72
        kDebug(1441) << "Error getting access point list: " << apPathList.error().name() << ": " << apPathList.error().message();
 
73
}
 
74
 
 
75
NMWirelessNetworkInterface::~NMWirelessNetworkInterface()
 
76
{
 
77
 
 
78
}
 
79
 
 
80
QStringList NMWirelessNetworkInterface::accessPoints() const
 
81
{
 
82
    Q_D(const NMWirelessNetworkInterface);
 
83
    return d->accessPoints;
 
84
}
 
85
 
 
86
QString NMWirelessNetworkInterface::activeAccessPoint() const
 
87
{
 
88
    Q_D(const NMWirelessNetworkInterface);
 
89
    return d->activeAccessPoint;
 
90
}
 
91
 
 
92
QString NMWirelessNetworkInterface::hardwareAddress() const
 
93
{
 
94
    Q_D(const NMWirelessNetworkInterface);
 
95
    return d->hardwareAddress;
 
96
}
 
97
 
 
98
Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::mode() const
 
99
{
 
100
    Q_D(const NMWirelessNetworkInterface);
 
101
    return d->mode;
 
102
}
 
103
 
 
104
int NMWirelessNetworkInterface::bitRate() const
 
105
{
 
106
    Q_D(const NMWirelessNetworkInterface);
 
107
    return d->bitRate;
 
108
}
 
109
 
 
110
Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::wirelessCapabilities() const
 
111
{
 
112
    Q_D(const NMWirelessNetworkInterface);
 
113
    return d->wirelessCapabilities;
 
114
}
 
115
 
 
116
QObject * NMWirelessNetworkInterface::createAccessPoint(const QString & uni)
 
117
{
 
118
    Q_D(NMWirelessNetworkInterface);
 
119
    NMAccessPoint * ap = 0;
 
120
    if (d->accessPoints.contains(uni)) {
 
121
        ap = new NMAccessPoint(uni, 0);
 
122
    }
 
123
 
 
124
    return ap;
 
125
}
 
126
 
 
127
void NMWirelessNetworkInterface::wirelessPropertiesChanged(const QVariantMap & changedProperties)
 
128
{
 
129
    //kDebug(1441) << changedProperties.keys();
 
130
    QStringList propKeys = changedProperties.keys();
 
131
    Q_D(NMWirelessNetworkInterface);
 
132
    QLatin1String activeApKey("ActiveAccessPoint"),
 
133
                  hwAddrKey("HwAddress"),
 
134
                  bitRateKey("Bitrate"),
 
135
                  modeKey("Mode"),
 
136
                  wirelessCapsKey("WirelessCapabilities");
 
137
    QVariantMap::const_iterator it = changedProperties.find(activeApKey);
 
138
    if (it != changedProperties.end()) {
 
139
        d->activeAccessPoint = qdbus_cast<QDBusObjectPath>(*it).path();
 
140
        emit activeAccessPointChanged(d->activeAccessPoint);
 
141
        propKeys.removeOne(activeApKey);
 
142
    }
 
143
    it = changedProperties.find(hwAddrKey);
 
144
    if (it != changedProperties.end()) {
 
145
        d->hardwareAddress = it->toString();
 
146
        propKeys.removeOne(hwAddrKey);
 
147
    }
 
148
    it = changedProperties.find(bitRateKey);
 
149
    if (it != changedProperties.end()) {
 
150
        d->bitRate = it->toUInt();
 
151
        emit bitRateChanged(d->bitRate);
 
152
        propKeys.removeOne(bitRateKey);
 
153
    }
 
154
    it = changedProperties.find(modeKey);
 
155
    if (it != changedProperties.end()) {
 
156
        d->mode = convertOperationMode(it->toUInt());
 
157
        emit modeChanged(d->mode);
 
158
        propKeys.removeOne(modeKey);
 
159
    }
 
160
    it = changedProperties.find(wirelessCapsKey);
 
161
    if (it != changedProperties.end()) {
 
162
        d->wirelessCapabilities = convertCapabilities(it->toUInt());
 
163
        propKeys.removeOne(wirelessCapsKey);
 
164
    }
 
165
    //if (propKeys.count()) {
 
166
    //    kDebug(1441) << "Unhandled properties: " << propKeys;
 
167
    //}
 
168
}
 
169
 
 
170
void NMWirelessNetworkInterface::accessPointAdded(const QDBusObjectPath &apPath)
 
171
{
 
172
    //kDebug(1441) << apPath.path();
 
173
    Q_D(NMWirelessNetworkInterface);
 
174
    if (!d->accessPoints.contains(apPath.path())) {
 
175
        d->accessPoints.append(apPath.path());
 
176
        emit accessPointAppeared(apPath.path());
 
177
    }
 
178
}
 
179
 
 
180
void NMWirelessNetworkInterface::accessPointRemoved(const QDBusObjectPath &apPath)
 
181
{
 
182
    //kDebug(1441) << apPath.path();
 
183
    Q_D(NMWirelessNetworkInterface);
 
184
    if (!d->accessPoints.contains(apPath.path())) {
 
185
        kDebug(1441) << "Access point list lookup failed for " << apPath.path();
 
186
    }
 
187
    d->accessPoints.removeAll(apPath.path());
 
188
    emit accessPointDisappeared(apPath.path());
 
189
}
 
190
 
 
191
Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::convertOperationMode(uint theirMode)
 
192
{
 
193
    Solid::Control::WirelessNetworkInterface::OperationMode ourMode = Solid::Control::WirelessNetworkInterface::Unassociated;
 
194
    switch ( theirMode ) {
 
195
        case NM_802_11_MODE_UNKNOWN:
 
196
            ourMode = Solid::Control::WirelessNetworkInterface::Unassociated;
 
197
            break;
 
198
        case NM_802_11_MODE_ADHOC:
 
199
            ourMode = Solid::Control::WirelessNetworkInterface::Adhoc;
 
200
            break;
 
201
        case NM_802_11_MODE_INFRA:
 
202
            ourMode = Solid::Control::WirelessNetworkInterface::Managed;
 
203
            break;
 
204
    }
 
205
    return ourMode;
 
206
}
 
207
 
 
208
Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::convertCapabilities(uint caps)
 
209
{
 
210
    return (Solid::Control::WirelessNetworkInterface::Capabilities)caps;
 
211
}
 
212