~ubuntu-branches/ubuntu/oneiric/knetworkmanager/oneiric

« back to all changes in this revision

Viewing changes to knetworkmanager/src/knetworkmanager-connection_setting_wireless_security_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-07-14 14:05:44 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080714140544-yjhxgrdwartk3kx7
Tags: 1:0.7svn830754-0ubuntu1
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *
 
3
 * knetworkmanager-connection_setting_wireless_security_widget.cpp
 
4
 * - A NetworkManager frontend for KDE
 
5
 *
 
6
 * Copyright (C) 2005, 2006 Novell, Inc.
 
7
 *
 
8
 * Author: Helmut Schaa <hschaa@suse.de>, <Helmut.Schaa@gmx.de>
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *
 
24
 **************************************************************************/
 
25
 
 
26
/* qt headers */
 
27
#include <qwidget.h>
 
28
#include <qlineedit.h>
 
29
#include <qgroupbox.h>
 
30
#include <qbuttongroup.h>
 
31
#include <qwidgetstack.h>
 
32
#include <qcombobox.h>
 
33
#include <qradiobutton.h>
 
34
#include <qlayout.h>
 
35
#include <qcheckbox.h>
 
36
 
 
37
/* kde headers */
 
38
#include <kurlrequester.h>
 
39
#include <klocale.h>
 
40
#include <kdebug.h>
 
41
#include <kpassdlg.h>
 
42
 
 
43
/* knetworkmanager headers */
 
44
#include "knetworkmanager-accesspoint.h"
 
45
#include "knetworkmanager-wireless_device.h"
 
46
#include "knetworkmanager-device.h"
 
47
#include "knetworkmanager-connection.h"
 
48
#include "knetworkmanager-connection_setting_wireless_security_widget.h"
 
49
#include "knetworkmanager-connection_setting_wireless_security.h"
 
50
#include "knetworkmanager-connection_setting_wireless.h"
 
51
#include "knetworkmanager-connection_setting_8021x.h"
 
52
#include "sha1.h"
 
53
#include "md5.h"
 
54
#include "knetworkmanager-wireless_manager.h"
 
55
 
 
56
#define WPA_PMK_LEN 32
 
57
 
 
58
using namespace ConnectionSettings;
 
59
 
 
60
/*
 
61
        class WirelessSecurityWEPImpl
 
62
*/
 
63
WirelessSecurityWEPImpl::WirelessSecurityWEPImpl(WirelessSecurity* sec, QWidget* parent, const char* name, WFlags fl)
 
64
        : ConnectionSettingWirelessSecurityWEP(parent, name, fl)
 
65
        , _security_setting(sec)
 
66
        , _wepKeyType( WEPKEY_TYPE_HEX )
 
67
{
 
68
        cboAuthentication->insertItem(i18n("Open System"), 0);
 
69
        cboAuthentication->insertItem(i18n("Shared Key"), 1);
 
70
        if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_OPEN)
 
71
                cboAuthentication->setCurrentItem(0);
 
72
        else if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_SHARED)
 
73
                cboAuthentication->setCurrentItem(1);
 
74
 
 
75
        cbKeyType->insertItem(i18n("WEP 40/128-bit ASCII"), WEPKEY_TYPE_ASCII);
 
76
        cbKeyType->insertItem(i18n("WEP 40/128-bit Hexadecimal"), WEPKEY_TYPE_HEX);
 
77
        cbKeyType->insertItem(i18n("WEP 128-bit passphrase"), WEPKEY_TYPE_PASSPHRASE);
 
78
        cbKeyType->setCurrentItem(_wepKeyType );
 
79
 
 
80
        txtWEPKey0->setText(_security_setting->getWepKey(0));
 
81
        txtWEPKey1->setText(_security_setting->getWepKey(1));
 
82
        txtWEPKey2->setText(_security_setting->getWepKey(2));
 
83
        txtWEPKey3->setText(_security_setting->getWepKey(3));
 
84
 
 
85
        switch(_security_setting->getWepTxidx())
 
86
        {
 
87
                case 0:
 
88
                        rbKeyIdx0->setChecked(true);
 
89
                        break;
 
90
                case 1:
 
91
                        rbKeyIdx1->setChecked(true);
 
92
                        break;
 
93
                case 2:
 
94
                        rbKeyIdx2->setChecked(true);
 
95
                        break;
 
96
                case 3:
 
97
                        rbKeyIdx3->setChecked(true);
 
98
                        break;
 
99
                default:
 
100
                        rbKeyIdx0->setChecked(true);
 
101
                        break;
 
102
        }
 
103
 
 
104
        connect(cboAuthentication, SIGNAL(activated(int)), this, SLOT(slotAuthAlgChanged(int)));
 
105
        connect(cbKeyType, SIGNAL(activated(int)), this, SLOT(slotKeyTypeChanged(int)));
 
106
        connect(txtWEPKey0, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey0Changed(const QString&)));
 
107
        connect(txtWEPKey1, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey1Changed(const QString&)));
 
108
        connect(txtWEPKey2, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey2Changed(const QString&)));
 
109
        connect(txtWEPKey3, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey3Changed(const QString&)));
 
110
 
 
111
        connect(rbKeyIdx0, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx0Checked(bool)));
 
112
        connect(rbKeyIdx1, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx1Checked(bool)));
 
113
        connect(rbKeyIdx2, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx2Checked(bool)));
 
114
        connect(rbKeyIdx3, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx3Checked(bool)));
 
115
}
 
116
 
 
117
void WirelessSecurityWEPImpl::slotAuthAlgChanged(int index)
 
118
{
 
119
        if (index == 0)
 
120
                _security_setting->setAuthAlg(WirelessSecurity::AUTH_ALG_OPEN);
 
121
        else if (index == 1)
 
122
                _security_setting->setAuthAlg(WirelessSecurity::AUTH_ALG_SHARED);
 
123
}
 
124
 
 
125
void WirelessSecurityWEPImpl::slotKeyTypeChanged(int index)
 
126
{
 
127
        _wepKeyType = (WEPKEY_TYPE)index;
 
128
 
 
129
        // update all WEP-Keys here due to the new key_type
 
130
}
 
131
 
 
132
void WirelessSecurityWEPImpl::slotWepKey0Changed(const QString &key)
 
133
{
 
134
        QCString hashed = getHashedWEPKey(key, _wepKeyType);
 
135
        _security_setting->setWepKey(0, hashed);
 
136
}
 
137
 
 
138
void WirelessSecurityWEPImpl::slotWepKey1Changed(const QString &key)
 
139
{
 
140
        QCString hashed = getHashedWEPKey(key, _wepKeyType);
 
141
        _security_setting->setWepKey(1, hashed);
 
142
}
 
143
 
 
144
void WirelessSecurityWEPImpl::slotWepKey2Changed(const QString &key)
 
145
{
 
146
        QCString hashed = getHashedWEPKey(key, _wepKeyType);
 
147
        _security_setting->setWepKey(2, hashed);
 
148
}
 
149
 
 
150
void WirelessSecurityWEPImpl::slotWepKey3Changed(const QString& key)
 
151
{
 
152
        QCString hashed = getHashedWEPKey(key, _wepKeyType);
 
153
        _security_setting->setWepKey(3, hashed);
 
154
}
 
155
 
 
156
void WirelessSecurityWEPImpl::slotWepIdx0Checked(bool check)
 
157
{
 
158
        if (check)
 
159
                _security_setting->setWepTxidx(0);
 
160
}
 
161
 
 
162
void WirelessSecurityWEPImpl::slotWepIdx1Checked(bool check)
 
163
{
 
164
        if (check)
 
165
                _security_setting->setWepTxidx(1);
 
166
}
 
167
 
 
168
void WirelessSecurityWEPImpl::slotWepIdx2Checked(bool check)
 
169
{
 
170
        if (check)
 
171
                _security_setting->setWepTxidx(2);
 
172
}
 
173
 
 
174
void WirelessSecurityWEPImpl::slotWepIdx3Checked(bool check)
 
175
{
 
176
        if (check)
 
177
                _security_setting->setWepTxidx(3);
 
178
}
 
179
 
 
180
QCString
 
181
WirelessSecurityWEPImpl::getHashedWEPKey(QString key, WEPKEY_TYPE type) const
 
182
{
 
183
        QCString hashed;
 
184
        switch(type)
 
185
        {
 
186
                case WEPKEY_TYPE_HEX:
 
187
                        return QCString(key);
 
188
                        break;
 
189
                case WEPKEY_TYPE_ASCII:
 
190
                        hashed = String2Hex(QCString(key), key.length() * 2);
 
191
                        return hashed;
 
192
                        break;
 
193
                case WEPKEY_TYPE_PASSPHRASE:
 
194
                        return getWEP128PassphraseHash(QCString(key));
 
195
                        break;
 
196
        }
 
197
        return hashed;
 
198
}
 
199
 
 
200
QCString
 
201
WirelessSecurityWEPImpl::getWEP128PassphraseHash(QCString input) const
 
202
{
 
203
        char md5_data[65];
 
204
        QCString digest(16);
 
205
        int input_len;
 
206
        int i;
 
207
 
 
208
        if (input.isNull()) return input;
 
209
 
 
210
        input_len = input.length();
 
211
        if (input_len < 1)
 
212
                return QCString();
 
213
 
 
214
        /* Get at least 64 bytes */
 
215
        for (i = 0; i < 64; i++)
 
216
                md5_data [i] = input [i % input_len];
 
217
 
 
218
        /* Null terminate md5 seed data and hash it */
 
219
        md5_data[64] = 0;
 
220
        gnome_keyring_md5_string (md5_data, (unsigned char*)digest.data());
 
221
        return (String2Hex(QByteArray(digest), 26));
 
222
 
 
223
}
 
224
 
 
225
QCString
 
226
WirelessSecurityWEPImpl::String2Hex(QByteArray bytes, int final_len) const
 
227
{
 
228
        QCString result(final_len+1);
 
229
        static char hex_digits[] = "0123456789abcdef";
 
230
        result.resize(bytes.size() * 2 + 1);
 
231
        for (uint i = 0; i < bytes.size(); i++)
 
232
        {
 
233
                result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
 
234
                result[2*i+1] = hex_digits[bytes[i] & 0xf];
 
235
        }
 
236
        /* Cut converted key off at the correct length for this cipher type */
 
237
        if (final_len > -1)
 
238
                result[final_len] = '\0';
 
239
        return result;
 
240
}
 
241
 
 
242
 
 
243
/*
 
244
        class WirelessSecurityWEPEncryptionImpl
 
245
*/
 
246
WirelessSecurityWEPEncryptionImpl::WirelessSecurityWEPEncryptionImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
 
247
        : ConnectionSettingWirelessSecurityWEPEncryption(parent, name, fl)
 
248
        , _security_setting(security_setting)
 
249
{
 
250
        cboEncryption->insertItem(i18n("None"));
 
251
        cboEncryption->insertItem(i18n("Dynamic WEP"));
 
252
}
 
253
 
 
254
 
 
255
/*
 
256
        class WirelessSecurityWPAVersionImpl
 
257
*/
 
258
WirelessSecurityWPAVersionImpl::WirelessSecurityWPAVersionImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
 
259
        : ConnectionSettingWirelessSecurityWPAVersion(parent, name, fl)
 
260
        , _security_setting(security_setting)
 
261
{
 
262
        cbWPA->setChecked(_security_setting->getProto() & WirelessSecurity::PROTO_WPA);
 
263
        cbRSN->setChecked(_security_setting->getProto() & WirelessSecurity::PROTO_RSN);
 
264
 
 
265
        connect(cbWPA, SIGNAL(toggled(bool)), this, SLOT(slotWPA1(bool)));
 
266
        connect(cbRSN, SIGNAL(toggled(bool)), this, SLOT(slotWPA2(bool)));
 
267
 
 
268
        connect(grpUseWPAVersion, SIGNAL(toggled(bool)), this, SLOT(slotAuto(bool)));
 
269
}
 
270
 
 
271
void
 
272
WirelessSecurityWPAVersionImpl::slotAuto(bool on)
 
273
{
 
274
        if (!on)
 
275
        {
 
276
                // auto-select proto
 
277
                _security_setting->setProto(WirelessSecurity::PROTO_AUTO);
 
278
        }
 
279
        else
 
280
        {
 
281
                // use selected wpa-version
 
282
                Q_UINT32 proto = WirelessSecurity::PROTO_NONE;
 
283
                if (cbWPA->isChecked())
 
284
                        proto |= WirelessSecurity::PROTO_WPA;
 
285
                if (cbRSN->isChecked())
 
286
                        proto  |= WirelessSecurity::PROTO_RSN;
 
287
                _security_setting->setProto(proto);
 
288
        }
 
289
}
 
290
 
 
291
void
 
292
WirelessSecurityWPAVersionImpl::slotWPA1(bool on)
 
293
{
 
294
        if (on)
 
295
                _security_setting->addProto(WirelessSecurity::PROTO_WPA);
 
296
        else
 
297
                _security_setting->delProto(WirelessSecurity::PROTO_WPA);
 
298
}
 
299
 
 
300
void
 
301
WirelessSecurityWPAVersionImpl::slotWPA2(bool on)
 
302
{
 
303
        if (on)
 
304
                _security_setting->addProto(WirelessSecurity::PROTO_RSN);
 
305
        else
 
306
                _security_setting->delProto(WirelessSecurity::PROTO_RSN);
 
307
}
 
308
 
 
309
/*
 
310
        class WirelessSecurityWPACipherImpl
 
311
*/
 
312
WirelessSecurityWPACipherImpl::WirelessSecurityWPACipherImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
 
313
        : ConnectionSettingWirelessSecurityWPACipher(parent, name, fl)
 
314
        , _security_setting(security_setting)
 
315
{
 
316
        connect(grpUseCipher, SIGNAL(toggled(bool)), this, SLOT(slotCipherChangedAuto(bool)));
 
317
 
 
318
        connect(chkGroupCipherTKIP, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedTKIP(bool)));
 
319
        connect(chkGroupCipherCCMP, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedCCMP(bool)));
 
320
        connect(chkGroupCipherWEP40, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedWEP40(bool)));
 
321
        connect(chkGroupCipherWEP104, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedWEP104(bool)));
 
322
 
 
323
        connect(chkPairwiseCipherTKIP, SIGNAL(toggled(bool)), this, SLOT(slotPairwiseCipherChangedTKIP(bool)));
 
324
        connect(chkPairwiseCipherCCMP, SIGNAL(toggled(bool)), this, SLOT(slotPairwiseCipherChangedCCMP(bool)));
 
325
 
 
326
        chkPairwiseCipherCCMP->setChecked(_security_setting->getPairwiseCiphers() & WirelessSecurity::CIPHER_CCMP);
 
327
        chkPairwiseCipherTKIP->setChecked(_security_setting->getPairwiseCiphers() & WirelessSecurity::CIPHER_TKIP);
 
328
 
 
329
        chkGroupCipherCCMP->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_CCMP);
 
330
        chkGroupCipherTKIP->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_TKIP);
 
331
        chkGroupCipherWEP40->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_WEP40);
 
332
        chkGroupCipherWEP104->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_WEP104);
 
333
 
 
334
}
 
335
 
 
336
void
 
337
WirelessSecurityWPACipherImpl::slotCipherChangedAuto(bool checked)
 
338
{
 
339
        if (!checked)
 
340
        {
 
341
                // select auto for both ciphers
 
342
                _security_setting->setGroupCiphers(WirelessSecurity::CIPHER_AUTO);
 
343
                _security_setting->setPairwiseCiphers(WirelessSecurity::CIPHER_AUTO);
 
344
        }
 
345
        else
 
346
        {
 
347
                // use the already selected ciphers
 
348
 
 
349
                // group cipher
 
350
                Q_UINT32 cipher = WirelessSecurity::CIPHER_NONE;
 
351
                if (chkGroupCipherTKIP->isChecked())
 
352
                        cipher |= WirelessSecurity::CIPHER_TKIP;
 
353
                if (chkGroupCipherCCMP->isChecked())
 
354
                        cipher |= WirelessSecurity::CIPHER_CCMP;
 
355
                if (chkGroupCipherWEP40->isChecked())
 
356
                        cipher |= WirelessSecurity::CIPHER_WEP40;
 
357
                if (chkGroupCipherWEP104->isChecked())
 
358
                        cipher |= WirelessSecurity::CIPHER_WEP104;
 
359
                _security_setting->setGroupCiphers(cipher);
 
360
 
 
361
                // pairwise cipher
 
362
                cipher = WirelessSecurity::CIPHER_NONE;
 
363
                if (chkPairwiseCipherTKIP->isChecked())
 
364
                        cipher |= WirelessSecurity::CIPHER_TKIP;
 
365
                if (chkPairwiseCipherCCMP->isChecked())
 
366
                        cipher |= WirelessSecurity::CIPHER_CCMP;
 
367
                _security_setting->setPairwiseCiphers(cipher);
 
368
 
 
369
        }
 
370
}
 
371
 
 
372
void
 
373
WirelessSecurityWPACipherImpl::slotGroupCipherChangedTKIP(bool checked)
 
374
{
 
375
        if (checked)
 
376
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_TKIP);
 
377
        else
 
378
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_TKIP));
 
379
}
 
380
 
 
381
void
 
382
WirelessSecurityWPACipherImpl::slotGroupCipherChangedCCMP(bool checked)
 
383
{
 
384
        if (checked)
 
385
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_CCMP);
 
386
        else
 
387
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_CCMP));
 
388
}
 
389
 
 
390
void
 
391
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP40(bool checked)
 
392
{
 
393
        if (checked)
 
394
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_WEP40);
 
395
        else
 
396
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_WEP40));
 
397
}
 
398
 
 
399
void
 
400
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP104(bool checked)
 
401
{
 
402
        if (checked)
 
403
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_WEP104);
 
404
        else
 
405
                _security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_WEP104));
 
406
}
 
407
 
 
408
void
 
409
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedTKIP(bool checked)
 
410
{
 
411
        if (checked)
 
412
                _security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() | WirelessSecurity::CIPHER_TKIP);
 
413
        else
 
414
                _security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() & (!WirelessSecurity::CIPHER_TKIP));
 
415
}
 
416
 
 
417
void
 
418
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedCCMP(bool checked)
 
419
{
 
420
        if (checked)
 
421
                _security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() | WirelessSecurity::CIPHER_CCMP);
 
422
        else
 
423
                _security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() & (!WirelessSecurity::CIPHER_CCMP));
 
424
}
 
425
 
 
426
/*
 
427
        class WirelessSecurityWPAPSK
 
428
*/
 
429
WirelessSecurityWPAPSKImpl::WirelessSecurityWPAPSKImpl(WirelessSecurity* security_setting, Wireless* wireless_setting, QWidget* parent, const char* name, WFlags fl)
 
430
        : ConnectionSettingWirelessSecurityWPAPSK(parent, name, fl)
 
431
        , _security_setting(security_setting)
 
432
        , _wireless_setting(wireless_setting)
 
433
{
 
434
        txtPSK->setText(_security_setting->getPSK());
 
435
        connect(txtPSK, SIGNAL(textChanged(const QString&)), this, SLOT(slotPSKChanged(const QString&)));
 
436
}
 
437
 
 
438
void
 
439
WirelessSecurityWPAPSKImpl::slotPSKChanged(const QString& psk)
 
440
{
 
441
 
 
442
        if (_wireless_setting)
 
443
        {
 
444
                QCString hashed;
 
445
                if (psk.length() == 64)
 
446
                        hashed = psk;
 
447
                else
 
448
                {
 
449
                        QCString buffer(WPA_PMK_LEN * 2);
 
450
                        QByteArray essid = _wireless_setting->getEssid();
 
451
                        pbkdf2_sha1 (QCString(psk).data(), essid.data(), essid.size(), 4096, (uint8_t*)buffer.data(), WPA_PMK_LEN);
 
452
                        hashed = String2Hex(buffer, WPA_PMK_LEN*2);
 
453
                }
 
454
                _security_setting->setPSK(hashed);
 
455
        }
 
456
}
 
457
 
 
458
QCString
 
459
WirelessSecurityWPAPSKImpl::String2Hex(QByteArray bytes, int final_len) const
 
460
{
 
461
        QCString result(final_len+1);
 
462
        static char hex_digits[] = "0123456789abcdef";
 
463
        result.resize(bytes.size() * 2 + 1);
 
464
        for (uint i = 0; i < bytes.size(); i++)
 
465
        {
 
466
                result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
 
467
                result[2*i+1] = hex_digits[bytes[i] & 0xf];
 
468
        }
 
469
        /* Cut converted key off at the correct length for this cipher type */
 
470
        if (final_len > -1)
 
471
                result[final_len] = '\0';
 
472
        return result;
 
473
}
 
474
 
 
475
/*
 
476
        class WirelessSecurityEAPImpl
 
477
*/
 
478
WirelessSecurityEAPImpl::WirelessSecurityEAPImpl(IEEE8021x* security_setting, WirelessSecurityPhase2Impl* phase2_widget, QWidget* parent, const char* name, WFlags fl)
 
479
        : ConnectionSettingWirelessSecurityEAP(parent, name, fl)
 
480
        , _security_setting(security_setting)
 
481
        , _phase2_widget(phase2_widget)
 
482
{
 
483
        // insert all EAP-Methods
 
484
        int index = 0;
 
485
        cboMethod->insertItem(i18n("None"), index);
 
486
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_NONE;
 
487
 
 
488
        cboMethod->insertItem(i18n("TTLS"), ++index);
 
489
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_TTLS;
 
490
 
 
491
        cboMethod->insertItem(i18n("PEAP"), ++index);
 
492
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_PEAP;
 
493
 
 
494
        cboMethod->insertItem(i18n("TLS"), ++index);
 
495
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_TLS;
 
496
 
 
497
        cboMethod->insertItem(i18n("Leap"), ++index);
 
498
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_LEAP;
 
499
 
 
500
        cboMethod->insertItem(i18n("MD5"), ++index);
 
501
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_MD5;
 
502
 
 
503
        cboMethod->insertItem(i18n("FAST"), ++index);
 
504
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_FAST;
 
505
 
 
506
        cboMethod->insertItem(i18n("SIM"), ++index);
 
507
        _eapIndexMap[index] = IEEE8021x::EAP_PHASE1_SIM;
 
508
 
 
509
        // preselect the correct method
 
510
        QBiDirectionalMap<int, IEEE8021x::EAP_PHASE1>::Iterator it = _eapIndexMap.findData(_security_setting->getEAP());
 
511
        cboMethod->setCurrentItem(it.key());
 
512
 
 
513
        txtIdentity->setText(_security_setting->getIdentity());
 
514
        txtAnonIdentity->setText(_security_setting->getAnonIdentity());
 
515
        txtPassword->setText(_security_setting->getPassword());
 
516
 
 
517
        // get notified if the method changes
 
518
        connect(cboMethod, SIGNAL(activated(int)), this, SLOT(slotMethodChanged(int)));
 
519
        connect(txtIdentity, SIGNAL(textChanged(const QString&)), this, SLOT(slotIdentityChanged(const QString&)));
 
520
        connect(txtAnonIdentity, SIGNAL(textChanged(const QString&)), this, SLOT(slotAnonIdentityChanged(const QString&)));
 
521
        connect(txtPassword, SIGNAL(textChanged(const QString&)), this, SLOT(slotPasswordChanged(const QString&)));
 
522
}
 
523
 
 
524
void WirelessSecurityEAPImpl::slotMethodChanged(int index)
 
525
{
 
526
        // new method choosen
 
527
        IEEE8021x::EAP_PHASE1 eap = _eapIndexMap[index];
 
528
        _security_setting->setEAP(eap);
 
529
 
 
530
        _phase2_widget->setAllowedPhase2Methods(_security_setting->getAllowedPhase2Methods());
 
531
}
 
532
 
 
533
void WirelessSecurityEAPImpl::slotIdentityChanged(const QString& identity)
 
534
{
 
535
        _security_setting->setIdentity(identity);
 
536
}
 
537
 
 
538
void WirelessSecurityEAPImpl::slotAnonIdentityChanged(const QString& identity)
 
539
{
 
540
        _security_setting->setAnonIdentity(identity);
 
541
}
 
542
 
 
543
void WirelessSecurityEAPImpl::slotPasswordChanged(const QString& pwd)
 
544
{
 
545
        _security_setting->setPassword(QString(txtPassword->password()));
 
546
}
 
547
 
 
548
/*
 
549
        class WirelessSecurityPhase2Impl
 
550
*/
 
551
WirelessSecurityPhase2Impl::WirelessSecurityPhase2Impl(IEEE8021x* security_setting, QWidget* parent, const char* name, WFlags fl)
 
552
        : ConnectionSettingWirelessSecurityPhase2(parent, name, fl)
 
553
        , _security_setting(security_setting)
 
554
{
 
555
        _allowed_methods.append(IEEE8021x::EAP_PHASE2_AUTH_NONE);
 
556
        updateMethodComboBox();
 
557
 
 
558
        connect(cboPhase2Method, SIGNAL(activated(int)), this, SLOT(slotPhase2MethodChanged(int)));
 
559
}
 
560
 
 
561
void WirelessSecurityPhase2Impl::updateMethodComboBox()
 
562
{
 
563
        // insert all phase2 EAP-Methods
 
564
        int index = 0;
 
565
        cboPhase2Method->clear();
 
566
        _eapIndexMap.clear();
 
567
 
 
568
        for (QValueList<IEEE8021x::EAP_PHASE2>::Iterator it = _allowed_methods.begin(); it != _allowed_methods.end(); ++it)
 
569
        {
 
570
                if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_NONE)
 
571
                {
 
572
                        cboPhase2Method->insertItem(i18n("None"), index);
 
573
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_NONE;
 
574
                        index++;
 
575
                }
 
576
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MSCHAPV2)
 
577
                {
 
578
                        cboPhase2Method->insertItem(i18n("MSCHAPv2"), index);
 
579
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MSCHAPV2;
 
580
                        index++;
 
581
                }
 
582
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_PAP)
 
583
                {       
 
584
                        cboPhase2Method->insertItem(i18n("PAP"), index);
 
585
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_PAP;
 
586
                        index++;
 
587
                }
 
588
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_CHAP)
 
589
                {
 
590
                        cboPhase2Method->insertItem(i18n("CHAP"), index);
 
591
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_CHAP;
 
592
                        index++;
 
593
                }
 
594
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MSCHAP)
 
595
                {
 
596
                        cboPhase2Method->insertItem(i18n("MSCHAP"), index);
 
597
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MSCHAP;
 
598
                        index++;
 
599
                }
 
600
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_GTC)
 
601
                {
 
602
                        cboPhase2Method->insertItem(i18n("GTC"), index);
 
603
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_GTC;
 
604
                        index++;
 
605
                }
 
606
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_OTP)
 
607
                {
 
608
                        cboPhase2Method->insertItem(i18n("OTP"), index);
 
609
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_OTP;
 
610
                        index++;
 
611
                }
 
612
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MD5)
 
613
                {
 
614
                        cboPhase2Method->insertItem(i18n("MD5"), index);
 
615
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MD5;
 
616
                        index++;
 
617
                }
 
618
                else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_TLS)
 
619
                {
 
620
                        cboPhase2Method->insertItem(i18n("TLS"), index);
 
621
                        _eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_TLS;
 
622
                        index++;
 
623
                }
 
624
        }
 
625
 
 
626
        // preselect the correct method
 
627
        QBiDirectionalMap<int, IEEE8021x::EAP_PHASE2>::Iterator it = _eapIndexMap.findData(_security_setting->getPhase2EAP());
 
628
        if (it != _eapIndexMap.end())
 
629
        {
 
630
                cboPhase2Method->setCurrentItem(it.key());
 
631
                _security_setting->setPhase2EAP(it.data());
 
632
        }
 
633
        else
 
634
        {
 
635
                cboPhase2Method->setCurrentItem(0);
 
636
                _security_setting->setPhase2EAP(_eapIndexMap[0]);
 
637
        }
 
638
}
 
639
 
 
640
void WirelessSecurityPhase2Impl::setAllowedPhase2Methods(const QValueList<IEEE8021x::EAP_PHASE2>& list)
 
641
{
 
642
        _allowed_methods = list;
 
643
        updateMethodComboBox();
 
644
}
 
645
 
 
646
void WirelessSecurityPhase2Impl::slotPhase2MethodChanged(int index)
 
647
{
 
648
        // new method choosen
 
649
        IEEE8021x::EAP_PHASE2 eap = _eapIndexMap[index];
 
650
        _security_setting->setPhase2EAP(eap);
 
651
}
 
652
 
 
653
/*
 
654
        class WirelessSecurityWidgetImpl
 
655
*/
 
656
 
 
657
WirelessSecurityWidgetImpl::WirelessSecurityWidgetImpl(Connection* conn, bool new_conn, QWidget* parent, const char* name, WFlags fl)
 
658
        : WidgetInterface(parent, name, fl)
 
659
{
 
660
        _security_setting = dynamic_cast<WirelessSecurity*> (conn->getSetting(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME));
 
661
        _wireless_setting = dynamic_cast<Wireless*> (conn->getSetting(NM_SETTING_WIRELESS_SETTING_NAME));
 
662
        _ieee8021x_setting = dynamic_cast<IEEE8021x*> (conn->getSetting(NM_SETTING_802_1X_SETTING_NAME));
 
663
        _new_conn = new_conn;
 
664
 
 
665
        QVBoxLayout* layout = new QVBoxLayout(this, 1, 1);
 
666
        _mainWid = new ConnectionSettingWirelessSecurityWidget(this);
 
667
        layout->addWidget(_mainWid);
 
668
 
 
669
        QTimer::singleShot(0, this, SLOT(slotInit()));  
 
670
}
 
671
 
 
672
void
 
673
WirelessSecurityWidgetImpl::slotInit()
 
674
{
 
675
        // create all security widgets...
 
676
        QWidget* wep = new WirelessSecurityWEPImpl(_security_setting, _mainWid->groupUseEncryption);
 
677
        QWidget* phase2 = new WirelessSecurityPhase2Impl(_ieee8021x_setting, _mainWid->groupUseEncryption);
 
678
        QWidget* eap = new WirelessSecurityEAPImpl(_ieee8021x_setting, (WirelessSecurityPhase2Impl*)phase2, _mainWid->groupUseEncryption);
 
679
        QWidget* wpaversion = new WirelessSecurityWPAVersionImpl(_security_setting, _mainWid->groupUseEncryption);
 
680
        QWidget* wpacipher = new WirelessSecurityWPACipherImpl(_security_setting, _mainWid->groupUseEncryption);
 
681
        QWidget* wpapsk = new WirelessSecurityWPAPSKImpl(_security_setting, _wireless_setting, _mainWid->groupUseEncryption);
 
682
        QWidget* wepencryption = new WirelessSecurityWEPEncryptionImpl(_security_setting, _mainWid->groupUseEncryption);
 
683
 
 
684
        wep->setHidden(true);
 
685
        eap->setHidden(true);
 
686
        wpaversion->setHidden(true);
 
687
        wpacipher->setHidden(true);
 
688
        phase2->setHidden(true);
 
689
        wpapsk->setHidden(true);
 
690
        wepencryption->setHidden(true);
 
691
 
 
692
        _widgets[SECURITY_WEP].clear();
 
693
        _widgets[SECURITY_WPA_PSK].clear();
 
694
        _widgets[SECURITY_WPA_EAP].clear();
 
695
        _widgets[SECURITY_IEEE8021X].clear();
 
696
 
 
697
        // create WEP widget list
 
698
        _widgets[SECURITY_WEP].append(wep);
 
699
 
 
700
        // create WPA PSK widget list
 
701
        _extra_widgets[SECURITY_WPA_PSK].append(wpaversion);
 
702
        _extra_widgets[SECURITY_WPA_PSK].append(wpacipher);
 
703
        _widgets[SECURITY_WPA_PSK].append(wpapsk);
 
704
 
 
705
        // create WPA EAP widget list
 
706
        _extra_widgets[SECURITY_WPA_EAP].append(wpaversion);
 
707
        _extra_widgets[SECURITY_WPA_EAP].append(wpacipher);
 
708
        _widgets[SECURITY_WPA_EAP].append(eap);
 
709
        _widgets[SECURITY_WPA_EAP].append(phase2);
 
710
 
 
711
        // create IEEE8021X widget list
 
712
        _widgets[SECURITY_IEEE8021X].append(wepencryption);
 
713
        _widgets[SECURITY_IEEE8021X].append(eap);
 
714
 
 
715
        connect(_mainWid->cboSecurity, SIGNAL(activated(int)), this, SLOT(slotComboSecurityActivated(int)));
 
716
        connect(_mainWid->groupUseEncryption, SIGNAL(toggled(bool)), this, SLOT(slotUseEncryptionToggled(bool)));
 
717
        connect(_mainWid->pbExtra, SIGNAL(toggled(bool)), this, SLOT(slotExtraSettingsToggled(bool)));
 
718
 
 
719
}
 
720
 
 
721
void
 
722
WirelessSecurityWidgetImpl::Activate()
 
723
{
 
724
        printf("Activate %s\n", _new_conn ? "New" : "Edit");
 
725
        comboSecurityInit();
 
726
}
 
727
 
 
728
void
 
729
WirelessSecurityWidgetImpl::comboSecurityInit()
 
730
{
 
731
        int index = 0;
 
732
 
 
733
        QValueList<SecurityMethods> allowed_methods;
 
734
        _mainWid->cboSecurity->clear();
 
735
 
 
736
        // TODO: Preselect the right security method
 
737
        // We should have an Essid already, fetch all possible APs
 
738
        QValueList<AccessPoint *> aps;
 
739
        if (_new_conn && !_wireless_setting->getEssid().isEmpty())
 
740
        {
 
741
                aps = WirelessManager::getAccessPointsForEssid(_wireless_setting->getEssid());
 
742
#if 0
 
743
                printf("Hugo %s\n", QString(QCString(_wireless_setting->getEssid())).ascii());
 
744
#endif
 
745
        }
 
746
        if (!aps.isEmpty())
 
747
        {
 
748
                // if at least one AP has this security setting show the entry in the combobox
 
749
                for (QValueList<AccessPoint*>::Iterator it = aps.begin(); it != aps.end(); ++it)
 
750
                {
 
751
                        if((*it)->isEncrypted())
 
752
                        {
 
753
                                printf("AP %s is encrypted\n", (*it)->getDisplaySsid().ascii());
 
754
                                if ((*it)->getRsnFlags() != NM_802_11_AP_SEC_NONE || (*it)->getWpaFlags() != NM_802_11_AP_SEC_NONE)
 
755
                                {
 
756
                                        // WPA or RSN
 
757
                                        if ((*it)->getRsnFlags() & NM_802_11_AP_SEC_KEY_MGMT_PSK || (*it)->getWpaFlags() & NM_802_11_AP_SEC_KEY_MGMT_PSK)
 
758
                                                if (!allowed_methods.contains(SECURITY_WPA_PSK))
 
759
                                                        allowed_methods.append(SECURITY_WPA_PSK);
 
760
 
 
761
                        
 
762
                                        if ((*it)->getRsnFlags() & NM_802_11_AP_SEC_KEY_MGMT_802_1X || (*it)->getWpaFlags() & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
 
763
                                                if (!allowed_methods.contains(SECURITY_WPA_EAP))
 
764
                                                        allowed_methods.append(SECURITY_WPA_EAP);
 
765
                                }
 
766
 
 
767
                                // No WPA & RSN => WEP or dynamic WEP with 802.1x authentication
 
768
                                // TODO: an AP can provide WEP in addition to WPA
 
769
                                if (!allowed_methods.contains(SECURITY_WEP))
 
770
                                        allowed_methods.append(SECURITY_WEP);
 
771
                                if (!allowed_methods.contains(SECURITY_IEEE8021X))
 
772
                                        allowed_methods.append(SECURITY_IEEE8021X);             
 
773
                        }
 
774
                }
 
775
 
 
776
                // insert only allowed security methods
 
777
                if (allowed_methods.contains(SECURITY_WPA_PSK))
 
778
                {
 
779
                        _securityComboMap.insert(index, SECURITY_WPA_PSK);
 
780
                        _mainWid->cboSecurity->insertItem(i18n("WPA Personal"), index++);
 
781
                }
 
782
 
 
783
                if (allowed_methods.contains(SECURITY_WPA_EAP))
 
784
                {
 
785
                        _securityComboMap.insert(index, SECURITY_WPA_EAP);
 
786
                        _mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), index++);
 
787
                }
 
788
 
 
789
                if (allowed_methods.contains(SECURITY_WEP))
 
790
                {
 
791
                        _securityComboMap.insert(index, SECURITY_WEP);
 
792
                        _mainWid->cboSecurity->insertItem(i18n("WEP"), index++);
 
793
                }
 
794
 
 
795
                if (allowed_methods.contains(SECURITY_IEEE8021X))
 
796
                {
 
797
                        _securityComboMap.insert(index, SECURITY_IEEE8021X);
 
798
                        _mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), index++);
 
799
                }
 
800
        }
 
801
        else
 
802
        {
 
803
                // insert all possible authentication methods
 
804
                _mainWid->cboSecurity->insertItem(i18n("WEP"),SECURITY_WEP );
 
805
                _mainWid->cboSecurity->insertItem(i18n("WPA Personal"), SECURITY_WPA_PSK);
 
806
                _mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), SECURITY_WPA_EAP);
 
807
                _mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), SECURITY_IEEE8021X);
 
808
                _securityComboMap.insert(SECURITY_WEP, SECURITY_WEP);
 
809
                _securityComboMap.insert(SECURITY_WPA_PSK, SECURITY_WPA_PSK);
 
810
                _securityComboMap.insert(SECURITY_WPA_EAP, SECURITY_WPA_EAP);
 
811
                _securityComboMap.insert(SECURITY_IEEE8021X, SECURITY_IEEE8021X);
 
812
        }
 
813
 
 
814
        if (!_new_conn)
 
815
        {
 
816
                switch(_security_setting->getKeyMgmt())
 
817
                {
 
818
                        case WirelessSecurity::KEY_MGMT_NONE:
 
819
                                if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_SHARED ||
 
820
                                    !_security_setting->getWepKey(0).isEmpty() ||
 
821
                                    !_security_setting->getWepKey(1).isEmpty() ||
 
822
                                    !_security_setting->getWepKey(2).isEmpty() ||
 
823
                                    !_security_setting->getWepKey(3).isEmpty() )
 
824
                                {
 
825
                                        _mainWid->groupUseEncryption->setChecked(true);
 
826
                                        _mainWid->cboSecurity->setCurrentItem(SECURITY_WEP);
 
827
                                        slotComboSecurityActivated(_securityComboMap[SECURITY_WEP]);
 
828
                                }
 
829
                                else
 
830
                                        _mainWid->groupUseEncryption->setChecked(false);
 
831
                                break;
 
832
                        case WirelessSecurity::KEY_MGMT_WPA_PSK:
 
833
                                _mainWid->groupUseEncryption->setChecked(true);
 
834
                                _mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_PSK);
 
835
                                slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_PSK]);
 
836
                                break;
 
837
                        case WirelessSecurity::KEY_MGMT_WPA_EAP:
 
838
                                _mainWid->groupUseEncryption->setChecked(true);
 
839
                                _mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_EAP);
 
840
                                slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_EAP]);
 
841
                                break;
 
842
                        case WirelessSecurity::KEY_MGMT_IEEE8021X:
 
843
                                _mainWid->groupUseEncryption->setChecked(true);
 
844
                                _mainWid->cboSecurity->setCurrentItem(SECURITY_IEEE8021X);
 
845
                                slotComboSecurityActivated(_securityComboMap[SECURITY_IEEE8021X]);
 
846
                                break;
 
847
 
 
848
                        default:
 
849
                                break;
 
850
                }
 
851
        }
 
852
        else
 
853
        {
 
854
                // select first possible security method
 
855
                if (_mainWid->cboSecurity->count() > 0)
 
856
                {
 
857
                        _mainWid->groupUseEncryption->setChecked(true);
 
858
                        _mainWid->groupUseEncryption->setEnabled(true);
 
859
                        _mainWid->cboSecurity->setCurrentItem(0);
 
860
                        slotComboSecurityActivated(0);
 
861
                }
 
862
                else
 
863
                {
 
864
                        _mainWid->groupUseEncryption->setChecked(false);
 
865
                        _mainWid->groupUseEncryption->setEnabled(false);
 
866
                }
 
867
        }
 
868
}
 
869
 
 
870
void
 
871
WirelessSecurityWidgetImpl::slotUseEncryptionToggled(bool on)
 
872
{
 
873
        _wireless_setting->setSecurity(on ? _security_setting->getType() : NULL);
 
874
}
 
875
 
 
876
void
 
877
WirelessSecurityWidgetImpl::slotComboSecurityActivated(int index)
 
878
{
 
879
        int i = _securityComboMap[index];
 
880
 
 
881
        // authentication switched, we have to show the appropriate widgets and hide some others
 
882
        switch(i)
 
883
        {
 
884
                case SECURITY_WEP:
 
885
                        configureForWEP();
 
886
                        break;
 
887
 
 
888
                case SECURITY_WPA_PSK:
 
889
                        configureForWPAPSK();
 
890
                        break;
 
891
 
 
892
                case SECURITY_WPA_EAP:
 
893
                        configureForWPAEAP();
 
894
                        break;
 
895
 
 
896
                case SECURITY_IEEE8021X:
 
897
                        configureForIEEE8021X();
 
898
                        break;
 
899
 
 
900
                default:
 
901
                        // should not happen, something is broken...
 
902
                        break;
 
903
        }
 
904
}
 
905
 
 
906
void
 
907
WirelessSecurityWidgetImpl::configureWidgets(SecurityMethods method)
 
908
{
 
909
        // store selected method
 
910
        _currentMethod = method;
 
911
 
 
912
        for (int i = 0; i < SECURITY_COUNT; ++i)
 
913
        {
 
914
                // remove all current widgets that do not belong to the selected method
 
915
                if (i != method)
 
916
                {
 
917
                        for (QValueList<QWidget*>::iterator it = _widgets[i].begin(); it != _widgets[i].end(); ++it)
 
918
                        {
 
919
                                _mainWid->groupUseEncryption->layout()->remove(*it);
 
920
                                (*it)->hide();
 
921
                        }
 
922
                        // remove extra widgets too
 
923
                        for (QValueList<QWidget*>::iterator it = _extra_widgets[i].begin(); it != _extra_widgets[i].end(); ++it)
 
924
                        {
 
925
                                _mainWid->groupUseEncryption->layout()->remove(*it);
 
926
                                (*it)->hide();
 
927
                        }
 
928
                }
 
929
        }
 
930
 
 
931
        // show all widgets widgets for the selected security method
 
932
        for (QValueList<QWidget*>::iterator it = _widgets[method].begin(); it != _widgets[method].end(); ++it)
 
933
        {
 
934
                _mainWid->groupUseEncryption->layout()->add(*it);
 
935
                (*it)->show();
 
936
        }
 
937
 
 
938
        if (_mainWid->pbExtra->isOn())
 
939
                for (QValueList<QWidget*>::iterator it = _extra_widgets[method].begin(); it != _extra_widgets[method].end(); ++it)
 
940
                {
 
941
                        _mainWid->groupUseEncryption->layout()->add(*it);
 
942
                        (*it)->show();
 
943
                }
 
944
 
 
945
        // deactivate button if no extra settings are available
 
946
        _mainWid->pbExtra->setEnabled(!(_extra_widgets[method].begin() == _extra_widgets[method].end()));
 
947
}
 
948
 
 
949
void
 
950
WirelessSecurityWidgetImpl::slotExtraSettingsToggled(bool on)
 
951
{
 
952
        if (on)
 
953
                for (QValueList<QWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
 
954
                {
 
955
                        _mainWid->groupUseEncryption->layout()->add(*it);
 
956
                        (*it)->show();
 
957
                }
 
958
        else
 
959
                for (QValueList<QWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
 
960
                {
 
961
                        _mainWid->groupUseEncryption->layout()->remove(*it);
 
962
                        (*it)->hide();
 
963
                }
 
964
}
 
965
 
 
966
void
 
967
WirelessSecurityWidgetImpl::configureForWEP()
 
968
{
 
969
        _security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_NONE);
 
970
        configureWidgets(SECURITY_WEP);
 
971
}
 
972
 
 
973
void
 
974
WirelessSecurityWidgetImpl::configureForWPAPSK()
 
975
{
 
976
        _security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_WPA_PSK);
 
977
        configureWidgets(SECURITY_WPA_PSK);
 
978
}
 
979
 
 
980
void
 
981
WirelessSecurityWidgetImpl::configureForWPAEAP()
 
982
{
 
983
        _security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_WPA_EAP);
 
984
        configureWidgets(SECURITY_WPA_EAP);
 
985
}
 
986
 
 
987
void
 
988
WirelessSecurityWidgetImpl::configureForIEEE8021X()
 
989
{
 
990
        _security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_IEEE8021X);
 
991
        configureWidgets(SECURITY_IEEE8021X);
 
992
}
 
993
 
 
994
 
 
995
 
 
996
 
 
997
#include "knetworkmanager-connection_setting_wireless_security_widget.moc"