summaryrefslogtreecommitdiffstats
path: root/src/modules/options/optw_servers.cpp
blob: 319f5be88db4cd6289d5f3edc1040f2a13e89bfa (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
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
//=============================================================================
//
//   File : optw_servers.cpp
//   Creation date : Wed Jun 12 2000 03:29:51 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2000-2004 Szymon Stefanek (pragma at kvirc dot net)
//
//   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 opinion) 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "optw_servers.h"
#include "optw_proxy.h"
#include "kvi_query.h"
#include "kvi_channel.h"
#include "kvi_locale.h"
#include "kvi_iconmanager.h"
#include "kvi_ircserverdb.h"
#include "kvi_ipeditor.h"
#include "kvi_netutils.h"
#include "kvi_settings.h"
#include "kvi_filedialog.h"
#include "kvi_config.h"
#include "kvi_scripteditor.h"
#include "kvi_options.h"

#include "kvi_app.h"
#include "kvi_console.h"
#include "kvi_ircurl.h"
#include "kvi_module.h"
#include "kvi_modulemanager.h"
#include "kvi_moduleextension.h"
#include "kvi_msgbox.h"
#include "kvi_mexserverimport.h"
#include "kvi_nickserv.h"
#include "optw_nickserv.h" // for the NickServ rule editor
#include "kvi_proxydb.h"
#include "kvi_kvs_script.h"
#include "kvi_styled_controls.h"

#include <tqtoolbutton.h>
#include <tqlineedit.h>
#include <tqcheckbox.h>
#include "kvi_tal_popupmenu.h"
#include <tqcursor.h>
#include "kvi_tal_tooltip.h"
#include <tqvalidator.h>
#include <tqmessagebox.h>
#include "kvi_pointerhashtable.h"
#include <tqcombobox.h>
#include <tqbuttongroup.h>
#include <tqmessagebox.h>
#include <tqinputdialog.h>
#include <tqmessagebox.h>


KviNetworkDetailsWidget::KviNetworkDetailsWidget(TQWidget * par,KviIrcNetwork * n)
	: TQDialog(par,"network_details",true)
{
	m_pOnConnectEditor=0;
	m_pOnLoginEditor=0;
	
	m_pUserEditor=0;
	m_pPassEditor=0;
	m_pNickEditor=0;
	m_pRealEditor=0;
	m_pDescEditor=0;
	
	m_pEncodingEditor=0;
		
	m_pAutoConnectCheck=0;
		
	m_pNickServListView=0;
	m_pNickServCheck=0;
	m_pAddRuleButton=0;
	m_pDelRuleButton=0;
	m_pEditRuleButton=0;
	
	m_pChannelListSelector=0;
	
	TQGridLayout * g = new TQGridLayout(this,4,4,10,4);

	setCaption(__tr2qs_ctx("Network Details","options"));
	setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)));

	TQString szTmp = "<font size=\"+1\"><b>";
	szTmp += n->name();
	szTmp += "</b></font>";

	TQLabel * l = new TQLabel(szTmp,this);
	l->setFrameStyle(TQFrame::Raised | TQFrame::StyledPanel);
	l->tqsetAlignment(TQt::AlignCenter);
	l->setMargin(10);
	g->addMultiCellWidget(l,0,0,0,3);
	l->setMinimumWidth(200);

	l = new TQLabel(__tr2qs_ctx("Description:","options"),this);
	g->addWidget(l,1,0);
	m_pDescEditor = new TQLineEdit(this);
	g->addMultiCellWidget(m_pDescEditor,1,1,1,3);
	m_pDescEditor->setText(n->description());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pDescEditor,__tr2qs_ctx("<center>Put here a brief description of the network.</center>","options"));
#endif

	// Identity tab

	TQTabWidget * tw = new TQTabWidget(this);
	g->addMultiCellWidget(tw,2,2,0,3);

	TQWidget * tab = new TQWidget(tw);
	TQGridLayout * gl = new TQGridLayout(tab,4,2,10,4);

	KviTalGroupBox *gbox = new KviTalGroupBox(2,Qt::Horizontal,__tr2qs_ctx("Properties","options"),tab);
	gl->addMultiCellWidget(gbox,0,0,0,1);

	l = new TQLabel(__tr2qs_ctx("Username:","options"),gbox);
	m_pUserEditor = new TQLineEdit(gbox);
	m_pUserEditor->setText(n->userName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUserEditor,__tr2qs_ctx("<center>This is the <b>username</b> that KVIrc will use to login to servers on this network.\n" \
										"If this field is left empty (most common case), KVIrc will use the default username " \
										"specified in the \"Identity\" options tab.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Nickname:","options"),gbox);
	m_pNickEditor = new TQLineEdit(gbox);
	TQValidator * v = new TQRegExpValidator(TQRegExp("[^-0-9 ][^ ]*","options"),TQT_TQOBJECT(gbox));
	m_pNickEditor->setValidator(v);
	m_pNickEditor->setText(n->nickName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNickEditor,__tr2qs_ctx("<center>You can specify a \"special\" <b>nickname</b> that will be used to log in to the servers on this network.<br>" \
									"If this field is left empty (most common case), the default nickname (specified in the \"Identity\" settings) will be used.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Real name:","options"),gbox);
	m_pRealEditor = new TQLineEdit(gbox);
	m_pRealEditor->setText(n->realName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pRealEditor,__tr2qs_ctx("<center>You can specify a \"special\" <b>real name</b> that will be used to login with the servers on this network.<br>" \
									"If you leave this field empty (most common case), the default \"real name\" (specified in the \"Identity\" settings) will be used.</center>","options"));
#endif


	l = new TQLabel(__tr2qs_ctx("Encoding:","options"),tab);
	gl->addWidget(l,1,0);
	m_pEncodingEditor = new TQComboBox(false,tab);
	m_pEncodingEditor->setDuplicatesEnabled(false);
	gl->addWidget(m_pEncodingEditor,1,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pEncodingEditor,__tr2qs_ctx("<center>This box allows you to choose the preferred encoding for the servers in this network. " \
									"If you choose \"Use System Encoding\" then the encoding will be set to the systemwide " \
									"value that you choose in the \"Encoding\" page of the options dialog.</center>","options"));
#endif

	int i = 0;
	int current = 0;
	KviLocale::EncodingDescription * d = KviLocale::encodingDescription(i);
	TQString tmp;
	m_pEncodingEditor->insertItem(__tr2qs_ctx("Use System Encoding","options"));
	while(d->szName)
	{
		KviTQString::sprintf(tmp,"%s (%s)",d->szName,d->szDescription);
		m_pEncodingEditor->insertItem(tmp);
		if(KviTQString::equalCI(d->szName,n->encoding()))current = i + 1;
		i = i + 1;
		d = KviLocale::encodingDescription(i);
	}

	m_pEncodingEditor->setCurrentItem(current);

	m_pAutoConnectCheck = new KviStyledCheckBox(__tr2qs_ctx("Connect to this network at startup","options"),tab);
	m_pAutoConnectCheck->setChecked(n->autoConnect());
	gl->addMultiCellWidget(m_pAutoConnectCheck,2,2,0,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pAutoConnectCheck,__tr2qs_ctx("<center>This option will cause KVIrc to automatically connect to this network at startup</center>","options"));
#endif


	l = new TQLabel("",tab);
	gl->addWidget(l,3,0);

	gl->setRowStretch(3,1);
	gl->setColStretch(1,1);

	tw->addTab(tab,__tr2qs_ctx("General","options"));

	// after login join channels
	tab = new TQWidget(tw);

	gl = new TQGridLayout(tab,1,1,10,4);

	if(n->autoJoinChannelList())
		m_lstChannels = *(n->autoJoinChannelList());
	m_pChannelListSelector = new KviCahnnelListSelector(tab,
		__tr2qs_ctx("Channels to join automatically upon connect:","options"),&m_lstChannels,true);
#ifdef COMPILE_INFO_TIPS
  KviTalToolTip::add(m_pChannelListSelector,__tr2qs_ctx("<center>Here you can set a list of channels to be joined automatically " \
		"after a connection to a server in this network has been established. To add a channel, type its name in the " \
		"text input below and click \"<b>Add</b>\".</center>","options"));
#endif
	gl->addWidget(m_pChannelListSelector,0,0);

	tw->addTab(tab,__tr2qs_ctx("Join Channels","options"));

	// after connect execute
	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,1,1,10,4);
	
	m_pOnConnectEditor = KviScriptEditor::createInstance(tab);
	gl->addWidget(m_pOnConnectEditor,0,0);
	m_pOnConnectEditor->setText(n->onConnectCommand());
	m_pOnConnectEditor->setMinimumHeight(150);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pOnConnectEditor,__tr2qs_ctx("<center>The following commands will be executed after a connection to a server in this network has been established.<br>" \
				"<b>Important:</b> Enter commands <b>without</b> a preceding slash (e.g. <tt>quote pass secret</tt> instead of <tt>/quote pass secret</tt>).<br>"\
				"KVIrc will first send the USER command, then eventually PASS and NICK and then execute this " \
				"command sequence.</center>","options"));
#endif
	
	tw->addTab(tab,__tr2qs_ctx("On Connect","options"));
	

	// after login execute
	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,1,1,10,4);

	m_pOnLoginEditor = KviScriptEditor::createInstance(tab);
	gl->addWidget(m_pOnLoginEditor,0,0);
	m_pOnLoginEditor->setText(n->onLoginCommand());
	
	m_pOnLoginEditor->setMinimumHeight(150);
	
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pOnLoginEditor,
				__tr2qs_ctx("<center>The following commands will be executed after a successful login to a server in this network.<br>" \
						"<b>Important:</b> Enter commands <b>without</b> a preceding slash (e.g. <tt>quote privatelog</tt> instead of <tt>/quote privatelog</tt>).<br>"
						"This is useful for automatically opening queries, setting variables, etc.</center>","options"));
#endif
	
	tw->addTab(tab,__tr2qs_ctx("On Login","options"));


	// nick serv rules
	
	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,3,3,10,5);
	
	KviNickServRuleSet * rs = n->nickServRuleSet();
	bool bNickServEnabled = rs ? (rs->isEnabled() && !rs->isEmpty()) : false;
	
	m_pNickServCheck = new KviStyledCheckBox(__tr2qs_ctx("Enable NickServ Identification","options"),tab);
	gl->addMultiCellWidget(m_pNickServCheck,0,0,0,2);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNickServCheck,
				__tr2qs_ctx("This check enables the automatic identification with NickServ","options"));
#endif
	m_pNickServCheck->setChecked(bNickServEnabled);
	
	m_pNickServListView = new KviTalListView(tab);
	m_pNickServListView->setSelectionMode(KviTalListView::Single);
	m_pNickServListView->setAllColumnsShowFocus(true);
	m_pNickServListView->addColumn(__tr2qs_ctx("Nickname","options"));
	m_pNickServListView->addColumn(__tr2qs_ctx("NickServ Mask","options"));
	m_pNickServListView->addColumn(__tr2qs_ctx("NickServ Request Mask","options"));
	m_pNickServListView->addColumn(__tr2qs_ctx("Identify Command","options"));
	connect(m_pNickServListView,TQT_SIGNAL(selectionChanged()),this,TQT_SLOT(enableDisableNickServControls()));
	
	gl->addMultiCellWidget(m_pNickServListView,1,1,0,2);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNickServListView,
		__tr2qs_ctx("<center>This is a list of NickServ identification rules. " \
				"KVIrc will use them to model its automatic interaction with NickServ on this network.<br>" \
				"Please be aware that this feature can cause your NickServ passwords to be stolen " \
				"if used improperly. Make sure that you fully understand the NickServ authentication protocol.<br>" \
				"In other words, be sure to know what you're doing.<br>" \
				"Also note that the password that you provide is stored as <b>PLAIN TEXT</b>.</center>","options"));
#endif
	
	m_pAddRuleButton = new TQPushButton(__tr2qs_ctx("Add Rule","options"),tab);
	connect(m_pAddRuleButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(addNickServRule()));
	gl->addWidget(m_pAddRuleButton,2,0);
	
	
	m_pEditRuleButton = new TQPushButton(__tr2qs_ctx("Edit Rule","options"),tab);
	connect(m_pEditRuleButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(editNickServRule()));
	gl->addWidget(m_pEditRuleButton,2,1);
	
	m_pDelRuleButton = new TQPushButton(__tr2qs_ctx("Delete Rule","options"),tab);
	connect(m_pDelRuleButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(delNickServRule()));
	gl->addWidget(m_pDelRuleButton,2,2);
	
	connect(m_pNickServCheck,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(enableDisableNickServControls()));
	
	if(rs && rs->rules())
	{
		KviPointerList<KviNickServRule> * ll = rs->rules();
		for(KviNickServRule * rule = ll->first();rule;rule = ll->next())
		{
			(void)new KviTalListViewItem(m_pNickServListView,rule->registeredNick(),rule->nickServMask(),rule->messageRegexp(),rule->identifyCommand());
		}
	}
	
	enableDisableNickServControls();
	
	gl->setRowStretch(1,1);
	
	tw->addTab(tab,__tr2qs_ctx("NickServ","options"));

	TQPushButton * b = new TQPushButton(__tr2qs_ctx("&OK","options"),this);
	b->setMinimumWidth(80);
	g->addWidget(b,3,2);
	b->setDefault(true);
	connect(b,TQT_SIGNAL(clicked()),this,TQT_SLOT(accept()));

	b = new TQPushButton(__tr2qs_ctx("Cancel","options"),this);
	g->addWidget(b,3,3);
	b->setMinimumWidth(80);
	connect(b,TQT_SIGNAL(clicked()),this,TQT_SLOT(reject()));


	g->setRowStretch(2,1);
	g->setColStretch(1,1);

	tw->setMinimumWidth(375);
}



KviNetworkDetailsWidget::~KviNetworkDetailsWidget()
{
	if(m_pOnConnectEditor) KviScriptEditor::destroyInstance(m_pOnConnectEditor);
	if(m_pOnLoginEditor) KviScriptEditor::destroyInstance(m_pOnLoginEditor);
}

void KviNetworkDetailsWidget::editNickServRule()
{
	KviTalListViewItem * it = m_pNickServListView->currentItem();
	if(!it)return;
	KviNickServRule r(it->text(0),it->text(1),it->text(2),it->text(3));
	KviNickServRuleEditor ed(this,false);
	if(ed.editRule(&r))
	{
		it->setText(0,r.registeredNick());
		it->setText(1,r.nickServMask());
		it->setText(2,r.messageRegexp());
		it->setText(3,r.identifyCommand());
	}
}

void KviNetworkDetailsWidget::addNickServRule()
{
	KviNickServRule r;
	KviNickServRuleEditor ed(this,false);
	if(ed.editRule(&r))
		(void)new KviTalListViewItem(m_pNickServListView,r.registeredNick(),r.nickServMask(),r.messageRegexp(),r.identifyCommand());
}

void KviNetworkDetailsWidget::delNickServRule()
{
	KviTalListViewItem * it = m_pNickServListView->currentItem();
	if(!it)return;
	delete it;
	enableDisableNickServControls();
}

void KviNetworkDetailsWidget::enableDisableNickServControls()
{
	bool bEnabled = m_pNickServCheck->isChecked();
	m_pNickServListView->setEnabled(bEnabled);
	m_pAddRuleButton->setEnabled(bEnabled);
	bEnabled = bEnabled && (m_pNickServListView->childCount() > 0) && m_pNickServListView->currentItem();
	m_pDelRuleButton->setEnabled(bEnabled);
	m_pEditRuleButton->setEnabled(bEnabled);
}

void KviNetworkDetailsWidget::fillData(KviIrcNetwork * n)
{
	n->setUserName(m_pUserEditor->text());
	n->setNickName(m_pNickEditor->text());
	n->setRealName(m_pRealEditor->text());
	n->setDescription(m_pDescEditor->text());
	if(m_pAutoConnectCheck)
		n->setAutoConnect(m_pAutoConnectCheck->isChecked());
	if(m_pEncodingEditor)
		if(m_pEncodingEditor->currentItem() <= 0)n->setEncoding(TQString());
		else {
			KviLocale::EncodingDescription * d = KviLocale::encodingDescription(m_pEncodingEditor->currentItem() - 1);
			n->setEncoding(d->szName);
		}
	if(m_pChannelListSelector)
		m_pChannelListSelector->commit();
	if(m_lstChannels.isEmpty())n->setAutoJoinChannelList(0);
	else n->setAutoJoinChannelList(new TQStringList(m_lstChannels));
	if(m_pNickServListView)
	{
		if(m_pNickServListView->childCount() > 0)
		{
			KviNickServRuleSet * rs = KviNickServRuleSet::createInstance();
			rs->setEnabled(m_pNickServCheck->isChecked());
			KviTalListViewItem * it = m_pNickServListView->firstChild();
			while(it)
			{
				rs->addRule(KviNickServRule::createInstance(it->text(0),it->text(1),it->text(2),it->text(3)));
				it = it->nextSibling();
			}
			n->setNickServRuleSet(rs);
		} else n->setNickServRuleSet(0);
	}
	if(m_pOnConnectEditor)
	{
		TQString tmp;
		m_pOnConnectEditor->getText(tmp);
		n->setOnConnectCommand(tmp);
	}
	if(m_pOnLoginEditor)
	{
		TQString tmp;
		m_pOnLoginEditor->getText(tmp);
		n->setOnLoginCommand(tmp);
	}
}







KviServerDetailsWidget::KviServerDetailsWidget(TQWidget * par,KviIrcServer * s)
    : TQDialog(par,"server_details",true)
{
	m_szHostname = s->hostName();
	TQGridLayout * g = new TQGridLayout(this,4,4,10,4);

	setCaption(__tr2qs_ctx("Server Details","options"));
	setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)));

	m_pHeaderLabel = new TQLabel("",this); // the text will be set later
	m_pHeaderLabel->setFrameStyle(TQFrame::Raised | TQFrame::StyledPanel);
	m_pHeaderLabel->tqsetAlignment(TQt::AlignCenter);
	m_pHeaderLabel->setMargin(10);
	g->addMultiCellWidget(m_pHeaderLabel,0,0,0,3);
	m_pHeaderLabel->setMinimumWidth(200);

	TQLabel * l = new TQLabel(__tr2qs_ctx("Description:","options"),this);
	g->addWidget(l,1,0);
	m_pDescEditor = new TQLineEdit(this);
	g->addMultiCellWidget(m_pDescEditor,1,1,1,3);
	m_pDescEditor->setText(s->description());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pDescEditor,__tr2qs_ctx("<center>This is a brief description of this server. " \
								"This field has no restrictions but many server lists use it to describe the server's physical location</center>","options"));
#endif

	// Identity tab

	TQTabWidget * tw = new TQTabWidget(this);
	g->addMultiCellWidget(tw,2,2,0,3);

	TQWidget * tab = new TQWidget(tw);
	TQGridLayout * gl = new TQGridLayout(tab,3,1,10,4);

	KviTalGroupBox *gbox = new KviTalGroupBox(2,Qt::Horizontal,__tr2qs_ctx("Properties","options"),tab);
	gl->addWidget(gbox,0,0);

	l = new TQLabel(__tr2qs_ctx("Username:","options"),gbox);
	m_pUserEditor = new TQLineEdit(gbox);
	m_pUserEditor->setText(s->userName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUserEditor,__tr2qs_ctx("<center>This is the <b>username</b> that KVIrc will use to login to this server.\n" \
										"If this field is left empty (most common case), KVIrc will first look if an username is specified " \
										"for the network that this server belongs to, and if that is empty then KVIrc will use the default username " \
										"specified in the \"Identity\" options tab.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Password:","options"),gbox);
	m_pPassEditor = new TQLineEdit(gbox);
	m_pPassEditor->setEchoMode(TQLineEdit::Password);
	m_pPassEditor->setText(s->password());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pPassEditor,__tr2qs_ctx("<center>If this server requires a password, put it in this field, otherwise leave it empty.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Nickname:","options"),gbox);
	m_pNickEditor = new TQLineEdit(gbox);
	TQValidator * v = new TQRegExpValidator(TQRegExp("[^-0-9 ][^ ]*"),TQT_TQOBJECT(gbox));
	m_pNickEditor->setValidator(v);
	m_pNickEditor->setText(s->nickName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNickEditor,__tr2qs_ctx("<center>You can specify a \"special\" <b>nickname</b> that will be used to log in to this server.<br>" \
									"If this field is left empty (most common case), KVIrc will first look if a nickname is specified " \
									"for the network that this server belongs to, and if that is empty then the default nickname (specified in the \"Identity\" settings) will be used.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Real name:","options"),gbox);
	m_pRealEditor = new TQLineEdit(gbox);
	m_pRealEditor->setText(s->realName());
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pRealEditor,__tr2qs_ctx("<center>You can specify a \"special\" <b>real name</b> that will be used to login with this server.<br>" \
									"If you leave this field empty (most common case), KVIrc will first look if a real name is specified " \
									"for the network that this server belongs to, and if that is empty the default \"real name\" (specified in the \"Identity\" settings) will be used.</center>","options"));
#endif
	gbox = new KviTalGroupBox(1,Qt::Horizontal,__tr2qs_ctx("User Mode","options"),tab);
	gl->addWidget(gbox,1,0);
	
	m_pUseDefaultInitUMode = new KviStyledCheckBox(__tr2qs_ctx("Use default user mode","options"),gbox);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUseDefaultInitUMode,__tr2qs_ctx("<center>If this is enabled, the global initial <b>user mode</b> (configured from"\
					" the identity dialog) will be used. If disabled, you can configure an initial user mode for this server","options"));
#endif
	bool bHasUmode = !(s->initUMode().isEmpty());
	KviStr szDefUMode = KVI_OPTION_STRING(KviOption_stringDefaultUserMode);
	m_pUseDefaultInitUMode->setChecked(!bHasUmode);
	connect(m_pUseDefaultInitUMode,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(useDefaultInitUModeToggled(bool)));
	
	m_pIMode = new KviStyledCheckBox(__tr2qs_ctx("Invisible (+i)","options"),gbox);
	m_pIMode->setEnabled(bHasUmode);
	m_pIMode->setChecked(bHasUmode ? s->initUMode().contains('i',false) : szDefUMode.contains('i',false));
	
	m_pSMode = new KviStyledCheckBox(__tr2qs_ctx("Server notices (+s)","options"),gbox);
	m_pSMode->setEnabled(bHasUmode);
	m_pSMode->setChecked(bHasUmode ? s->initUMode().contains('s',false) : szDefUMode.contains('s',false));
	
	m_pWMode = new KviStyledCheckBox(__tr2qs_ctx("Wallops (+w)","options"),gbox);
	m_pWMode->setEnabled(bHasUmode);
	m_pWMode->setChecked(bHasUmode ? s->initUMode().contains('w',false) : szDefUMode.contains('w',false));

	l = new TQLabel("",tab);
	gl->addWidget(l,2,0);

	gl->setRowStretch(2,1);
	//gl->setColStretch(1,1);

	tw->addTab(tab,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WHO)),__tr2qs_ctx("Identity","options"));

	// Connection tab
	
	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,11,1,10,4);
	
	l = new TQLabel(__tr2qs_ctx("Port:","options"),tab);
	gl->addWidget(l,0,0);
	

	m_pPortEditor = new TQLineEdit(tab);
	gl->addWidget(m_pPortEditor,0,1);
	TQString tmpz;
	tmpz.setNum(s->port());
	m_pPortEditor->setText(tmpz);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pPortEditor,__tr2qs_ctx("<center>This is the default <b>port</b> that this server will be contacted on.<br>Usually <b>6667</b> is OK.</center>","options"));
#endif
	connect(m_pPortEditor,TQT_SIGNAL(textChanged(const TQString &)),this,TQT_SLOT(portEditorTextChanged(const TQString &)));



	l = new TQLabel(__tr2qs_ctx("IP address:","options"),tab);
	gl->addWidget(l,1,0);
	m_pIpEditor = new KviIpEditor(tab,KviIpEditor::IpV4);
	gl->addWidget(m_pIpEditor,1,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pIpEditor,__tr2qs_ctx("<center>This is the <b>IP address</b> of this server, it is here for caching purposes.<br>" \
										"If you leave this field empty, KVIrc will fill it in the first time it connects to the server. " \
										"If you enable the \"cache IP address\" option below, KVIrc will use it as a \"cached result\" " \
										"and avoid looking it up again.</center>","options"));
#endif
#ifdef COMPILE_IPV6_SUPPORT
	m_pIpEditor->setAddressType(s->isIpV6() ? KviIpEditor::IpV6 : KviIpEditor::IpV4);
#else
	m_pIpEditor->setAddressType(KviIpEditor::IpV4);
#endif
	
	if(!m_pIpEditor->setAddress(s->m_szIp))
	{
#ifdef COMPILE_IPV6_SUPPORT
		m_pIpEditor->setAddress(s->isIpV6() ? "0:0:0:0:0:0:0:0" : "0.0.0.0");
#else
		m_pIpEditor->setAddress("0.0.0.0");
#endif
	}
	
	m_pCacheIpCheck = new KviStyledCheckBox(__tr2qs_ctx("Cache IP address","options"),tab);
	gl->addMultiCellWidget(m_pCacheIpCheck,2,2,0,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pCacheIpCheck,__tr2qs_ctx("<center>This check will enable <b>IP address caching</b> for this server:<br>" \
												"DNS lookups can be time-consuming and might be blocking on some platforms; " \
												"this option will cause KVIrc to look up the server hostname only once.<br><br> " \
												"Advanced: you can also use this option to force a certain server name to resolve " \
												"to a fixed ip address when either the dns for that server is temporairly " \
												"unreachable or you want to avoid the round-robin lookups.</center>","options"));
#endif
	m_pCacheIpCheck->setChecked(s->cacheIp());


	m_pUseIPV6Check = new KviStyledCheckBox(__tr2qs_ctx("Use IPv6 protocol","options"),tab);
	gl->addMultiCellWidget(m_pUseIPV6Check,3,3,0,1);
#ifdef COMPILE_IPV6_SUPPORT
	m_pUseIPV6Check->setChecked(s->isIpV6());
#else
	m_pUseIPV6Check->setEnabled(false);
#endif
	connect(m_pUseIPV6Check,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(useIPV6CheckToggled(bool)));

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUseIPV6Check,__tr2qs_ctx("<center>This check identifies IPv6 servers.<br>If enabled, KVIrc will attempt to use the IPv6 protocol " \
						"(thus your OS <b>must</b> have a working IPv6 stack and you <b>must</b> have an IPv6 connection).</center>","options"));
#endif


	m_pUseSSLCheck = new KviStyledCheckBox(__tr2qs_ctx("Use SSL protocol","options"),tab);
	gl->addMultiCellWidget(m_pUseSSLCheck,4,4,0,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUseSSLCheck,__tr2qs_ctx("<center>This check will cause the connection to use the <b>Secure Socket Layer</b> " \
						"encryption support. Obviously, this server must have support for this, too. :)</center>","options"));
#endif
#ifndef COMPILE_SSL_SUPPORT
	m_pUseSSLCheck->setEnabled(false);
#endif
	m_pUseSSLCheck->setChecked(s->useSSL());
	
	
	m_pUseAutoConnect = new KviStyledCheckBox(__tr2qs_ctx("Connect to this server at startup","options"),tab);
	m_pUseAutoConnect->setChecked(s->autoConnect());
	
	gl->addMultiCellWidget(m_pUseAutoConnect,5,5,0,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pUseAutoConnect,__tr2qs_ctx("<center>This option will cause KVIrc to connect to the IRC server when it is started.</center>","options"));
#endif
	
	l = new TQLabel(__tr2qs_ctx("Encoding:","options"),tab);
	gl->addWidget(l,6,0);
	m_pEncodingEditor = new TQComboBox(false,tab);
	m_pEncodingEditor->setDuplicatesEnabled(false);
	gl->addWidget(m_pEncodingEditor,6,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pEncodingEditor,__tr2qs_ctx("<center>This box allows you to choose the preferred encoding for this sever. " \
									"If you choose \"Use Network Encoding\" then the encoding will be inherited from the " \
									"network that this server belongs to.</center>","options"));
#endif

	int i = 0;
	int current = 0;
	KviLocale::EncodingDescription * d = KviLocale::encodingDescription(i);
	TQString tmp;
	m_pEncodingEditor->insertItem(__tr2qs_ctx("Use Network Encoding","options"));
	while(d->szName)
	{
		KviTQString::sprintf(tmp,"%s (%s)",d->szName,d->szDescription);
		m_pEncodingEditor->insertItem(tmp);
		if(KviTQString::equalCI(d->szName,s->encoding()))current = i + 1;
		i = i + 1;
		d = KviLocale::encodingDescription(i);
	}

	m_pEncodingEditor->setCurrentItem(current);


	l = new TQLabel(__tr2qs_ctx("Link filter:","options"),tab);
	gl->addWidget(l,7,0);
	m_pLinkFilterEditor = new TQComboBox(true,tab);
	m_pLinkFilterEditor->setDuplicatesEnabled(false);
	gl->addWidget(m_pLinkFilterEditor,7,1);

	m_pLinkFilterEditor->insertItem("");

	g_pModuleManager->loadModulesByCaps("linkfilter");
	KviModuleExtensionDescriptorList * mexl = KviModuleExtensionManager::instance()->getExtensionList("linkfilter");



	if(mexl)
	{
		for(KviModuleExtensionDescriptor * d = mexl->first();d;d = mexl->next())
			m_pLinkFilterEditor->insertItem(d->name().ptr());
	} else {
		if(!s->linkFilter().isEmpty())
			m_pLinkFilterEditor->insertItem(s->linkFilter());
	}

	if(!s->linkFilter().isEmpty())
		m_pLinkFilterEditor->setCurrentText(s->linkFilter());
	else
		m_pLinkFilterEditor->setCurrentText("");


#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pLinkFilterEditor,__tr2qs_ctx("<center>This field specifies the name of a module that exports a link filter for this type of server.<br>" \
		"For plain IRC connections, you don't need any link filters; this is used for incompatible protocols.</center>","options"));
#endif

	l = new TQLabel(__tr2qs_ctx("Id:","options"),tab);
	gl->addWidget(l,8,0);
	m_pIdEditor = new TQLineEdit(tab);
	if(s->id().isEmpty())s->generateUniqueId();
	m_pIdEditor->setText(s->id());
	gl->addWidget(m_pIdEditor,8,1);

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pIdEditor,__tr2qs_ctx("<center>This field allows you to specify a really unique id for this server. " \
		"You will then be able to use /server -x &lt;this_id&gt; to make the connection. This is especially " \
		"useful when you have multiple server entries with the same hostname and port in different networks (bouncers?)</center>","options"));
#endif


	l = new TQLabel(__tr2qs_ctx("Proxy server:","options"),tab);
	gl->addWidget(l,9,0);
	m_pProxyEditor = new TQComboBox(tab);
	gl->addWidget(m_pProxyEditor,9,1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pProxyEditor,__tr2qs_ctx("<center>This is the <b>proxy</b> that KVIrc will use to connect to thos server.\n" \
										"If this field is set in \"Default\" KVirc will use global proxy settings, if it is set in \"Direct connection\" " \
										"KVirc will connect to this server without proxy. You can define new proxy server in global options' \"Proxy servers\" menu.</center>","options"));
#endif	
	
	m_pProxyEditor->insertItem(__tr2qs_ctx("Default","options"));
	m_pProxyEditor->insertItem(__tr2qs_ctx("Direct connection","options"));	
	
	KviPointerList<KviProxy> * proxylist = g_pProxyDataBase->proxyList();
	for(KviProxy * p = proxylist->first();p;p = proxylist->next())
	{
		m_pProxyEditor->insertItem(TQString("%1:%2").tqarg(p->hostname()).tqarg(p->port()));
	}
	if(m_pProxyEditor->count() > (s->proxy()+2))
		m_pProxyEditor->setCurrentItem(s->proxy()+2);


	l = new TQLabel("",tab);
	gl->addMultiCellWidget(l,10,10,0,1);

	gl->setRowStretch(10,1);

	tw->addTab(tab,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SOCKETWARNING)),__tr2qs_ctx("Connection","options"));

	// after login join channels
	tab = new TQWidget(tw);

	gl = new TQGridLayout(tab,1,1,10,4);

	if(s->autoJoinChannelList())
		m_lstChannels = *(s->autoJoinChannelList());
	m_pChannelListSelector = new KviCahnnelListSelector(tab,
		__tr2qs_ctx("Channels to join automatically upon connect:","options"),&m_lstChannels,true);
#ifdef COMPILE_INFO_TIPS
  KviTalToolTip::add(m_pChannelListSelector,__tr2qs_ctx("<center>Here you can set a list of channels to be joined automatically " \
		"after a connection to this server has been established. To add a channel, type its name in the " \
		"text input below and click \"<b>Add</b>\".</center>","options"));
#endif
	gl->addWidget(m_pChannelListSelector,0,0);

	tw->addTab(tab,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)),__tr2qs_ctx("Join Channels","options"));

	// after connect execute
	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,1,1,10,4);


	m_pOnConnectEditor = KviScriptEditor::createInstance(tab);
	gl->addWidget(m_pOnConnectEditor,0,0);
	m_pOnConnectEditor->setText(s->onConnectCommand());
	m_pOnConnectEditor->setMinimumHeight(150);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pOnConnectEditor,__tr2qs_ctx("<center>The following commands will be executed after a connection has been established.<br>" \
			"<b>Important:</b> Enter commands <b>without</b> a preceding slash (e.g. <tt>quote pass secret</tt> instead of <tt>/quote pass secret</tt>).<br>"\
			"KVIrc will first send the USER command, then eventually PASS and NICK and then execute this " \
			"command sequence.<br>This is particularly useful for IRC bouncers that require login commands.</center>","options"));
#endif

	tw->addTab(tab,__tr2qs_ctx("On Connect","options"));
	// after login execute

	tab = new TQWidget(tw);
	gl = new TQGridLayout(tab,1,1,10,4);

	m_pOnLoginEditor = KviScriptEditor::createInstance(tab);
	gl->addWidget(m_pOnLoginEditor,0,0);
	m_pOnLoginEditor->setText(s->onLoginCommand());

	m_pOnLoginEditor->setMinimumHeight(150);

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pOnLoginEditor,
			__tr2qs_ctx("<center>The following commands will be executed after a successful login to this server.<br>" \
					"<b>Important:</b> Enter commands <b>without</b> a preceding slash (e.g. <tt>quote privatelog</tt> instead of <tt>/quote privatelog</tt>).<br>"
					"This is useful for automatically opening queries, setting variables, etc.</center>","options"));
#endif

	tw->addTab(tab,__tr2qs_ctx("On Login","options"));

	TQPushButton * b = new TQPushButton(__tr2qs_ctx("OK","options"),this);
	b->setMinimumWidth(80);
	g->addWidget(b,3,2);
	b->setDefault(true);
	connect(b,TQT_SIGNAL(clicked()),this,TQT_SLOT(accept()));

	b = new TQPushButton(__tr2qs_ctx("Cancel","options"),this);
	g->addWidget(b,3,3);
	b->setMinimumWidth(80);
	connect(b,TQT_SIGNAL(clicked()),this,TQT_SLOT(reject()));

	g->setRowStretch(2,1);
	g->setColStretch(1,1);

	tw->setMinimumWidth(390);
	
	setHeaderLabelText();
}

KviServerDetailsWidget::~KviServerDetailsWidget()
{
	if(m_pOnConnectEditor) KviScriptEditor::destroyInstance(m_pOnConnectEditor);
	if(m_pOnLoginEditor) KviScriptEditor::destroyInstance(m_pOnLoginEditor);
}

void KviServerDetailsWidget::useIPV6CheckToggled(bool)
{
#ifdef COMPILE_IPV6_SUPPORT
	m_pIpEditor->setAddressType(m_pUseIPV6Check->isChecked() ? KviIpEditor::IpV6 : KviIpEditor::IpV4);
#else
	m_pIpEditor->setAddressType(KviIpEditor::IpV4);
#endif
	setHeaderLabelText();
}

void KviServerDetailsWidget::portEditorTextChanged(const TQString &)
{
	setHeaderLabelText();
}

void KviServerDetailsWidget::setHeaderLabelText()
{
	TQString szTmp = "<font size=\"+1\"><b>irc";
	if(m_pUseIPV6Check->isChecked())szTmp += "6";
	szTmp += "://";
	szTmp += m_szHostname;
	szTmp += ":";

	bool bOk;

	TQString num = m_pPortEditor->text();
	unsigned int uPort = num.toUInt(&bOk);
	if(!bOk)uPort = 6667;
	num.setNum(uPort);
	szTmp += num;
	szTmp += "</b></font>";
	
	m_pHeaderLabel->setText(szTmp);
}

void KviServerDetailsWidget::fillData(KviIrcServer * s)
{
	s->setUserName(m_pUserEditor->text());
	s->setPassword(m_pPassEditor->text());
	s->setNickName(m_pNickEditor->text());
	s->setRealName(m_pRealEditor->text());
	if(m_pDescEditor)
		s->setDescription(m_pDescEditor->text());
	if(m_pLinkFilterEditor)
		s->setLinkFilter(m_pLinkFilterEditor->lineEdit()->text());
	if(m_pEncodingEditor)
		if(m_pEncodingEditor->currentItem() <= 0)s->m_szEncoding = "";
		else {
			KviLocale::EncodingDescription * d = KviLocale::encodingDescription(m_pEncodingEditor->currentItem() - 1);
			s->m_szEncoding = d->szName;
		}
	s->setIpAddress("");
	if(m_pCacheIpCheck)
		s->setCacheIp(m_pCacheIpCheck->isChecked());
	if(m_pUseSSLCheck)
		s->setUseSSL(m_pUseSSLCheck->isChecked());
	if(m_pIdEditor)
		s->setId(m_pIdEditor->text());
	if(s->id().isEmpty())s->generateUniqueId();

	if(m_pUseDefaultInitUMode)
	{
		KviStr szUMode;
		if(!m_pUseDefaultInitUMode->isChecked())
		{
			if(m_pIMode->isChecked())szUMode.append('i');
			if(m_pWMode->isChecked())szUMode.append('w');
			if(m_pSMode->isChecked())szUMode.append('s');
		}
		s->setInitUMode(szUMode.ptr());
	}
	
	TQString tmp = m_pPortEditor->text();
	bool bOk;
	kvi_u32_t uPort = tmp.toUInt(&bOk);
	if(!bOk)uPort = 6667;
	s->m_uPort = uPort;
#ifdef COMPILE_IPV6_SUPPORT
	s->setIpV6(m_pUseIPV6Check->isChecked());
#else
	s->setIpV6(false);
#endif

	if(m_pIpEditor)
	{
		KviStr tmpAddr = m_pIpEditor->address();
	
		if(!m_pIpEditor->hasEmptyFields())
		{
#ifdef COMPILE_IPV6_SUPPORT
			if(s->isIpV6())
			{
				if((!kvi_strEqualCI(tmpAddr.ptr(),"0:0:0:0:0:0:0:0")) && kvi_isValidStringIp_V6(tmpAddr.ptr()))
				{
					s->setIpAddress(tmpAddr.ptr());
				} else {
					s->setCacheIp(false);
					s->setIpAddress("");
				}
			} else {
#endif
				if((!kvi_strEqualCI(tmpAddr.ptr(),"0.0.0.0")) && kvi_isValidStringIp(tmpAddr.ptr()))
				{
					s->setIpAddress(tmpAddr.ptr());
				} else {
					s->setCacheIp(false);
					s->setIpAddress("");
				}
#ifdef COMPILE_IPV6_SUPPORT
			}
#endif
		} else {
			s->setCacheIp(false);
			s->setIpAddress("");
		}
	}
	if(m_pOnConnectEditor)
	{
		TQString tmp;
		m_pOnConnectEditor->getText(tmp);
		s->setOnConnectCommand(tmp);
	}
	if(m_pOnLoginEditor)
	{
		TQString tmp;
		m_pOnLoginEditor->getText(tmp);
		s->setOnLoginCommand(tmp);
	}
	if(m_pChannelListSelector)
		m_pChannelListSelector->commit();
	if(m_lstChannels.isEmpty())s->setAutoJoinChannelList(0);
	else s->setAutoJoinChannelList(new TQStringList(m_lstChannels));
	if(m_pUseAutoConnect)
		s->setAutoConnect(m_pUseAutoConnect->isChecked());
	if(m_pProxyEditor)
		s->setProxy(m_pProxyEditor->currentItem()-2);
}

void KviServerDetailsWidget::useDefaultInitUModeToggled(bool b)
{
	m_pIMode->setEnabled(!b);
	m_pWMode->setEnabled(!b);
	m_pSMode->setEnabled(!b);
}

// kvi_app.cpp
extern KVIRC_API KviIrcServerDataBase * g_pIrcServerDataBase;

KviServerOptionsListViewItem::KviServerOptionsListViewItem(KviTalListView *parent,const TQPixmap &pm,const KviIrcNetwork *n)
    : KviTalListViewItem(parent)
{
	setPixmap(0,pm);
	m_pServerData = 0;
	m_pNetworkData = new KviIrcNetwork(*n);
	setText(0,n->name());
	setText(1,n->description());
}

KviServerOptionsListViewItem::KviServerOptionsListViewItem(KviTalListViewItem *parent,const TQPixmap &pm,const KviIrcServer *s)
    : KviTalListViewItem(parent)
{
	setPixmap(0,pm);
	m_pServerData = new KviIrcServer(*s);
	setText(0,s->hostName());
	setText(1,s->description());
	m_pNetworkData = 0;
}

KviServerOptionsListViewItem::~KviServerOptionsListViewItem()
{
	if(m_pServerData)delete m_pServerData;
	if(m_pNetworkData)delete m_pNetworkData;
}

void KviServerOptionsListViewItem::updateVisibleStrings()
{
	if(m_pNetworkData)
	{
		setText(0,m_pNetworkData->name());
		setText(1,m_pNetworkData->description());
		return;
	}
	if(m_pServerData)
	{
		setText(0,m_pServerData->hostName());
		setText(1,m_pServerData->description());
	}
}








KviServerOptionsWidget::KviServerOptionsWidget(TQWidget * parent)
    : KviOptionsWidget(parent,"server_options_widget")
{
	createLayout(4,2);

	m_pContextPopup = new KviTalPopupMenu(this);
	m_pImportPopup = new KviTalPopupMenu(this);

	connect(m_pImportPopup,TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(importPopupAboutToShow()));
	connect(m_pImportPopup,TQT_SIGNAL(activated(int)),this,TQT_SLOT(importPopupActivated(int)));

	m_pServerDetailsDialog = 0;
	m_pNetworkDetailsDialog = 0;
	m_pImportFilter = 0;

	m_pListView = new KviTalListView(this);
	addWidgetToLayout(m_pListView,0,0,0,0);
	m_pListView->addColumn(__tr2qs_ctx("Server","options"));
	m_pListView->addColumn(__tr2qs_ctx("Description","options"));
	m_pListView->setRootIsDecorated(true);
	m_pListView->setAllColumnsShowFocus(true);
	m_pListView->setSelectionMode(KviTalListView::Single);
	connect(m_pListView,TQT_SIGNAL(selectionChanged(KviTalListViewItem *)),
		this,TQT_SLOT(listViewItemSelectionChanged(KviTalListViewItem *)));
	connect(m_pListView,TQT_SIGNAL(rightButtonPressed(KviTalListViewItem *,const TQPoint &,int)),
		this,TQT_SLOT(listViewRightButtonPressed(KviTalListViewItem *,const TQPoint &,int)));
	connect(m_pListView,TQT_SIGNAL(doubleClicked(KviTalListViewItem*, const TQPoint&, int )),
		this,TQT_SLOT(detailsClicked()));

#ifdef COMPILE_INFO_TIPS
	TQString tiptxt = __tr2qs_ctx("<center>This is the list of available IRC servers.<br>" \
							"Right-click on the list to add or remove servers and perform other actions.<br>"\
							"Double-click on a item for advanced options.</center>","options");
	KviTalToolTip::add(m_pListView,tiptxt);
	KviTalToolTip::add(m_pListView->viewport(),tiptxt);
#endif

	KviTalVBox * vbox = new KviTalVBox(this);
	addWidgetToLayout(vbox,1,0,1,0);

	m_pNewNetworkButton = new KviStyledToolButton(vbox);
	m_pNewNetworkButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)));
	m_pNewNetworkButton->setAutoRaise(true);
	connect(m_pNewNetworkButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(newNetwork()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNewNetworkButton,__tr2qs_ctx("New Network","options"));
#endif

	m_pNewServerButton = new KviStyledToolButton(vbox);
	m_pNewServerButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)));
	m_pNewServerButton->setAutoRaise(true);
	connect(m_pNewServerButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(newServer()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pNewServerButton,__tr2qs_ctx("New Server","options"));
#endif

	m_pRemoveButton = new KviStyledToolButton(vbox);
	m_pRemoveButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CUT)));
	m_pRemoveButton->setEnabled(false);
	m_pRemoveButton->setAutoRaise(true);
	connect(m_pRemoveButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(removeCurrent()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pRemoveButton,__tr2qs_ctx("Remove Network/Server","options"));
#endif

	TQFrame * f = new TQFrame(vbox);
	f->setFrameStyle(TQFrame::Sunken | TQFrame::HLine);

	m_pCopyServerButton = new KviStyledToolButton(vbox);
	m_pCopyServerButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_COPY)));
	m_pCopyServerButton->setEnabled(false);
	m_pCopyServerButton->setAutoRaise(true);
	connect(m_pCopyServerButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(copyServer()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pCopyServerButton,__tr2qs_ctx("Copy Server","options"));
#endif

	m_pPasteServerButton = new KviStyledToolButton(vbox);
	m_pPasteServerButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_PASTE)));
	m_pPasteServerButton->setEnabled(false);
	m_pPasteServerButton->setAutoRaise(true);
	connect(m_pPasteServerButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(pasteServer()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pPasteServerButton,__tr2qs_ctx("Paste Server","options"));
#endif

	f = new TQFrame(vbox);
	f->setFrameStyle(TQFrame::Sunken | TQFrame::HLine);

	m_pImportButton = new KviStyledToolButton(vbox);
	m_pImportButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_FOLDER)));
	m_pImportButton->setAutoRaise(true);
	m_pImportButton->setPopup(m_pImportPopup);
	m_pImportButton->setPopupDelay(1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pImportButton,__tr2qs_ctx("Import List","options"));
#endif

	TQFrame * lll = new TQFrame(vbox);
	vbox->setStretchFactor(lll,100);
	
	KviTalGroupBox *gbox = addGroupBox(0,1,1,1,3,Qt::Horizontal,__tr2qs_ctx("Active Configuration","options"));
	m_pSrvNetLabel = new TQLabel(__tr2qs_ctx("Server:","options"),gbox);

	m_pSrvNetEdit = new TQLineEdit(gbox);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pSrvNetEdit,__tr2qs_ctx("<center>This is the name of the currently selected server or network</center>","options"));
#endif

/*
	m_pIpV6Check = new KviStyledCheckBox(__tr2qs_ctx("Use IPv6 protocol","options"),gbox);

#ifndef COMPILE_IPV6_SUPPORT
	m_pIpV6Check->setEnabled(false);
#endif

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pIpV6Check,__tr2qs_ctx("<center>This check identifies IPv6 servers.<br>If enabled, KVIrc will attempt to use the IPv6 protocol " \
						"(thus your OS <b>must</b> have a working IPv6 stack and you <b>must</b> have an IPv6 connection).</center>","options"));
#endif

	m_pPortLabel = new TQLabel(__tr2qs_ctx("Port:","options"),gbox);

	m_pPortEdit = new TQLineEdit(gbox);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pPortEdit,__tr2qs_ctx("<center>This is the default <b>port</b> that this server will be contacted on.<br>Usually <b>6667</b> is OK.</center>","options"));
#endif
*/

	m_pDetailsButton = new TQPushButton(__tr2qs_ctx("Advanced...","options"),gbox);
	connect(m_pDetailsButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(detailsClicked()));
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pDetailsButton,__tr2qs_ctx("<center>Click here to edit advanced options for this entry</center>","options"));
#endif

	m_pConnectCurrent = new TQPushButton(__tr2qs_ctx("Connect &Now","options"),this);
	addWidgetToLayout(m_pConnectCurrent,0,2,0,2);
	connect(m_pConnectCurrent,TQT_SIGNAL(clicked()),this,TQT_SLOT(connectCurrentClicked()));

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(m_pConnectCurrent,__tr2qs_ctx("<center>Hit this button to connect to the currently selected server.</center>","options"));
#endif

	m_pRecentPopup = new KviTalPopupMenu(this);
	connect(m_pRecentPopup,TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(recentServersPopupAboutToShow()));
	connect(m_pRecentPopup,TQT_SIGNAL(activated(int)),this,TQT_SLOT(recentServersPopupClicked(int)));

	TQToolButton * tb = new KviStyledToolButton(this);
	addWidgetToLayout(tb,1,2,1,2);
	tb->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_TIME)));
	tb->setPopup(m_pRecentPopup);
	tb->setPopupDelay(1);
#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(tb,__tr2qs_ctx("<center>This button shows a list of recently used servers. It allows you to quickly find them in the list.</center>","options"));
#endif


	KviBoolSelector * b = addBoolSelector(0,3,1,3,__tr2qs_ctx("Show this dialog at startup","options"),KviOption_boolShowServersConnectDialogOnStart);

#ifdef COMPILE_INFO_TIPS
	KviTalToolTip::add(b,__tr2qs_ctx("<center>If this option is enabled, the Servers dialog will appear every time you start KVIrc</center>","options"));
#endif

	// KviBoolSelector * c = addBoolSelector(0,6,2,6,__tr("Close after connection","options"),KviOption_boolCloseServerWidgetAfterConnect);

	m_pLastEditedItem = 0;

	m_pClipboard = 0;

	fillServerList();

	tqlayout()->setRowStretch(0,1);
	//tqlayout()->setColStretch(1,5);
	//tqlayout()->setColStretch(2,2);
	tqlayout()->setColStretch(0,1);
	setMinimumWidth(320);
}

KviServerOptionsWidget::~KviServerOptionsWidget()
{
	if(m_pImportFilter)
	{
		disconnect(m_pImportFilter,0,this,0);
		m_pImportFilter->die();
		m_pImportFilter = 0;
	}

	if(m_pClipboard)delete m_pClipboard;
	if(m_pServerDetailsDialog)delete m_pServerDetailsDialog;
	if(m_pNetworkDetailsDialog)delete m_pNetworkDetailsDialog;
}

void KviServerOptionsWidget::recentServersPopupAboutToShow()
{
	g_pApp->fillRecentServersPopup(m_pRecentPopup);
}

void KviServerOptionsWidget::recentServersPopupClicked(int id)
{
	KviStr data = m_pRecentPopup->text(id);
	data.cutToFirst('/');
	while(data.firstCharIs('/'))data.cutLeft(1);
	data.cutFromLast(':');
	data.replaceAll("/","");
	// we should have a full server name now , with no port
	
	KviStr port = m_pRecentPopup->text(id);
	port.cutToLast(':');
	bool bOk;
	kvi_u32_t uPort = port.toUInt(&bOk);
	// we have the port too

	KviTalListViewItem * pFoundNet = 0;
	KviTalListViewItem * pFoundSrv = 0;

	for(KviTalListViewItem * net = m_pListView->firstChild();net;net = net->nextSibling())
	{
		for(KviTalListViewItem * srv = net->firstChild();srv;srv = srv->nextSibling())
		{
			KviStr tmp = ((KviServerOptionsListViewItem *)srv)->m_pServerData->hostName();
			if(kvi_strEqualCI(tmp.ptr(),data.ptr()))
			{
				if(((KviServerOptionsListViewItem *)srv)->m_pServerData->port() == uPort)
				{
					net->setOpen(true);
					m_pListView->setCurrentItem(srv);
					m_pListView->ensureItemVisible(srv);
					return;
				} else {
					if(!pFoundNet)
					{
						// the port doesn't match.. check for
						// another entry with the correct port
						// but keep track of this entry in case we don't find it
						pFoundNet = srv;
						pFoundSrv = net;
					}
				}
			}
		}
	}
	
	// fallback to the server with the wrong port
	if(pFoundNet)
	{
		pFoundNet->setOpen(true);
		m_pListView->setCurrentItem(pFoundSrv);
		m_pListView->ensureItemVisible(pFoundSrv);
	}
}


void KviServerOptionsWidget::connectCurrentClicked()
{
	saveLastItem();
	commit();
	KviStr szServer = m_pSrvNetEdit->text();
	if(szServer.isEmpty())return;
	KviKvsScript::run("server -u",g_pApp->activeConsole());
}


void KviServerOptionsWidget::fillServerList()
{
	KviServerOptionsListViewItem * net;
	KviServerOptionsListViewItem * srv;
	KviServerOptionsListViewItem * cur = 0;

	KviPointerHashTableIterator<TQString,KviIrcServerDataBaseRecord> it(*(g_pIrcServerDataBase->recordDict()));

	while(KviIrcServerDataBaseRecord * r = it.current())
	{
		net = new KviServerOptionsListViewItem(m_pListView,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)),r->network());
		KviPointerList<KviIrcServer> * sl = r->serverList();
		bool bCurrent = r->network()->name() == g_pIrcServerDataBase->currentNetworkName().utf8().data();
		net->setOpen(bCurrent);
		for(KviIrcServer * s = sl->first();s;s = sl->next())
		{
			srv = new KviServerOptionsListViewItem(net,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)),s);

			if((s == r->currentServer()) && bCurrent)
			{
				m_pListView->setSelected(srv,true);
				cur = srv;
			}
		}
		++it;
	}
	if(cur)m_pListView->ensureItemVisible(cur);
}

void KviServerOptionsWidget::listViewItemSelectionChanged(KviTalListViewItem *it)
{
	saveLastItem();
	m_pLastEditedItem = (KviServerOptionsListViewItem *)it;

	if(m_pLastEditedItem)
	{
		m_pSrvNetLabel->setEnabled(true);
		m_pSrvNetEdit->setEnabled(true);
		m_pDetailsButton->setEnabled(true);
		m_pConnectCurrent->setEnabled(m_pLastEditedItem->m_pServerData);

		m_pRemoveButton->setEnabled(true);
		m_pCopyServerButton->setEnabled(m_pLastEditedItem->m_pServerData);

		if(m_pLastEditedItem->m_pServerData)
		{
			m_pSrvNetLabel->setText(__tr2qs_ctx("Server:","options"));
			m_pSrvNetEdit->setText(m_pLastEditedItem->m_pServerData->m_szHostname);
		} else {
			m_pSrvNetLabel->setText(__tr2qs_ctx("Network:","options"));
			m_pSrvNetEdit->setText(it->text(0));
		}
	} else {
		m_pRemoveButton->setEnabled(false);
		m_pCopyServerButton->setEnabled(true);
		
		m_pConnectCurrent->setEnabled(false);
		m_pSrvNetLabel->setEnabled(false);
		m_pSrvNetEdit->setEnabled(false);
		m_pSrvNetEdit->setText(__tr2qs_ctx("No selection","options"));
		m_pDetailsButton->setEnabled(false);
	}
}



void KviServerOptionsWidget::saveLastItem()
{
	if(!m_pLastEditedItem)return;
	if(m_pLastEditedItem->m_pServerData)
	{
		KviStr tmp = m_pSrvNetEdit->text();
		if(tmp.isEmpty())tmp = "irc.unknown.net";
		m_pLastEditedItem->m_pServerData->m_szHostname = tmp;
		m_pLastEditedItem->updateVisibleStrings();
	} else if(m_pLastEditedItem->m_pNetworkData)
	{
		TQString tmp = m_pSrvNetEdit->text();
		if(tmp.isEmpty())tmp = __tr2qs_ctx("UnknownNet","options");
		m_pLastEditedItem->m_pNetworkData->setName(tmp);
		m_pLastEditedItem->updateVisibleStrings();
	}
}

void KviServerOptionsWidget::commit()
{
	saveLastItem();
	g_pIrcServerDataBase->clear();
	KviServerOptionsListViewItem * it = (KviServerOptionsListViewItem *)m_pListView->firstChild();
	while(it)
	{
		TQString tmp = it->m_pNetworkData ? it->m_pNetworkData->name() : TQString();
		if(!tmp.isEmpty())
		{
			KviIrcNetwork * net = 0;
			KviIrcServerDataBaseRecord * r = g_pIrcServerDataBase->findRecord(tmp);
			if(r)
			{
				net = r->network();
				net->copyFrom(*(it->m_pNetworkData));
			} else {
				net = new KviIrcNetwork(tmp);
				net->copyFrom(*(it->m_pNetworkData));
				r = g_pIrcServerDataBase->insertNetwork(net);
			}
			if(it == m_pLastEditedItem)g_pIrcServerDataBase->setCurrentNetwork(net->name());

			KviServerOptionsListViewItem * ch = (KviServerOptionsListViewItem *)it->firstChild();
			KviIrcServer *srv;
			
			while(ch)
			{
				if(ch->m_pServerData)
				{
					if(!ch->m_pServerData->m_szHostname.isEmpty())
					{
						srv = r->findServer(ch->m_pServerData);
						if(!srv)
						{
							srv = new KviIrcServer(*(ch->m_pServerData));
							r->insertServer(srv);
						} else *srv = *(ch->m_pServerData);
						if(srv->id().isEmpty())srv->generateUniqueId();
						if(ch == m_pLastEditedItem)
						{
							g_pIrcServerDataBase->setCurrentNetwork(net->name());
							r->setCurrentServer(srv);
						}
					}
				}
				ch = (KviServerOptionsListViewItem *)ch->nextSibling();
			}
		}
		it = (KviServerOptionsListViewItem *)it->nextSibling();
	}

	KviOptionsWidget::commit();
}

void KviServerOptionsWidget::listViewRightButtonPressed(KviTalListViewItem *it,const TQPoint &pnt,int col)
{
	int id;
	bool bServer = (it && ((KviServerOptionsListViewItem *)it)->m_pServerData);
	m_pContextPopup->clear();
	m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)),__tr2qs_ctx("New Network","options"),this,TQT_SLOT(newNetwork()));
	id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CUT)),__tr2qs_ctx("Remove Network","options"),this,TQT_SLOT(removeCurrent()));
	m_pContextPopup->setItemEnabled(id,!bServer);
	m_pContextPopup->insertSeparator();
	id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)),__tr2qs_ctx("&New Server","options"),this,TQT_SLOT(newServer()));
	id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CUT)),__tr2qs_ctx("Re&move Server","options"),this,TQT_SLOT(removeCurrent()));
	m_pContextPopup->setItemEnabled(id,bServer);
	id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_COPY)),__tr2qs_ctx("&Copy Server","options"),this,TQT_SLOT(copyServer()));
	m_pContextPopup->setItemEnabled(id,bServer);
	id = m_pContextPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_PASTE)),__tr2qs_ctx("&Paste Server","options"),this,TQT_SLOT(pasteServer()));
	m_pContextPopup->setItemEnabled(id,m_pClipboard);

	m_pContextPopup->insertSeparator();
	//	m_pContextPopup->insertItem(__c2q(__tr("Merge list from server.ini","options")),this,TQT_SLOT(importFromIni()));
	m_pContextPopup->insertItem(__tr2qs_ctx("Clear List","options"),this,TQT_SLOT(clearList()));
	m_pContextPopup->insertSeparator();
	m_pContextPopup->insertItem(__tr2qs_ctx("Import List","options"),m_pImportPopup);
	m_pContextPopup->popup(TQCursor::pos());
}

void KviServerOptionsWidget::importPopupAboutToShow()
{
	g_pModuleManager->loadModulesByCaps("serverimport");
	m_pImportPopup->clear();

	KviModuleExtensionDescriptorList * l = KviModuleExtensionManager::instance()->getExtensionList("serverimport");

	if(!l)return;

	int id;

	for(KviModuleExtensionDescriptor * d = l->first();d;d = l->next())
	{
		if(d->icon())
			id = m_pImportPopup->insertItem(*(d->icon()),d->visibleName());
		else
			id = m_pImportPopup->insertItem(d->visibleName());
		m_pImportPopup->setItemParameter(id,d->id());
	}
}

void KviServerOptionsWidget::importPopupActivated(int id)
{
	// ensure that we have all the modules : they could have been unloaded while the popup was displayed
	g_pModuleManager->loadModulesByCaps("serverimport");

	KviModuleExtensionDescriptorList * l = KviModuleExtensionManager::instance()->getExtensionList("serverimport");

	if(!l)
	{
		// ops.. internal error: I thought to have a module capable of importing servers
		// but actually it's not the case.. something weird happened (in the best case
		// the user has just unloaded the module and removed it from disk ?)
		KviMessageBox::warning(__tr2qs_ctx("Oops... something weird happened:<br>Can't find any module capable of importing servers.","options"));
		return;
	}

	if(m_pImportFilter)
	{
		disconnect(m_pImportFilter,0,this,0);
		m_pImportFilter->die();
		m_pImportFilter = 0;
	}

	id = m_pImportPopup->itemParameter(id);

	m_pImportFilter = (KviMexServerImport *)KviModuleExtensionManager::instance()->allocateExtension("serverimport",id,0);

	if(!m_pImportFilter)
	{
		KviMessageBox::warning(__tr2qs_ctx("Oops... something weird happened:<br>Can't find the module that was capable of this import action. :(","options"));
		return;
	}

	connect(m_pImportFilter,TQT_SIGNAL(server(const KviIrcServer &,const char *)),this,TQT_SLOT(importServer(const KviIrcServer &,const char *)));
	connect(m_pImportFilter,TQT_SIGNAL(destroyed()),this,TQT_SLOT(importerDead()));

	m_pImportFilter->start();
}

void KviServerOptionsWidget::importerDead()
{
	m_pImportFilter = 0;
}

void KviServerOptionsWidget::importServer(const KviIrcServer &s,const char * network)
{
	KviServerOptionsListViewItem * net = findNetItem(network);
	if(!net)
	{
		KviIrcNetwork d(network);
		net = new KviServerOptionsListViewItem(m_pListView,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)),&d);
		net->setOpen(true);
	}

	for(KviServerOptionsListViewItem * srv = (KviServerOptionsListViewItem *)net->firstChild();srv;srv = (KviServerOptionsListViewItem *)srv->nextSibling())
	{
		if((srv)->m_pServerData->useSSL() == s.useSSL())
		{
			if(srv->m_pServerData->isIpV6() == s.isIpV6())
			{
				if(KviTQString::equalCI(srv->m_pServerData->hostName(),s.hostName()))
				{
					// update the port
					srv->m_pServerData->setPort(s.port());
					if(!s.ipAddress().isEmpty())srv->m_pServerData->setIpAddress(s.ipAddress());
					if(!s.password().isEmpty())srv->m_pServerData->setPassword(s.password());
					if(!s.nickName().isEmpty())srv->m_pServerData->setNickName(s.nickName());
					m_pListView->setCurrentItem(srv);
					m_pListView->ensureItemVisible(srv);
					return;
				}
			}
		}
	}

	// not found : add it!
	KviServerOptionsListViewItem * newServer = new KviServerOptionsListViewItem(net,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)),&s);
	m_pListView->setCurrentItem(newServer);
	m_pListView->ensureItemVisible(newServer);
}

void KviServerOptionsWidget::newNetwork()
{
	KviIrcNetwork d(__tr2qs_ctx("New Network","options"));
	KviServerOptionsListViewItem * it = new KviServerOptionsListViewItem(m_pListView,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_WORLD)),&d);
	it->setOpen(true);
	m_pListView->setSelected(it,true);
	m_pListView->ensureItemVisible(it);
}

void KviServerOptionsWidget::newServer()
{
	if(m_pLastEditedItem)
	{
		KviServerOptionsListViewItem * net;
		if(m_pLastEditedItem->m_pServerData)
		{
			net = (KviServerOptionsListViewItem *)m_pLastEditedItem->parent();
			if(!net)return;
		}
		else net = m_pLastEditedItem;

		KviIrcServer tmp;
		tmp.m_szHostname = __tr2qs_ctx("irc.unknown.net","options");
		tmp.setCacheIp(false);
		tmp.generateUniqueId();

		KviServerOptionsListViewItem * it = new KviServerOptionsListViewItem(net,
									*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)),&tmp);

		net->setOpen(true);

		m_pListView->setSelected(it,true);
		m_pListView->ensureItemVisible(it);
	}
}

void KviServerOptionsWidget::copyServer()
{
	if(m_pLastEditedItem)
	{
		if(m_pLastEditedItem->m_pServerData)
		{
			if(!m_pClipboard)m_pClipboard = new KviIrcServer();
			*m_pClipboard = *(m_pLastEditedItem->m_pServerData);
			m_pPasteServerButton->setEnabled(true);
		}
	}
}

void KviServerOptionsWidget::pasteServer()
{
	if(m_pClipboard)
	{
		if(m_pLastEditedItem)
		{
			KviServerOptionsListViewItem * net;
			if(m_pLastEditedItem->m_pServerData)
			{
				net = (KviServerOptionsListViewItem *)m_pLastEditedItem->parent();
				if(!net)return;
			}
			else net = m_pLastEditedItem;

			KviServerOptionsListViewItem * it = new KviServerOptionsListViewItem(net,
							*(g_pIconManager->getSmallIcon(KVI_SMALLICON_SERVER)),m_pClipboard);

			net->setOpen(true);

			m_pListView->setSelected(it,true);
			m_pListView->ensureItemVisible(it);
		}
	}
}

void KviServerOptionsWidget::removeCurrent()
{
	if(m_pLastEditedItem)
	{
		KviTalListViewItem * it = m_pLastEditedItem->itemAbove();
		if(!it)it = m_pLastEditedItem->firstChild() ? m_pLastEditedItem->nextSibling() : m_pLastEditedItem->itemBelow();
		delete m_pLastEditedItem;
		m_pLastEditedItem = 0;
		if(!it)it = m_pListView->firstChild();
		if(it)
		{
			m_pListView->setSelected(it,true);
			m_pListView->ensureItemVisible(it);
		}
	}
}

KviServerOptionsListViewItem * KviServerOptionsWidget::findNetItem(const char * netname)
{
	KviServerOptionsListViewItem * it = (KviServerOptionsListViewItem *)m_pListView->firstChild();
	while(it)
	{
		KviStr szNetName = it->text(0);
		if(kvi_strEqualCI(szNetName.ptr(),netname))return it;
		it = (KviServerOptionsListViewItem *)it->nextSibling();
	}
	return 0;
}

void KviServerOptionsWidget::clearList()
{
	m_pListView->clear();
	m_pLastEditedItem = 0;
	listViewItemSelectionChanged(0);
}

void KviServerOptionsWidget::detailsClicked()
{
	if(!m_pLastEditedItem)return;
	if(m_pLastEditedItem->m_pServerData)
	{
		saveLastItem();

		m_pServerDetailsDialog = new KviServerDetailsWidget(this,m_pLastEditedItem->m_pServerData);

		int retCode = m_pServerDetailsDialog->exec();
		if(retCode == TQDialog::Accepted)
		{
			if(m_pLastEditedItem)
			{
				if(m_pLastEditedItem->m_pServerData)
				{
					m_pServerDetailsDialog->fillData(m_pLastEditedItem->m_pServerData);
					saveLastItem();
				}
			}
		}

		delete m_pServerDetailsDialog;
		m_pServerDetailsDialog = 0;
		return;
	}
	if(m_pLastEditedItem->m_pNetworkData)
	{
		saveLastItem();

		m_pNetworkDetailsDialog = new KviNetworkDetailsWidget(this,m_pLastEditedItem->m_pNetworkData);

		int retCode = m_pNetworkDetailsDialog->exec();
		if(retCode == TQDialog::Accepted)
		{
			if(m_pLastEditedItem)
			{
				if(m_pLastEditedItem->m_pNetworkData)
				{
					m_pNetworkDetailsDialog->fillData(m_pLastEditedItem->m_pNetworkData);
					saveLastItem();
				}
			}
		}

		delete m_pNetworkDetailsDialog;
		m_pNetworkDetailsDialog = 0;
	}
}

#include "m_optw_servers.moc"