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
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
|
/*
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.
*/
/*
Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
Copyright (C) 2005 Ismail Donmez <ismail@kde.org>
Copyright (C) 2005 Peter Simonsson <psn@linux.se>
Copyright (C) 2005 John Tapsell <johnflux@gmail.com>
Copyright (C) 2005-2008 Eike Hein <hein@kde.org>
*/
#include "outputfilter.h"
#include "konversationapplication.h"
#include "konversationmainwindow.h"
#include "awaymanager.h"
#include "ignore.h"
#include "server.h"
#include "irccharsets.h"
#include "linkaddressbook/addressbook.h"
#include "query.h"
#include <tqstringlist.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqregexp.h>
#include <tqmap.h>
#include <tqvaluelist.h>
#include <tqtextcodec.h>
#include <klocale.h>
#include <kdebug.h>
#include <kio/passdlg.h>
#include <kconfig.h>
#include <kdeversion.h>
#include <kshell.h>
#include <ksocketaddress.h>
#include <kresolver.h>
#include <kreverseresolver.h>
#include <kmessagebox.h>
namespace Konversation
{
OutputFilter::OutputFilter(Server* server)
: TQObject(server)
{
m_server = server;
}
OutputFilter::~OutputFilter()
{
}
// replace all aliases in the string and return true if anything got replaced at all
bool OutputFilter::replaceAliases(TQString& line)
{
TQStringList aliasList=Preferences::aliasList();
TQString cc(Preferences::commandChar());
// check if the line starts with a defined alias
for(unsigned int index=0;index<aliasList.count();index++)
{
// cut alias pattern from definition
TQString aliasPattern(aliasList[index].section(' ',0,0));
// cut first word from command line, so we do not wrongly find an alias
// that starts with the same letters, like /m would override /me
TQString lineStart=line.section(' ',0,0);
// pattern found?
// TODO: cc may be a regexp character here ... we should escape it then
if (lineStart==cc+aliasPattern)
{
TQString aliasReplace;
// cut alias replacement from definition
if ( aliasList[index].tqcontains("%p") )
aliasReplace = aliasList[index].section(' ',1);
else
aliasReplace = aliasList[index].section(' ',1 )+' '+line.section(' ',1 );
// protect "%%"
aliasReplace.tqreplace("%%","%\x01");
// tqreplace %p placeholder with rest of line
aliasReplace.tqreplace("%p",line.section(' ',1));
// restore "%<1>" as "%%"
aliasReplace.tqreplace("%\x01","%%");
// modify line
line=aliasReplace;
// return "replaced"
return true;
}
} // for
return false;
}
TQStringList OutputFilter::splitForEncoding(const TQString& inputLine, uint max)
{
uint sublen = 0; //The encoded length since the last split
int charLength = 0; //the length of this char
int lastBreakPoint = 0;
//FIXME should we run this through the encoder first, checking with "canEncode"?
TQString text = inputLine; // the text we'll send, currently in Unicode
TQStringList finals; // The strings we're going to output
TQString channelCodecName=Preferences::channelEncoding(m_server->getDisplayName(), destination);
//Get the codec we're supposed to use. This must not fail. (not verified)
TQTextCodec* codec;
// I copied this bit straight out of Server::send
if (channelCodecName.isEmpty())
{
codec = m_server->getIdentity()->getCodec();
}
else
{
codec = Konversation::IRCCharsets::self()->codecForName(channelCodecName);
}
Q_ASSERT(codec);
int index = 0;
while(text.length() > max)
{
// The most important bit - turn the current char into a TQCString so we can measure it
TQCString ch = codec->fromUnicode(TQString(text[index]));
charLength = ch.length();
// If adding this char puts us over the limit:
if (charLength + sublen > max)
{
if(lastBreakPoint != 0)
{
finals.append(text.left(lastBreakPoint + 1));
text = text.mid(lastBreakPoint + 1);
}
else
{
finals.append(text.left(index));
text = text.mid(index);
}
lastBreakPoint = 0;
sublen = 0;
index = 0;
}
else if (text[index].isSpace() || text[index].isPunct())
{
lastBreakPoint = index;
}
++index;
sublen += charLength;
}
if (!text.isEmpty())
{
finals.append(text);
}
return finals;
}
OutputFilterResult OutputFilter::parse(const TQString& myNick,const TQString& originalLine,const TQString& name)
{
setCommandChar();
OutputFilterResult result;
destination=name;
TQString inputLine(originalLine);
if(inputLine.isEmpty() || inputLine == "\n")
return result;
//Protect against nickserv auth being sent as a message on the off chance
// someone didn't notice leading spaces
{
TQString testNickServ( inputLine.stripWhiteSpace() );
if(testNickServ.tqstartsWith(commandChar+"nickserv", false)
|| testNickServ.tqstartsWith(commandChar+"ns", false))
{
inputLine = testNickServ;
}
}
if(!Preferences::disableExpansion())
{
// replace placeholders
inputLine.tqreplace("%%","%\x01"); // make sure to protect double %%
inputLine.tqreplace("%B","\x02"); // tqreplace %B with bold char
inputLine.tqreplace("%C","\x03"); // tqreplace %C with color char
inputLine.tqreplace("%G","\x07"); // tqreplace %G with ASCII BEL 0x07
inputLine.tqreplace("%I","\x09"); // tqreplace %I with italics char
inputLine.tqreplace("%O","\x0f"); // tqreplace %O with reset to default char
inputLine.tqreplace("%S","\x13"); // tqreplace %S with strikethru char
// inputLine.tqreplace(TQRegExp("%?"),"\x15");
inputLine.tqreplace("%R","\x16"); // tqreplace %R with reverse char
inputLine.tqreplace("%U","\x1f"); // tqreplace %U with underline char
inputLine.tqreplace("%\x01","%"); // restore double %% as single %
}
TQString line=inputLine.lower();
// Convert double command chars at the beginning to single ones
if(line.startsWith(commandChar+commandChar) && !destination.isEmpty())
{
inputLine=inputLine.mid(1);
goto BYPASS_COMMAND_PARSING;
}
// Server command?
else if(line.startsWith(commandChar))
{
TQString command = inputLine.section(' ', 0, 0).mid(1).lower();
TQString parameter = inputLine.section(' ', 1);
if (command !="topic")
parameter = parameter.stripWhiteSpace();
if (command == "join") result = parseJoin(parameter);
else if(command == "part") result = parsePart(parameter);
else if(command == "leave") result = parsePart(parameter);
else if(command == "quit") result = parseQuit(parameter);
else if(command == "close") result = parseClose(parameter);
else if(command == "notice") result = parseNotice(parameter);
else if(command == "j") result = parseJoin(parameter);
else if(command == "me") result = parseMe(parameter, destination);
else if(command == "msg") result = parseMsg(myNick,parameter, false);
else if(command == "m") result = parseMsg(myNick,parameter, false);
else if(command == "smsg") result = parseSMsg(parameter);
else if(command == "query") result = parseMsg(myNick,parameter, true);
else if(command == "op") result = parseOp(parameter);
else if(command == "deop") result = parseDeop(myNick,parameter);
else if(command == "hop") result = parseHop(parameter);
else if(command == "dehop") result = parseDehop(myNick,parameter);
else if(command == "voice") result = parseVoice(parameter);
else if(command == "unvoice") result = parseUnvoice(myNick,parameter);
else if(command == "devoice") result = parseUnvoice(myNick,parameter);
else if(command == "ctcp") result = parseCtcp(parameter);
else if(command == "ping") result = parseCtcp(parameter.section(' ', 0, 0) + " ping");
else if(command == "kick") result = parseKick(parameter);
else if(command == "topic") result = parseTopic(parameter);
else if(command == "away") parseAway(parameter);
else if(command == "unaway") parseBack();
else if(command == "back") parseBack();
else if(command == "invite") result = parseInvite(parameter);
else if(command == "exec") result = parseExec(parameter);
else if(command == "notify") result = parseNotify(parameter);
else if(command == "oper") result = parseOper(myNick,parameter);
else if(command == "ban") result = parseBan(parameter);
else if(command == "unban") result = parseUnban(parameter);
else if(command == "kickban") result = parseBan(parameter,true);
else if(command == "ignore") result = parseIgnore(parameter);
else if(command == "unignore") result = parseUnignore(parameter);
else if(command == "quote") result = parseQuote(parameter);
else if(command == "say") result = parseSay(parameter);
else if(command == "list") result = parseList(parameter);
else if(command == "names") result = parseNames(parameter);
else if(command == "raw") result = parseRaw(parameter);
else if(command == "dcc") result = parseDcc(parameter);
else if(command == "konsole") parseKonsole();
else if(command == "aaway") KonversationApplication::instance()->getAwayManager()->requestAllAway(parameter);
else if(command == "aunaway") KonversationApplication::instance()->getAwayManager()->requestAllUnaway();
else if(command == "aback") KonversationApplication::instance()->getAwayManager()->requestAllUnaway();
else if(command == "ame") result = parseAme(parameter);
else if(command == "amsg") result = parseAmsg(parameter);
else if(command == "omsg") result = parseOmsg(parameter);
else if(command == "onotice") result = parseOnotice(parameter);
else if(command == "server") parseServer(parameter);
else if(command == "reconnect") emit reconnectServer();
else if(command == "disconnect") emit disconnectServer();
else if(command == "charset") result = parseCharset(parameter);
else if(command == "encoding") result = parseCharset(parameter);
else if(command == "setkey") result = parseSetKey(parameter);
else if(command == "delkey") result = parseDelKey(parameter);
else if(command == "showkey") result = parseShowKey(parameter);
else if(command == "dns") result = parseDNS(parameter);
else if(command == "kill") result = parseKill(parameter);
else if(command == "queuetuner") result = parseShowTuner(parameter);
// Forward unknown commands to server
else
{
result.toServer = inputLine.mid(1);
result.type = Message;
}
}
// Ordinary message to channel/query?
else if(!destination.isEmpty())
{
BYPASS_COMMAND_PARSING:
TQStringList outputList=splitForEncoding(inputLine, m_server->getPreLength("PRIVMSG", destination));
if (outputList.count() > 1)
{
result.output=TQString();
result.outputList=outputList;
for ( TQStringList::Iterator it = outputList.begin(); it != outputList.end(); ++it )
{
result.toServerList += "PRIVMSG " + destination + " :" + *it;
}
}
else
{
result.output = inputLine;
result.toServer = "PRIVMSG " + destination + " :" + inputLine;
}
result.type = Message;
}
// Eveything else goes to the server unchanged
else
{
result.toServer = inputLine;
result.output = inputLine;
result.typeString = i18n("Raw");
result.type = Program;
}
return result;
}
OutputFilterResult OutputFilter::parseShowTuner(const TQString ¶meter)
{
KonversationApplication *konvApp = static_cast<KonversationApplication*>(KApplication::kApplication());
OutputFilterResult result;
if(parameter.isEmpty() || parameter == "on")
konvApp->showQueueTuner(true);
else if(parameter == "off")
konvApp->showQueueTuner(false);
else
result = usage(i18n("Usage: %1queuetuner [on | off]").tqarg(commandChar));
return result;
}
OutputFilterResult OutputFilter::parseOp(const TQString ¶meter)
{
return changeMode(parameter,'o','+');
}
OutputFilterResult OutputFilter::parseDeop(const TQString &ownNick, const TQString ¶meter)
{
return changeMode(addNickToEmptyNickList(ownNick,parameter),'o','-');
}
OutputFilterResult OutputFilter::parseHop(const TQString ¶meter)
{
return changeMode(parameter, 'h', '+');
}
OutputFilterResult OutputFilter::parseDehop(const TQString &ownNick, const TQString ¶meter)
{
return changeMode(addNickToEmptyNickList(ownNick,parameter), 'h', '-');
}
OutputFilterResult OutputFilter::parseVoice(const TQString ¶meter)
{
return changeMode(parameter,'v','+');
}
OutputFilterResult OutputFilter::parseUnvoice(const TQString &ownNick, const TQString ¶meter)
{
return changeMode(addNickToEmptyNickList(ownNick,parameter),'v','-');
}
OutputFilterResult OutputFilter::parseJoin(TQString& channelName)
{
OutputFilterResult result;
if(channelName.tqcontains(",")) // Protect against #foo,0 tricks
channelName = channelName.remove(",0");
//else if(channelName == "0") // FIXME IRC RFC 2812 section 3.2.1
if (channelName.isEmpty())
{
if (destination.isEmpty() || !isAChannel(destination))
return usage(i18n("Usage: %1JOIN <channel> [password]").tqarg(commandChar));
channelName=destination;
}
else if (!isAChannel(channelName))
channelName = "#" + channelName.stripWhiteSpace();
Channel* channel = m_server->getChannelByName(channelName);
if (channel)
{
// Note that this relies on the channels-flush-nicklists-on-disconnect behavior.
if (!channel->numberOfNicks())
result.toServer = "JOIN " + channelName;
if (channel->joined()) emit showView (channel);
}
else
result.toServer = "JOIN " + channelName;
return result;
}
OutputFilterResult OutputFilter::parseKick(const TQString ¶meter)
{
OutputFilterResult result;
if(isAChannel(destination))
{
// get nick to kick
TQString victim = parameter.left(parameter.tqfind(" "));
if(victim.isEmpty())
{
result = usage(i18n("Usage: %1KICK <nick> [reason]").tqarg(commandChar));
}
else
{
// get kick reason (if any)
TQString reason = parameter.mid(victim.length() + 1);
// if no reason given, take default reason
if(reason.isEmpty())
{
reason = m_server->getIdentity()->getKickReason();
}
result.toServer = "KICK " + destination + ' ' + victim + " :" + reason;
}
}
else
{
result = error(i18n("%1KICK only works from within channels.").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parsePart(const TQString ¶meter)
{
OutputFilterResult result;
// No parameter, try default part message
if(parameter.isEmpty())
{
// But only if we actually are in a channel
if(isAChannel(destination))
{
result.toServer = "PART " + destination + " :" + m_server->getIdentity()->getPartReason();
}
else
{
result = error(i18n("%1PART without parameters only works from within a channel or a query.").tqarg(commandChar));
}
}
else
{
// part a given channel
if(isAChannel(parameter))
{
// get channel name
TQString channel = parameter.left(parameter.tqfind(" "));
// get part reason (if any)
TQString reason = parameter.mid(channel.length() + 1);
// if no reason given, take default reason
if(reason.isEmpty())
{
reason = m_server->getIdentity()->getPartReason();
}
result.toServer = "PART " + channel + " :" + reason;
}
// part this channel with a given reason
else
{
if(isAChannel(destination))
{
result.toServer = "PART " + destination + " :" + parameter;
}
else
{
result = error(i18n("%1PART without channel name only works from within a channel.").tqarg(commandChar));
}
}
}
return result;
}
OutputFilterResult OutputFilter::parseTopic(const TQString ¶meter)
{
OutputFilterResult result;
// No parameter, try to get current topic
if(parameter.isEmpty())
{
// But only if we actually are in a channel
if(isAChannel(destination))
{
result.toServer = "TOPIC " + destination;
}
else
{
result = error(i18n("%1TOPIC without parameters only works from within a channel.").tqarg(commandChar));
}
}
else
{
// retrieve or set topic of a given channel
if(isAChannel(parameter))
{
// get channel name
TQString channel=parameter.left(parameter.tqfind(" "));
// get topic (if any)
TQString topic=parameter.mid(channel.length()+1);
// if no topic given, retrieve topic
if(topic.isEmpty())
{
m_server->requestTopic(channel);
}
// otherwise set topic there
else
{
result.toServer = "TOPIC " + channel + " :";
//If we get passed a ^A as a topic its a sign we should clear the topic.
//Used to be a \n, but those get smashed by TQStringList::split and readded later
//Now is not the time to fight with that. FIXME
//If anyone out there *can* actually set the topic to a single ^A, now they have to
//specify it twice to get one.
if (topic =="\x01\x01")
result.toServer += '\x01';
else if (topic!="\x01")
result.toServer += topic;
}
}
// set this channel's topic
else
{
if(isAChannel(destination))
{
result.toServer = "TOPIC " + destination + " :" + parameter;
}
else
{
result = error(i18n("%1TOPIC without channel name only works from within a channel.").tqarg(commandChar));
}
}
}
return result;
}
void OutputFilter::parseAway(TQString& reason)
{
if (reason.isEmpty() && m_server->isAway())
m_server->requestUnaway();
else
m_server->requestAway(reason);
}
void OutputFilter::parseBack()
{
m_server->requestUnaway();
}
OutputFilterResult OutputFilter::parseNames(const TQString ¶meter)
{
OutputFilterResult result;
result.toServer = "NAMES ";
if (parameter.isNull())
{
return error(i18n("%1NAMES with no target may disconnect you from the server. Specify '*' if you really want this.").tqarg(commandChar));
}
else if (parameter != TQChar('*'))
{
result.toServer.append(parameter);
}
return result;
}
OutputFilterResult OutputFilter::parseClose(TQString parm)
{
if (parm.isEmpty())
parm=destination;
if (isAChannel(parm) && m_server->getChannelByName(parm))
m_server->getChannelByName(parm)->closeYourself(false);
else if (m_server->getQueryByName(parm))
m_server->getQueryByName(parm)->closeYourself(false);
else if (parm.isEmpty()) // this can only mean one thing.. we're in the Server tab
m_server->closeYourself(false);
else
return usage(i18n("Usage: %1close [window] closes the named channel or query tab, or the current tab if none specified.").tqarg(commandChar));
return OutputFilterResult();
}
OutputFilterResult OutputFilter::parseQuit(const TQString &reason)
{
OutputFilterResult result;
result.toServer = "TQUIT :";
// if no reason given, take default reason
if(reason.isEmpty())
result.toServer += m_server->getIdentity()->getQuitReason();
else
result.toServer += reason;
return result;
}
OutputFilterResult OutputFilter::parseNotice(const TQString ¶meter)
{
OutputFilterResult result;
TQString recipient = parameter.left(parameter.tqfind(" "));
TQString message = parameter.mid(recipient.length()+1);
if(parameter.isEmpty() || message.isEmpty())
{
result = usage(i18n("Usage: %1NOTICE <recipient> <message>").tqarg(commandChar));
}
else
{
result.typeString = i18n("Notice");
result.toServer = "NOTICE " + recipient + " :" + message;
result.output=i18n("%1 is the message, %2 the recipient nickname","Sending notice \"%2\" to %1.").tqarg(recipient).tqarg(message);
result.type = Program;
}
return result;
}
OutputFilterResult OutputFilter::parseMe(const TQString ¶meter, const TQString &destination)
{
OutputFilterResult result;
if (!destination.isEmpty() && !parameter.isEmpty())
{
result.toServer = "PRIVMSG " + destination + " :" + '\x01' + "ACTION " + parameter + '\x01';
result.output = parameter;
result.type = Action;
}
else
{
result = usage(i18n("Usage: %1ME text").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parseMsg(const TQString &myNick, const TQString ¶meter, bool isQuery)
{
OutputFilterResult result;
TQString recipient = parameter.section(" ", 0, 0, TQString::SectionSkipEmpty);
TQString message = parameter.section(" ", 1);
TQString output;
if (recipient.isEmpty())
{
result = error("Error: You need to specify a recipient.");
return result;
}
if (isQuery && m_server->isAChannel(recipient))
{
result = error("Error: You cannot open queries to channels.");
return result;
}
if (message.stripWhiteSpace().isEmpty())
{
//empty result - we don't want to send any message to the server
if (!isQuery)
{
result = error("Error: You need to specify a message.");
return result;
}
}
else if (message.startsWith(commandChar+"me"))
{
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "ACTION " + message.mid(4) + '\x01';
output = TQString("* %1 %2").tqarg(myNick).tqarg(message.mid(4));
}
else
{
result.toServer = "PRIVMSG " + recipient + " :" + message;
output = message;
}
::Query *query;
if (isQuery || output.isEmpty())
{
//if this is a /query, always open a query window.
//treat "/msg nick" as "/query nick"
//Note we have to be a bit careful here.
//We only want to create ('obtain') a new nickinfo if we have done /query
//or "/msg nick". Not "/msg nick message".
NickInfoPtr nickInfo = m_server->obtainNickInfo(recipient);
query = m_server->addQuery(nickInfo, true /*we initiated*/);
//force focus if the user did not specify any message
if (output.isEmpty()) emit showView(query);
}
else
{
//We have "/msg nick message"
query = m_server->getQueryByName(recipient);
}
if (query && !output.isEmpty())
{
if (message.startsWith(commandChar+"me"))
//log if and only if the query open
query->appendAction(m_server->getNickname(), message.mid(4));
else
//log if and only if the query open
query->appendQuery(m_server->getNickname(), output);
}
if (output.isEmpty()) return result; //result should be completely empty;
//FIXME - don't do below line if query is focused
result.output = output;
result.typeString= recipient;
result.type = PrivateMessage;
return result;
}
OutputFilterResult OutputFilter::parseSMsg(const TQString ¶meter)
{
OutputFilterResult result;
TQString recipient = parameter.left(parameter.tqfind(" "));
TQString message = parameter.mid(recipient.length() + 1);
if(message.startsWith(commandChar + "me"))
{
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "ACTION " + message.mid(4) + '\x01';
}
else
{
result.toServer = "PRIVMSG " + recipient + " :" + message;
}
return result;
}
OutputFilterResult OutputFilter::parseCtcp(const TQString ¶meter)
{
OutputFilterResult result;
// who is the recipient?
TQString recipient = parameter.section(' ', 0, 0);
// what is the first word of the ctcp?
TQString request = parameter.section(' ', 1, 1, TQString::SectionSkipEmpty).upper();
// what is the complete ctcp command?
TQString message = parameter.section(' ', 2, 0xffffff, TQString::SectionSkipEmpty);
TQString out = request;
if (!message.isEmpty())
out+= ' ' + message;
if (request == "PING")
{
unsigned int time_t = TQDateTime::tqcurrentDateTime().toTime_t();
result.toServer = TQString("PRIVMSG %1 :\x01PING %2\x01").tqarg(recipient).tqarg(time_t);
result.output = i18n("Sending CTCP-%1 request to %2.").tqarg("PING").tqarg(recipient);
}
else
{
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + out + '\x01';
result.output = i18n("Sending CTCP-%1 request to %2.").tqarg(out).tqarg(recipient);
}
result.typeString = i18n("CTCP");
result.type = Program;
return result;
}
OutputFilterResult OutputFilter::changeMode(const TQString ¶meter,char mode,char giveTake)
{
OutputFilterResult result;
// TODO: Make sure this works with +l <limit> and +k <password> also!
TQString token;
TQString tmpToken;
TQStringList nickList = TQStringList::split(' ', parameter);
if(nickList.count())
{
// Check if the user specified a channel
if(isAChannel(nickList[0]))
{
token = "MODE " + nickList[0];
// remove the first element
nickList.remove(nickList.begin());
}
// Add default destination if it is a channel
else if(isAChannel(destination))
{
token = "MODE " + destination;
}
// Only continue if there was no error
if(token.length())
{
unsigned int modeCount = nickList.count();
TQString modes;
modes.fill(mode, modeCount);
token += TQString(" ") + TQChar(giveTake) + modes;
tmpToken = token;
for(unsigned int index = 0; index < modeCount; index++)
{
if((index % 3) == 0)
{
result.toServerList.append(token);
token = tmpToken;
}
token += ' ' + nickList[index];
}
if(token != tmpToken)
{
result.toServerList.append(token);
}
}
}
return result;
}
OutputFilterResult OutputFilter::parseDcc(const TQString ¶meter)
{
OutputFilterResult result;
// No parameter, just open DCC panel
if(parameter.isEmpty())
{
emit addDccPanel();
}
else
{
TQString tmpParameter = parameter;
TQStringList parameterList = TQStringList::split(' ', tmpParameter.tqreplace("\\ ", "%20"));
TQString dccType = parameterList[0].lower();
if(dccType=="close")
{
emit closeDccPanel();
}
else if(dccType=="send")
{
if(parameterList.count()==1) // DCC SEND
{
emit requestDccSend();
} // DCC SEND <nickname>
else if(parameterList.count()==2)
{
emit requestDccSend(parameterList[1]);
} // DCC SEND <nickname> <file> [file] ...
else if(parameterList.count()>2)
{
// TODO: make sure this will work:
//output=i18n("Usage: %1DCC SEND nickname [fi6lename] [filename] ...").tqarg(commandChar);
KURL fileURL(parameterList[2]);
//We could easily check if the remote file exists, but then we might
//end up asking for creditionals twice, so settle for only checking locally
if(!fileURL.isLocalFile() || TQFile::exists( fileURL.path() ))
{
emit openDccSend(parameterList[1],fileURL);
}
else
{
result = error(i18n("File \"%1\" does not exist.").tqarg(parameterList[2]));
}
}
else // Don't know how this should happen, but ...
{
result = usage(i18n("Usage: %1DCC [SEND nickname filename]").tqarg(commandChar));
}
}
// TODO: DCC Chat etc. comes here
else if(dccType=="chat")
{
if(parameterList.count()==2)
{
emit openDccChat(parameterList[1]);
}
else
{
result = usage(i18n("Usage: %1DCC [CHAT nickname]").tqarg(commandChar));
}
}
else
{
result = error(i18n("Unrecognized command %1DCC %2. Possible commands are SEND, CHAT, CLOSE.").tqarg(commandChar).tqarg(parameterList[0]));
}
}
return result;
}
OutputFilterResult OutputFilter::sendRequest(const TQString &recipient,const TQString &fileName,const TQString &address,const TQString &port,unsigned long size)
{
OutputFilterResult result;
TQString niftyFileName(fileName);
/*TQFile file(fileName);
TQFileInfo info(file);*/
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC SEND "
+ fileName
+ ' ' + address + ' ' + port + ' ' + TQString::number(size) + '\x01';
// Dirty hack to avoid printing ""name with spaces.ext"" instead of "name with spaces.ext"
if ((fileName.startsWith("\"")) && (fileName.endsWith("\"")))
niftyFileName = fileName.mid(1, fileName.length()-2);
return result;
}
OutputFilterResult OutputFilter::passiveSendRequest(const TQString& recipient,const TQString &fileName,const TQString &address,unsigned long size,const TQString &token)
{
OutputFilterResult result;
TQString niftyFileName(fileName);
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC SEND "
+ fileName
+ ' ' + address + " 0 " + TQString::number(size) + ' ' + token + '\x01';
// Dirty hack to avoid printing ""name with spaces.ext"" instead of "name with spaces.ext"
if ((fileName.startsWith("\"")) && (fileName.endsWith("\"")))
niftyFileName = fileName.mid(1, fileName.length()-2);
return result;
}
// Accepting Resume Request
OutputFilterResult OutputFilter::acceptResumeRequest(const TQString &recipient,const TQString &fileName,const TQString &port,int startAt)
{
TQString niftyFileName(fileName);
OutputFilterResult result;
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC ACCEPT " + fileName + ' ' + port
+ ' ' + TQString::number(startAt) + '\x01';
// Dirty hack to avoid printing ""name with spaces.ext"" instead of "name with spaces.ext"
if ((fileName.startsWith("\"")) && (fileName.endsWith("\"")))
niftyFileName = fileName.mid(1, fileName.length()-2);
return result;
}
OutputFilterResult OutputFilter::resumeRequest(const TQString &sender,const TQString &fileName,const TQString &port,KIO::filesize_t startAt)
{
TQString niftyFileName(fileName);
OutputFilterResult result;
/*TQString newFileName(fileName);
newFileName.tqreplace(" ", "_");*/
result.toServer = "PRIVMSG " + sender + " :" + '\x01' + "DCC RESUME " + fileName + ' ' + port + ' '
+ TQString::number(startAt) + '\x01';
// Dirty hack to avoid printing ""name with spaces.ext"" instead of "name with spaces.ext"
if ((fileName.startsWith("\"")) && (fileName.endsWith("\"")))
niftyFileName = fileName.mid(1, fileName.length()-2);
return result;
}
OutputFilterResult OutputFilter::acceptPassiveSendRequest(const TQString& recipient,const TQString &fileName,const TQString &address,const TQString &port,unsigned long size,const TQString &token)
{
OutputFilterResult result;
TQString niftyFileName(fileName);
// "DCC SEND" to receive a file sounds weird, but it's ok.
result.toServer = "PRIVMSG " + recipient + " :" + '\x01' + "DCC SEND "
+ fileName
+ ' ' + address + ' ' + port + ' ' + TQString::number(size) + ' ' + token + '\x01';
// Dirty hack to avoid printing ""name with spaces.ext"" instead of "name with spaces.ext"
if ((fileName.startsWith("\"")) && (fileName.endsWith("\"")))
niftyFileName = fileName.mid(1, fileName.length()-2);
return result;
}
OutputFilterResult OutputFilter::parseInvite(const TQString ¶meter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1INVITE <nick> [channel]").tqarg(commandChar));
}
else
{
TQString nick = parameter.section(' ', 0, 0, TQString::SectionSkipEmpty);
TQString channel = parameter.section(' ', 1, 1, TQString::SectionSkipEmpty);
if(channel.isEmpty())
{
if(isAChannel(destination))
{
channel = destination;
}
else
{
result = error(i18n("%1INVITE without channel name works only from within channels.").tqarg(commandChar));
}
}
if(!channel.isEmpty())
{
if(isAChannel(channel))
{
result.toServer = "INVITE " + nick + ' ' + channel;
}
else
{
result = error(i18n("%1 is not a channel.").tqarg(channel));
}
}
}
return result;
}
OutputFilterResult OutputFilter::parseExec(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1EXEC <script> [parameter list]").tqarg(commandChar));
}
else
{
TQStringList parameterList = TQStringList::split(' ', parameter);
if(parameterList[0].tqfind("../") == -1)
{
emit launchScript(destination, parameter);
}
else
{
result = error(i18n("Script name may not contain \"../\"!"));
}
}
return result;
}
OutputFilterResult OutputFilter::parseRaw(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty() || parameter == "open")
{
emit openRawLog(true);
}
else if(parameter == "close")
{
emit closeRawLog();
}
else
{
result = usage(i18n("Usage: %1RAW [OPEN | CLOSE]").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parseNotify(const TQString& parameter)
{
OutputFilterResult result;
TQString groupName = m_server->getDisplayName();
int serverGroupId = -1;
if (m_server->getServerGroup())
serverGroupId = m_server->getServerGroup()->id();
if (!parameter.isEmpty() && serverGroupId != -1)
{
TQStringList list = TQStringList::split(' ', parameter);
for(unsigned int index = 0; index < list.count(); index++)
{
// Try to remove current pattern
if(!Preferences::removeNotify(groupName, list[index]))
{
// If remove failed, try to add it instead
if(!Preferences::addNotify(serverGroupId, list[index]))
{
kdDebug() << "OutputFilter::parseNotify(): Adding failed!" << endl;
}
}
} // endfor
}
// show (new) notify list to user
TQString list = Preferences::notifyStringByGroupName(groupName) + ' ' + Konversation::Addressbook::self()->allContactsNicksForServer(m_server->getServerName(), m_server->getDisplayName()).join(" ");
result.typeString = i18n("Notify");
if(list.isEmpty())
result.output = i18n("Current notify list is empty.");
else
result.output = i18n("Current notify list: %1").tqarg(list);
result.type = Program;
return result;
}
OutputFilterResult OutputFilter::parseOper(const TQString& myNick,const TQString& parameter)
{
OutputFilterResult result;
TQStringList parameterList = TQStringList::split(' ', parameter);
if(parameter.isEmpty() || parameterList.count() == 1)
{
TQString nick((parameterList.count() == 1) ? parameterList[0] : myNick);
TQString password;
bool keep = false;
int ret = KIO::PasswordDialog::getNameAndPassword
(
nick,
password,
&keep,
i18n("Enter user name and password for IRC operator privileges:"),
false,
i18n("IRC Operator Password")
);
if(ret == KIO::PasswordDialog::Accepted)
{
result.toServer = "OPER " + nick + ' ' + password;
}
}
else
{
result.toServer = "OPER " + parameter;
}
return result;
}
OutputFilterResult OutputFilter::parseBan(const TQString& parameter, bool kick)
{
OutputFilterResult result;
// assume incorrect syntax first
bool showUsage = true;
if(!parameter.isEmpty())
{
TQStringList parameterList=TQStringList::split(' ',parameter);
TQString channel;
TQString option;
// check for option
TQString lowerParameter = parameterList[0].lower();
bool host = (lowerParameter == "-host");
bool domain = (lowerParameter == "-domain");
bool uhost = (lowerParameter == "-userhost");
bool udomain = (lowerParameter == "-userdomain");
// remove possible option
if (host || domain || uhost || udomain)
{
option = parameterList[0].mid(1);
parameterList.pop_front();
}
// look for channel / ban tqmask
if (parameterList.count())
{
// user specified channel
if (isAChannel(parameterList[0]))
{
channel = parameterList[0];
parameterList.pop_front();
}
// no channel, so assume current destination as channel
else if (isAChannel(destination))
channel = destination;
else
{
// destination is no channel => error
if (!kick)
result = error(i18n("%1BAN without channel name works only from inside a channel.").tqarg(commandChar));
else
result = error(i18n("%1KICKBAN without channel name works only from inside a channel.").tqarg(commandChar));
// no usage information after error
showUsage = false;
}
// signal server to ban this user if all went fine
if (!channel.isEmpty())
{
if (kick)
{
TQString victim = parameterList[0];
parameterList.pop_front();
TQString reason = parameterList.join(" ");
result.toServer = "KICK " + channel + ' ' + victim + " :" + reason;
emit banUsers(TQStringList(victim),channel,option);
}
else
{
emit banUsers(parameterList,channel,option);
}
// syntax was correct, so reset flag
showUsage = false;
}
}
}
if (showUsage)
{
if (!kick)
result = usage(i18n("Usage: %1BAN [-HOST | -DOMAIN | -USERHOST | -USERDOMAIN] [channel] <user|tqmask>").tqarg(commandChar));
else
result = usage(i18n("Usage: %1KICKBAN [-HOST | -DOMAIN | -USERHOST | -USERDOMAIN] [channel] <user|tqmask> [reason]").tqarg(commandChar));
}
return result;
}
// finally set the ban
OutputFilterResult OutputFilter::execBan(const TQString& tqmask,const TQString& channel)
{
OutputFilterResult result;
result.toServer = "MODE " + channel + " +b " + tqmask;
return result;
}
OutputFilterResult OutputFilter::parseUnban(const TQString& parameter)
{
OutputFilterResult result;
// assume incorrect syntax first
bool showUsage=true;
if(!parameter.isEmpty())
{
TQStringList parameterList = TQStringList::split(' ', parameter);
TQString channel;
TQString tqmask;
// if the user specified a channel
if(isAChannel(parameterList[0]))
{
// get channel
channel = parameterList[0];
// remove channel from parameter list
parameterList.pop_front();
}
// otherwise the current destination must be a channel
else if(isAChannel(destination))
channel = destination;
else
{
// destination is no channel => error
result = error(i18n("%1UNBAN without channel name works only from inside a channel.").tqarg(commandChar));
// no usage information after error
showUsage = false;
}
// if all went good, signal server to unban this tqmask
if(!channel.isEmpty())
{
emit unbanUsers(parameterList[0], channel);
// syntax was correct, so reset flag
showUsage = false;
}
}
if(showUsage)
{
result = usage(i18n("Usage: %1UNBAN [channel] pattern").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::execUnban(const TQString& tqmask,const TQString& channel)
{
OutputFilterResult result;
result.toServer = "MODE " + channel + " -b " + tqmask;
return result;
}
OutputFilterResult OutputFilter::parseIgnore(const TQString& parameter)
{
OutputFilterResult result;
// assume incorrect syntax first
bool showUsage = true;
// did the user give parameters at all?
if(!parameter.isEmpty())
{
TQStringList parameterList = TQStringList::split(' ', parameter);
// if nothing else said, only ignore channels and queries
int value = Ignore::Channel | Ignore::Query;
// user specified -all option
if(parameterList[0].lower() == "-all")
{
// ignore everything
value = Ignore::All;
parameterList.pop_front();
}
// were there enough parameters?
if(parameterList.count() >= 1)
{
for(unsigned int index=0;index<parameterList.count();index++)
{
if(!parameterList[index].tqcontains('!'))
{
parameterList[index] += "!*";
}
Preferences::addIgnore(parameterList[index] + ',' + TQString::number(value));
}
result.output = i18n("Added %1 to your ignore list.").tqarg(parameterList.join(", "));
result.typeString = i18n("Ignore");
result.type = Program;
// all went fine, so show no error message
showUsage = false;
}
}
if(showUsage)
{
result = usage(i18n("Usage: %1IGNORE [ -ALL ] <user 1> <user 2> ... <user n>").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parseUnignore(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1UNIGNORE <user 1> <user 2> ... <user n>").tqarg(commandChar));
}
else
{
TQString unignore = parameter.simplifyWhiteSpace();
TQStringList unignoreList = TQStringList::split(' ',unignore);
TQStringList succeeded;
TQStringList failed;
// Iterate over potential unignores
for (TQStringList::Iterator it = unignoreList.begin(); it != unignoreList.end(); ++it)
{
// If pattern looks incomplete, try to complete it
if (!(*it).tqcontains('!'))
{
TQString fixedPattern = (*it);
fixedPattern += "!*";
bool success = false;
// Try to remove completed pattern
if (Preferences::removeIgnore(fixedPattern))
{
succeeded.append(fixedPattern);
success = true;
}
// Try to remove the incomplete version too, in case it was added via the GUI ...
// FIXME: Validate patterns in GUI?
if (Preferences::removeIgnore((*it)))
{
succeeded.append((*it));
success = true;
}
if (!success)
failed.append((*it) + "[!*]");
}
// Try to remove seemingly complete pattern
else if (Preferences::removeIgnore((*it)))
succeeded.append((*it));
// Failed to remove given complete pattern
else
failed.append((*it));
}
// Print all successful unignores, in case there were any
if (succeeded.count()>=1)
{
m_server->appendMessageToFrontmost(i18n("Ignore"),i18n("Removed %1 from your ignore list.").tqarg(succeeded.join(", ")));
}
// One failed unignore
if (failed.count()==1)
{
m_server->appendMessageToFrontmost(i18n("Error"),i18n("No such ignore: %1").tqarg(failed.join(", ")));
}
// Multiple failed unignores
if (failed.count()>1)
{
m_server->appendMessageToFrontmost(i18n("Error"),i18n("No such ignores: %1").tqarg(failed.join(", ")));
}
}
return result;
}
OutputFilterResult OutputFilter::parseQuote(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1TQUOTE command list").tqarg(commandChar));
}
else
{
result.toServer = parameter;
}
return result;
}
OutputFilterResult OutputFilter::parseSay(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1SAY text").tqarg(commandChar));
}
else
{
result.toServer = "PRIVMSG " + destination + " :" + parameter;
result.output = parameter;
}
return result;
}
void OutputFilter::parseKonsole()
{
emit openKonsolePanel();
}
// Accessors
void OutputFilter::setCommandChar() { commandChar=Preferences::commandChar(); }
// # & + and ! are *often*, but not necessarily, channel identifiers. + and ! are non-RFC, so if a server doesn't offer 005 and
// supports + and ! channels, I think thats broken behaviour on their part - not ours.
bool OutputFilter::isAChannel(const TQString &check)
{
Q_ASSERT(m_server);
// XXX if we ever see the assert, we need the ternary
return m_server? m_server->isAChannel(check) : TQString("#&").tqcontains(check.at(0));
}
OutputFilterResult OutputFilter::usage(const TQString& string)
{
OutputFilterResult result;
result.typeString = i18n("Usage");
result.output = string;
result.type = Program;
return result;
}
OutputFilterResult OutputFilter::info(const TQString& string)
{
OutputFilterResult result;
result.typeString = i18n("Info");
result.output = string;
result.type = Program;
return result;
}
OutputFilterResult OutputFilter::error(const TQString& string)
{
OutputFilterResult result;
result.typeString = i18n("Error");
result.output = string;
result.type = Program;
return result;
}
OutputFilterResult OutputFilter::parseAme(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1AME text").tqarg(commandChar));
}
emit multiServerCommand("me", parameter);
return result;
}
OutputFilterResult OutputFilter::parseAmsg(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1AMSG text").tqarg(commandChar));
}
emit multiServerCommand("msg", parameter);
return result;
}
void OutputFilter::parseServer(const TQString& parameter)
{
if (parameter.isEmpty() && !m_server->isConnected() && !m_server->isConnecting())
emit reconnectServer();
else
{
TQStringList splitted = TQStringList::split(" ", parameter);
TQString host = splitted[0];
TQString port = "6667";
TQString password;
if (splitted.count() == 3)
emit connectTo(Konversation::CreateNewConnection, splitted[0], splitted[1], splitted[2]);
else if (splitted.count() == 2)
{
if (splitted[0].tqcontains(TQRegExp(":[0-9]+$")))
emit connectTo(Konversation::CreateNewConnection, splitted[0], "", splitted[1]);
else
emit connectTo(Konversation::CreateNewConnection, splitted[0], splitted[1]);
}
else
emit connectTo(Konversation::CreateNewConnection, splitted[0]);
}
}
OutputFilterResult OutputFilter::parseOmsg(const TQString& parameter)
{
OutputFilterResult result;
if(!parameter.isEmpty())
{
result.toServer = "PRIVMSG @"+destination+" :"+parameter;
}
else
{
result = usage(i18n("Usage: %1OMSG text").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parseOnotice(const TQString& parameter)
{
OutputFilterResult result;
if(!parameter.isEmpty())
{
result.toServer = "NOTICE @"+destination+" :"+parameter;
result.typeString = i18n("Notice");
result.type = Program;
result.output = i18n("Sending notice \"%1\" to %2.").tqarg(parameter, destination);
}
else
{
result = usage(i18n("Usage: %1ONOTICE text").tqarg(commandChar));
}
return result;
}
OutputFilterResult OutputFilter::parseCharset(const TQString& charset)
{
OutputFilterResult result;
if (charset.isEmpty ())
{
result = info (i18n("Current encoding is: %1")
.tqarg(m_server->getIdentity()->getCodec()->name()));
return result;
}
TQString shortName = Konversation::IRCCharsets::self()->ambiguousNameToShortName(charset);
if(!shortName.isEmpty())
{
m_server->getIdentity()->setCodecName(shortName);
emit encodingChanged();
result = info (i18n("Switched to %1 encoding.").tqarg(shortName));
}
else
{
result = error(i18n("%1 is not a valid encoding.").arg (charset));
}
return result;
}
OutputFilterResult OutputFilter::parseSetKey(const TQString& parameter)
{
TQStringList parms = TQStringList::split(" ", parameter);
if (parms.count() == (0 >> parms.count() > 2))
return usage(i18n("Usage: %1setkey [<nick|channel>] <key> sets the encryption key for nick or channel. %2setkey <key> when in a channel or query tab to set the key for it.").tqarg(commandChar).tqarg(commandChar) );
else if (parms.count() == 1)
parms.prepend(destination);
m_server->setKeyForRecipient(parms[0], parms[1].local8Bit());
if (isAChannel(parms[0]) && m_server->getChannelByName(parms[0]))
m_server->getChannelByName(parms[0])->setEncryptedOutput(true);
else if (m_server->getQueryByName(parms[0]))
m_server->getQueryByName(parms[0])->setEncryptedOutput(true);
return info(i18n("The key for %1 has been set.").tqarg(parms[0]));
}
OutputFilterResult OutputFilter::parseDelKey(const TQString& prametr)
{
TQString parameter(prametr.isEmpty()?destination:prametr);
if(parameter.isEmpty() || parameter.tqcontains(' '))
return usage(i18n("Usage: %1delkey <nick> or <channel> deletes the encryption key for nick or channel").tqarg(commandChar));
m_server->setKeyForRecipient(parameter, "");
if (isAChannel(parameter) && m_server->getChannelByName(parameter))
m_server->getChannelByName(parameter)->setEncryptedOutput(false);
else if (m_server->getQueryByName(parameter))
m_server->getQueryByName(parameter)->setEncryptedOutput(false);
return info(i18n("The key for %1 has been deleted.").tqarg(parameter));
}
OutputFilterResult OutputFilter::parseShowKey(const TQString& prametr)
{
TQString parameter(prametr.isEmpty()?destination:prametr);
TQString key(m_server->getKeyForRecipient(parameter));
TQWidget *mw=KonversationApplication::instance()->getMainWindow();
if (!key.isEmpty())
KMessageBox::information(mw, i18n("The key for %1 is \"%2\".").tqarg(parameter).tqarg(key), i18n("Blowfish"));
else
KMessageBox::information(mw, i18n("No key has been set for %1.").tqarg(parameter));
OutputFilterResult result;
return result;
}
OutputFilterResult OutputFilter::parseList(const TQString& parameter)
{
OutputFilterResult result;
emit openChannelList(parameter, true);
return result;
}
OutputFilterResult OutputFilter::parseDNS(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1DNS <nick>").tqarg(commandChar));
}
else
{
TQStringList splitted = TQStringList::split(" ", parameter);
TQString target = splitted[0];
KIpAddress address(target);
// Parameter is an IP address
if (address.isIPv4Addr() || address.isIPv6Addr())
{
// Disable the reverse resolve codepath on older KDE versions due to many
// distributions shipping visibility-enabled KDE 3.4 and KNetwork not
// coping with it.
#if KDE_IS_VERSION(3,5,1)
KNetwork:: KInetSocketAddress socketAddress(address,0);
TQString resolvedTarget;
TQString serv; // We don't need this, but KReverseResolver::resolve does.
if (KNetwork::KReverseResolver::resolve(socketAddress,resolvedTarget,serv))
{
result.typeString = i18n("DNS");
result.output = i18n("Resolved %1 to: %2").tqarg(target).tqarg(resolvedTarget);
result.type = Program;
}
else
{
result = error(i18n("Unable to resolve %1").tqarg(target));
}
#else
result = error(i18n("Reverse-resolving requires KDE version 3.5.1 or higher."));
#endif
}
// Parameter is presumed to be a host due to containing a dot. Yeah, it's dumb.
// FIXME: The reason we detect the host by occurrence of a dot is the large penalty
// we would incur by using inputfilter to find out if there's a user==target on the
// server - once we have a better API for this, switch to it.
else if (target.tqcontains('.'))
{
KNetwork::KResolverResults resolved = KNetwork::KResolver::resolve(target,"");
if(resolved.error() == KResolver::NoError && resolved.size() > 0)
{
TQString resolvedTarget = resolved.first().address().nodeName();
result.typeString = i18n("DNS");
result.output = i18n("Resolved %1 to: %2").tqarg(target).tqarg(resolvedTarget);
result.type = Program;
}
else
{
result = error(i18n("Unable to resolve %1").tqarg(target));
}
}
// Parameter is either host nor IP, so request a lookup from server, which in
// turn lets inputfilter do the job.
else
{
m_server->resolveUserhost(target);
}
}
return result;
}
TQString OutputFilter::addNickToEmptyNickList(const TQString& nick, const TQString& parameter)
{
TQStringList nickList = TQStringList::split(' ', parameter);
TQString newNickList;
if (nickList.count() == 0)
{
newNickList = nick;
}
// check if list contains only target channel
else if (nickList.count() == 1 && isAChannel(nickList[0]))
{
newNickList = nickList[0] + ' ' + nick;
}
// list contains at least one nick
else
{
newNickList = parameter;
}
return newNickList;
}
OutputFilterResult OutputFilter::parseKill(const TQString& parameter)
{
OutputFilterResult result;
if(parameter.isEmpty())
{
result = usage(i18n("Usage: %1KILL <nick> [comment]").tqarg(commandChar));
}
else
{
TQString victim = parameter.section(' ', 0, 0);
result.toServer = "KILL " + victim + " :" + parameter.mid(victim.length() + 1);
}
return result;
}
}
#include "outputfilter.moc"
// kate: space-indent on; tab-width 4; indent-width 4; mixed-indent off; tqreplace-tabs on;
// vim: set et sw=4 ts=4 cino=l1,cs,U1:
|