~ubuntu-branches/ubuntu/edgy/kopete/edgy-updates

« back to all changes in this revision

Viewing changes to kopete/kopete/chatwindow/chatmessagepart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sarah Hobbs
  • Date: 2006-07-14 23:45:58 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060714234558-gq6jzmy117r2pj4r
Tags: 4:3.5.4+kopete0.12.1-0ubuntu1
* New upstream version
* Reverted patch 01_kopete_kdesktop_freeze.diff (fixed upstream)
* Reverted patch 02_icq_version_too_old.diff (fixed upstream)
* Bumped Version so that this gets installed, instead of the kopete in kdenetwork

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <qregexp.h>
35
35
#include <qvaluelist.h>
36
36
#include <qtimer.h>
 
37
#include <qstylesheet.h>
37
38
 
38
39
// KHTML::DOM includes
39
40
#include <dom/dom_doc.h>
547
548
#endif
548
549
}
549
550
 
550
 
const QString ChatMessagePart::addNickLinks( const QString &html ) const
551
 
{
552
 
        QString retVal = html;
553
 
 
554
 
        Kopete::ContactPtrList members = d->manager->members();
555
 
        for ( QPtrListIterator<Kopete::Contact> it( members ); it.current(); ++it )
556
 
        {
557
 
                QString nick = (*it)->property( Kopete::Global::Properties::self()->nickName().key() ).value().toString();
558
 
                //FIXME: this is really slow in channels with lots of contacts
559
 
                QString parsed_nick = Kopete::Emoticons::parseEmoticons( nick );
560
 
 
561
 
                if ( nick != parsed_nick )
562
 
                {
563
 
                        retVal.replace( QRegExp( QString::fromLatin1("([\\s&;>])%1([\\s&;<:])")
564
 
                                        .arg( QRegExp::escape( parsed_nick ) )  ), QString::fromLatin1("\\1%1\\2").arg( nick ) );
565
 
                }
566
 
                if ( nick.length() > 0 && ( retVal.find( nick ) > -1 ) && d->manager->protocol() )
567
 
                {
568
 
                        retVal.replace(
569
 
                                QRegExp( QString::fromLatin1("([\\s&;>])(%1)([\\s&;<:])")
570
 
                                        .arg( QRegExp::escape( nick ) )  ),
571
 
                        QString::fromLatin1("\\1<a href=\"kopetemessage://%1/?protocolId=%2&accountId=%3\" class=\"KopeteDisplayName\">\\2</a>\\3")
572
 
                                .arg( (*it)->contactId(), d->manager->protocol()->pluginId(), d->manager->account()->accountId() )
573
 
                        );
574
 
                }
575
 
        }
576
 
#if 0  //disabled because it causes crash on exit  - Olivier 2006-03-31
577
 
        QString nick = d->manager->myself()->property( Kopete::Global::Properties::self()->nickName().key() ).value().toString();
578
 
        retVal.replace( QRegExp( QString::fromLatin1("([\\s&;>])%1([\\s&;<:])")
579
 
                        .arg( QRegExp::escape( Kopete::Emoticons::parseEmoticons( nick ) ) )  ), QString::fromLatin1("\\1%1\\2").arg( nick ) );
580
 
#endif
581
 
        return retVal;
582
 
}
583
 
 
584
551
void ChatMessagePart::slotRefreshView()
585
552
{
586
553
        DOM::HTMLElement kopeteNode = document().getElementById( QString::fromUtf8("KopeteStyle") );
954
921
}
955
922
 
956
923
// Style formatting for messages(incoming, outgoing, status)
957
 
QString ChatMessagePart::formatStyleKeywords( const QString &sourceHTML, Kopete::Message &message )
 
924
QString ChatMessagePart::formatStyleKeywords( const QString &sourceHTML, const Kopete::Message &_message )
958
925
{
 
926
        Kopete::Message message=_message; //we will eventually need to modify it before showing it.
959
927
        QString resultHTML = sourceHTML;
960
 
        QString nick, contactId, service, protocolIcon;
 
928
        QString nick, contactId, service, protocolIcon, nickLink;
961
929
        
962
930
        if( message.from() )
963
931
        {
988
956
                }
989
957
 
990
958
                protocolIcon = KGlobal::iconLoader()->iconPath( iconName, KIcon::Small );
991
 
        }
 
959
                
 
960
                nickLink=QString::fromLatin1("<a href=\"kopetemessage://%1/?protocolId=%2&amp;accountId=%3\" class=\"KopeteDisplayName\">")
 
961
                                .arg( QStyleSheet::escape(message.from()->contactId()).replace('"',"&quot;"),
 
962
                                          QStyleSheet::escape(message.from()->protocol()->pluginId()).replace('"',"&quot;"), 
 
963
                                          QStyleSheet::escape(message.from()->account()->accountId() ).replace('"',"&quot;"));
 
964
        }
 
965
        else
 
966
        {
 
967
                nickLink="<a>";
 
968
        }
 
969
        
992
970
        
993
971
        // Replace sender (contact nick)
994
 
        resultHTML = resultHTML.replace( QString::fromUtf8("%sender%"), nick );
 
972
        resultHTML = resultHTML.replace( QString::fromUtf8("%sender%"), nickLink+nick+"</a>" );
995
973
        // Replace time, by default display only time and display seconds(that was true means).
996
974
        resultHTML = resultHTML.replace( QString::fromUtf8("%time%"), KGlobal::locale()->formatTime(message.timestamp().time(), true) );
997
975
        // Replace %screenName% (contact ID)
998
 
        resultHTML = resultHTML.replace( QString::fromUtf8("%senderScreenName%"), contactId );
 
976
        resultHTML = resultHTML.replace( QString::fromUtf8("%senderScreenName%"), nickLink+QStyleSheet::escape(contactId)+"</a>" );
999
977
        // Replace service name (protocol name)
1000
 
        resultHTML = resultHTML.replace( QString::fromUtf8("%service%"), service );
 
978
        resultHTML = resultHTML.replace( QString::fromUtf8("%service%"), QStyleSheet::escape(service) );
1001
979
        // Replace protocolIcon (sender statusIcon)
1002
 
        resultHTML = resultHTML.replace( QString::fromUtf8("%senderStatusIcon%"), protocolIcon );
 
980
        resultHTML = resultHTML.replace( QString::fromUtf8("%senderStatusIcon%"), QStyleSheet::escape(protocolIcon).replace('"',"&quot;") );
1003
981
        
1004
982
        // Look for %time{X}%
1005
983
        QRegExp timeRegExp("%time\\{([^}]*)\\}%");
1062
1040
        {
1063
1041
                kdDebug(14000) << k_funcinfo << "Map Action message to Status template. " << endl;
1064
1042
 
1065
 
                QString boldNick = QString::fromUtf8("<b>%1</b> ").arg(nick);
1066
 
                // Don't set the body twice.
1067
 
                if( !message.parsedBody().contains(boldNick) )
1068
 
                {
1069
 
                        QString newBody = boldNick + message.parsedBody();
1070
 
                        message.setBody(newBody, Kopete::Message::ParsedHTML );
1071
 
                }
 
1043
                QString boldNick = QString::fromUtf8("%1<b>%2</b></a> ").arg(nickLink,nick);
 
1044
                QString newBody = boldNick + message.parsedBody();
 
1045
                message.setBody(newBody, Kopete::Message::ParsedHTML );
1072
1046
        }
1073
1047
 
1074
1048
        // Set message direction("rtl"(Right-To-Left) or "ltr"(Left-to-right))
1109
1083
        resultHTML = resultHTML.replace( QString::fromUtf8("%message%"), formatMessageBody(message) );
1110
1084
 
1111
1085
        // TODO: %status
1112
 
        resultHTML = addNickLinks( resultHTML );
 
1086
//      resultHTML = addNickLinks( resultHTML );
1113
1087
        return resultHTML;
1114
1088
}
1115
1089