From cdda411c7929b7283ab22fcfc7751a6fbf7ba6ea Mon Sep 17 00:00:00 2001 From: hunbernd Date: Mon, 7 Dec 2015 01:21:16 +0100 Subject: [PATCH] /me TODO: allow customizing the style --- retroshare-gui/src/gui/chat/ChatStyle.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index b6a27b90c..3cb74a4cf 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -267,6 +267,7 @@ static QString getStyle(const QDir &styleDir, const QString &styleVariant, enumG QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, const QDateTime ×tamp, const QString &message, unsigned int flag) { + bool me = false; QDomDocument doc ; QString styleOptimized ; QString errorMsg ; int errorLine ; int errorColumn ; @@ -279,6 +280,12 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co for (int curs = 0; curs < count; ++curs){ QDomNode it = body.childNodes().item(curs); if (it.nodeName().toLower() != "style") { + //find out if the message starts with /me + if(it.isText()){ + me = me || it.toText().data().trimmed().startsWith("/me "); + }else if(it.isElement()){ + me = me || it.toElement().text().trimmed().startsWith("/me "); + } QString str; QTextStream stream(&str); it.toElement().save(stream, -1); @@ -354,6 +361,13 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co QString strName = RsHtml::plainText(name).prepend(QString("")).append(QString("")); QString strDate = DateTime::formatDate(timestamp.date()).prepend(QString("")).append(QString("")); QString strTime = DateTime::formatTime(timestamp.time()).prepend(QString("")).append(QString("")); + + //handle /me + if(me){ + messageBody = messageBody.replace(messageBody.indexOf("/me "), 3, strName); //replace only the first /me + strName = "*"; + } + QString formatMsg = style.replace("%name%", strName) .replace("%date%", strDate) .replace("%time%", strTime)