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

« back to all changes in this revision

Viewing changes to src/viewer/ircview.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:
110
110
    connect( this, SIGNAL( highlighted ( const QString &) ), this, SLOT( highlightedSlot( const QString &) ) );
111
111
    setOpenLinks(false);
112
112
    setUndoRedoEnabled(0);
113
 
    //setLinkUnderline(false);
114
113
    document()->setDefaultStyleSheet("a.nick:link {text-decoration: none}");
115
114
    setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
116
115
    //setNotifyClick(true); // TODO FIXME import the rest of the link handling
271
270
    QString nickLine = createNickLine(nick);
272
271
 
273
272
    QString line;
274
 
    line = "<p><font color=\"" + channelColor + "\">%1" + nickLine + " %3</font></p>\n";
 
273
    line = "<p><font color=\"" + channelColor + "\">%1" + nickLine + " %3</font></p>";
275
274
    line = line.arg(timeStamp(), nick, filter(message, channelColor, nick, true));
276
275
 
277
276
    emit textToLog(QString("<%1>\t%2").arg(nick).arg(message));
286
285
 
287
286
    QString line;
288
287
    if (suppressTimestamps)
289
 
        line = QString("<p><font color=\"" + channelColor.name() + "\">" + message + "</font></p>\n");
 
288
        line = QString("<p><font color=\"" + channelColor.name() + "\">" + message + "</font></p>");
290
289
    else
291
 
        line = QString("<p>" + timeStamp() + " <font color=\"" + channelColor.name() + "\">" + message + "</font></p>\n");
 
290
        line = QString("<p>" + timeStamp() + " <font color=\"" + channelColor.name() + "\">" + message + "</font></p>");
292
291
 
293
292
    doAppend(line, self);
294
293
}
295
294
 
 
295
void IRCView::appendLog(const QString & message)
 
296
{
 
297
    QColor channelColor = Preferences::self()->color(Preferences::ChannelMessage);
 
298
    m_tabNotification = Konversation::tnfNone;
 
299
 
 
300
    QString line("<p><font color=\"" + channelColor.name() + "\">" + message + "</font></p>");
 
301
 
 
302
    doRawAppend(line);
 
303
}
 
304
 
296
305
void IRCView::appendQuery(const QString& nick, const QString& message, bool inChannel)
297
306
{
298
307
    QString queryColor=Preferences::self()->color(Preferences::QueryMessage).name();
302
311
    QString nickLine = createNickLine(nick, true, inChannel);
303
312
 
304
313
    QString line;
305
 
    line = "<p><font color=\"" + queryColor + "\">%1 " + nickLine + " %3</font></p>\n";
 
314
    line = "<p><font color=\"" + queryColor + "\">%1 " + nickLine + " %3</font></p>";
306
315
    line = line.arg(timeStamp(), nick, filter(message, queryColor, nick, true));
307
316
 
308
317
    emit textToLog(QString("<%1>\t%2").arg(nick).arg(message));
329
338
    QString nickLine = createNickLine(nick, false);
330
339
 
331
340
    QString line;
332
 
    line = "<p><font color=\"" + actionColor + "\">%1 * " + nickLine + " %3</font></p>\n";
 
341
    line = "<p><font color=\"" + actionColor + "\">%1 * " + nickLine + " %3</font></p>";
333
342
    line = line.arg(timeStamp(), nick, filter(message, actionColor, nick, true));
334
343
 
335
344
    emit textToLog(QString("\t * %1 %2").arg(nick).arg(message));
351
360
    }
352
361
 
353
362
    QString line;
354
 
    line = "<p><font color=\"" + serverColor + "\"" + fixed + ">%1 <b>[</b>%2<b>]</b> %3</font></p>\n";
 
363
    line = "<p><font color=\"" + serverColor + "\"" + fixed + ">%1 <b>[</b>%2<b>]</b> %3</font></p>";
355
364
    if(type != i18n("Notify"))
356
365
        line = line.arg(timeStamp(), type, filter(message, serverColor, 0 , true, parseURL));
357
366
    else
384
393
    prefix=Qt::escape(prefix);
385
394
 
386
395
    QString line;
387
 
    line = "<p><font color=\"" + commandColor + "\">%1 %2 %3</font></p>\n";
 
396
    line = "<p><font color=\"" + commandColor + "\">%1 %2 %3</font></p>";
388
397
 
389
398
    line = line.arg(timeStamp(), prefix, filter(message, commandColor, 0, true, parseURL, self));
390
399
 
404
413
    time = nick.section(' ', 0, 4);
405
414
    nick = nick.section(' ', 5);
406
415
 
407
 
    if(!nick.isEmpty() && !nick.startsWith("<") && !nick.startsWith("*"))
 
416
    if(!nick.isEmpty() && !nick.startsWith('<') && !nick.startsWith('*'))
408
417
    {
409
418
        nick = '|' + nick + '|';
410
419
    }
411
420
 
412
421
    // Nicks are in "<nick>" format so replace the "<>"
413
 
    nick.replace("<","&lt;");
414
 
    nick.replace(">","&gt;");
 
422
    nick.replace('<',"&lt;");
 
423
    nick.replace('>',"&gt;");
415
424
 
416
425
    QString line;
417
426
 
418
 
    line = "<p><font color=\"" + backlogColor + "\">%1 %2 %3</font></p>\n";
 
427
    line = "<p><font color=\"" + backlogColor + "\">%1 %2 %3</font></p>";
419
428
    line = line.arg(time, nick, filter(message, backlogColor, NULL, false, false));
420
429
 
421
430
    doAppend(line);
423
432
 
424
433
void IRCView::doAppend(const QString& newLine, bool self)
425
434
{
426
 
    QString line(newLine);
427
 
 
428
435
    if (!self && m_chatWin)
429
436
        m_chatWin->activateTabNotification(m_tabNotification);
430
437
 
431
438
    int scrollMax = Preferences::self()->scrollbackMax();
432
 
    if (scrollMax != 0) {
 
439
    if (scrollMax != 0)
 
440
    {
433
441
        //don't remove lines if the user has scrolled up to read old lines
434
442
        bool atBottom = (verticalScrollBar()->value() == verticalScrollBar()->maximum());
435
443
        document()->setMaximumBlockCount(atBottom ? scrollMax : document()->maximumBlockCount() + 1);
436
444
        //setMaximumBlockCount(atBottom ? scrollMax : maximumBlockCount() + 1);
437
445
    }
438
446
 
439
 
    line.remove('\n'); // TODO why have newlines? we get <p>, so the \n are unnecessary...
440
 
 
441
 
    line.remove("<p>");//remove <p> for qtextbrowser
442
 
    KTextBrowser::append(line);
 
447
    doRawAppend(newLine);
443
448
 
444
449
    //appendHtml(line);
445
450
 
463
468
        emit clearStatusBarTempText();
464
469
}
465
470
 
 
471
void IRCView::doRawAppend(const QString& newLine)
 
472
{
 
473
    QString line(newLine);
 
474
 
 
475
    line.remove('\n'); // TODO why have newlines? we get <p>, so the \n are unnecessary...
 
476
    line.remove("<p>");//remove <p> for qtextbrowser
 
477
 
 
478
    KTextBrowser::append(line);
 
479
}
 
480
 
466
481
QString IRCView::timeStamp()
467
482
{
468
483
    if(Preferences::self()->timestamping())
562
577
 
563
578
    // TODO: Use QStyleSheet::escape() here
564
579
    // Replace all < with &lt;
565
 
    filteredLine.replace("<","\x0blt;");
 
580
    filteredLine.replace('<',"\x0blt;");
566
581
    // Replace all > with &gt;
567
 
    filteredLine.replace(">", "\x0bgt;");
 
582
    filteredLine.replace('>', "\x0bgt;");
568
583
 
569
584
    if(filteredLine.contains('\x07'))
570
585
    {
587
602
    {
588
603
        if(!allowColors)
589
604
        {
590
 
            colorString = QString();
 
605
            colorString.clear();
591
606
        }
592
607
        else
593
608
        {
619
634
        filteredLine+="</font>";
620
635
 
621
636
    // Replace all text decorations
622
 
    // TODO: \017 should reset all textt decorations to plain text
 
637
    // TODO: \017 should reset all text decorations to plain text
623
638
    replaceDecoration(filteredLine,'\x02','b');
624
639
    replaceDecoration(filteredLine,'\x09','i');
625
640
    replaceDecoration(filteredLine,'\x13','s');
721
736
                {
722
737
                  m_autoTextToSend.replace(QString("%%1").arg(capture),captures[capture]);
723
738
                }
724
 
                m_autoTextToSend.replace(QRegExp("%[0-9]"),QString());
 
739
                m_autoTextToSend.remove(QRegExp("%[0-9]"));
725
740
            }
726
741
        }
727
742
 
753
768
 
754
769
void IRCView::clearContextNick()
755
770
{
756
 
    m_currentNick = QString();
 
771
    m_currentNick.clear();
757
772
}
758
773
 
759
774
KMenu* IRCView::getPopup() const
877
892
// FIXME do we still care about newtab? looks like konqi has lots of config now..
878
893
void IRCView::openLink(const QString& url, bool)
879
894
{
880
 
    if (!url.isEmpty() && !url.startsWith("#"))
 
895
    QString link(url);
 
896
    // HACK Replace " " with %20 for channelnames, NOTE there can't be 2 channelnames in one link
 
897
    link = link.replace (" ", "%20");
 
898
 
 
899
    if (!link.isEmpty() && !link.startsWith('#'))
881
900
    {
882
 
        if (url.startsWith("irc://"))
 
901
        if (link.startsWith("irc://"))
883
902
        {
884
903
            KonversationApplication* konvApp = KonversationApplication::instance();
885
 
            konvApp->getConnectionManager()->connectTo(Konversation::SilentlyReuseConnection, url);
 
904
            konvApp->getConnectionManager()->connectTo(Konversation::SilentlyReuseConnection, link);
886
905
        }
887
 
        else if (!Preferences::self()->useCustomBrowser() || url.startsWith("mailto:"))
 
906
        else if (!Preferences::self()->useCustomBrowser() || link.startsWith("mailto:"))
888
907
        {
889
 
            if (url.startsWith("mailto:"))
890
 
                KToolInvocation::invokeMailer(KUrl(url));
 
908
            if (link.startsWith("mailto:"))
 
909
                KToolInvocation::invokeMailer(KUrl(link));
891
910
            else
892
 
                KToolInvocation::invokeBrowser(url);
 
911
                KToolInvocation::invokeBrowser(link);
893
912
        }
894
913
        else
895
914
        {
896
915
            QString cmd = Preferences::self()->webBrowserCmd();
897
 
            cmd.replace("%u", url);
 
916
            cmd.replace("%u", link);
898
917
            KProcess *proc = new KProcess;
899
918
            QStringList cmdAndArgs = KShell::splitArgs(cmd);
900
919
            *proc << cmdAndArgs;
907
926
        }
908
927
    }
909
928
    //FIXME: Don't do channel links in DCC Chats to begin with since they don't have a server.
910
 
    else if (url.startsWith("##") && m_server && m_server->isConnected())
 
929
    else if (link.startsWith("##") && m_server && m_server->isConnected())
911
930
    {
912
 
        QString channel(url);
 
931
        QString channel(link);
913
932
        channel.replace("##", "#");
914
933
        m_server->sendJoinCommand(channel);
915
934
    }
916
935
    //FIXME: Don't do user links in DCC Chats to begin with since they don't have a server.
917
 
    else if (url.startsWith("#") && m_server && m_server->isConnected())
 
936
    else if (link.startsWith('#') && m_server && m_server->isConnected())
918
937
    {
919
 
        QString recipient(url);
920
 
        recipient.remove("#");
 
938
        QString recipient(link);
 
939
        recipient.remove('#');
921
940
        NickInfoPtr nickInfo = m_server->obtainNickInfo(recipient);
922
941
        m_server->addQuery(nickInfo, true /*we initiated*/);
923
942
    }
940
959
void IRCView::highlightedSlot(const QString& _link)
941
960
{
942
961
    QString link = _link;
943
 
    // HACK Replace % with \x03 in the url to keep Qt from doing stupid things
944
 
    link = link.replace ('\x03', "%");
 
962
    // HACK Replace " " with %20 for channelnames, NOTE there can't be 2 channelnames in one link
 
963
    link = link.replace (" ", "%20");
 
964
 
945
965
    //Hack to handle the fact that we get a decoded url
946
966
    //FIXME someone who knows what it looks like when we get a decoded url can reenable this if necessary...
947
967
    //link = KUrl(link).url();
958
978
        if (!m_lastStatusText.isEmpty())
959
979
        {
960
980
            emit clearStatusBarTempText();
961
 
            m_lastStatusText = QString();
 
981
            m_lastStatusText.clear();
962
982
        }
963
983
    } else
964
984
    {
965
985
        m_lastStatusText = link;
966
986
    }
967
987
 
968
 
    if(!link.startsWith("#"))
 
988
    if(!link.startsWith('#'))
969
989
    {
970
990
        m_isOnNick = false;
971
991
        m_isOnChannel = false;
993
1013
            m_urlToCopy = link;
994
1014
        }
995
1015
    }
996
 
    else if (link.startsWith("#") && !link.startsWith("##"))
 
1016
    else if (link.startsWith('#') && !link.startsWith("##"))
997
1017
    {
998
1018
        m_currentNick = link.mid(1);
999
1019
        //FIXME how are menu titles done now? /me is too tired