Ejemplo n.º 1
0
void HistoryDialog::setMessages(QValueList<Kopete::Message> msgs)
{
    // Clear View
    DOM::HTMLElement htmlBody = mHtmlPart->htmlDocument().body();
    while(htmlBody.hasChildNodes())
        htmlBody.removeChild(htmlBody.childNodes().item(htmlBody.childNodes().length() - 1));
    // ----

    QString dir = (QApplication::reverseLayout() ? QString::fromLatin1("rtl") :
                   QString::fromLatin1("ltr"));

    QValueList<Kopete::Message>::iterator it = msgs.begin();


    QString accountLabel;
    QString resultHTML = "<b><font color=\"red\">" + (*it).timestamp().date().toString() + "</font></b><br/>";
    DOM::HTMLElement newNode = mHtmlPart->document().createElement(QString::fromLatin1("span"));
    newNode.setAttribute(QString::fromLatin1("dir"), dir);
    newNode.setInnerHTML(resultHTML);
    mHtmlPart->htmlDocument().body().appendChild(newNode);

    // Populating HTML Part with messages
    for ( it = msgs.begin(); it != msgs.end(); ++it )
    {
        if ( mMainWidget->messageFilterBox->currentItem() == 0
                || ( mMainWidget->messageFilterBox->currentItem() == 1 && (*it).direction() == Kopete::Message::Inbound )
                || ( mMainWidget->messageFilterBox->currentItem() == 2 && (*it).direction() == Kopete::Message::Outbound ) )
        {
            resultHTML = "";

            if (accountLabel.isEmpty() || accountLabel != (*it).from()->account()->accountLabel())
                // If the message's account is new, just specify it to the user
            {
                if (!accountLabel.isEmpty())
                    resultHTML += "<br/><br/><br/>";
                resultHTML += "<b><font color=\"blue\">" + (*it).from()->account()->accountLabel() + "</font></b><br/>";
            }
            accountLabel = (*it).from()->account()->accountLabel();

            QString body = (*it).parsedBody();

            if (!mMainWidget->searchLine->text().isEmpty())
                // If there is a search, then we hightlight the keywords
            {
                body = body.replace(mMainWidget->searchLine->text(), "<span style=\"background-color:yellow\">" + mMainWidget->searchLine->text() + "</span>", false);
            }

            resultHTML += "(<b>" + (*it).timestamp().time().toString() + "</b>) "
                          + ((*it).direction() == Kopete::Message::Outbound ?
                             "<font color=\"" + KopetePrefs::prefs()->textColor().dark().name() + "\"><b>&gt;</b></font> "
                             : "<font color=\"" + KopetePrefs::prefs()->textColor().light(200).name() + "\"><b>&lt;</b></font> ")
                          + body + "<br/>";

            newNode = mHtmlPart->document().createElement(QString::fromLatin1("span"));
            newNode.setAttribute(QString::fromLatin1("dir"), dir);
            newNode.setInnerHTML(resultHTML);

            mHtmlPart->htmlDocument().body().appendChild(newNode);
        }
    }
}