~ubuntu-branches/ubuntu/lucid/konversation/lucid-updates

« back to all changes in this revision

Viewing changes to src/irc/inputfilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2009-05-15 11:24:24 UTC
  • mfrom: (1.15.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20090515112424-b74i26lciabf4qnk
Tags: 1.1.75+svn968012-1
* New upstream development snapshot:
  - Last Changed Author: hein
  - Last Changed Rev: 968012
  - Last Changed Date: 2009-05-14 21:03:55 +0300
* Update README.source.
* Use dh --quilt instead of custom patch handling, build depend on
  quilt 0.46-7~.
* Update patches to upstream changes.
* Update konversation.install: remove docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    server=newServer;
49
49
}
50
50
 
51
 
void InputFilter::parseLine(const QString& a_newLine)
52
 
{
53
 
    QString trailing;
54
 
    QString newLine(a_newLine);
55
 
 
56
 
    // Remove white spaces at the end and beginning
57
 
    newLine = newLine.trimmed();
58
 
    // Find end of middle parameter list
59
 
    int pos = newLine.indexOf(" :");
60
 
    // Was there a trailing parameter?
61
 
    if(pos != -1)
62
 
    {
63
 
        // Copy trailing parameter
64
 
        trailing = newLine.mid(pos + 2);
65
 
        // Cut trailing parameter from string
66
 
        newLine = newLine.left(pos);
67
 
    }
68
 
    // Remove all unnecessary white spaces to make parsing easier
69
 
    newLine = newLine.simplified();
70
 
 
 
51
/*
 
52
Prefix parsePrefix(QString prefix)
 
53
{
 
54
    //3 possibilities - bare nickname, nickname and a host with optional ident, or a server if there is no punct, its a nickname
 
55
    //there must be at least 1 character before a symbol or its some kind of screwed up nickname
 
56
    Prefix pre;
 
57
    int id=prefix.indexOf("!");
 
58
    int ad=prefix.indexOf("@");
 
59
    if (prefix.indexOf(".") > 0 && id==-1 && ad==-1 ) // it is a server
 
60
    {
 
61
        pre.isServer=true;
 
62
        pre.host=prefix;
 
63
    }
 
64
    else
 
65
    {
 
66
        if (ad >0)
 
67
        {
 
68
            pre.host=prefix.mid(ad+1);
 
69
            prefix.truncate(ad);
 
70
            if (id > 0 && id < ad)
 
71
            {
 
72
                pre.ident=prefix.mid(id+1);
 
73
                prefix.truncate(id);
 
74
            }
 
75
        }
 
76
        //else // consider all of it a nickname
 
77
        pre.nickname=prefix;
 
78
    }
 
79
    return pre;
 
80
}
 
81
*/
 
82
 
 
83
template<typename T>
 
84
int posOrLen(T chr, const QString& str, int from=0)
 
85
{
 
86
    int p=str.indexOf(chr, from);
 
87
    if (p<0)
 
88
        return str.size();
 
89
    return p;
 
90
}
 
91
 
 
92
/// "[22:08] >> :thiago!n=thiago@kde/thiago QUIT :Read error: 110 (Connection timed out)"
 
93
/// "[21:47] >> :Zarin!n=x365@kde/developer/lmurray PRIVMSG #plasma :If the decoration doesn't have paint( QPixmap ) it falls back to the old one"
 
94
/// "[21:49] >> :niven.freenode.net 352 argonel #kde-forum i=beezle konversation/developer/argonel irc.freenode.net argonel H :0 Konversation User "
 
95
void InputFilter::parseLine(const QString& line)
 
96
{
71
97
    QString prefix;
 
98
    int start=0;
 
99
    int end(posOrLen(' ', line));
72
100
 
73
 
    // Do we have a prefix?
74
 
    if(newLine[0] == ':')
 
101
    if (line[0]==':')
75
102
    {
76
 
        // Find end of prefix
77
 
        pos = newLine.indexOf(' ');
78
 
        // Copy prefix
79
 
        prefix = newLine.mid(1, pos - 1);
80
 
        // Remove prefix from line
81
 
        newLine = newLine.mid(pos + 1);
 
103
        start=end+1;
 
104
        prefix=line.mid(1, end-1); //skips the colon and does not include the trailing space
 
105
        end=posOrLen(' ', line, start);
82
106
    }
83
107
 
84
 
    // Find end of command
85
 
    pos = newLine.indexOf(' ');
86
 
    // Copy command (all lowercase to make parsing easier)
87
 
    QString command = newLine.left(pos).toLower();
88
 
    // Are there parameters left in the string?
 
108
    //even though the standard is UPPER CASE, someone when through a great deal of trouble to make this lower case...
 
109
    QString command = QString(line.mid(start, end-start)).toLower();
 
110
    start=end+1;
 
111
 
 
112
    int trailing=line.indexOf(" :", end);
 
113
    if (trailing >= 0)
 
114
        end=trailing;
 
115
    else
 
116
        end=line.size();
 
117
 
89
118
    QStringList parameterList;
90
119
 
91
 
    if(pos != -1)
 
120
    while (start < end)
92
121
    {
93
 
        // Cut out the command
94
 
        newLine = newLine.mid(pos + 1);
95
 
        // The rest of the string will be the parameter list
96
 
        parameterList = newLine.split(' ');
97
 
    }
98
 
 
99
 
    Q_ASSERT(server);
100
 
 
 
122
        if (line[start]==' ')
 
123
            start++;
 
124
        else
 
125
        {
 
126
            int p=line.indexOf(' ', start); //easier to have Qt loop for me :)
 
127
            if (p<0)
 
128
                p=end;
 
129
            parameterList << line.mid(start, p-start);
 
130
            start=p+1;
 
131
        }
 
132
    };
 
133
 
 
134
    /* Quote: "The final colon is specified as a "last argument" designator, and
 
135
     * is always valid before the final argument."
 
136
     * Quote: "The last parameter may be an empty string."
 
137
     * Quote: "After extracting the parameter list, all parameters are equal
 
138
     * whether matched by <middle> or <trailing>. <trailing> is just a
 
139
     * syntactic trick to allow SPACE within the parameter."
 
140
     */
 
141
 
 
142
    if (trailing >= 0 ) //<-- trailing == ":" - per above we need the empty string
 
143
        parameterList << line.mid( qMin(trailing+2, line.size()) );
 
144
 
 
145
    Q_ASSERT(server); //how could we have gotten a line without a server?
 
146
 
 
147
    
101
148
    // Server command, if no "!" was found in prefix
102
 
    if((!prefix.contains('!')) && (prefix != server->getNickname()))
 
149
    if ((!prefix.contains('!')) && (prefix != server->getNickname()))
103
150
    {
104
 
 
105
 
        parseServerCommand(prefix, command, parameterList, trailing);
 
151
        parseServerCommand(prefix, command, parameterList);
106
152
    }
107
153
    else
108
154
    {
109
 
        parseClientCommand(prefix, command, parameterList, trailing);
 
155
        parseClientCommand(prefix, command, parameterList);
110
156
    }
111
157
}
112
158
 
113
 
void InputFilter::parseClientCommand(const QString &prefix, const QString &command, const QStringList &parameterList, const QString &_trailing)
114
 
{
115
 
    KonversationApplication* konv_app = static_cast<KonversationApplication *>(KApplication::kApplication());
 
159
#define trailing parameterList.last()
 
160
#define plHas(x) _plHas(parameterList.count(), (x))
 
161
 
 
162
bool _plHad=false;
 
163
int _plWanted = 0;
 
164
 
 
165
bool _plHas(int count, int x)
 
166
{
 
167
    _plHad=(count >= x);
 
168
    _plWanted = x;
 
169
    if (!_plHad)
 
170
        kDebug() << "plhad" << count << "wanted" << x;
 
171
    return _plHad;
 
172
}
 
173
 
 
174
void InputFilter::parseClientCommand(const QString &prefix, const QString &command, QStringList &parameterList)
 
175
{
 
176
    KonversationApplication* konv_app = KonversationApplication::instance();
116
177
    Q_ASSERT(konv_app);
117
178
    Q_ASSERT(server);
 
179
 
118
180
    // Extract nickname from prefix
119
181
    int pos = prefix.indexOf('!');
120
182
    QString sourceNick = prefix.left(pos);
121
183
    QString sourceHostmask = prefix.mid(pos + 1);
 
184
 
122
185
    // remember hostmask for this nick, it could have changed
123
 
    server->addHostmaskToNick(sourceNick,sourceHostmask);
124
 
    QString trailing = _trailing;
 
186
    server->addHostmaskToNick(sourceNick, sourceHostmask);
 
187
    if (parameterList.isEmpty())
 
188
        return;
125
189
 
126
 
    if(command=="privmsg")
 
190
    //PRIVMSG #channel :message
 
191
    if (command == "privmsg" && plHas(2))
127
192
    {
128
193
        bool isChan = isAChannel(parameterList.value(0));
129
194
        // CTCP message?
130
 
        if(server->identifyMsg() && (trailing.at(0) == '+' || trailing.at(0) == '-')) {
 
195
        if (server->identifyMsg() && (trailing.length() > 1 && (trailing.at(0) == '+' || trailing.at(0) == '-')))
 
196
        {
131
197
            trailing = trailing.mid(1);
132
198
        }
133
199
 
134
 
        if(!trailing.isEmpty() && trailing.at(0)==QChar(0x01))
 
200
        if (!trailing.isEmpty() && trailing.at(0)==QChar(0x01))
135
201
        {
136
202
            // cut out the CTCP command
137
 
            QString ctcp = trailing.mid(1,trailing.indexOf(1,1)-1);
 
203
            QString ctcp = trailing.mid(1,trailing.indexOf(QChar(0x01),1)-1);
138
204
 
139
 
            QString ctcpCommand=ctcp.left(ctcp.indexOf(' ')).toLower();
140
 
            QString ctcpArgument=ctcp.mid(ctcp.indexOf(' ')+1);
141
 
            ctcpArgument=static_cast<KonversationApplication*>(kapp)->doAutoreplace(ctcpArgument,false);
 
205
            //QString::left(-1) returns the entire string
 
206
            QString ctcpCommand = ctcp.left(ctcp.indexOf(' ')).toLower();
 
207
            bool hasArg = ctcp.indexOf(' ') > 0;
 
208
            //QString::mid(-1)+1 = 0, which returns the entire string if there is no space, resulting in command==arg
 
209
            QString ctcpArgument = hasArg ? ctcp.mid(ctcp.indexOf(' ')+1) : QString();
 
210
            hasArg = !ctcpArgument.isEmpty();
 
211
            if (hasArg)
 
212
                ctcpArgument = konv_app->doAutoreplace(ctcpArgument, false);
142
213
 
143
214
            // If it was a ctcp action, build an action string
144
 
            if(ctcpCommand=="action" && isChan)
 
215
            if (ctcpCommand == "action" && isChan && hasArg)
145
216
            {
146
 
                if(!isIgnore(prefix,Ignore::Channel))
 
217
                if (!isIgnore(prefix,Ignore::Channel))
147
218
                {
148
219
                    Channel* channel = server->getChannelByName( parameterList.value(0) );
149
220
 
150
 
                    if(!channel) {
 
221
                    if (!channel) {
151
222
                        kError() << "Didn't find the channel " << parameterList.value(0) << endl;
152
223
                        return;
153
224
                    }
154
225
 
155
 
                    channel->appendAction(sourceNick,ctcpArgument);
 
226
                    channel->appendAction(sourceNick, ctcpArgument);
156
227
 
157
 
                    if(sourceNick != server->getNickname())
 
228
                    if (sourceNick != server->getNickname())
158
229
                    {
159
 
                        if(ctcpArgument.toLower().contains(QRegExp("(^|[^\\d\\w])"
 
230
                        if (ctcpArgument.toLower().contains(QRegExp("(^|[^\\d\\w])"
160
231
                            + QRegExp::escape(server->loweredNickname())
161
232
                            + "([^\\d\\w]|$)")))
162
233
                        {
170
241
                }
171
242
            }
172
243
            // If it was a ctcp action, build an action string
173
 
            else if(ctcpCommand=="action" && !isChan)
 
244
            else if (ctcpCommand == "action" && !isChan && hasArg)
174
245
            {
175
246
                // Check if we ignore queries from this nick
176
 
                if(!isIgnore(prefix,Ignore::Query))
 
247
                if (!isIgnore(prefix,Ignore::Query))
177
248
                {
178
249
                    NickInfoPtr nickinfo = server->obtainNickInfo(sourceNick);
179
250
                    nickinfo->setHostmask(sourceHostmask);
192
263
            }
193
264
 
194
265
            // Answer ping requests
195
 
            else if(ctcpCommand=="ping")
 
266
            else if (ctcpCommand == "ping" && hasArg)
196
267
            {
197
 
                if(!isIgnore(prefix,Ignore::CTCP))
 
268
                if (!isIgnore(prefix,Ignore::CTCP))
198
269
                {
199
 
                    if(isChan)
 
270
                    if (isChan)
200
271
                    {
201
272
                        server->appendMessageToFrontmost(i18n("CTCP"),
202
273
                            i18n("Received CTCP-PING request from %1 to channel %2, sending answer.",
215
286
            }
216
287
 
217
288
            // Maybe it was a version request, so act appropriately
218
 
            else if(ctcpCommand=="version")
 
289
            else if (ctcpCommand == "version")
219
290
            {
220
291
                if(!isIgnore(prefix,Ignore::CTCP))
221
292
                {
235
306
                    }
236
307
 
237
308
                    QString reply;
238
 
                    if(Preferences::self()->customVersionReplyEnabled())
 
309
                    if (Preferences::self()->customVersionReplyEnabled())
239
310
                    {
240
311
                        reply = Preferences::self()->customVersionReply().trimmed();
241
312
                    }
251
322
                }
252
323
            }
253
324
            // DCC request?
254
 
            else if(ctcpCommand=="dcc" && !isChan)
 
325
            else if (ctcpCommand=="dcc" && !isChan && hasArg)
255
326
            {
256
 
                if(!isIgnore(prefix,Ignore::DCC))
 
327
                if (!isIgnore(prefix,Ignore::DCC))
257
328
                {
258
329
                    // Extract DCC type and argument list
259
330
                    QString dccType=ctcpArgument.toLower().section(' ',0,0);
273
344
                    }
274
345
                    dccArgumentList += dccArguments.split(' ', QString::SkipEmptyParts);
275
346
 
276
 
                    if(dccType=="send")
 
347
                    if (dccType=="send")
277
348
                    {
278
 
                        if(dccArgumentList.count()==4)
 
349
                        if (dccArgumentList.count()==4)
279
350
                        {
280
351
                            // incoming file
281
352
                            konv_app->notificationHandler()->dccIncoming(server->getStatusView(), sourceNick);
282
353
                            emit addDccGet(sourceNick,dccArgumentList);
283
354
                        }
284
 
                        else if(dccArgumentList.count()>=5)
 
355
                        else if (dccArgumentList.count() >= 5)
285
356
                        {
286
 
                            if(dccArgumentList[dccArgumentList.size() - 3] == "0")
 
357
                            if (dccArgumentList[dccArgumentList.size() - 3] == "0")
287
358
                            {
288
359
                                // incoming file (Reverse DCC)
289
360
                                konv_app->notificationHandler()->dccIncoming(server->getStatusView(), sourceNick);
303
374
                                );
304
375
                        }
305
376
                    }
306
 
                    else if(dccType=="accept")
 
377
                    else if (dccType=="accept")
307
378
                    {
308
379
                        // resume request was accepted
309
 
                        if(dccArgumentList.count()>=3)
 
380
                        if (dccArgumentList.count() >= 3)
310
381
                        {
311
382
                            emit resumeDccGetTransfer(sourceNick,dccArgumentList);
312
383
                        }
319
390
                        }
320
391
                    }
321
392
                    // Remote client wants our sent file resumed
322
 
                    else if(dccType=="resume")
 
393
                    else if (dccType=="resume")
323
394
                    {
324
 
                        if(dccArgumentList.count()>=3)
 
395
                        if (dccArgumentList.count() >= 3)
325
396
                        {
326
397
                            emit resumeDccSendTransfer(sourceNick,dccArgumentList);
327
398
                        }
333
404
                                );
334
405
                        }
335
406
                    }
336
 
                    else if(dccType=="chat")
 
407
                    else if (dccType=="chat")
337
408
                    {
338
409
 
339
 
                        if(dccArgumentList.count()==3)
 
410
                        if (dccArgumentList.count()==3)
340
411
                        {
341
412
                            // will be connected via Server to KonversationMainWindow::addDccChat()
342
413
                            emit addDccChat(server->getNickname(),sourceNick,dccArgumentList,false);
366
437
                    );
367
438
                server->ctcpReply(sourceNick,QString("CLIENTINFO ACTION CLIENTINFO DCC PING TIME VERSION"));
368
439
            }
369
 
            else if(ctcpCommand=="time" && !isChan)
 
440
            else if (ctcpCommand=="time" && !isChan)
370
441
            {
371
442
                server->appendMessageToFrontmost(i18n("CTCP"),
372
443
                    i18n("Received CTCP-%1 request from %2, sending answer.",
378
449
            // No known CTCP request, give a general message
379
450
            else
380
451
            {
381
 
                if(!isIgnore(prefix,Ignore::CTCP))
 
452
                if (!isIgnore(prefix,Ignore::CTCP))
382
453
                {
383
454
                    if (isChan)
384
455
                        server->appendServerMessageToChannel(
398
469
        // No CTCP, so it's an ordinary channel or query message
399
470
        else
400
471
        {
401
 
            parsePrivMsg (prefix, parameterList, trailing);
 
472
            parsePrivMsg(prefix, parameterList);
402
473
        }
403
474
    }
404
 
    else if(command=="notice")
 
475
    else if (command=="notice" && plHas(2))
405
476
    {
406
 
        if(!isIgnore(prefix,Ignore::Notice))
 
477
        if (!isIgnore(prefix,Ignore::Notice))
407
478
        {
408
479
            // Channel notice?
409
480
            if(isAChannel(parameterList.value(0)))
410
481
            {
411
 
                if(server->identifyMsg())
 
482
                if (server->identifyMsg() && (trailing.length() > 1 && (trailing.at(0) == '+' || trailing.at(0) == '-')))
412
483
                {
413
484
                    trailing = trailing.mid(1);
414
485
                }
415
486
 
416
487
                server->appendServerMessageToChannel(parameterList.value(0), i18n("Notice"),
417
 
                    i18n("-%1 to %2- %3",
418
 
                         sourceNick, parameterList.value(0), trailing)
 
488
                        i18n("-%1 to %2- %3", sourceNick, parameterList.value(0), trailing)
419
489
                    );
420
490
            }
421
491
            // Private notice
422
492
            else
423
493
            {
424
494
                // Was this a CTCP reply?
425
 
                if(!trailing.isEmpty() && trailing.at(0)==QChar(0x01))
 
495
                if (!trailing.isEmpty() && trailing.at(0) == QChar(0x01))
426
496
                {
427
497
                    // cut 0x01 bytes from trailing string
428
498
                    QString ctcp(trailing.mid(1,trailing.length()-2));
430
500
                    QString reply(ctcp.section(' ',1));
431
501
 
432
502
                    // pong reply, calculate turnaround time
433
 
                    if(replyReason.toLower()=="ping")
 
503
                    if (replyReason.toLower()=="ping")
434
504
                    {
435
505
                        int dateArrived=QDateTime::currentDateTime().toTime_t();
436
506
                        int dateSent=reply.toInt();
466
536
                    else if (server->identifyMsg())
467
537
                        trailing = trailing.mid(1);
468
538
 
469
 
                    if(trailing.toLower() == "password accepted - you are now recognized"
 
539
                    if (trailing.toLower() == "password accepted - you are now recognized"
470
540
                        || trailing.toLower() == "you have already identified")
471
541
                    {
472
542
                        NickInfoPtr nickInfo = server->getNickInfo(server->getNickname());
478
548
            }
479
549
        }
480
550
    }
481
 
    else if(command=="join")
 
551
    else if (command=="join" && plHas(1))
482
552
    {
483
553
        QString channelName(trailing);
484
554
        // Sometimes JOIN comes without ":" in front of the channel name
485
 
        if(channelName.isEmpty())
486
 
            channelName=parameterList[parameterList.count()-1];
487
555
 
488
556
        // Did we join the channel, or was it someone else?
489
 
        if(server->isNickname(sourceNick))
 
557
        if (server->isNickname(sourceNick))
490
558
        {
491
559
            /*
492
560
                QString key;
525
593
            konv_app->notificationHandler()->join(channel, sourceNick);
526
594
        }
527
595
    }
528
 
    else if(command=="kick")
 
596
    else if (command=="kick" && plHas(2))
529
597
    {
530
598
        server->nickWasKickedFromChannel(parameterList.value(0),parameterList.value(1),sourceNick,trailing);
531
599
    }
532
 
    else if(command=="part")
 
600
    else if (command=="part" && plHas(1))
533
601
    {
534
 
        /* FIXME: Ugly workaround for a version of the PART line encountered on ircu:
535
 
         *   :Nick!user@host PART :#channel
536
 
         * Quote: "The final colon is specified as a "last argument" designator, and
537
 
         * is always valid before the final argument."
538
 
         */
539
 
 
540
 
        QString channel;
541
 
        QString reason;
542
 
 
543
 
        if (parameterList.value(0).isEmpty())
544
 
        {
545
 
            channel = trailing;
546
 
        }
547
 
        else
548
 
        {
549
 
            channel = parameterList.value(0);
550
 
            reason = trailing;
551
 
        }
552
 
 
553
 
        Channel* channelPtr = server->removeNickFromChannel(channel,sourceNick,reason);
554
 
 
555
 
        if(sourceNick != server->getNickname())
 
602
        // A version of the PART line encountered on ircu: ":Nick!user@host PART :#channel"
 
603
 
 
604
        QString channel(parameterList.value(0));
 
605
        QString reason(parameterList.value(1));
 
606
 
 
607
        Channel* channelPtr = server->removeNickFromChannel(channel, sourceNick, reason);
 
608
 
 
609
        if (sourceNick != server->getNickname())
556
610
        {
557
611
            konv_app->notificationHandler()->part(channelPtr, sourceNick);
558
612
        }
559
613
    }
560
 
    else if(command=="quit")
 
614
    else if (command=="quit" && plHas(1))
561
615
    {
562
 
        server->removeNickFromServer(sourceNick,trailing);
563
 
        if(sourceNick != server->getNickname())
 
616
        server->removeNickFromServer(sourceNick, trailing);
 
617
        if (sourceNick != server->getNickname())
564
618
        {
565
619
            konv_app->notificationHandler()->quit(server->getStatusView(), sourceNick);
566
620
        }
567
621
    }
568
 
    else if(command=="nick")
 
622
    else if (command=="nick" && plHas(1))
569
623
    {
570
 
        QString newNick(trailing);
571
 
 
572
 
        // Message may not include ":" in front of the new nickname
573
 
        if (newNick.isEmpty())
574
 
            newNick=parameterList[parameterList.count()-1];
 
624
        QString newNick(parameterList.value(0)); // Message may not include ":" in front of the new nickname
575
625
 
576
626
        server->renameNick(sourceNick,newNick);
577
627
 
580
630
            konv_app->notificationHandler()->nickChange(server->getStatusView(), sourceNick, newNick);
581
631
        }
582
632
    }
583
 
    else if(command=="topic")
 
633
    else if (command=="topic" && plHas(2))
584
634
    {
585
635
        server->setChannelTopic(sourceNick,parameterList.value(0),trailing);
586
636
    }
587
 
    else if(command=="mode") // mode #channel -/+ mmm params
 
637
    else if (command=="mode" && plHas(2)) // mode #channel -/+ mmm params
588
638
    {
589
 
        QStringList params=parameterList;
590
 
        if (!trailing.isEmpty())
591
 
            params << trailing;
592
 
        parseModes(sourceNick, params);
 
639
        parseModes(sourceNick, parameterList);
593
640
        Channel* channel = server->getChannelByName(parameterList.value(0));
594
 
        if(sourceNick != server->getNickname())
 
641
        if (sourceNick != server->getNickname())
595
642
        {
596
643
            konv_app->notificationHandler()->mode(channel, sourceNick);
597
644
        }
598
645
    }
599
 
    else if(command=="invite")
 
646
    else if (command=="invite" && plHas(2)) //:ejm!i=beezle@bas5-oshawa95-1176455927.dsl.bell.ca INVITE argnl :#sug4
600
647
    {
601
 
        QString channel;
602
 
 
603
 
        if (parameterList.count() > 1)
604
 
            channel = parameterList.value(1);
605
 
        else
606
 
            channel = trailing;
 
648
        QString channel(trailing);
607
649
 
608
650
        server->appendMessageToFrontmost(i18n("Invite"),
609
 
            i18n("%1 invited you to channel %2.",
610
 
                 sourceNick, channel)
 
651
            i18n("%1 invited you to channel %2.", sourceNick, channel)
611
652
            );
612
653
        emit invitation(sourceNick,channel);
613
654
    }
614
655
    else
615
656
    {
616
 
        server->appendMessageToFrontmost(command,parameterList.join(" ")+' '+trailing);
 
657
        kDebug() << "unknown client command" << parameterList.count() << _plHad << _plWanted << command << parameterList.join(" ");
 
658
        server->appendMessageToFrontmost(command, parameterList.join(" "));
617
659
    }
618
660
}
619
661
 
620
 
void InputFilter::parseServerCommand(const QString &prefix, const QString &command, const QStringList &parameterList, const QString &trailing)
 
662
void InputFilter::parseServerCommand(const QString &prefix, const QString &command, QStringList &parameterList)
621
663
{
622
664
    bool isNumeric;
623
665
    int numeric = command.toInt(&isNumeric);
624
666
 
625
 
    Q_ASSERT(server); if(!server) return;
 
667
    Q_ASSERT(server);
 
668
    if (!server)
 
669
        return;
626
670
 
627
 
    if(!isNumeric)
 
671
    if (!isNumeric)
628
672
    {
629
 
        if(command=="ping")
 
673
        if (command == "ping")
630
674
        {
631
675
            QString text;
632
676
            text = (!trailing.isEmpty()) ? trailing : parameterList.join(" ");
633
677
 
634
 
            if(!trailing.isEmpty())
 
678
            if (!trailing.isEmpty())
635
679
            {
636
680
                text = prefix + " :" + text;
637
681
            }
638
682
 
639
 
            if(!text.startsWith(" "))
 
683
            if (!text.startsWith(' '))
640
684
            {
641
685
                text.prepend(' ');
642
686
            }
645
689
            server->queue("PONG"+text, Server::HighPriority);
646
690
 
647
691
        }
648
 
        else if(command=="error :closing link:")
 
692
        else if (command == "error :closing link:")
649
693
        {
650
694
            kDebug() << "link closed";
651
695
        }
652
 
        else if(command=="pong")
 
696
        else if (command == "pong")
653
697
        {
654
698
            // double check if we are in lag measuring mode since some servers fail to send
655
699
            // the LAG cookie back in PONG
656
 
            if(trailing.startsWith("LAG") || getLagMeasuring())
 
700
            if (trailing.startsWith("LAG") || getLagMeasuring())
657
701
            {
658
702
                server->pongReceived();
659
703
            }
660
704
        }
661
 
        else if(command=="mode")
 
705
        else if (command == "mode")
662
706
        {
663
 
            QStringList params=parameterList;
664
 
            if (!trailing.isEmpty())
665
 
                params << trailing;
666
 
            parseModes(prefix, params);
 
707
            parseModes(prefix, parameterList);
667
708
        }
668
 
        else if(command=="notice")
 
709
        else if (command == "notice")
669
710
        {
670
711
            server->appendStatusMessage(i18n("Notice"),i18n("-%1- %2", prefix, trailing));
671
712
        }
672
 
        else if(command=="kick")
 
713
        else if (command == "kick" && plHas(3))
673
714
        {
674
 
            server->nickWasKickedFromChannel(parameterList.value(0),parameterList.value(1),prefix,trailing);
 
715
            server->nickWasKickedFromChannel(parameterList.value(1), parameterList.value(2), prefix, trailing);
675
716
        }
676
 
        else if(command == "privmsg")
 
717
        else if (command == "privmsg")
677
718
        {
678
 
            parsePrivMsg(prefix, parameterList, trailing);
 
719
            parsePrivMsg(prefix, parameterList);
679
720
        }
680
721
        // All yet unknown messages go into the frontmost window unaltered
681
722
        else
682
723
        {
683
 
            server->appendMessageToFrontmost(command,parameterList.join(" ")+' '+trailing);
 
724
            kDebug() << "unknown server command" << command;
 
725
            server->appendMessageToFrontmost(command, parameterList.join(" "));
684
726
        }
685
727
    }
686
 
    else
 
728
    else if (plHas(2)) //[0]==ourNick, [1] needs to be *something*
687
729
    {
 
730
        //:niven.freenode.net 353 argnl @ #konversation :@argonel psn @argnl bugbot pinotree CIA-13
 
731
        //QString serverAssignedNick(parameterList.takeFirst());
 
732
        QString serverAssignedNick(parameterList.first());
 
733
 
688
734
        switch (numeric)
689
735
        {
690
736
            case RPL_WELCOME:
691
737
            case RPL_YOURHOST:
692
738
            case RPL_CREATED:
693
739
            {
694
 
                if(numeric==RPL_WELCOME)
 
740
                if (plHas(0)) //make the script happy
695
741
                {
696
 
                    QString host;
697
 
 
698
 
                    if(trailing.contains("@"))
699
 
                        host = trailing.section("@",1);
700
 
 
701
 
                    // re-set nickname, since the server may have truncated it
702
 
                    if(parameterList.value(0)!=server->getNickname())
703
 
                        server->renameNick(server->getNickname(), parameterList.value(0));
704
 
 
705
 
                    // Send the welcome signal, so the server class knows we are connected properly
706
 
                    emit welcome(host);
707
 
                    m_connecting = true;
 
742
                    if (numeric == RPL_WELCOME)
 
743
                    {
 
744
                        QString host;
 
745
 
 
746
                        if (trailing.contains("@"))
 
747
                            host = trailing.section('@', 1);
 
748
 
 
749
                        // re-set nickname, since the server may have truncated it
 
750
                        if (serverAssignedNick != server->getNickname())
 
751
                        {
 
752
                            server->renameNick(server->getNickname(), serverAssignedNick);
 
753
                        }
 
754
 
 
755
                        // Send the welcome signal, so the server class knows we are connected properly
 
756
                        emit welcome(host);
 
757
                        m_connecting = true;
 
758
                    }
 
759
                    server->appendStatusMessage(i18n("Welcome"), trailing);
708
760
                }
709
 
                server->appendStatusMessage(i18n("Welcome"),trailing);
710
761
                break;
711
762
            }
712
763
            case RPL_MYINFO:
713
764
            {
714
 
                server->appendStatusMessage(i18n("Welcome"),
715
 
                    i18n("Server %1 (Version %2), User modes: %3, Channel modes: %4",
 
765
                if (plHas(5))
 
766
                {
 
767
                    server->appendStatusMessage(i18n("Welcome"),
 
768
                        i18n("Server %1 (Version %2), User modes: %3, Channel modes: %4",
716
769
                         parameterList.value(1),
717
770
                         parameterList.value(2),
718
771
                         parameterList.value(3),
719
772
                         parameterList.value(4))
720
 
                    );
 
773
                        );
721
774
                server->setAllowedChannelModes(parameterList.value(4));
 
775
                }
722
776
                break;
723
777
            }
724
778
            //case RPL_BOUNCE:   // RFC 1459 name, now seems to be obsoleted by ...
725
779
            case RPL_ISUPPORT:                    // ... DALnet RPL_ISUPPORT
726
780
            {
727
 
                server->appendStatusMessage(i18n("Support"),parameterList.join(" "));
 
781
                if (plHas(0)) //make the script happy
 
782
                {
 
783
                    server->appendStatusMessage(i18n("Support"),parameterList.join(" "));
728
784
 
729
785
                // The following behaviour is neither documented in RFC 1459 nor in 2810-2813
730
 
                // Nowadays, most ircds send server capabilities out via 005 (BOUNCE).
731
 
                // refer to http://www.irc.org/tech_docs/005.html for a kind of documentation.
732
 
                // More on http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt
 
786
                    // Nowadays, most ircds send server capabilities out via 005 (BOUNCE).
 
787
                    // refer to http://www.irc.org/tech_docs/005.html for a kind of documentation.
 
788
                    // More on http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt
733
789
 
734
 
                QStringList::const_iterator it = parameterList.constBegin();
735
 
                // don't want the user name
736
 
                ++it;
737
 
                for (; it != parameterList.constEnd(); ++it )
738
 
                {
739
 
                    QString property, value;
740
 
                    int pos;
741
 
                    if ((pos=(*it).indexOf( '=' )) !=-1)
742
 
                    {
743
 
                        property = (*it).left(pos);
744
 
                        value = (*it).mid(pos+1);
745
 
                    }
746
 
                    else
747
 
                    {
748
 
                        property = *it;
749
 
                    }
750
 
                    if (property=="PREFIX")
751
 
                    {
752
 
                        pos = value.indexOf(')',1);
753
 
                        if(pos==-1)
754
 
                        {
755
 
                            server->setPrefixes(QString(), value);
756
 
                            // XXX if ) isn't in the string, NOTHING should be there. anyone got a server
757
 
                            if (value.length() || property.length())
758
 
                                server->appendStatusMessage("","XXX Server sent bad PREFIX in RPL_ISUPPORT, please report.");
759
 
                        }
760
 
                        else
761
 
                        {
762
 
                            server->setPrefixes (value.mid(1, pos-1), value.mid(pos+1));
763
 
                        }
764
 
                    }
765
 
                    else if (property=="CHANTYPES")
766
 
                    {
767
 
                        server->setChannelTypes(value);
768
 
                    }
769
 
                    else if (property == "CAPAB")
770
 
                    {
771
 
                        // Disable as we don't use this for anything yet
772
 
                        //server->queue("CAPAB IDENTIFY-MSG");
773
 
                    }
774
 
                    else
775
 
                    {
776
 
                        //kDebug() << "Ignored server-capability: " << property << " with value '" << value << "'";
777
 
                    }
778
 
                }                                 // endfor
 
790
                    QStringList::const_iterator it = parameterList.constBegin();
 
791
                    // don't want the user name
 
792
                    ++it;
 
793
                    for (; it != parameterList.constEnd(); ++it )
 
794
                    {
 
795
                        QString property, value;
 
796
                        int pos;
 
797
                        if ((pos=(*it).indexOf( '=' )) !=-1)
 
798
                        {
 
799
                            property = (*it).left(pos);
 
800
                            value = (*it).mid(pos+1);
 
801
                        }
 
802
                        else
 
803
                        {
 
804
                            property = *it;
 
805
                        }
 
806
                        if (property=="PREFIX")
 
807
                        {
 
808
                            pos = value.indexOf(')',1);
 
809
                            if(pos==-1)
 
810
                            {
 
811
                                server->setPrefixes(QString(), value);
 
812
                                // XXX if ) isn't in the string, NOTHING should be there. anyone got a server
 
813
                                if (value.length() || property.length())
 
814
                                    server->appendStatusMessage("","XXX Server sent bad PREFIX in RPL_ISUPPORT, please report.");
 
815
                            }
 
816
                            else
 
817
                            {
 
818
                                server->setPrefixes (value.mid(1, pos-1), value.mid(pos+1));
 
819
                            }
 
820
                        }
 
821
                        else if (property=="CHANTYPES")
 
822
                        {
 
823
                            server->setChannelTypes(value);
 
824
                        }
 
825
                        else if (property == "CAPAB")
 
826
                        {
 
827
                            // Disable as we don't use this for anything yet
 
828
                            //server->queue("CAPAB IDENTIFY-MSG");
 
829
                        }
 
830
                        else
 
831
                        {
 
832
                            //kDebug() << "Ignored server-capability: " << property << " with value '" << value << "'";
 
833
                        }
 
834
                    }                                 // endfor
 
835
                }
779
836
                break;
780
837
            }
781
838
            case RPL_UMODEIS:
782
839
            {
783
 
                QString message=QString("%1 %2").arg(i18n("Your personal modes are:")).arg(parameterList.join(" ").section(' ',1) + ' '+trailing);
784
 
                server->appendMessageToFrontmost("Info", message);
 
840
                if (plHas(0))
 
841
                {
 
842
                    // TODO check this one... I amputated  + ' '+trailing
 
843
                    QString message=QString("%1 %2").arg(i18n("Your personal modes are:")).arg(parameterList.join(QChar(' ')).section(' ',1));
 
844
                    server->appendMessageToFrontmost("Info", message);
 
845
                }
785
846
                break;
786
847
            }
787
848
            case RPL_CHANNELMODEIS:
788
849
            {
789
 
                const QString modeString=parameterList.value(2);
790
 
                // This is the string the user will see
791
 
                QString modesAre;
792
 
                QString message = i18n("Channel modes: ") + modeString;
 
850
                if (plHas(2))
 
851
                {
 
852
                    const QString modeString=parameterList.value(2); // TEST this one was a 2
 
853
                    // This is the string the user will see
 
854
                    QString modesAre;
 
855
                    QString message = i18n("Channel modes: ") + modeString;
793
856
 
794
 
                for(int index=0;index<modeString.length();index++)
795
 
                {
796
 
                    QString parameter;
797
 
                    int parameterCount=3;
798
 
                    char mode(modeString[index].toAscii());
799
 
                    if(mode!='+')
800
 
                    {
801
 
                        if(!modesAre.isEmpty())
802
 
                            modesAre+=", ";
803
 
                        if(mode=='t')
804
 
                            modesAre+=i18n("topic protection");
805
 
                        else if(mode=='n')
806
 
                            modesAre+=i18n("no messages from outside");
807
 
                        else if(mode=='s')
808
 
                            modesAre+=i18n("secret");
809
 
                        else if(mode=='i')
810
 
                            modesAre+=i18n("invite only");
811
 
                        else if(mode=='p')
812
 
                            modesAre+=i18n("private");
813
 
                        else if(mode=='m')
814
 
                            modesAre+=i18n("moderated");
815
 
                        else if(mode=='k')
816
 
                        {
817
 
                            parameter=parameterList[parameterCount++];
818
 
                            message += ' ' + parameter;
819
 
                            modesAre+=i18n("password protected");
820
 
                        }
821
 
                        else if(mode=='a')
822
 
                            modesAre+=i18n("anonymous");
823
 
                        else if(mode=='r')
824
 
                            modesAre+=i18n("server reop");
825
 
                        else if(mode=='c')
826
 
                            modesAre+=i18n("no colors allowed");
827
 
                        else if(mode=='l')
828
 
                        {
829
 
                            parameter=parameterList[parameterCount++];
830
 
                            message += ' ' + parameter;
831
 
                            modesAre+=i18np("limited to %1 user", "limited to %1 users", parameter.toInt());
832
 
                        }
833
 
                        else
834
 
                        {
835
 
                            modesAre+=mode;
836
 
                        }
837
 
                        server->updateChannelModeWidgets(parameterList.value(1),mode,parameter);
838
 
                    }
839
 
                } // endfor
840
 
                if(!modesAre.isEmpty() && Preferences::self()->useLiteralModes())
841
 
                {
842
 
                    server->appendCommandMessageToChannel(parameterList.value(1),i18n("Mode"),message);
843
 
                }
844
 
                else
845
 
                {
846
 
                    server->appendCommandMessageToChannel(parameterList.value(1),i18n("Mode"),
847
 
                        i18n("Channel modes: ") + modesAre
848
 
                        );
 
857
                    for (int index=0;index<modeString.length();index++)
 
858
                    {
 
859
                        QString parameter;
 
860
                        int parameterCount=3;
 
861
                        char mode(modeString[index].toAscii());
 
862
                        if(mode!='+')
 
863
                        {
 
864
                            if(!modesAre.isEmpty())
 
865
                                modesAre+=", ";
 
866
                            if(mode=='t')
 
867
                                modesAre+=i18n("topic protection");
 
868
                            else if(mode=='n')
 
869
                                modesAre+=i18n("no messages from outside");
 
870
                            else if(mode=='s')
 
871
                                modesAre+=i18n("secret");
 
872
                            else if(mode=='i')
 
873
                                modesAre+=i18n("invite only");
 
874
                            else if(mode=='p')
 
875
                                modesAre+=i18n("private");
 
876
                            else if(mode=='m')
 
877
                                modesAre+=i18n("moderated");
 
878
                            else if(mode=='k')
 
879
                            {
 
880
                                parameter=parameterList.value(parameterCount++);
 
881
                                message += ' ' + parameter;
 
882
                                modesAre+=i18n("password protected");
 
883
                            }
 
884
                            else if(mode=='a')
 
885
                                modesAre+=i18n("anonymous");
 
886
                            else if(mode=='r')
 
887
                                modesAre+=i18n("server reop");
 
888
                            else if(mode=='c')
 
889
                                modesAre+=i18n("no colors allowed");
 
890
                            else if(mode=='l')
 
891
                            {
 
892
                                parameter=parameterList.value(parameterCount++);
 
893
                                message += ' ' + parameter;
 
894
                                modesAre+=i18np("limited to %1 user", "limited to %1 users", parameter.toInt());
 
895
                            }
 
896
                            else
 
897
                            {
 
898
                                modesAre+=mode;
 
899
                            }
 
900
                            server->updateChannelModeWidgets(parameterList.value(1), mode, parameter);
 
901
                        }
 
902
                    } // endfor
 
903
                    if (!modesAre.isEmpty() && Preferences::self()->useLiteralModes())
 
904
                    {
 
905
                        server->appendCommandMessageToChannel(parameterList.value(1), i18n("Mode"), message);
 
906
                    }
 
907
                    else
 
908
                    {
 
909
                        server->appendCommandMessageToChannel(parameterList.value(1), i18n("Mode"),
 
910
                            i18n("Channel modes: ") + modesAre
 
911
                            );
 
912
                    }
849
913
                }
850
914
                break;
851
915
            }
852
916
            case RPL_CHANNELURLIS:
853
917
            {// :niven.freenode.net 328 argonel #channel :http://www.buggeroff.com/
854
 
                server->appendCommandMessageToChannel(parameterList.value(1), i18n("URL"),
855
 
                    i18n("Channel URL: %1", trailing));
 
918
                if (plHas(3))
 
919
                {
 
920
                    server->appendCommandMessageToChannel(parameterList.value(1), i18n("URL"),
 
921
                        i18n("Channel URL: %1", trailing));
 
922
                }
856
923
                break;
857
924
            }
858
925
            case RPL_CHANNELCREATED:
859
926
            {
860
 
                QDateTime when;
861
 
                when.setTime_t(parameterList.value(2).toUInt());
862
 
                server->appendCommandMessageToChannel(parameterList.value(1),i18n("Created"),
863
 
                    i18n("This channel was created on %1.",
864
 
                         when.toString(Qt::LocalDate))
865
 
                    );
866
 
 
867
 
                if(Preferences::self()->autoWhoContinuousEnabled())
 
927
                if (plHas(3))
868
928
                {
869
 
                    emit endOfWho(parameterList.value(1));
 
929
                    QDateTime when;
 
930
                    when.setTime_t(parameterList.value(2).toUInt());
 
931
                    server->appendCommandMessageToChannel(parameterList.value(1), i18n("Created"),
 
932
                        i18n("This channel was created on %1.",
 
933
                            when.toString(Qt::LocalDate))
 
934
                        );
870
935
                }
871
 
 
872
936
                break;
873
937
            }
874
938
            case RPL_WHOISACCOUNT:
875
939
            {
876
 
                // Display message only if this was not an automatic request.
877
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
940
                if (plHas(2))
878
941
                {
879
 
                    server->appendMessageToFrontmost(i18n("Whois"),i18n("%1 is logged in as %2.", parameterList.value(1), parameterList.value(2)));
 
942
                    // Display message only if this was not an automatic request.
 
943
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
944
                    {
 
945
                        server->appendMessageToFrontmost(i18n("Whois"), i18n("%1 is logged in as %2.", parameterList.value(1), parameterList.value(2)) );
 
946
                    }
880
947
                }
881
948
                break;
882
949
            }
 
950
            //:niven.freenode.net 353 argnl @ #konversation :@argonel psn @argnl bugbot pinotree CIA-13
883
951
            case RPL_NAMREPLY:
884
952
            {
885
 
                QStringList nickList;
 
953
                if (plHas(4))
 
954
                {
 
955
                    QStringList nickList;
886
956
 
887
 
                if(!trailing.isEmpty())
888
 
                {
889
 
                    nickList = trailing.split(' ', QString::SkipEmptyParts);
890
 
                }
891
 
                else if(parameterList.count() > 3)
892
 
                {
893
 
                    for(int i = 3; i < parameterList.count(); i++) {
 
957
                    if (!trailing.isEmpty())
 
958
                    {
 
959
                        nickList = trailing.split(' ', QString::SkipEmptyParts);
 
960
                    }
 
961
                    else if (parameterList.count() > 3)
 
962
                    {
 
963
                        for(int i = 3; i < parameterList.count(); i++) {
894
964
                        nickList.append(parameterList.value(i));
895
 
                    }
896
 
                }
897
 
                else
898
 
                {
899
 
                    kDebug() << "Hmm seems something is broken... can't get to the names!";
900
 
                }
901
 
 
902
 
                // send list to channel
903
 
                server->addPendingNickList(parameterList.value(2), nickList);
904
 
 
905
 
                // Display message only if this was not an automatic request.
906
 
                if(!getAutomaticRequest("NAMES",parameterList.value(2))==1)
907
 
                {
908
 
                    server->appendMessageToFrontmost(i18n("Names"),trailing);
 
965
                        }
 
966
                    }
 
967
                    else
 
968
                    {
 
969
                        kDebug() << "Hmm seems something is broken... can't get to the names!";
 
970
                    }
 
971
 
 
972
                    // send list to channel
 
973
                    server->addPendingNickList(parameterList.value(2), nickList); // TEST this was a 2
 
974
 
 
975
                    // Display message only if this was not an automatic request.
 
976
                    if (!getAutomaticRequest("NAMES", parameterList.value(2)) == 1)
 
977
                    {
 
978
                        server->appendMessageToFrontmost(i18n("Names"), trailing);
 
979
                    }
909
980
                }
910
981
                break;
911
982
            }
912
983
            case RPL_ENDOFNAMES:
913
984
            {
914
 
                if(getAutomaticRequest("NAMES",parameterList.value(1))==1)
915
 
                {
916
 
                    // This code path was taken for the automatic NAMES input on JOIN, upcoming
917
 
                    // NAMES input for this channel will be manual invocations of /names
918
 
                    setAutomaticRequest("NAMES",parameterList.value(1),false);
919
 
                }
920
 
                else
921
 
                {
922
 
                    server->appendMessageToFrontmost(i18n("Names"),i18n("End of NAMES list."));
 
985
                if (plHas(2))
 
986
                {
 
987
                    if (getAutomaticRequest("NAMES",parameterList.value(1)) == 1)
 
988
                    {
 
989
                        // This code path was taken for the automatic NAMES input on JOIN, upcoming
 
990
                        // NAMES input for this channel will be manual invocations of /names
 
991
                        setAutomaticRequest("NAMES", parameterList.value(1), false);
 
992
 
 
993
                    if (Preferences::self()->autoWhoContinuousEnabled())
 
994
                    {
 
995
                        emit endOfWho(parameterList.value(1));
 
996
                    }
 
997
                    }
 
998
                    else
 
999
                    {
 
1000
                        server->appendMessageToFrontmost(i18n("Names"),i18n("End of NAMES list."));
 
1001
                    }
923
1002
                }
924
1003
                break;
925
1004
            }
926
1005
            // Topic set messages
927
1006
            case RPL_NOTOPIC:
928
1007
            {
929
 
                server->appendMessageToFrontmost(i18n("TOPIC"),i18n("The channel %1 has no topic set.", parameterList.value(1)) /*.arg(parameterList.value(2))*/); //FIXME ok, whats the second parameter supposed to be?
930
 
 
 
1008
                if (plHas(2))
 
1009
                {
 
1010
                    //this really has 3, but [2] is "No topic has been set"
 
1011
                    server->appendMessageToFrontmost(i18n("TOPIC"), i18n("The channel %1 has no topic set.", parameterList.value(1)));
 
1012
                }
931
1013
                break;
932
1014
            }
933
1015
            case RPL_TOPIC:
934
1016
            {
935
 
                QString topic = Konversation::removeIrcMarkup(trailing);
936
 
 
937
 
                // FIXME: This is an abuse of the automaticRequest system: We're
938
 
                // using it in an inverted manner, i.e. the automaticRequest is
939
 
                // set to true by a manual invocation of /topic. Bad bad bad -
940
 
                // needs rethinking of automaticRequest.
941
 
                if(getAutomaticRequest("TOPIC",parameterList.value(1))==0)
942
 
                {
943
 
                    // Update channel window
944
 
                    server->setChannelTopic(parameterList.value(1),topic);
945
 
                }
946
 
                else
947
 
                {
948
 
                    server->appendMessageToFrontmost(i18n("Topic"),i18n("The channel topic for %1 is: \"%2\"", parameterList.value(1), topic));
949
 
                }
950
 
 
 
1017
                if (plHas(3))
 
1018
                {
 
1019
                    QString topic = Konversation::removeIrcMarkup(trailing);
 
1020
 
 
1021
                    // FIXME: This is an abuse of the automaticRequest system: We're
 
1022
                    // using it in an inverted manner, i.e. the automaticRequest is
 
1023
                    // set to true by a manual invocation of /topic. Bad bad bad -
 
1024
                    // needs rethinking of automaticRequest.
 
1025
                    if (getAutomaticRequest("TOPIC", parameterList.value(1)) == 0)
 
1026
                    {
 
1027
                        // Update channel window
 
1028
                        server->setChannelTopic(parameterList.value(1), topic);
 
1029
                    }
 
1030
                    else
 
1031
                    {
 
1032
                        server->appendMessageToFrontmost(i18n("Topic"), i18n("The channel topic for %1 is: \"%2\"", parameterList.value(1), topic));
 
1033
                    }
 
1034
                }
951
1035
                break;
952
1036
            }
953
1037
            case RPL_TOPICSETBY:
954
1038
            {
955
 
                // Inform user who set the topic and when
956
 
                QDateTime when;
957
 
                when.setTime_t(parameterList.value(3).toUInt());
958
 
 
959
 
                // See FIXME in RPL_TOPIC
960
 
                if(getAutomaticRequest("TOPIC",parameterList.value(1))==0)
961
 
                {
962
 
                    server->appendCommandMessageToChannel(parameterList.value(1),i18n("Topic"),
963
 
                        i18n("The topic was set by %1 on %2.",
964
 
                             parameterList.value(2), when.toString(Qt::LocalDate)),
965
 
                        false);
966
 
                }
967
 
                else
968
 
                {
969
 
                    server->appendMessageToFrontmost(i18n("Topic"),i18n("The topic for %1 was set by %2 on %3.",
970
 
                        parameterList.value(1),
971
 
                        parameterList.value(2),
972
 
                        when.toString(Qt::LocalDate))
973
 
                        );
974
 
                    setAutomaticRequest("TOPIC",parameterList.value(1),false);
975
 
                }
976
 
                emit topicAuthor(parameterList.value(1), parameterList.value(2), when);
977
 
 
 
1039
                if (plHas(4))
 
1040
                {
 
1041
                    // Inform user who set the topic and when
 
1042
                    QDateTime when;
 
1043
                    when.setTime_t(parameterList.value(3).toUInt());
 
1044
 
 
1045
                    // See FIXME in RPL_TOPIC
 
1046
                    if (getAutomaticRequest("TOPIC", parameterList.value(1)) == 0)
 
1047
                    {
 
1048
                        server->appendCommandMessageToChannel(parameterList.value(1), i18n("Topic"),
 
1049
                            i18n("The topic was set by %1 on %2.",
 
1050
                                parameterList.value(2), when.toString(Qt::LocalDate)),
 
1051
                            false);
 
1052
                    }
 
1053
                    else
 
1054
                    {
 
1055
                        server->appendMessageToFrontmost(i18n("Topic"),i18n("The topic for %1 was set by %2 on %3.",
 
1056
                            parameterList.value(1),
 
1057
                            parameterList.value(2),
 
1058
                            when.toString(Qt::LocalDate))
 
1059
                            );
 
1060
                        setAutomaticRequest("TOPIC",parameterList.value(1), false);
 
1061
                    }
 
1062
                    emit topicAuthor(parameterList.value(1), parameterList.value(2), when);
 
1063
                }
978
1064
                break;
979
1065
            }
980
1066
            case RPL_WHOISACTUALLY:
981
1067
            {
982
 
                // Display message only if this was not an automatic request.
983
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
1068
                if (plHas(3))
984
1069
                {
985
 
                    server->appendMessageToFrontmost(i18n("Whois"),i18n("%1 is actually using the host %2.", parameterList.value(1), parameterList.value(2)));
 
1070
                    // Display message only if this was not an automatic request.
 
1071
                    if (getAutomaticRequest("WHOIS",parameterList.value(1)) == 0)
 
1072
                    {
 
1073
                        server->appendMessageToFrontmost(i18n("Whois"),i18n("%1 is actually using the host %2.", parameterList.value(1), parameterList.value(2)));
 
1074
                    }
986
1075
                }
987
1076
                break;
988
1077
            }
989
1078
            case ERR_NOSUCHNICK:
990
1079
            {
991
 
                // Display slightly different error message in case we performed a WHOIS for
992
 
                // IP resolve purposes, and clear it from the automaticRequest list
993
 
                if(getAutomaticRequest("DNS",parameterList.value(1))==0)
994
 
                {
995
 
                    server->appendMessageToFrontmost(i18n("Error"),i18n("%1: No such nick/channel.", parameterList.value(1)));
996
 
                }
997
 
                else if(getAutomaticRequest("WHOIS",parameterList.value(1))==0) //Display message only if this was not an automatic request.
998
 
                {
999
 
                    server->appendMessageToFrontmost(i18n("Error"),i18n("No such nick: %1.", parameterList.value(1)));
1000
 
                    setAutomaticRequest("DNS", parameterList.value(1), false);
1001
 
                }
1002
 
 
 
1080
                if (plHas(2))
 
1081
                {
 
1082
                    // Display slightly different error message in case we performed a WHOIS for
 
1083
                    // IP resolve purposes, and clear it from the automaticRequest list
 
1084
                    if (getAutomaticRequest("DNS", parameterList.value(1)) == 0)
 
1085
                    {
 
1086
                        server->appendMessageToFrontmost(i18n("Error"), i18n("%1: No such nick/channel.", parameterList.value(1)));
 
1087
                    }
 
1088
                    else if(getAutomaticRequest("WHOIS", parameterList.value(1)) == 0) //Display message only if this was not an automatic request.
 
1089
                    {
 
1090
                        server->appendMessageToFrontmost(i18n("Error"), i18n("No such nick: %1.", parameterList.value(1)));
 
1091
                        setAutomaticRequest("DNS", parameterList.value(1), false);
 
1092
                    }
 
1093
                }
1003
1094
                break;
1004
1095
            }
1005
1096
            case ERR_NOSUCHCHANNEL:
1006
1097
            {
1007
 
                // Display message only if this was not an automatic request.
1008
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
1098
                if (plHas(2))
1009
1099
                {
1010
 
                    server->appendMessageToFrontmost(i18n("Error"),i18n("%1: No such channel.", parameterList.value(1)));
 
1100
                    // Display message only if this was not an automatic request.
 
1101
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1102
                    {
 
1103
                        server->appendMessageToFrontmost(i18n("Error"), i18n("%1: No such channel.", parameterList.value(1)));
 
1104
                    }
1011
1105
                }
1012
1106
                break;
1013
1107
            }
1014
1108
            // Nick already on the server, so try another one
1015
1109
            case ERR_NICKNAMEINUSE:
1016
1110
            {
1017
 
                // if we are already connected, don't try tro find another nick ourselves
1018
 
                if(server->isConnected())
1019
 
                {                                 // Show message
1020
 
                    server->appendMessageToFrontmost(i18n("Nick"),i18n("Nickname already in use, try a different one."));
1021
 
                }
1022
 
                else                              // not connected yet, so try to find a nick that's not in use
 
1111
                if (plHas(1))
1023
1112
                {
1024
 
                    // Get the next nick from the list or ask for a new one
1025
 
                    QString newNick = server->getNextNickname();
 
1113
                    // if we are already connected, don't try tro find another nick ourselves
 
1114
                    if (server->isConnected()) // Show message
 
1115
                    {
 
1116
                        server->appendMessageToFrontmost(i18n("Nick"), i18n("Nickname already in use, try a different one."));
 
1117
                    }
 
1118
                    else // not connected yet, so try to find a nick that's not in use
 
1119
                    {
 
1120
                        // Get the next nick from the list or ask for a new one
 
1121
                        QString newNick = server->getNextNickname();
1026
1122
 
1027
 
                    // The user chose to disconnect
1028
 
                    if (newNick.isNull())
1029
 
                    {
1030
 
                        server->disconnect();
1031
 
                    }
1032
 
                    else
1033
 
                    {
1034
 
                        // Update Server window
1035
 
                        server->obtainNickInfo(server->getNickname()) ;
1036
 
                        server->renameNick(server->getNickname(), newNick);
1037
 
                        // Show message
1038
 
                        server->appendMessageToFrontmost(i18n("Nick"), i18n("Nickname already in use. Trying %1.", newNick));
1039
 
                        // Send nickchange request to the server
1040
 
                        server->queue("NICK "+newNick);
 
1123
                        // The user chose to disconnect
 
1124
                        if (newNick.isNull())
 
1125
                        {
 
1126
                            server->disconnect();
 
1127
                        }
 
1128
                        else
 
1129
                        {
 
1130
                            // Update Server window
 
1131
                            server->obtainNickInfo(server->getNickname()) ;
 
1132
                            server->renameNick(server->getNickname(), newNick);
 
1133
                            // Show message
 
1134
                            server->appendMessageToFrontmost(i18n("Nick"), i18n("Nickname already in use. Trying %1.", newNick));
 
1135
                            // Send nickchange request to the server
 
1136
                            server->queue("NICK "+newNick);
 
1137
                        }
1041
1138
                    }
1042
1139
                }
1043
1140
                break;
1044
1141
            }
1045
1142
            case ERR_ERRONEUSNICKNAME:
1046
1143
            {
1047
 
                if(server->isConnected())
1048
 
                {                                 // We are already connected. Just print the error message
1049
 
                    server->appendMessageToFrontmost(i18n("Nick"), trailing);
1050
 
                }
1051
 
                else                              // Find a new nick as in ERR_NICKNAMEINUSE
 
1144
                if (plHas(1))
1052
1145
                {
1053
 
                    QString newNick = server->getNextNickname();
 
1146
                    if (server->isConnected())
 
1147
                    {                                 // We are already connected. Just print the error message
 
1148
                        server->appendMessageToFrontmost(i18n("Nick"), trailing);
 
1149
                    }
 
1150
                    else                              // Find a new nick as in ERR_NICKNAMEINUSE
 
1151
                    {
 
1152
                        QString newNick = server->getNextNickname();
1054
1153
 
1055
 
                    // The user chose to disconnect
1056
 
                    if (newNick.isNull())
1057
 
                    {
1058
 
                        server->disconnect();
1059
 
                    }
1060
 
                    else
1061
 
                    {
1062
 
                        server->obtainNickInfo(server->getNickname()) ;
1063
 
                        server->renameNick(server->getNickname(), newNick);
1064
 
                        server->appendMessageToFrontmost(i18n("Nick"), i18n("Erroneus nickname. Changing nick to %1.", newNick));
1065
 
                        server->queue("NICK "+newNick);
 
1154
                        // The user chose to disconnect
 
1155
                        if (newNick.isNull())
 
1156
                        {
 
1157
                            server->disconnect();
 
1158
                        }
 
1159
                        else
 
1160
                        {
 
1161
                            server->obtainNickInfo(server->getNickname()) ;
 
1162
                            server->renameNick(server->getNickname(), newNick);
 
1163
                            server->appendMessageToFrontmost(i18n("Nick"), i18n("Erroneus nickname. Changing nick to %1.", newNick));
 
1164
                            server->queue("NICK "+newNick);
 
1165
                        }
1066
1166
                    }
1067
1167
                }
1068
1168
                break;
1069
1169
            }
1070
1170
            case ERR_NOTONCHANNEL:
1071
1171
            {
1072
 
                server->appendMessageToFrontmost(i18n("Error"),i18n("You are not on %1.", parameterList.value(1)));
1073
 
 
 
1172
                if (plHas(2))
 
1173
                {
 
1174
                    server->appendMessageToFrontmost(i18n("Error"), i18n("You are not on %1.", parameterList.value(1)));
 
1175
                }
1074
1176
                break;
1075
1177
            }
1076
1178
            case RPL_MOTDSTART:
1077
1179
            {
1078
 
                if(!m_connecting || !Preferences::self()->skipMOTD())
1079
 
                  server->appendStatusMessage(i18n("MOTD"),i18n("Message of the day:"));
 
1180
                if (plHas(1))
 
1181
                {
 
1182
                    if (!m_connecting || !Preferences::self()->skipMOTD())
 
1183
                    server->appendStatusMessage(i18n("MOTD"), i18n("Message of the day:"));
 
1184
                }
1080
1185
                break;
1081
1186
            }
1082
1187
            case RPL_MOTD:
1083
1188
            {
1084
 
                if(!m_connecting || !Preferences::self()->skipMOTD())
1085
 
                    server->appendStatusMessage(i18n("MOTD"),trailing);
 
1189
                if (plHas(2))
 
1190
                {
 
1191
                    if (!m_connecting || !Preferences::self()->skipMOTD())
 
1192
                        server->appendStatusMessage(i18n("MOTD"), trailing);
 
1193
                }
1086
1194
                break;
1087
1195
            }
1088
1196
            case RPL_ENDOFMOTD:
1089
1197
            {
1090
 
                if(!m_connecting || !Preferences::self()->skipMOTD())
1091
 
                    server->appendStatusMessage(i18n("MOTD"),i18n("End of message of the day"));
1092
 
 
1093
 
                if(m_connecting)
1094
 
                    server->autoCommandsAndChannels();
1095
 
 
1096
 
                m_connecting = false;
 
1198
                if (plHas(1))
 
1199
                {
 
1200
                    if (!m_connecting || !Preferences::self()->skipMOTD())
 
1201
                        server->appendStatusMessage(i18n("MOTD"), i18n("End of message of the day"));
 
1202
 
 
1203
                    if (m_connecting)
 
1204
                        server->autoCommandsAndChannels();
 
1205
 
 
1206
                    m_connecting = false;
 
1207
                }
1097
1208
                break;
1098
1209
            }
1099
1210
            case ERR_NOMOTD:
1100
1211
            {
1101
 
                if(m_connecting)
1102
 
                    server->autoCommandsAndChannels();
 
1212
                if (plHas(1))
 
1213
                {
 
1214
                    if (m_connecting)
 
1215
                        server->autoCommandsAndChannels();
1103
1216
 
1104
 
                m_connecting = false;
 
1217
                    m_connecting = false;
 
1218
                }
1105
1219
                break;
1106
1220
            }
1107
1221
            case RPL_YOUREOPER:
1108
1222
            {
1109
 
                server->appendMessageToFrontmost(i18n("Notice"),i18n("You are now an IRC operator on this server."));
1110
 
 
 
1223
                if (plHas(1))
 
1224
                {
 
1225
                    server->appendMessageToFrontmost(i18n("Notice"), i18n("You are now an IRC operator on this server."));
 
1226
                }
1111
1227
                break;
1112
1228
            }
1113
1229
            case RPL_GLOBALUSERS:                 // Current global users: 589 Max: 845
1114
1230
            {
1115
 
                QString current(trailing.section(' ',3));
1116
 
                //QString max(trailing.section(' ',5,5));
1117
 
                server->appendStatusMessage(i18n("Users"),i18n("Current users on the network: %1", current));
 
1231
                if (plHas(2))
 
1232
                {
 
1233
                    QString current(trailing.section(' ',3));
 
1234
                    //QString max(trailing.section(' ',5,5));
 
1235
                    server->appendStatusMessage(i18n("Users"), i18n("Current users on the network: %1", current));
 
1236
                }
1118
1237
                break;
1119
1238
            }
1120
1239
            case RPL_LOCALUSERS:                  // Current local users: 589 Max: 845
1121
1240
            {
1122
 
                QString current(trailing.section(' ',3));
1123
 
                //QString max(trailing.section(' ',5,5));
1124
 
                server->appendStatusMessage(i18n("Users"),i18n("Current users on %1: %2.", prefix, current));
 
1241
                if (plHas(2))
 
1242
                {
 
1243
                    QString current(trailing.section(' ', 3));
 
1244
                    //QString max(trailing.section(' ',5,5));
 
1245
                    server->appendStatusMessage(i18n("Users"),i18n("Current users on %1: %2.", prefix, current));
 
1246
                }
1125
1247
                break;
1126
1248
            }
1127
1249
            case RPL_ISON:
1128
1250
            {
1129
 
                // Tell server to start the next notify timer round
1130
 
                emit notifyResponse(trailing);
 
1251
                if (plHas(2))
 
1252
                {
 
1253
                    // Tell server to start the next notify timer round
 
1254
                    emit notifyResponse(trailing);
 
1255
                }
1131
1256
                break;
1132
1257
            }
1133
1258
            case RPL_AWAY:
1134
1259
            {
1135
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1136
 
                if(nickInfo)
1137
 
                {
1138
 
                    nickInfo->setAway(true);
1139
 
                    if( nickInfo->getAwayMessage() == trailing )
1140
 
                        break;
1141
 
                    nickInfo->setAwayMessage(trailing);
1142
 
                }
1143
 
 
1144
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1145
 
                {
1146
 
                    server->appendMessageToFrontmost(i18n("Away"),i18n("%1 is away: %2",
1147
 
                        parameterList.value(1), trailing)
1148
 
                        );
1149
 
                }
1150
 
 
 
1260
                if (plHas(3))
 
1261
                {
 
1262
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
 
1263
                    if (nickInfo)
 
1264
                    {
 
1265
                        nickInfo->setAway(true);
 
1266
                        if (nickInfo->getAwayMessage() != trailing) // FIXME i think this check should be in the setAwayMessage method
 
1267
                        {
 
1268
                            nickInfo->setAwayMessage(trailing);
 
1269
                            // TEST this used to skip the automatic request handler below
 
1270
                        }
 
1271
                    }
 
1272
 
 
1273
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1274
                    {
 
1275
                        server->appendMessageToFrontmost(i18n("Away"),
 
1276
                            i18n("%1 is away: %2", parameterList.value(1), trailing)
 
1277
                            );
 
1278
                    }
 
1279
                }
1151
1280
                break;
1152
1281
            }
1153
1282
            case RPL_INVITING:
1154
1283
            {
1155
 
                server->appendMessageToFrontmost(i18n("Invite"),
1156
 
                    i18n("You invited %1 to channel %2.",
1157
 
                         parameterList.value(1), parameterList.value(2))
1158
 
                    );
 
1284
                if (plHas(3))
 
1285
                {
 
1286
                    server->appendMessageToFrontmost(i18n("Invite"),
 
1287
                            i18n("You invited %1 to channel %2.",
 
1288
                            parameterList.value(1), parameterList.value(2))
 
1289
                        );
 
1290
                }
1159
1291
                break;
1160
1292
            }
1161
1293
            //Sample WHOIS response
1169
1301
            //[19:11] :zahn.freenode.net 318 PhantomsDad psn :End of /WHOIS list.
1170
1302
            case RPL_WHOISUSER:
1171
1303
            {
1172
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1173
 
                if(nickInfo)
1174
 
                {
1175
 
                    nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3)));
1176
 
                    nickInfo->setRealName(trailing);
1177
 
                }
1178
 
                // Display message only if this was not an automatic request.
1179
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1180
 
                {
1181
 
                    // escape html tags
1182
 
                    QString escapedRealName(trailing);
1183
 
                    escapedRealName.replace("<","&lt;").replace(">","&gt;");
1184
 
                    server->appendMessageToFrontmost(i18n("Whois"),
1185
 
                        i18n("%1 is %2@%3 (%4)",
1186
 
                             parameterList.value(1),
1187
 
                             parameterList.value(2),
1188
 
                             parameterList.value(3),
1189
 
                             escapedRealName), false);   // Don't parse any urls
1190
 
                }
1191
 
                else
1192
 
                {
1193
 
                    // This WHOIS was requested by Server for DNS resolve purposes; try to resolve the host
1194
 
                    if(getAutomaticRequest("DNS",parameterList.value(1))==1)
1195
 
                    {
1196
 
                        QHostInfo resolved = QHostInfo::fromName(parameterList.value(3));
1197
 
                        if(resolved.error() == QHostInfo::NoError && !resolved.addresses().isEmpty())
1198
 
                        {
1199
 
                            QString ip = resolved.addresses().first().toString();
1200
 
                            server->appendMessageToFrontmost(i18n("DNS"),
1201
 
                                i18n("Resolved %1 (%2) to address: %3",
1202
 
                                     parameterList.value(1),
1203
 
                                     parameterList.value(3),
1204
 
                                     ip)
1205
 
                                );
1206
 
                        }
1207
 
                        else
1208
 
                        {
1209
 
                            server->appendMessageToFrontmost(i18n("Error"),
1210
 
                                i18n("Unable to resolve address for %1 (%2)",
1211
 
                                     parameterList.value(1),
1212
 
                                     parameterList.value(3))
1213
 
                                );
1214
 
                        }
 
1304
                if (plHas(4))
 
1305
                {
 
1306
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
 
1307
                    if (nickInfo)
 
1308
                    {
 
1309
                        nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3)));
 
1310
                        nickInfo->setRealName(trailing);
 
1311
                    }
 
1312
                    // Display message only if this was not an automatic request.
 
1313
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1314
                    {
 
1315
                        // escape html tags
 
1316
                        QString escapedRealName(trailing);
 
1317
                        escapedRealName.replace('<', "&lt;").replace('>', "&gt;");
 
1318
                        server->appendMessageToFrontmost(i18n("Whois"),
 
1319
                            i18n("%1 is %2@%3 (%4)",
 
1320
                                parameterList.value(1),
 
1321
                                parameterList.value(2),
 
1322
                                parameterList.value(3),
 
1323
                                escapedRealName), false);   // Don't parse any urls
 
1324
                    }
 
1325
                    else
 
1326
                    {
 
1327
                        // This WHOIS was requested by Server for DNS resolve purposes; try to resolve the host
 
1328
                        if (getAutomaticRequest("DNS", parameterList.value(1)) == 1)
 
1329
                        {
 
1330
                            QHostInfo resolved = QHostInfo::fromName(parameterList.value(3));
 
1331
                            if (resolved.error() == QHostInfo::NoError && !resolved.addresses().isEmpty())
 
1332
                            {
 
1333
                                QString ip = resolved.addresses().first().toString();
 
1334
                                server->appendMessageToFrontmost(i18n("DNS"),
 
1335
                                    i18n("Resolved %1 (%2) to address: %3",
 
1336
                                        parameterList.value(1),
 
1337
                                        parameterList.value(3),
 
1338
                                        ip)
 
1339
                                    );
 
1340
                            }
 
1341
                            else
 
1342
                            {
 
1343
                                server->appendMessageToFrontmost(i18n("Error"),
 
1344
                                    i18n("Unable to resolve address for %1 (%2)",
 
1345
                                        parameterList.value(1),
 
1346
                                        parameterList.value(3))
 
1347
                                    );
 
1348
                            }
1215
1349
 
1216
 
                        // Clear this from the automaticRequest list so it works repeatedly
1217
 
                        setAutomaticRequest("DNS", parameterList.value(1), false);
 
1350
                            // Clear this from the automaticRequest list so it works repeatedly
 
1351
                            setAutomaticRequest("DNS", parameterList.value(1), false);
 
1352
                        }
1218
1353
                    }
1219
1354
                }
1220
1355
                break;
1224
1359
            case RPL_WHOISIDENTIFY:
1225
1360
            case RPL_IDENTIFIED:
1226
1361
            {
1227
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1228
 
                if(nickInfo)
1229
 
                {
1230
 
                    nickInfo->setIdentified(true);
1231
 
                }
1232
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1233
 
                {
1234
 
                    // Prints "psn is an identified user"
1235
 
                    //server->appendStatusMessage(i18n("Whois"),parameterList.join(" ").section(' ',1)+' '+trailing);
1236
 
                    // The above line works fine, but can't be i18n'ised. So use the below instead.. I hope this is okay.
1237
 
                    server->appendMessageToFrontmost(i18n("Whois"), i18n("%1 is an identified user.", parameterList.value(1)));
 
1362
                if (plHas(2))
 
1363
                {
 
1364
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
 
1365
                    if (nickInfo)
 
1366
                    {
 
1367
                        nickInfo->setIdentified(true);
 
1368
                    }
 
1369
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1370
                    {
 
1371
                        // Prints "psn is an identified user"
 
1372
                        //server->appendStatusMessage(i18n("Whois"),parameterList.join(" ").section(' ',1)+' '+trailing);
 
1373
                        // The above line works fine, but can't be i18n'ised. So use the below instead.. I hope this is okay.
 
1374
                        server->appendMessageToFrontmost(i18n("Whois"), i18n("%1 is an identified user.", parameterList.value(1)));
 
1375
                    }
1238
1376
                }
1239
1377
                break;
1240
1378
            }
1244
1382
            //[21:39] [352] #lounge ~Nottingha worldforge.org irc.worldforge.org SherwoodSpirit H 0 Arboreal Entity
1245
1383
            case RPL_WHOREPLY:
1246
1384
            {
1247
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(5));
1248
 
                                                  // G=away G@=away,op G+=away,voice
1249
 
                bool bAway = parameterList.value(6).toUpper().startsWith("G");
1250
 
                if(nickInfo)
 
1385
                if (plHas(6))
1251
1386
                {
1252
 
                    nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3)));
1253
 
                                                  //Strip off the "0 "
1254
 
                    nickInfo->setRealName(trailing.section(" ", 1));
1255
 
                    nickInfo->setAway(bAway);
1256
 
                    if(!bAway)
 
1387
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(5));
 
1388
                                                    // G=away G@=away,op G+=away,voice
 
1389
                    bool bAway = parameterList.value(6).toUpper().startsWith('G');
 
1390
                    if (nickInfo)
1257
1391
                    {
1258
 
                        nickInfo->setAwayMessage(QString());
 
1392
                        nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3)));
 
1393
                                                    //Strip off the "0 "
 
1394
                        nickInfo->setRealName(trailing.section(' ', 1));
 
1395
                        nickInfo->setAway(bAway);
 
1396
                        if(!bAway)
 
1397
                        {
 
1398
                            nickInfo->setAwayMessage(QString());
 
1399
                        }
1259
1400
                    }
1260
 
                }
1261
 
                // Display message only if this was not an automatic request.
1262
 
                if(!whoRequestList.isEmpty())     // for safe
1263
 
                {
1264
 
                    if(getAutomaticRequest("WHO",whoRequestList.front())==0)
 
1401
                    // Display message only if this was not an automatic request.
 
1402
                    if (!whoRequestList.isEmpty())     // for safe
1265
1403
                    {
1266
 
                        server->appendMessageToFrontmost(i18n("Who"),
1267
 
                            i18n("%1 is %2@%3 (%4)%5",parameterList.value(5),
1268
 
                            parameterList.value(2),
1269
 
                            parameterList.value(3),
1270
 
                            trailing.section(" ", 1),
1271
 
                            bAway?i18n(" (Away)"):QString())
1272
 
                            , false); // Don't parse as url
 
1404
                        if (getAutomaticRequest("WHO",whoRequestList.front())==0)
 
1405
                        {
 
1406
                            server->appendMessageToFrontmost(i18n("Who"),
 
1407
                                i18n("%1 is %2@%3 (%4)%5", parameterList.value(5),
 
1408
                                    parameterList.value(2),
 
1409
                                    parameterList.value(3),
 
1410
                                    trailing.section(' ', 1),
 
1411
                                    bAway?i18n(" (Away)"):QString()),
 
1412
                                false); // Don't parse as url
 
1413
                        }
1273
1414
                    }
1274
1415
                }
1275
1416
                break;
1276
1417
            }
1277
1418
            case RPL_ENDOFWHO:
1278
1419
            {
1279
 
                if(!whoRequestList.isEmpty())
 
1420
                if (plHas(2))
1280
1421
                {
1281
 
                    const QString param = parameterList.value(1).toLower();
1282
 
                    // for safety
1283
 
                    const int idx = whoRequestList.indexOf(param);
1284
 
                    if(idx > -1)
 
1422
                    if (!whoRequestList.isEmpty())
1285
1423
                    {
1286
 
                        if(getAutomaticRequest("WHO", param) == 0)
 
1424
                        const QString param = parameterList.value(1).toLower();
 
1425
                        // for safety
 
1426
                        const int idx = whoRequestList.indexOf(param);
 
1427
                        if (idx > -1)
1287
1428
                        {
1288
 
                            server->appendMessageToFrontmost(i18n("Who"),
1289
 
                                i18n("End of /WHO list for %1",
1290
 
                                     parameterList.value(1)));
 
1429
                            if (getAutomaticRequest("WHO", param) == 0)
 
1430
                            {
 
1431
                                server->appendMessageToFrontmost(i18n("Who"),
 
1432
                                    i18n("End of /WHO list for %1",
 
1433
                                        parameterList.value(1)));
 
1434
                            }
 
1435
                            else
 
1436
                            {
 
1437
                                setAutomaticRequest("WHO", param, false);
 
1438
                            }
 
1439
 
 
1440
                            whoRequestList.removeAt(idx);
1291
1441
                        }
1292
1442
                        else
1293
1443
                        {
1294
 
                            setAutomaticRequest("WHO", param, false);
 
1444
                            // whoRequestList seems to be broken.
 
1445
                            kDebug() << "RPL_ENDOFWHO: malformed ENDOFWHO. retrieved: "
 
1446
                                << parameterList.value(1) << " expected: " << whoRequestList.front();
 
1447
                            whoRequestList.clear();
1295
1448
                        }
1296
 
 
1297
 
                        whoRequestList.removeAt(idx);
1298
1449
                    }
1299
1450
                    else
1300
1451
                    {
1301
 
                        // whoRequestList seems to be broken.
1302
 
                        kDebug() << "RPL_ENDOFWHO: malformed ENDOFWHO. retrieved: "
1303
 
                            << parameterList.value(1) << " expected: " << whoRequestList.front();
1304
 
                        whoRequestList.clear();
 
1452
                        kDebug() << "RPL_ENDOFWHO: unexpected ENDOFWHO. retrieved: "
 
1453
                            << parameterList.value(1);
1305
1454
                    }
1306
 
                }
1307
 
                else
1308
 
                {
1309
 
                    kDebug() << "RPL_ENDOFWHO: unexpected ENDOFWHO. retrieved: "
1310
 
                        << parameterList.value(1);
1311
 
                }
1312
1455
 
1313
 
                emit endOfWho(parameterList.value(1));
 
1456
                    emit endOfWho(parameterList.value(1));
 
1457
                }
1314
1458
                break;
1315
1459
            }
1316
1460
            case RPL_WHOISCHANNELS:
1317
1461
            {
1318
 
                QStringList userChannels,voiceChannels,opChannels,halfopChannels,ownerChannels,adminChannels;
1319
 
 
1320
 
                // get a list of all channels the user is in
1321
 
                QStringList channelList=trailing.split(' ', QString::SkipEmptyParts);
1322
 
                channelList.sort();
1323
 
 
1324
 
                // split up the list in channels where they are operator / user / voice
1325
 
                for(int index=0; index < channelList.count(); index++)
1326
 
                {
1327
 
                    QString lookChannel=channelList[index];
1328
 
                    if(lookChannel.startsWith('*') || lookChannel.startsWith('&'))
1329
 
                    {
1330
 
                        adminChannels.append(lookChannel.mid(1));
1331
 
                        server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 16);
1332
 
                    }
1333
 
                                                  // See bug #97354 part 2
1334
 
                    else if((lookChannel.startsWith("!") || lookChannel.startsWith("~")) && server->isAChannel(lookChannel.mid(1)))
1335
 
                    {
1336
 
                        ownerChannels.append(lookChannel.mid(1));
1337
 
                        server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 8);
1338
 
                    }
1339
 
                                                  // See bug #97354 part 1
1340
 
                    else if(lookChannel.startsWith("@+"))
1341
 
                    {
1342
 
                        opChannels.append(lookChannel.mid(2));
1343
 
                        server->setChannelNick(lookChannel.mid(2), parameterList.value(1), 4);
1344
 
                    }
1345
 
                    else if(lookChannel.startsWith("@"))
1346
 
                    {
1347
 
                        opChannels.append(lookChannel.mid(1));
1348
 
                        server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 4);
1349
 
                    }
1350
 
                    else if(lookChannel.startsWith("%"))
1351
 
                    {
1352
 
                        halfopChannels.append(lookChannel.mid(1));
1353
 
                        server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 2);
1354
 
                    }
1355
 
                    else if(lookChannel.startsWith("+"))
1356
 
                    {
1357
 
                        voiceChannels.append(lookChannel.mid(1));
1358
 
                        server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 1);
1359
 
                    }
1360
 
                    else
1361
 
                    {
1362
 
                        userChannels.append(lookChannel);
1363
 
                        server->setChannelNick(lookChannel, parameterList.value(1), 0);
1364
 
                    }
1365
 
                }                                 // endfor
1366
 
                // Display message only if this was not an automatic request.
1367
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1368
 
                {
1369
 
                    if(userChannels.count())
1370
 
                    {
1371
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1372
 
                            i18n("%1 is a user on channels: %2",
1373
 
                                 parameterList.value(1),
1374
 
                                 userChannels.join(" "))
1375
 
                            );
1376
 
                    }
1377
 
                    if(voiceChannels.count())
1378
 
                    {
1379
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1380
 
                            i18n("%1 has voice on channels: %2",
1381
 
                                 parameterList.value(1), voiceChannels.join(" "))
1382
 
                            );
1383
 
                    }
1384
 
                    if(halfopChannels.count())
1385
 
                    {
1386
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1387
 
                            i18n("%1 is a halfop on channels: %2",
1388
 
                                 parameterList.value(1), halfopChannels.join(" "))
1389
 
                            );
1390
 
                    }
1391
 
                    if(opChannels.count())
1392
 
                    {
1393
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1394
 
                            i18n("%1 is an operator on channels: %2",
1395
 
                                 parameterList.value(1), opChannels.join(" "))
1396
 
                            );
1397
 
                    }
1398
 
                    if(ownerChannels.count())
1399
 
                    {
1400
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1401
 
                            i18n("%1 is owner of channels: %2",
1402
 
                                 parameterList.value(1), ownerChannels.join(" "))
1403
 
                            );
1404
 
                    }
1405
 
                    if(adminChannels.count())
1406
 
                    {
1407
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1408
 
                            i18n("%1 is admin on channels: %2",
1409
 
                                 parameterList.value(1), adminChannels.join(" "))
1410
 
                            );
 
1462
                if (plHas(3))
 
1463
                {
 
1464
                    QStringList userChannels,voiceChannels,opChannels,halfopChannels,ownerChannels,adminChannels;
 
1465
 
 
1466
                    // get a list of all channels the user is in
 
1467
                    QStringList channelList=trailing.split(' ', QString::SkipEmptyParts);
 
1468
                    channelList.sort();
 
1469
 
 
1470
                    // split up the list in channels where they are operator / user / voice
 
1471
                    for (int index=0; index < channelList.count(); index++)
 
1472
                    {
 
1473
                        QString lookChannel=channelList[index];
 
1474
                        if (lookChannel.startsWith('*') || lookChannel.startsWith('&'))
 
1475
                        {
 
1476
                            adminChannels.append(lookChannel.mid(1));
 
1477
                            server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 16);
 
1478
                        }
 
1479
                                                    // See bug #97354 part 2
 
1480
                        else if((lookChannel.startsWith('!') || lookChannel.startsWith('~')) && server->isAChannel(lookChannel.mid(1)))
 
1481
                        {
 
1482
                            ownerChannels.append(lookChannel.mid(1));
 
1483
                            server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 8);
 
1484
                        }
 
1485
                                                    // See bug #97354 part 1
 
1486
                        else if (lookChannel.startsWith("@+"))
 
1487
                        {
 
1488
                            opChannels.append(lookChannel.mid(2));
 
1489
                            server->setChannelNick(lookChannel.mid(2), parameterList.value(1), 4);
 
1490
                        }
 
1491
                        else if (lookChannel.startsWith('@'))
 
1492
                        {
 
1493
                            opChannels.append(lookChannel.mid(1));
 
1494
                            server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 4);
 
1495
                        }
 
1496
                        else if (lookChannel.startsWith('%'))
 
1497
                        {
 
1498
                            halfopChannels.append(lookChannel.mid(1));
 
1499
                            server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 2);
 
1500
                        }
 
1501
                        else if (lookChannel.startsWith('+'))
 
1502
                        {
 
1503
                            voiceChannels.append(lookChannel.mid(1));
 
1504
                            server->setChannelNick(lookChannel.mid(1), parameterList.value(1), 1);
 
1505
                        }
 
1506
                        else
 
1507
                        {
 
1508
                            userChannels.append(lookChannel);
 
1509
                            server->setChannelNick(lookChannel, parameterList.value(1), 0);
 
1510
                        }
 
1511
                    }                                 // endfor
 
1512
                    // Display message only if this was not an automatic request.
 
1513
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1514
                    {
 
1515
                        if (userChannels.count())
 
1516
                        {
 
1517
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1518
                                i18n("%1 is a user on channels: %2",
 
1519
                                    parameterList.value(1),
 
1520
                                    userChannels.join(" "))
 
1521
                                );
 
1522
                        }
 
1523
                        if (voiceChannels.count())
 
1524
                        {
 
1525
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1526
                                i18n("%1 has voice on channels: %2",
 
1527
                                    parameterList.value(1), voiceChannels.join(" "))
 
1528
                                );
 
1529
                        }
 
1530
                        if (halfopChannels.count())
 
1531
                        {
 
1532
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1533
                                i18n("%1 is a halfop on channels: %2",
 
1534
                                    parameterList.value(1), halfopChannels.join(" "))
 
1535
                                );
 
1536
                        }
 
1537
                        if (opChannels.count())
 
1538
                        {
 
1539
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1540
                                i18n("%1 is an operator on channels: %2",
 
1541
                                    parameterList.value(1), opChannels.join(" "))
 
1542
                                );
 
1543
                        }
 
1544
                        if (ownerChannels.count())
 
1545
                        {
 
1546
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1547
                                i18n("%1 is owner of channels: %2",
 
1548
                                    parameterList.value(1), ownerChannels.join(" "))
 
1549
                                );
 
1550
                        }
 
1551
                        if (adminChannels.count())
 
1552
                        {
 
1553
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1554
                                i18n("%1 is admin on channels: %2",
 
1555
                                    parameterList.value(1), adminChannels.join(" "))
 
1556
                                );
 
1557
                        }
1411
1558
                    }
1412
1559
                }
1413
1560
                break;
1414
1561
            }
1415
1562
            case RPL_WHOISSERVER:
1416
1563
            {
1417
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1418
 
                if(nickInfo)
1419
 
                {
1420
 
                    nickInfo->setNetServer(parameterList.value(2));
1421
 
                    nickInfo->setNetServerInfo(trailing);
1422
 
                    // Clear the away state on assumption that if nick is away, this message will be followed
1423
 
                    // by a 301 RPL_AWAY message.  Not necessary a invalid assumption, but what can we do?
1424
 
                    nickInfo->setAway(false);
1425
 
                    nickInfo->setAwayMessage(QString());
1426
 
                }
1427
 
                // Display message only if this was not an automatic request.
1428
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1429
 
                {
1430
 
                    server->appendMessageToFrontmost(i18n("Whois"),
1431
 
                        i18n("%1 is online via %2 (%3).",parameterList.value(1),
1432
 
                        parameterList.value(2),trailing)
1433
 
                        );
 
1564
                if (plHas(4))
 
1565
                {
 
1566
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
 
1567
                    if (nickInfo)
 
1568
                    {
 
1569
                        nickInfo->setNetServer(parameterList.value(2));
 
1570
                        nickInfo->setNetServerInfo(trailing);
 
1571
                        // Clear the away state on assumption that if nick is away, this message will be followed
 
1572
                        // by a 301 RPL_AWAY message.  Not necessary a invalid assumption, but what can we do?
 
1573
                        nickInfo->setAway(false);
 
1574
                        nickInfo->setAwayMessage(QString());
 
1575
                    }
 
1576
                    // Display message only if this was not an automatic request.
 
1577
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1578
                    {
 
1579
                        server->appendMessageToFrontmost(i18n("Whois"),
 
1580
                            i18n("%1 is online via %2 (%3).", parameterList.value(1),
 
1581
                                parameterList.value(2), trailing)
 
1582
                            );
 
1583
                    }
1434
1584
                }
1435
1585
                break;
1436
1586
            }
1437
1587
            case RPL_WHOISHELPER:
1438
1588
            {
1439
 
                // Display message only if this was not an automatic request.
1440
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
1589
                if (plHas(2))
1441
1590
                {
1442
 
                    server->appendMessageToFrontmost(i18n("Whois"),
1443
 
                        i18n("%1 is available for help.",
1444
 
                             parameterList.value(1))
1445
 
                        );
 
1591
                    // Display message only if this was not an automatic request.
 
1592
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1593
                    {
 
1594
                        server->appendMessageToFrontmost(i18n("Whois"),
 
1595
                            i18n("%1 is available for help.",
 
1596
                                parameterList.value(1))
 
1597
                            );
 
1598
                    }
1446
1599
                }
1447
1600
                break;
1448
1601
            }
1449
1602
            case RPL_WHOISOPERATOR:
1450
1603
            {
1451
 
                // Display message only if this was not an automatic request.
1452
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
1604
                if (plHas(2))
1453
1605
                {
1454
 
                    if (trailing.toLower().simplified().startsWith("is an irc operator"))
1455
 
                        server->appendMessageToFrontmost(i18n("Whois"),i18n("%1 is an IRC Operator.", parameterList.value(1)));
1456
 
                    else
1457
 
                        server->appendMessageToFrontmost(i18n("Whois"),QString("%1 %2").arg(parameterList.value(1)).arg(trailing));
 
1606
                    // Display message only if this was not an automatic request.
 
1607
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1608
                    {
 
1609
                        if (trailing.toLower().simplified().startsWith("is an irc operator"))
 
1610
                            server->appendMessageToFrontmost(i18n("Whois"), i18n("%1 is an IRC Operator.", parameterList.value(1)));
 
1611
                        else
 
1612
                            server->appendMessageToFrontmost(i18n("Whois"),QString("%1 %2").arg(parameterList.value(1)).arg(trailing));
 
1613
                    }
1458
1614
                }
1459
1615
                break;
1460
1616
            }
1461
1617
            case RPL_WHOISIDLE:
1462
1618
            {
1463
 
                // get idle time in seconds
1464
 
                long seconds=parameterList.value(2).toLong();
1465
 
                long minutes=seconds/60;
1466
 
                long hours  =minutes/60;
1467
 
                long days   =hours/24;
1468
 
 
1469
 
                // if idle time is longer than a day
1470
 
                // Display message only if this was not an automatic request.
1471
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
 
1619
                if (plHas(3))
1472
1620
                {
1473
 
                    if(days)
1474
 
                    {
1475
 
                        const QString daysString = i18np("1 day", "%1 days", days);
1476
 
                        const QString hoursString = i18np("1 hour", "%1 hours", (hours % 24));
1477
 
                        const QString minutesString = i18np("1 minute", "%1 minutes", (minutes % 60));
1478
 
                        const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
1479
 
 
1480
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1481
 
                            i18nc("%1 = name of person, %2 = (x days), %3 = (x hours), %4 = (x minutes), %5 = (x seconds)",
1482
 
                            "%1 has been idle for %2, %3, %4, and %5.",
1483
 
                            parameterList.value(1),
1484
 
                            daysString, hoursString, minutesString, secondsString)
1485
 
                            );
1486
 
                        // or longer than an hour
1487
 
                    }
1488
 
                    else if(hours)
1489
 
                    {
 
1621
                    // get idle time in seconds
 
1622
                    long seconds = parameterList.value(2).toLong();
 
1623
                    long minutes = seconds/60;
 
1624
                    long hours   = minutes/60;
 
1625
                    long days    = hours/24;
 
1626
 
 
1627
                    // if idle time is longer than a day
 
1628
                    // Display message only if this was not an automatic request.
 
1629
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1630
                    {
 
1631
                        if (days)
 
1632
                        {
 
1633
                            const QString daysString = i18np("1 day", "%1 days", days);
 
1634
                            const QString hoursString = i18np("1 hour", "%1 hours", (hours % 24));
 
1635
                            const QString minutesString = i18np("1 minute", "%1 minutes", (minutes % 60));
 
1636
                            const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
 
1637
 
 
1638
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1639
                                i18nc("%1 = name of person, %2 = (x days), %3 = (x hours), %4 = (x minutes), %5 = (x seconds)",
 
1640
                                    "%1 has been idle for %2, %3, %4, and %5.",
 
1641
                                    parameterList.value(1),
 
1642
                                    daysString, hoursString, minutesString, secondsString)
 
1643
                                );
 
1644
                            // or longer than an hour
 
1645
                        }
 
1646
                        else if (hours)
 
1647
                        {
1490
1648
                        const QString hoursString = i18np("1 hour", "%1 hours", hours);
1491
 
                        const QString minutesString = i18np("1 minute", "%1 minutes", (minutes % 60));
1492
 
                        const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
1493
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1494
 
                            i18nc("%1 = name of person, %2 = (x hours), %3 = (x minutes), %4 = (x seconds)",
1495
 
                            "%1 has been idle for %2, %3, and %4.", parameterList.value(1), hoursString, minutesString, secondsString)
1496
 
                            );
1497
 
                        // or longer than a minute
1498
 
                    }
1499
 
                    else if(minutes)
1500
 
                    {
1501
 
                        const QString minutesString = i18np("1 minute", "%1 minutes", minutes);
1502
 
                        const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
1503
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1504
 
                            i18nc("%1 = name of person, %2 = (x minutes), %3 = (x seconds)",
1505
 
                            "%1 has been idle for %2 and %3.", parameterList.value(1), minutesString, secondsString)
1506
 
                            );
1507
 
                        // or just some seconds
1508
 
                    }
1509
 
                    else
1510
 
                    {
1511
 
                        server->appendMessageToFrontmost(i18n("Whois"),
 
1649
                            const QString minutesString = i18np("1 minute", "%1 minutes", (minutes % 60));
 
1650
                            const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
 
1651
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1652
                                i18nc("%1 = name of person, %2 = (x hours), %3 = (x minutes), %4 = (x seconds)",
 
1653
                                    "%1 has been idle for %2, %3, and %4.", parameterList.value(1), hoursString,
 
1654
                                    minutesString, secondsString)
 
1655
                                );
 
1656
                            // or longer than a minute
 
1657
                        }
 
1658
                        else if (minutes)
 
1659
                        {
 
1660
                            const QString minutesString = i18np("1 minute", "%1 minutes", minutes);
 
1661
                            const QString secondsString = i18np("1 second", "%1 seconds", (seconds % 60));
 
1662
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1663
                                i18nc("%1 = name of person, %2 = (x minutes), %3 = (x seconds)",
 
1664
                                    "%1 has been idle for %2 and %3.", parameterList.value(1), minutesString, secondsString)
 
1665
                                );
 
1666
                            // or just some seconds
 
1667
                        }
 
1668
                        else
 
1669
                        {
 
1670
                            server->appendMessageToFrontmost(i18n("Whois"),
1512
1671
                            i18np("%1 has been idle for 1 second.", "%1 has been idle for %2 seconds.", parameterList.value(1), seconds)
1513
 
                            );
 
1672
                                );
 
1673
                        }
1514
1674
                    }
1515
 
                }
1516
1675
 
1517
 
                if(parameterList.count()==4)
1518
 
                {
1519
 
                    QDateTime when;
1520
 
                    when.setTime_t(parameterList.value(3).toUInt());
1521
 
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1522
 
                    if(nickInfo)
1523
 
                    {
1524
 
                        nickInfo->setOnlineSince(when);
1525
 
                    }
1526
 
                    // Display message only if this was not an automatic request.
1527
 
                    if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1528
 
                    {
1529
 
                        server->appendMessageToFrontmost(i18n("Whois"),
1530
 
                            i18n("%1 has been online since %2.",
1531
 
                                 parameterList.value(1), when.toString(Qt::LocalDate))
1532
 
                            );
 
1676
                    // FIXME this one will fail if we pop the nick off
 
1677
                    if (parameterList.count()==4)
 
1678
                    {
 
1679
                        QDateTime when;
 
1680
                        when.setTime_t(parameterList.value(3).toUInt());
 
1681
                        NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
 
1682
                        if (nickInfo)
 
1683
                        {
 
1684
                            nickInfo->setOnlineSince(when);
 
1685
                        }
 
1686
                        // Display message only if this was not an automatic request.
 
1687
                        if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1688
                        {
 
1689
                            server->appendMessageToFrontmost(i18n("Whois"),
 
1690
                                i18n("%1 has been online since %2.",
 
1691
                                    parameterList.value(1), when.toString(Qt::LocalDate))
 
1692
                                );
 
1693
                        }
1533
1694
                    }
1534
1695
                }
1535
1696
                break;
1536
1697
            }
1537
1698
            case RPL_ENDOFWHOIS:
1538
1699
            {
 
1700
                if (plHas(2))
 
1701
                {
 
1702
                    /*FIXME why is the nickinfo line below commented out?
1539
1703
                //NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(1));
1540
 
                // Display message only if this was not an automatic request.
1541
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))==0)
1542
 
                {
1543
 
                    server->appendMessageToFrontmost(i18n("Whois"),i18n("End of WHOIS list."));
1544
 
                }
1545
 
                // was this an automatic request?
1546
 
                if(getAutomaticRequest("WHOIS",parameterList.value(1))!=0)
1547
 
                {
1548
 
                    setAutomaticRequest("WHOIS",parameterList.value(1),false);
 
1704
                    */
 
1705
                    // Display message only if this was not an automatic request.
 
1706
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
 
1707
                    {
 
1708
                        server->appendMessageToFrontmost(i18n("Whois"),i18n("End of WHOIS list."));
 
1709
                    }
 
1710
                    // was this an automatic request?
 
1711
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) != 0)
 
1712
                    {
 
1713
                        setAutomaticRequest("WHOIS", parameterList.value(1), false);
 
1714
                    }
1549
1715
                }
1550
1716
                break;
1551
1717
            }
1552
1718
            case RPL_USERHOST:
1553
1719
            {
1554
 
                // iterate over all nick/masks in reply
1555
 
                QStringList uhosts=trailing.split(' ', QString::SkipEmptyParts);
1556
 
 
1557
 
                for(int index=0;index<uhosts.count();index++)
 
1720
                if (plHas(2))
1558
1721
                {
1559
 
                    // extract nickname and hostmask from reply
1560
 
                    QString nick(uhosts[index].section('=',0,0));
1561
 
                    QString mask(uhosts[index].section('=',1));
1562
 
 
1563
 
                    // get away and IRC operator flags
1564
 
                    bool away=(mask[0]=='-');
1565
 
                    bool ircOp=(nick[nick.length()-1]=='*');
1566
 
 
1567
 
                    // cut flags from nick/hostmask
1568
 
                    mask=mask.mid(1);
1569
 
                    if(ircOp)
1570
 
                    {
1571
 
                        nick=nick.left(nick.length()-1);
1572
 
                    }
1573
 
 
1574
 
                    // inform server of this user's data
1575
 
                    emit userhost(nick,mask,away,ircOp);
1576
 
 
1577
 
                    // display message only if this was no automatic request
1578
 
                    if(getAutomaticRequest("USERHOST",nick)==0)
1579
 
                    {
1580
 
                        server->appendMessageToFrontmost(i18n("Userhost"),
1581
 
                            i18nc("%1 = nick, %2 = shows if nick is op, %3 = hostmask, %4 = shows away", "%1%2 is %3%4.",
1582
 
                            nick,
1583
 
                            (ircOp) ? i18n(" (IRC Operator)") : QString()
1584
 
                            ,mask,
1585
 
                            (away) ? i18n(" (away)") : QString()));
1586
 
                    }
1587
 
 
1588
 
                    // was this an automatic request?
1589
 
                    if(getAutomaticRequest("USERHOST",nick)!=0)
1590
 
                    {
1591
 
                        setAutomaticRequest("USERHOST",nick,false);
1592
 
                    }
1593
 
                }                                 // for
 
1722
                    // iterate over all nick/masks in reply
 
1723
                    QStringList uhosts=trailing.split(' ', QString::SkipEmptyParts);
 
1724
 
 
1725
                    for (int index=0;index<uhosts.count();index++)
 
1726
                    {
 
1727
                        // extract nickname and hostmask from reply
 
1728
                        QString nick(uhosts[index].section('=',0,0));
 
1729
                        QString mask(uhosts[index].section('=',1));
 
1730
 
 
1731
                        // get away and IRC operator flags
 
1732
                        bool away=(mask[0]=='-');
 
1733
                        bool ircOp=(nick[nick.length()-1]=='*');
 
1734
 
 
1735
                        // cut flags from nick/hostmask
 
1736
                        mask=mask.mid(1);
 
1737
                        if (ircOp)
 
1738
                        {
 
1739
                            nick=nick.left(nick.length()-1);
 
1740
                        }
 
1741
 
 
1742
                        // inform server of this user's data
 
1743
                        emit userhost(nick,mask,away,ircOp);
 
1744
 
 
1745
                        // display message only if this was no automatic request
 
1746
                        if (getAutomaticRequest("USERHOST",nick)==0)
 
1747
                        {
 
1748
                            server->appendMessageToFrontmost(i18n("Userhost"),
 
1749
                                i18nc("%1 = nick, %2 = shows if nick is op, %3 = hostmask, %4 = shows away", "%1%2 is %3%4.",
 
1750
                                nick,
 
1751
                                (ircOp) ? i18n(" (IRC Operator)") : QString()
 
1752
                                ,mask,
 
1753
                                (away) ? i18n(" (away)") : QString()));
 
1754
                        }
 
1755
 
 
1756
                        // was this an automatic request?
 
1757
                        if (getAutomaticRequest("USERHOST",nick)!=0)
 
1758
                        {
 
1759
                            setAutomaticRequest("USERHOST",nick,false);
 
1760
                        }
 
1761
                    }                                 // for
 
1762
                }
1594
1763
                break;
1595
1764
            }
1596
1765
            case RPL_LISTSTART:                   //FIXME This reply is obsolete!!!
1597
1766
            {
1598
 
                if(getAutomaticRequest("LIST",QString())==0)
 
1767
                if (plHas(0))
1599
1768
                {
1600
 
                    server->appendMessageToFrontmost(i18n("List"),i18n("List of channels:"));
 
1769
                    if (getAutomaticRequest("LIST",QString())==0)
 
1770
                    {
 
1771
                        server->appendMessageToFrontmost(i18n("List"),i18n("List of channels:"));
 
1772
                    }
1601
1773
                }
1602
1774
                break;
1603
1775
            }
1604
1776
            case RPL_LIST:
1605
1777
            {
1606
 
                if(getAutomaticRequest("LIST",QString())==0)
1607
 
                {
1608
 
                    QString message;
1609
 
                    message=i18np("%2 (%1 user): %3", "%2 (%1 users): %3", parameterList.value(2).toInt(), parameterList.value(1), trailing);
1610
 
                    server->appendMessageToFrontmost(i18n("List"),message);
1611
 
                }
1612
 
                else                              // send them to /LIST window
1613
 
                {
1614
 
                    emit addToChannelList(parameterList.value(1),parameterList.value(2).toInt(),trailing);
1615
 
                }
1616
 
 
 
1778
                if (plHas(3))
 
1779
                {
 
1780
                    if (getAutomaticRequest("LIST",QString())==0)
 
1781
                    {
 
1782
                        QString message;
 
1783
                        message=i18np("%2 (%1 user): %3", "%2 (%1 users): %3", parameterList.value(2).toInt(), parameterList.value(1), trailing);
 
1784
                        server->appendMessageToFrontmost(i18n("List"),message);
 
1785
                    }
 
1786
                    else                              // send them to /LIST window
 
1787
                    {
 
1788
                        emit addToChannelList(parameterList.value(1), parameterList.value(2).toInt(), trailing);
 
1789
                    }
 
1790
                }
1617
1791
                break;
1618
1792
            }
1619
1793
            case RPL_LISTEND:
1620
1794
            {
1621
 
                // was this an automatic request?
1622
 
                if(getAutomaticRequest("LIST",QString())==0)
1623
 
                {
1624
 
                    server->appendMessageToFrontmost(i18n("List"),i18n("End of channel list."));
1625
 
                }
1626
 
                else
1627
 
                {
1628
 
                    setAutomaticRequest("LIST",QString(),false);
 
1795
                if (plHas(0))
 
1796
                {
 
1797
                    // was this an automatic request?
 
1798
                    if (getAutomaticRequest("LIST",QString())==0)
 
1799
                    {
 
1800
                        server->appendMessageToFrontmost(i18n("List"),i18n("End of channel list."));
 
1801
                    }
 
1802
                    else
 
1803
                    {
 
1804
                        setAutomaticRequest("LIST",QString(),false);
 
1805
                    }
1629
1806
                }
1630
1807
                break;
1631
1808
            }
1632
1809
            case RPL_NOWAWAY:
1633
1810
            {
1634
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(0));
1635
 
                if (nickInfo) nickInfo->setAway(true);
1636
 
 
1637
 
                server->setAway(true);
1638
 
 
 
1811
                if (plHas(1))
 
1812
                {
 
1813
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(0));
 
1814
                    if (nickInfo)
 
1815
                    {
 
1816
                        nickInfo->setAway(true);
 
1817
                    }
 
1818
 
 
1819
                    server->setAway(true);
 
1820
                }
1639
1821
                break;
1640
1822
            }
1641
1823
            case RPL_UNAWAY:
1642
1824
            {
1643
 
                NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(0));
1644
 
 
1645
 
                if (nickInfo)
 
1825
                if (plHas(1))
1646
1826
                {
1647
 
                    nickInfo->setAway(false);
1648
 
                    nickInfo->setAwayMessage(QString());
 
1827
                    NickInfoPtr nickInfo = server->getNickInfo(parameterList.value(0));
 
1828
 
 
1829
                    if (nickInfo)
 
1830
                    {
 
1831
                        nickInfo->setAway(false);
 
1832
                        nickInfo->setAwayMessage(QString());
 
1833
                    }
 
1834
 
 
1835
                    server->setAway(false);
1649
1836
                }
1650
 
 
1651
 
                server->setAway(false);
1652
 
 
1653
1837
                break;
1654
1838
            }
1655
1839
            case RPL_BANLIST:
1656
1840
            {
1657
 
                if (getAutomaticRequest("BANLIST", parameterList.value(1)))
 
1841
                if (plHas(5))
1658
1842
                {
1659
 
                    server->addBan(parameterList.value(1), parameterList.join(" ").section(' ', 2, 4));
1660
 
                } else {
1661
 
                    QDateTime when;
1662
 
                    when.setTime_t(parameterList.value(4).toUInt());
 
1843
                    if (getAutomaticRequest("BANLIST", parameterList.value(1)))
 
1844
                    {
 
1845
                        server->addBan(parameterList.value(1), parameterList.join(" ").section(' ', 2, 4));
 
1846
                    }
 
1847
                    else
 
1848
                    {
 
1849
                        QDateTime when;
 
1850
                        when.setTime_t(parameterList.value(4).toUInt());
1663
1851
 
1664
 
                    server->appendMessageToFrontmost(i18n("BanList:%1", parameterList.value(1)), i18nc("BanList message: e.g. *!*@aol.com set by MrGrim on <date>", "%1 set by %2 on %3", parameterList.value(2), parameterList.value(3).section('!', 0, 0), when.toString(Qt::LocalDate)));
 
1852
                        server->appendMessageToFrontmost(i18n("BanList:%1", parameterList.value(1)),
 
1853
                                    i18nc("BanList message: e.g. *!*@aol.com set by MrGrim on <date>", "%1 set by %2 on %3",
 
1854
                                        parameterList.value(2), parameterList.value(3).section('!', 0, 0), when.toString(Qt::LocalDate))
 
1855
                                    );
 
1856
                    }
1665
1857
                }
1666
1858
                break;
1667
1859
            }
1668
1860
            case RPL_ENDOFBANLIST:
1669
1861
            {
1670
 
                if (getAutomaticRequest("BANLIST", parameterList.value(1)))
 
1862
                if (plHas(2))
1671
1863
                {
1672
 
                    setAutomaticRequest("BANLIST", parameterList.value(1), false);
1673
 
                } else {
1674
 
                    server->appendMessageToFrontmost(i18n("BanList:%1", parameterList.value(1)), i18n("End of Ban List."));
 
1864
                    if (getAutomaticRequest("BANLIST", parameterList.value(1)))
 
1865
                    {
 
1866
                        setAutomaticRequest("BANLIST", parameterList.value(1), false);
 
1867
                    }
 
1868
                    else
 
1869
                    {
 
1870
                        server->appendMessageToFrontmost(i18n("BanList:%1", parameterList.value(1)), i18n("End of Ban List."));
 
1871
                    }
1675
1872
                }
1676
1873
                break;
1677
1874
            }
1678
1875
            case ERR_NOCHANMODES:
1679
1876
            {
1680
 
                ChatWindow *chatwindow = server->getChannelByName(parameterList.value(1));
1681
 
                if(chatwindow)
1682
 
                {
1683
 
                    chatwindow->appendServerMessage(i18n("Channel"), trailing);
1684
 
                }
1685
 
                else                              // We couldn't join the channel , so print the error. with [#channel] : <Error Message>
1686
 
                {
1687
 
                    server->appendMessageToFrontmost(i18n("Channel"), trailing);
 
1877
                if (plHas(3))
 
1878
                {
 
1879
                    ChatWindow *chatwindow = server->getChannelByName(parameterList.value(1));
 
1880
                    if (chatwindow)
 
1881
                    {
 
1882
                        chatwindow->appendServerMessage(i18n("Channel"), trailing);
 
1883
                    }
 
1884
                    else // We couldn't join the channel , so print the error. with [#channel] : <Error Message>
 
1885
                    {
 
1886
                        server->appendMessageToFrontmost(i18n("Channel"), trailing);
 
1887
                    }
1688
1888
                }
1689
1889
                break;
1690
1890
            }
1691
1891
            case ERR_NOSUCHSERVER:
1692
1892
            {
1693
 
                //Some servers don't know their name, so they return an error instead of the PING data
1694
 
                if (getLagMeasuring() && trailing.startsWith(prefix))
 
1893
                if (plHas(2))
1695
1894
                {
1696
 
                    server->pongReceived();
 
1895
                    //Some servers don't know their name, so they return an error instead of the PING data
 
1896
                    if (getLagMeasuring() && trailing.startsWith(prefix))
 
1897
                    {
 
1898
                        server->pongReceived();
 
1899
                    }
1697
1900
                }
1698
1901
                break;
1699
1902
            }
1700
1903
            case ERR_UNAVAILRESOURCE:
1701
1904
            {
1702
 
                server->appendMessageToFrontmost(i18n("Error"),i18n("%1 is currently unavailable.", parameterList.value(1)));
1703
 
 
 
1905
                if (plHas(2))
 
1906
                {
 
1907
                    server->appendMessageToFrontmost(i18n("Error"), i18n("%1 is currently unavailable.", parameterList.value(1)));
 
1908
                }
1704
1909
                break;
1705
1910
            }
1706
1911
            case RPL_HIGHCONNECTCOUNT:
1709
1914
            case RPL_LUSERUNKNOWN:
1710
1915
            case RPL_LUSERCHANNELS:
1711
1916
            case RPL_LUSERME:
1712
 
            {
1713
 
                server->appendStatusMessage(i18n("Users"), parameterList.join(" ").section(' ',1) + ' '+trailing);
 
1917
            { // TODO make sure this works, i amputated the "+ ' '+trailing"
 
1918
                if (plHas(0))
 
1919
                {
 
1920
                    server->appendStatusMessage(i18n("Users"), parameterList.join(" ").section(' ',1));
 
1921
                }
1714
1922
                break;
1715
1923
            }
1716
1924
            case ERR_UNKNOWNCOMMAND:
1717
1925
            {
1718
 
                server->appendMessageToFrontmost(i18n("Error"),i18n("%1: Unknown command.", parameterList.value(1)));
1719
 
 
 
1926
                if (plHas(2))
 
1927
                {
 
1928
                    server->appendMessageToFrontmost(i18n("Error"), i18n("%1: Unknown command.", parameterList.value(1)));
 
1929
                }
1720
1930
                break;
1721
1931
            }
1722
1932
            case ERR_NOTREGISTERED:
1723
1933
            {
1724
 
                server->appendMessageToFrontmost(i18n("Error"),i18n("Not registered."));
1725
 
 
 
1934
                if (plHas(0))
 
1935
                {
 
1936
                    server->appendMessageToFrontmost(i18n("Error"),i18n("Not registered."));
 
1937
                }
1726
1938
                break;
1727
1939
            }
1728
1940
            case ERR_NEEDMOREPARAMS:
1729
1941
            {
1730
 
                server->appendMessageToFrontmost(i18n("Error"),i18n("%1: This command requires more parameters.", parameterList.value(1)));
1731
 
 
 
1942
                if (plHas(2))
 
1943
                {
 
1944
                    server->appendMessageToFrontmost(i18n("Error"),i18n("%1: This command requires more parameters.", parameterList.value(1)));
 
1945
                }
1732
1946
                break;
1733
1947
            }
1734
1948
            case RPL_CAPAB: // Special freenode reply afaik
1735
1949
            {
1736
 
                // Disable as we don't use this for anything yet
1737
 
                if(trailing.contains("IDENTIFY-MSG"))
 
1950
                if (plHas(2))
1738
1951
                {
1739
 
                    server->enableIdentifyMsg(true);
1740
 
                    break;
 
1952
                    // Disable as we don't use this for anything yet
 
1953
                    if (trailing.contains("IDENTIFY-MSG"))
 
1954
                    {
 
1955
                        server->enableIdentifyMsg(true);
 
1956
                    }
 
1957
                    else // TEST is this right? split the logic up in prep for slotization
 
1958
                    {
 
1959
                        server->appendMessageToFrontmost(command, parameterList.join(" ").section(' ',1) + ' '+trailing);
 
1960
                    }
1741
1961
                }
1742
 
 
1743
 
            /* don't break; - this is also used as RPL_DATASTR on ircu and some others */
 
1962
                break;
1744
1963
            }
1745
 
            // FALLTHROUGH to default to let the error display otherwise
1746
1964
            default:
1747
1965
            {
1748
1966
                // All yet unknown messages go into the frontmost window without the
1749
1967
                // preceding nickname
 
1968
                kDebug() << "unknown numeric" << parameterList.count() << _plHad << _plWanted << command << parameterList.join(" ");
1750
1969
                server->appendMessageToFrontmost(command, parameterList.join(" ").section(' ',1) + ' '+trailing);
1751
1970
            }
1752
 
        }                                         // end of numeric switch
 
1971
        } // end of numeric switch
 
1972
        if (!_plHad)
 
1973
            kDebug() << "numeric format error" << parameterList.count() << _plHad << _plWanted << command << parameterList.join(" ");
 
1974
    } // end of numeric elseif
 
1975
    else
 
1976
    {
 
1977
        kDebug() << "unknown message format" << parameterList.count() << _plHad << _plWanted << command << parameterList.join(" ");
1753
1978
    }
1754
 
}
 
1979
} // end of server
1755
1980
 
1756
1981
void InputFilter::parseModes(const QString &sourceNick, const QStringList &parameterList)
1757
1982
{
1763
1988
        if (parameterList.value(0) == server->getNickname())
1764
1989
        {
1765
1990
            if (sourceNick == server->getNickname())
1766
 
            {
1767
 
                //XXX someone might care about the potentially unnecessary plural here
 
1991
            { //XXX someone might care about the potentially unnecessary plural here
1768
1992
                message = i18n("You have set personal modes: ") + modestring;
1769
1993
            }
1770
1994
            else
1771
 
            {   //XXX someone might care about the potentially unnecessary plural here
 
1995
            { //XXX someone might care about the potentially unnecessary plural here
1772
1996
                message = QString("%1 %2 %3").arg(sourceNick).arg(i18n("has changed your personal modes:")).arg(modestring);
1773
1997
            }
1774
1998
        }
1782
2006
    // List of modes that need a parameter (note exception with -k and -l)
1783
2007
    // Mode q is quiet on freenode and acts like b... if this is a channel mode on other
1784
2008
    //  networks then more logic is needed here. --MrGrim
1785
 
    QString parameterModes="aAoOvhkbleIq";
 
2009
    QString parameterModes = "aAoOvhkbleIq";
1786
2010
    QString message = sourceNick + i18n(" sets mode: ") + modestring;
1787
2011
 
1788
 
    for(int index=0;index<modestring.length();index++)
 
2012
    for (int index=0;index<modestring.length();index++)
1789
2013
    {
1790
2014
        unsigned char mode(modestring[index].toAscii());
1791
2015
        QString parameter;
1792
2016
 
1793
2017
        // Check if this is a mode or a +/- qualifier
1794
 
        if(mode=='+' || mode=='-')
 
2018
        if (mode=='+' || mode=='-')
1795
2019
        {
1796
2020
            plus=(mode=='+');
1797
2021
        }
1798
2022
        else
1799
2023
        {
1800
2024
            // Check if this was a parameter mode
1801
 
            if(parameterModes.contains(mode))
 
2025
            if (parameterModes.contains(mode))
1802
2026
            {
1803
2027
                // Check if the mode actually wants a parameter. -k and -l do not!
1804
 
                if(plus || (!plus && (mode!='k') && (mode!='l')))
 
2028
                if (plus || (!plus && (mode!='k') && (mode!='l')))
1805
2029
                {
1806
2030
                    // Remember the mode parameter
1807
 
                    parameter=parameterList[2+parameterIndex];
 
2031
                    parameter = parameterList[2+parameterIndex];
1808
2032
                    message += ' ' + parameter;
1809
2033
                    // Switch to next parameter
1810
2034
                    ++parameterIndex;
1811
2035
                }
1812
2036
            }
1813
2037
            // Let the channel update its modes
1814
 
            if(parameter.isEmpty())               // XXX Check this to ensure the braces are in the correct place
 
2038
            if (parameter.isEmpty())               // XXX Check this to ensure the braces are in the correct place
1815
2039
            {
1816
2040
                kDebug()   << "in updateChannelMode.  sourceNick: '" << sourceNick << "'  parameterlist: '"
1817
2041
                    << parameterList.join(", ") << "'";
1818
2042
            }
1819
2043
            server->updateChannelMode(sourceNick,parameterList.value(0),mode,plus,parameter);
1820
2044
        }
1821
 
    }                                             // endfor
 
2045
    } // endfor
1822
2046
 
1823
2047
    if (Preferences::self()->useLiteralModes())
1824
2048
    {
1831
2055
// on their part - not ours. --Argonel
1832
2056
bool InputFilter::isAChannel(const QString &check)
1833
2057
{
 
2058
    if (check.isEmpty())
 
2059
        return false;
1834
2060
    Q_ASSERT(server);
1835
2061
    // if we ever see the assert, we need the ternary
1836
2062
    return server? server->isAChannel(check) : QString("#&").contains(check.at(0));
1882
2108
 
1883
2109
bool InputFilter::getLagMeasuring()           { return lagMeasuring; }
1884
2110
 
1885
 
void InputFilter::parsePrivMsg(const QString& prefix,
1886
 
                               const QStringList& parameterList,
1887
 
                               const QString& trailing)
 
2111
void InputFilter::parsePrivMsg(const QString& prefix, QStringList& parameterList)
1888
2112
{
1889
2113
    int pos = prefix.indexOf('!');
1890
2114
    QString source;