summaryrefslogtreecommitdiffstats
path: root/tdenetworkmanager/src/configwidgets/tdenetman-connection_setting_wireless_security_widget.cpp
blob: e1c8fac12303638fca26fd5bb9c370531d1f11be (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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
/***************************************************************************
 *
 * tdenetman-connection_setting_wireless_security_widget.cpp
 * - A NetworkManager frontend for TDE
 *
 * Copyright (C) 2005, 2006 Novell, Inc.
 *
 * Author: Helmut Schaa <hschaa@suse.de>, <Helmut.Schaa@gmx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

/* qt headers */
#include <tqwidget.h>
#include <tqlineedit.h>
#include <tqgroupbox.h>
#include <tqbuttongroup.h>
#include <tqwidgetstack.h>
#include <tqcombobox.h>
#include <tqradiobutton.h>
#include <tqlayout.h>
#include <tqcheckbox.h>

/* kde headers */
#include <kurlrequester.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <kpassdlg.h>
#include <kmdcodec.h>

/* tdenetman headers */
#include "tdenetman-connection_setting_wireless_security_widget.h"
#include "sha1.h"
#include "tdenetman-wireless_manager.h"

#define WPA_PMK_LEN 32

#define SET_FLAG_IF_TRUE_CLEAR_IF_FALSE(x,y,z)		{					\
								if (z) {			\
									x |= y;			\
								}				\
								else {				\
									x &= (~y);		\
								}				\
							}

using namespace ConnectionSettings;

/*
	class WirelessSecurityWEPImpl
*/
WirelessSecurityWEPImpl::WirelessSecurityWEPImpl(TDEWiFiConnection* sec, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityWEP(parent, name, fl)
	, _security_setting(sec)
	, _wepKeyType( WEPKEY_TYPE_HEX )
{
	_parentdialog = connsettings;

	cboAuthentication->insertItem(i18n("Open System"), 0);
	cboAuthentication->insertItem(i18n("Shared Key"), 1);
	if (_security_setting->securitySettings.authType == TDENetworkWiFiAuthType::Open) {
		cboAuthentication->setCurrentItem(0);
	}
	else if (_security_setting->securitySettings.authType == TDENetworkWiFiAuthType::Shared) {
		cboAuthentication->setCurrentItem(1);
	}
	else {
		// Set up defaults
		_security_setting->securitySettings.authType = TDENetworkWiFiAuthType::Open;
		cboAuthentication->setCurrentItem(0);
	}

	cbKeyType->insertItem(i18n("WEP 40/128-bit ASCII"), WEPKEY_TYPE_ASCII);
	cbKeyType->insertItem(i18n("WEP 40/128-bit Hexadecimal"), WEPKEY_TYPE_HEX);
	cbKeyType->insertItem(i18n("WEP 128-bit passphrase"), WEPKEY_TYPE_PASSPHRASE);
	cbKeyType->setCurrentItem( _wepKeyType );

	if (_security_setting->securitySettings.authType == TDENetworkWiFiAuthType::Other) {
		// Set up defaults
		_security_setting->securitySettings.wepKeyType = TDENetworkWepKeyType::Hexadecimal;
		cbKeyType->setCurrentItem(WEPKEY_TYPE_HEX);
	}

	txtWEPKey0->setText(_security_setting->securitySettings.wepKey0);
	txtWEPKey1->setText(_security_setting->securitySettings.wepKey1);
	txtWEPKey2->setText(_security_setting->securitySettings.wepKey2);
	txtWEPKey3->setText(_security_setting->securitySettings.wepKey3);

	switch(_security_setting->securitySettings.wepKeyIndex)
	{
		case 0:
			rbKeyIdx0->setChecked(true);
			break;
		case 1:
			rbKeyIdx1->setChecked(true);
			break;
		case 2:
			rbKeyIdx2->setChecked(true);
			break;
		case 3:
			rbKeyIdx3->setChecked(true);
			break;
		default:
			rbKeyIdx0->setChecked(true);
			break;
	}

	connect(cboAuthentication, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotAuthAlgChanged(int)));
	connect(cbKeyType, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotKeyTypeChanged(int)));
	connect(txtWEPKey0, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotWepKey0Changed(const TQString&)));
	connect(txtWEPKey1, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotWepKey1Changed(const TQString&)));
	connect(txtWEPKey2, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotWepKey2Changed(const TQString&)));
	connect(txtWEPKey3, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotWepKey3Changed(const TQString&)));

	connect(rbKeyIdx0, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWepIdx0Checked(bool)));
	connect(rbKeyIdx1, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWepIdx1Checked(bool)));
	connect(rbKeyIdx2, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWepIdx2Checked(bool)));
	connect(rbKeyIdx3, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWepIdx3Checked(bool)));
}

void WirelessSecurityWEPImpl::slotAuthAlgChanged(int index)
{
	if (index == 0) {
		_security_setting->securitySettings.authType = TDENetworkWiFiAuthType::Open;
	}
	else if (index == 1) {
		_security_setting->securitySettings.authType = TDENetworkWiFiAuthType::Shared;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotKeyTypeChanged(int index)
{
	_wepKeyType = (WEPKEY_TYPE)index;

	if (index == WEPKEY_TYPE_ASCII) {
		_security_setting->securitySettings.wepKeyType = TDENetworkWepKeyType::Ascii;
	}
	else if (index == WEPKEY_TYPE_HEX) {
		_security_setting->securitySettings.wepKeyType = TDENetworkWepKeyType::Hexadecimal;
	}
	else if (index == WEPKEY_TYPE_PASSPHRASE) {
		_security_setting->securitySettings.wepKeyType = TDENetworkWepKeyType::Passphrase;
	}
	_security_setting->securitySettings.secretsValid = true;

	// update all WEP-Keys here due to the new key_type

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepKey0Changed(const TQString &key)
{
	TQCString hashed = getHashedWEPKey(key, _wepKeyType);
	_security_setting->securitySettings.wepKey0 = hashed;
	_security_setting->securitySettings.secretsValid = true;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepKey1Changed(const TQString &key)
{
	TQCString hashed = getHashedWEPKey(key, _wepKeyType);
	_security_setting->securitySettings.wepKey1 = hashed;
	_security_setting->securitySettings.secretsValid = true;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepKey2Changed(const TQString &key)
{
	TQCString hashed = getHashedWEPKey(key, _wepKeyType);
	_security_setting->securitySettings.wepKey2 = hashed;
	_security_setting->securitySettings.secretsValid = true;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepKey3Changed(const TQString& key)
{
	TQCString hashed = getHashedWEPKey(key, _wepKeyType);
	_security_setting->securitySettings.wepKey3 = hashed;
	_security_setting->securitySettings.secretsValid = true;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepIdx0Checked(bool check)
{
	if (check) {
		_security_setting->securitySettings.wepKeyIndex = 0;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepIdx1Checked(bool check)
{
	if (check) {
		_security_setting->securitySettings.wepKeyIndex = 1;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepIdx2Checked(bool check)
{
	if (check) {
		_security_setting->securitySettings.wepKeyIndex = 2;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityWEPImpl::slotWepIdx3Checked(bool check)
{
	if (check) {
		_security_setting->securitySettings.wepKeyIndex = 3;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

TQCString
WirelessSecurityWEPImpl::getHashedWEPKey(TQString key, WEPKEY_TYPE type) const
{
	TQCString hashed;
	switch(type)
	{
		case WEPKEY_TYPE_HEX:
			return TQCString(key);
			break;
		case WEPKEY_TYPE_ASCII:
			hashed = String2Hex(TQCString(key), key.length() * 2);
			return hashed;
			break;
		case WEPKEY_TYPE_PASSPHRASE:
			return TQCString(key);
			break;
	}
	return hashed;
}

TQCString
WirelessSecurityWEPImpl::getWEP128PassphraseHash(TQCString input) const
{
	char md5_data[65];
	int input_len;
	int i;

	if (input.isNull()) return input;

	input_len = input.length();
	if (input_len < 1)
		return TQCString();

	/* Get at least 64 bytes */
	for (i = 0; i < 64; i++)
		md5_data [i] = input [i % input_len];

	/* Null terminate md5 seed data and hash it */
	md5_data[64] = 0;
	KMD5 context(md5_data);
	return (String2Hex(context.hexDigest(), 26));

}

TQCString
WirelessSecurityWEPImpl::String2Hex(TQByteArray bytes, int final_len) const
{
	TQCString result(final_len+1);
	static char hex_digits[] = "0123456789abcdef";
	result.resize(bytes.size() * 2 + 1);
	for (uint i = 0; i < bytes.size(); i++)
	{
		result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
		result[2*i+1] = hex_digits[bytes[i] & 0xf];
	}
	/* Cut converted key off at the correct length for this cipher type */
	if (final_len > -1)
		result[final_len] = '\0';
	return result;
}


/*
	class WirelessSecurityWEPEncryptionImpl
*/
WirelessSecurityWEPEncryptionImpl::WirelessSecurityWEPEncryptionImpl(TDEWiFiConnection* security_setting, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityWEPEncryption(parent, name, fl)
	, _security_setting(security_setting)
{
	_parentdialog = connsettings;

	cboEncryption->insertItem(i18n("None"));
	cboEncryption->insertItem(i18n("Dynamic WEP"));
}


/*
	class WirelessSecurityWPAVersionImpl
*/
WirelessSecurityWPAVersionImpl::WirelessSecurityWPAVersionImpl(TDEWiFiConnection* security_setting, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityWPAVersion(parent, name, fl)
	, _security_setting(security_setting)
{
	_parentdialog = connsettings;

	cbWPA->setChecked(_security_setting->securitySettings.wpaVersion & TDENetworkWiFiWPAVersionFlags::WPA);
	cbRSN->setChecked(_security_setting->securitySettings.wpaVersion & TDENetworkWiFiWPAVersionFlags::RSN);

	connect(cbWPA, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWPA1(bool)));
	connect(cbRSN, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotWPA2(bool)));

	connect(grpUseWPAVersion, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotAuto(bool)));
}

void
WirelessSecurityWPAVersionImpl::slotAuto(bool on)
{
	if (!on) {
		// auto-select proto
		_security_setting->securitySettings.wpaVersion = TDENetworkWiFiWPAVersionFlags::Any;
	}
	else {
		// use selected wpa-version
		TDENetworkWiFiWPAVersionFlags::TDENetworkWiFiWPAVersionFlags proto = TDENetworkWiFiWPAVersionFlags::None;
		if (cbWPA->isChecked()) {
			proto |= TDENetworkWiFiWPAVersionFlags::WPA;
		}
		if (cbRSN->isChecked()) {
			proto |= TDENetworkWiFiWPAVersionFlags::RSN;
		}
		_security_setting->securitySettings.wpaVersion = proto;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPAVersionImpl::slotWPA1(bool on)
{
	SET_FLAG_IF_TRUE_CLEAR_IF_FALSE(_security_setting->securitySettings.wpaVersion, TDENetworkWiFiWPAVersionFlags::WPA, on);

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPAVersionImpl::slotWPA2(bool on)
{
	SET_FLAG_IF_TRUE_CLEAR_IF_FALSE(_security_setting->securitySettings.wpaVersion, TDENetworkWiFiWPAVersionFlags::RSN, on);

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

/*
	class WirelessSecurityWPACipherImpl
*/
WirelessSecurityWPACipherImpl::WirelessSecurityWPACipherImpl(TDEWiFiConnection* security_setting, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityWPACipher(parent, name, fl)
	, _security_setting(security_setting)
{
	_parentdialog = connsettings;

	connect(grpUseCipher, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotCipherChangedAuto(bool)));

	connect(chkGroupCipherTKIP, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotGroupCipherChangedTKIP(bool)));
	connect(chkGroupCipherCCMP, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotGroupCipherChangedCCMP(bool)));
	connect(chkGroupCipherWEP40, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotGroupCipherChangedWEP40(bool)));
	connect(chkGroupCipherWEP104, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotGroupCipherChangedWEP104(bool)));

	connect(chkPairwiseCipherTKIP, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotPairwiseCipherChangedTKIP(bool)));
	connect(chkPairwiseCipherCCMP, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotPairwiseCipherChangedCCMP(bool)));

	chkPairwiseCipherCCMP->setChecked(_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherCCMP));
	chkPairwiseCipherTKIP->setChecked(_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherTKIP));

	chkGroupCipherCCMP->setChecked(_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherCCMP));
	chkGroupCipherTKIP->setChecked(_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherTKIP));
	chkGroupCipherWEP40->setChecked(_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherWEP40));
	chkGroupCipherWEP104->setChecked(_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::Any) || _security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherWEP104));
}

void
WirelessSecurityWPACipherImpl::slotCipherChangedAuto(bool checked)
{
	if (!checked)
	{
		// select auto for both ciphers
		_security_setting->securitySettings.allowedGroupWiseCiphers.clear();
		_security_setting->securitySettings.allowedGroupWiseCiphers.append(TDENetworkWiFiConnectionCipher::Any);
		_security_setting->securitySettings.allowedPairWiseCiphers.clear();
		_security_setting->securitySettings.allowedPairWiseCiphers.append(TDENetworkWiFiConnectionCipher::Any);
	}
	else
	{
		// use the already selected ciphers

		// group cipher
		TDENetworkWiFiConnectionCipherList cipher;
		if (chkGroupCipherTKIP->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherTKIP);
		}
		if (chkGroupCipherCCMP->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherCCMP);
		}
		if (chkGroupCipherWEP40->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherWEP40);
		}
		if (chkGroupCipherWEP104->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherWEP104);
		}
		_security_setting->securitySettings.allowedGroupWiseCiphers = cipher;

		// pairwise cipher
		cipher.clear();
		if (chkPairwiseCipherTKIP->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherTKIP);
		}
		if (chkPairwiseCipherCCMP->isChecked()) {
			cipher.append(TDENetworkWiFiConnectionCipher::CipherCCMP);
		}
		_security_setting->securitySettings.allowedPairWiseCiphers = cipher;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotGroupCipherChangedTKIP(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherTKIP)) _security_setting->securitySettings.allowedGroupWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherTKIP);
	}
	else {
		_security_setting->securitySettings.allowedGroupWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherTKIP);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotGroupCipherChangedCCMP(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedGroupWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherCCMP)) _security_setting->securitySettings.allowedGroupWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherCCMP);
	}
	else {
		_security_setting->securitySettings.allowedGroupWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherCCMP);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP40(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherWEP40)) _security_setting->securitySettings.allowedPairWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherWEP40);
	}
	else {
		_security_setting->securitySettings.allowedPairWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherWEP40);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP104(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherWEP104)) _security_setting->securitySettings.allowedPairWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherWEP104);
	}
	else {
		_security_setting->securitySettings.allowedPairWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherWEP104);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedTKIP(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherTKIP)) _security_setting->securitySettings.allowedPairWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherTKIP);
	}
	else {
		_security_setting->securitySettings.allowedPairWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherTKIP);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedCCMP(bool checked)
{
	if (checked) {
		if (!_security_setting->securitySettings.allowedPairWiseCiphers.contains(TDENetworkWiFiConnectionCipher::CipherCCMP)) _security_setting->securitySettings.allowedPairWiseCiphers.append(TDENetworkWiFiConnectionCipher::CipherCCMP);
	}
	else {
		_security_setting->securitySettings.allowedPairWiseCiphers.remove(TDENetworkWiFiConnectionCipher::CipherCCMP);
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

/*
	class WirelessSecurityWPAPSK
*/
WirelessSecurityWPAPSKImpl::WirelessSecurityWPAPSKImpl(TDEWiFiConnection* security_setting, TDEWiFiConnection* wireless_setting, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityWPAPSK(parent, name, fl)
	, _security_setting(security_setting)
	, _wireless_setting(wireless_setting)
{
	_parentdialog = connsettings;

	if (_security_setting->securitySettings.secretsValid) {
		txtPSK->setText(_security_setting->securitySettings.psk);
	}
	connect(txtPSK, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotPSKChanged(const TQString&)));
}

void
WirelessSecurityWPAPSKImpl::slotPSKChanged(const TQString& psk)
{
	if (_wireless_setting)
	{
		_security_setting->securitySettings.psk = psk;
		_security_setting->securitySettings.secretsValid = true;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

TQCString
WirelessSecurityWPAPSKImpl::String2Hex(TQByteArray bytes, int final_len) const
{
	TQCString result(final_len+1);
	static char hex_digits[] = "0123456789abcdef";
	result.resize(bytes.size() * 2 + 1);
	for (uint i = 0; i < bytes.size(); i++)
	{
		result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
		result[2*i+1] = hex_digits[bytes[i] & 0xf];
	}
	/* Cut converted key off at the correct length for this cipher type */
	if (final_len > -1)
		result[final_len] = '\0';
	return result;
}

/*
	class WirelessSecurityEAPImpl
*/
WirelessSecurityEAPImpl::WirelessSecurityEAPImpl(TDEWiFiConnection* security_setting, WirelessSecurityPhase2Impl* phase2_widget, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityEAP(parent, name, fl)
	, _security_setting(security_setting)
	, _phase2_widget(phase2_widget)
{
	_parentdialog = connsettings;

	// insert all EAP-Methods
	int index = 0;
	cboMethod->insertItem(i18n("None"), index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::None;

	cboMethod->insertItem(i18n("TTLS"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::TTLS;

	cboMethod->insertItem(i18n("PEAP"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::PEAP;

	cboMethod->insertItem(i18n("TLS"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::TLS;

	cboMethod->insertItem(i18n("Leap"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::LEAP;

	cboMethod->insertItem(i18n("MD5"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::MD5;

	cboMethod->insertItem(i18n("FAST"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::Fast;

	cboMethod->insertItem(i18n("SIM"), ++index);
	_eapIndexMap[index] = TDENetworkIEEE8021xType::SIM;

	// preselect the correct method
	TQBiDirectionalMap<int, TDENetworkIEEE8021xType::TDENetworkIEEE8021xType>::Iterator it = _eapIndexMap.findData(_security_setting->eapConfig.type);
	if (it != _eapIndexMap.end()) {
		cboMethod->setCurrentItem(it.key());
	}

	// update phase2 combobox
	_phase2_widget->setAllowedPhase2Methods(_security_setting->eapConfig.allowedPhase2EAPMethods);

	txtIdentity->setText(_security_setting->eapConfig.userName);
	txtAnonIdentity->setText(_security_setting->eapConfig.anonymousUserName);
	if (_security_setting->eapConfig.secretsValid) {
		txtPassword->setText(_security_setting->eapConfig.password);
	}

	chkCAStore->setChecked(_security_setting->eapConfig.forceSystemCaCertificates);
	kURLCACert->setEnabled(!_security_setting->eapConfig.forceSystemCaCertificates);

	// get notified if the method changes
	connect(cboMethod, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMethodChanged(int)));
	connect(txtIdentity, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotIdentityChanged(const TQString&)));
	connect(txtAnonIdentity, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotAnonIdentityChanged(const TQString&)));
	connect(txtPassword, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotPasswordChanged(const TQString&)));
	connect(chkCAStore, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUseSystemCaCertChanged(bool)));
}

void WirelessSecurityEAPImpl::slotUseSystemCaCertChanged(bool on)
{
	_security_setting->eapConfig.forceSystemCaCertificates = on;
	kURLCACert->setEnabled(!on);

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityEAPImpl::slotMethodChanged(int index)
{
	// new method choosen
	TDENetworkIEEE8021xType::TDENetworkIEEE8021xType eap = _eapIndexMap[index];
	_security_setting->eapConfig.type = eap;

	_phase2_widget->setAllowedPhase2Methods(_security_setting->eapConfig.allowedPhase2EAPMethods);

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityEAPImpl::slotIdentityChanged(const TQString& identity)
{
	_security_setting->eapConfig.userName = identity;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityEAPImpl::slotAnonIdentityChanged(const TQString& identity)
{
	_security_setting->eapConfig.anonymousUserName = identity;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void WirelessSecurityEAPImpl::slotPasswordChanged(const TQString& pwd)
{
	_security_setting->eapConfig.password = txtPassword->password();
	_security_setting->eapConfig.secretsValid = true;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

/*
	class WirelessSecurityPhase2Impl
*/
WirelessSecurityPhase2Impl::WirelessSecurityPhase2Impl(TDEWiFiConnection* security_setting, TQWidget* parent, ConnectionSettingsDialogImpl* connsettings, const char* name, WFlags fl)
	: ConnectionSettingWirelessSecurityPhase2(parent, name, fl)
	, _security_setting(security_setting)
{
	_parentdialog = connsettings;

	_allowed_methods.append(TDENetworkIEEE8021xType::None);
	updateMethodComboBox();

	connect(cboPhase2Method, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotPhase2MethodChanged(int)));
}

void WirelessSecurityPhase2Impl::updateMethodComboBox()
{
	// insert all phase2 EAP-Methods
	int index = 0;
	cboPhase2Method->clear();
	_eapIndexMap.clear();

	for (TQValueList<TDENetworkIEEE8021xType::TDENetworkIEEE8021xType>::Iterator it = _allowed_methods.begin(); it != _allowed_methods.end(); ++it)
	{
		if ((*it) == TDENetworkIEEE8021xType::None)
		{
			cboPhase2Method->insertItem(i18n("None"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::None;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::MSCHAPV2)
		{
			cboPhase2Method->insertItem(i18n("MSCHAPv2"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::MSCHAPV2;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::PAP)
		{	
			cboPhase2Method->insertItem(i18n("PAP"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::PAP;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::CHAP)
		{
			cboPhase2Method->insertItem(i18n("CHAP"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::CHAP;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::MSCHAP)
		{
			cboPhase2Method->insertItem(i18n("MSCHAP"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::MSCHAP;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::GTC)
		{
			cboPhase2Method->insertItem(i18n("GTC"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::GTC;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::OTP)
		{
			cboPhase2Method->insertItem(i18n("OTP"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::OTP;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::MD5)
		{
			cboPhase2Method->insertItem(i18n("MD5"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::MD5;
			index++;
		}
		else if ((*it) == TDENetworkIEEE8021xType::TLS)
		{
			cboPhase2Method->insertItem(i18n("TLS"), index);
			_eapIndexMap[index] = TDENetworkIEEE8021xType::TLS;
			index++;
		}
	}

	// preselect the correct method
	TQBiDirectionalMap<int, TDENetworkIEEE8021xType::TDENetworkIEEE8021xType>::Iterator it = _eapIndexMap.findData(_security_setting->eapConfig.phase2EAPAuthMethod);
	if (it != _eapIndexMap.end())
	{
		cboPhase2Method->setCurrentItem(it.key());
		_security_setting->eapConfig.phase2EAPAuthMethod = it.data();
	}
	else
	{
		cboPhase2Method->setCurrentItem(0);
		_security_setting->eapConfig.phase2EAPAuthMethod = _eapIndexMap[0];
	}
}

void WirelessSecurityPhase2Impl::setAllowedPhase2Methods(const TQValueList<TDENetworkIEEE8021xType::TDENetworkIEEE8021xType>& list)
{
	_allowed_methods = list;
	updateMethodComboBox();
}

void WirelessSecurityPhase2Impl::slotPhase2MethodChanged(int index)
{
	// new method choosen
	TDENetworkIEEE8021xType::TDENetworkIEEE8021xType eap = _eapIndexMap[index];
	_security_setting->eapConfig.phase2EAPAuthMethod = eap;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

/*
	class WirelessSecurityWidgetImpl
*/

WirelessSecurityWidgetImpl::WirelessSecurityWidgetImpl(TDENetworkConnection* conn, bool new_conn, TQWidget* parent, const char* name, WFlags fl)
	: WidgetInterface(parent, name, fl)
{
	_parentdialog = dynamic_cast<ConnectionSettingsDialogImpl*>(parent);
	_security_setting = dynamic_cast<TDEWiFiConnection*> (conn);
	_wireless_setting = dynamic_cast<TDEWiFiConnection*> (conn);
	_ieee8021x_setting = dynamic_cast<TDEWiFiConnection*> (conn);
	_new_conn = new_conn;

	TQVBoxLayout* layout = new TQVBoxLayout(this, 1, 1);
	_mainWid = new ConnectionSettingWirelessSecurityWidget(this);
	layout->addWidget(_mainWid);

	TQTimer::singleShot(0, this, TQT_SLOT(slotInit()));	
}

void
WirelessSecurityWidgetImpl::slotInit()
{
	// create all security widgets...
	TQWidget* wep = new WirelessSecurityWEPImpl(_security_setting, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* phase2 = new WirelessSecurityPhase2Impl(_ieee8021x_setting, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* eap = new WirelessSecurityEAPImpl(_ieee8021x_setting, (WirelessSecurityPhase2Impl*)phase2, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* wpaversion = new WirelessSecurityWPAVersionImpl(_security_setting, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* wpacipher = new WirelessSecurityWPACipherImpl(_security_setting, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* wpapsk = new WirelessSecurityWPAPSKImpl(_security_setting, _wireless_setting, _mainWid->groupUseEncryption, _parentdialog);
	TQWidget* wepencryption = new WirelessSecurityWEPEncryptionImpl(_security_setting, _mainWid->groupUseEncryption, _parentdialog);

	wep->setHidden(true);
	eap->setHidden(true);
	wpaversion->setHidden(true);
	wpacipher->setHidden(true);
	phase2->setHidden(true);
	wpapsk->setHidden(true);
	wepencryption->setHidden(true);

	_widgets[SECURITY_WEP].clear();
	_widgets[SECURITY_WPA_PSK].clear();
	_widgets[SECURITY_WPA_EAP].clear();
	_widgets[SECURITY_IEEE8021X].clear();

	// create WEP widget list
	_widgets[SECURITY_WEP].append(wep);

	// create WPA PSK widget list
	_extra_widgets[SECURITY_WPA_PSK].append(wpaversion);
	_extra_widgets[SECURITY_WPA_PSK].append(wpacipher);
	_widgets[SECURITY_WPA_PSK].append(wpapsk);

	// create WPA EAP widget list
	_extra_widgets[SECURITY_WPA_EAP].append(wpaversion);
	_extra_widgets[SECURITY_WPA_EAP].append(wpacipher);
	_widgets[SECURITY_WPA_EAP].append(eap);
	_widgets[SECURITY_WPA_EAP].append(phase2);

	// create IEEE8021X widget list
	_widgets[SECURITY_IEEE8021X].append(wepencryption);
	_widgets[SECURITY_IEEE8021X].append(eap);

	connect(_mainWid->cboSecurity, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotComboSecurityActivated(int)));
	connect(_mainWid->groupUseEncryption, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUseEncryptionToggled(bool)));
	connect(_mainWid->pbExtra, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotExtraSettingsToggled(bool)));

}

void
WirelessSecurityWidgetImpl::Activate()
{
	kdDebug() << "Activate " << (_new_conn ? "New" : "Edit") << endl;
	comboSecurityInit();
}

void
WirelessSecurityWidgetImpl::comboSecurityInit()
{
	int index = 0;

	TQValueList<SecurityMethods> allowed_methods;
	_mainWid->cboSecurity->clear();

	// TODO: Preselect the right security method
	// We should have an Essid already, fetch all possible APs
	TQValueList<TDENetworkWiFiAPInfo*> aps;
	if (_new_conn && !_wireless_setting->SSID.isEmpty()) {
		aps = WirelessManager::getAccessPointsForEssid(_wireless_setting->SSID);
#if 0
		kdDebug() << "Hugo " << TQString(TQCString(_wireless_setting->getEssid())).ascii() << endl;
#endif
	}
	if (!aps.isEmpty()) {
		// if at least one AP has this security setting show the entry in the combobox
		for (TQValueList<TDENetworkWiFiAPInfo*>::Iterator it = aps.begin(); it != aps.end(); ++it) {
			if (((*it)->wpaFlags & TDENetworkWiFiAPFlags::PrivacySupport) || ((*it)->rsnFlags & TDENetworkWiFiAPFlags::PrivacySupport)) {
				kdDebug() << "AP " << (*it)->friendlySSID().ascii() << " is encrypted" << endl;
				if ((((*it)->rsnFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask) != TDENetworkWiFiAPFlags::None) || (((*it)->wpaFlags & TDENetworkWiFiAPFlags::EncryptionFlagsMask) != TDENetworkWiFiAPFlags::None)) {
					// WPA or RSN
					if ((*it)->rsnFlags & TDENetworkWiFiAPFlags::KeyManagementPSK || (*it)->wpaFlags & TDENetworkWiFiAPFlags::KeyManagementPSK) {
						if (!allowed_methods.contains(SECURITY_WPA_PSK)) {
							allowed_methods.append(SECURITY_WPA_PSK);
						}
					}
			
					if ((*it)->rsnFlags & TDENetworkWiFiAPFlags::KeyManagement80211 || (*it)->wpaFlags & TDENetworkWiFiAPFlags::KeyManagement80211) {
						if (!allowed_methods.contains(SECURITY_WPA_EAP)) {
							allowed_methods.append(SECURITY_WPA_EAP);
						}
					}
				}

				// No WPA & RSN => WEP or dynamic WEP with 802.1x authentication
				// TODO: an AP can provide WEP in addition to WPA
				if (!allowed_methods.contains(SECURITY_WEP)) {
					allowed_methods.append(SECURITY_WEP);
				}
				if (!allowed_methods.contains(SECURITY_IEEE8021X)) {
					allowed_methods.append(SECURITY_IEEE8021X);
				}
			}
		}

		// insert only allowed security methods
		if (allowed_methods.contains(SECURITY_WPA_PSK))
		{
			_securityComboMap.insert(index, SECURITY_WPA_PSK);
			_mainWid->cboSecurity->insertItem(i18n("WPA Personal"), index++);
		}

		if (allowed_methods.contains(SECURITY_WPA_EAP))
		{
			_securityComboMap.insert(index, SECURITY_WPA_EAP);
			_mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), index++);
		}

		if (allowed_methods.contains(SECURITY_WEP))
		{
			_securityComboMap.insert(index, SECURITY_WEP);
			_mainWid->cboSecurity->insertItem(i18n("WEP"), index++);
		}

		if (allowed_methods.contains(SECURITY_IEEE8021X))
		{
			_securityComboMap.insert(index, SECURITY_IEEE8021X);
			_mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), index++);
		}
	}
	else
	{
		// insert all possible authentication methods
		_mainWid->cboSecurity->insertItem(i18n("WEP"),SECURITY_WEP );
		_mainWid->cboSecurity->insertItem(i18n("WPA Personal"), SECURITY_WPA_PSK);
		_mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), SECURITY_WPA_EAP);
		_mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), SECURITY_IEEE8021X);
		_securityComboMap.insert(SECURITY_WEP, SECURITY_WEP);
		_securityComboMap.insert(SECURITY_WPA_PSK, SECURITY_WPA_PSK);
		_securityComboMap.insert(SECURITY_WPA_EAP, SECURITY_WPA_EAP);
		_securityComboMap.insert(SECURITY_IEEE8021X, SECURITY_IEEE8021X);
	}

	if (!_new_conn)
	{
		switch(_security_setting->securitySettings.keyType)
		{
			case TDENetworkWiFiKeyType::WEP:
				if (_security_setting->securitySettings.authType == TDENetworkWiFiAuthType::Shared ||
				    !_security_setting->securitySettings.wepKey0.isEmpty() ||
				    !_security_setting->securitySettings.wepKey1.isEmpty() ||
				    !_security_setting->securitySettings.wepKey2.isEmpty() ||
				    !_security_setting->securitySettings.wepKey3.isEmpty() )
				{
					_mainWid->groupUseEncryption->setChecked(true);
					_mainWid->cboSecurity->setCurrentItem(SECURITY_WEP);
					slotComboSecurityActivated(_securityComboMap[SECURITY_WEP]);
				}
				else
					_mainWid->groupUseEncryption->setChecked(false);
				break;
			case TDENetworkWiFiKeyType::WPAInfrastructure:
				_mainWid->groupUseEncryption->setChecked(true);
				_mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_PSK);
				slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_PSK]);
				break;
			case TDENetworkWiFiKeyType::WPAEnterprise:
				_mainWid->groupUseEncryption->setChecked(true);
				_mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_EAP);
				slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_EAP]);
				break;
			case TDENetworkWiFiKeyType::DynamicWEP:
				_mainWid->groupUseEncryption->setChecked(true);
				_mainWid->cboSecurity->setCurrentItem(SECURITY_IEEE8021X);
				slotComboSecurityActivated(_securityComboMap[SECURITY_IEEE8021X]);
				break;

			default:
				break;
		}
	}
	else
	{
		// select first possible security method
		if (_mainWid->cboSecurity->count() > 0)
		{
			_mainWid->groupUseEncryption->setChecked(true);
			_mainWid->groupUseEncryption->setEnabled(true);
			_mainWid->cboSecurity->setCurrentItem(0);
			slotComboSecurityActivated(0);
		}
		else
		{
			_mainWid->groupUseEncryption->setChecked(false);
			_mainWid->groupUseEncryption->setEnabled(false);
		}
	}
}

void
WirelessSecurityWidgetImpl::slotUseEncryptionToggled(bool on)
{
	_wireless_setting->securityRequired = on;

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWidgetImpl::slotComboSecurityActivated(int index)
{
	int i = _securityComboMap[index];

	// authentication switched, we have to show the appropriate widgets and hide some others
	switch(i)
	{
		case SECURITY_WEP:
			configureForWEP();
			break;

		case SECURITY_WPA_PSK:
			configureForWPAPSK();
			break;

		case SECURITY_WPA_EAP:
			configureForWPAEAP();
			break;

		case SECURITY_IEEE8021X:
			configureForIEEE8021X();
			break;

		default:
			// should not happen, something is broken...
			break;
	}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWidgetImpl::configureWidgets(SecurityMethods method)
{
	// store selected method
	_currentMethod = method;

	for (int i = 0; i < SECURITY_COUNT; ++i)
	{
		// remove all current widgets that do not belong to the selected method
		if (i != method)
		{
			for (TQValueList<TQWidget*>::iterator it = _widgets[i].begin(); it != _widgets[i].end(); ++it)
			{
				_mainWid->groupUseEncryption->layout()->remove(*it);
				(*it)->hide();
			}
			// remove extra widgets too
			for (TQValueList<TQWidget*>::iterator it = _extra_widgets[i].begin(); it != _extra_widgets[i].end(); ++it)
			{
				_mainWid->groupUseEncryption->layout()->remove(*it);
				(*it)->hide();
			}
		}
	}

	// show all widgets widgets for the selected security method
	for (TQValueList<TQWidget*>::iterator it = _widgets[method].begin(); it != _widgets[method].end(); ++it)
	{
		_mainWid->groupUseEncryption->layout()->add(*it);
		(*it)->show();
	}

	if (_mainWid->pbExtra->isOn())
		for (TQValueList<TQWidget*>::iterator it = _extra_widgets[method].begin(); it != _extra_widgets[method].end(); ++it)
		{
			_mainWid->groupUseEncryption->layout()->add(*it);
			(*it)->show();
		}

	// deactivate button if no extra settings are available
	_mainWid->pbExtra->setEnabled(!(_extra_widgets[method].begin() == _extra_widgets[method].end()));
}

void
WirelessSecurityWidgetImpl::slotExtraSettingsToggled(bool on)
{
	if (on)
		for (TQValueList<TQWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
		{
			_mainWid->groupUseEncryption->layout()->add(*it);
			(*it)->show();
		}
	else
		for (TQValueList<TQWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
		{
			_mainWid->groupUseEncryption->layout()->remove(*it);
			(*it)->hide();
		}

	if (_parentdialog) _parentdialog->slotEnableButtons();	// Update lockouts
}

void
WirelessSecurityWidgetImpl::configureForWEP()
{
	_security_setting->securitySettings.keyType = TDENetworkWiFiKeyType::WEP;
	configureWidgets(SECURITY_WEP);
}

void
WirelessSecurityWidgetImpl::configureForWPAPSK()
{
	_security_setting->securitySettings.keyType = TDENetworkWiFiKeyType::WPAInfrastructure;
	configureWidgets(SECURITY_WPA_PSK);
}

void
WirelessSecurityWidgetImpl::configureForWPAEAP()
{
	_security_setting->securitySettings.keyType = TDENetworkWiFiKeyType::WPAEnterprise;
	configureWidgets(SECURITY_WPA_EAP);
}

void
WirelessSecurityWidgetImpl::configureForIEEE8021X()
{
	_security_setting->securitySettings.keyType = TDENetworkWiFiKeyType::DynamicWEP;
	configureWidgets(SECURITY_IEEE8021X);
}




#include "tdenetman-connection_setting_wireless_security_widget.moc"