From d1281fa275f9d419682f0fbb0b414f92e7b667ee Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 6 Aug 2012 20:57:37 +0100 Subject: More consistent linkification and emoticonification. Resolves: #959 diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index d20c627..f42469b 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -479,21 +479,11 @@ void QtChatWindow::updateTitleWithUnreadCount() { } std::string QtChatWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const boost::posix_time::ptime& time) { - return addMessage(message, senderName, senderIsSelf, label, avatarPath, "", time); + return addMessage(linkimoticonify(P2QSTRING(message)), senderName, senderIsSelf, label, avatarPath, "", time); } -std::string QtChatWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time) { - if (isWidgetSelected()) { - onAllMessagesRead(); - } - QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str()); - - QString htmlString; - if (label) { - htmlString = QString("").arg(Qt::escape(P2QSTRING(label->getForegroundColor()))).arg(Qt::escape(P2QSTRING(label->getBackgroundColor()))); - htmlString += QString("%1 ").arg(Qt::escape(P2QSTRING(label->getDisplayMarking()))); - } - QString messageHTML(P2QSTRING(message)); +QString QtChatWindow::linkimoticonify(const QString& message) const { + QString messageHTML(message); messageHTML = Qt::escape(messageHTML); QMapIterator it(emoticons_); QString textStyle = showEmoticons_ ? "style='display:none'" : ""; @@ -506,6 +496,21 @@ std::string QtChatWindow::addMessage(const std::string &message, const std::stri messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML))); } messageHTML.replace("\n","
"); + return messageHTML; +} + +std::string QtChatWindow::addMessage(const QString &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time) { + if (isWidgetSelected()) { + onAllMessagesRead(); + } + QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str()); + + QString htmlString; + if (label) { + htmlString = QString("").arg(Qt::escape(P2QSTRING(label->getForegroundColor()))).arg(Qt::escape(P2QSTRING(label->getBackgroundColor()))); + htmlString += QString("%1 ").arg(Qt::escape(P2QSTRING(label->getDisplayMarking()))); + } + QString messageHTML(message); QString styleSpanStart = style == "" ? "" : ""; QString styleSpanEnd = style == "" ? "" : ""; htmlString += "" + styleSpanStart + messageHTML + styleSpanEnd + "" ; @@ -565,7 +570,7 @@ int QtChatWindow::getCount() { } std::string QtChatWindow::addAction(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const boost::posix_time::ptime& time) { - return addMessage(" *" + message + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time); + return addMessage(" *" + linkimoticonify(P2QSTRING(message)) + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time); } std::string formatSize(const boost::uintmax_t bytes) { @@ -707,31 +712,28 @@ void QtChatWindow::addSystemMessage(const std::string& message) { onAllMessagesRead(); } - QString messageHTML(Qt::escape(P2QSTRING(message))); - messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML))); - messageHTML.replace("\n","
"); + QString messageHTML(P2QSTRING(message)); + messageHTML = linkimoticonify(messageHTML); messageLog_->addMessage(boost::shared_ptr(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_))); previousMessageKind_ = PreviousMessageWasSystem; } void QtChatWindow::replaceWithAction(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) { - replaceMessage(" *" + message + "*", id, time, "font-style:italic "); + replaceMessage(" *" + linkimoticonify(P2QSTRING(message)) + "*", id, time, "font-style:italic "); } void QtChatWindow::replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) { - replaceMessage(message, id, time, ""); + replaceMessage(linkimoticonify(P2QSTRING(message)), id, time, ""); } -void QtChatWindow::replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style) { +void QtChatWindow::replaceMessage(const QString& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style) { if (!id.empty()) { if (isWidgetSelected()) { onAllMessagesRead(); } - QString messageHTML(Qt::escape(P2QSTRING(message))); - messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML))); - messageHTML.replace("\n","
"); + QString messageHTML(message); QString styleSpanStart = style == "" ? "" : ""; QString styleSpanEnd = style == "" ? "" : ""; @@ -749,9 +751,8 @@ void QtChatWindow::addPresenceMessage(const std::string& message) { onAllMessagesRead(); } - QString messageHTML(Qt::escape(P2QSTRING(message))); - messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML))); - messageHTML.replace("\n","
"); + QString messageHTML(P2QSTRING(message)); + messageHTML = linkimoticonify(messageHTML); messageLog_->addMessage(boost::shared_ptr(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_))); previousMessageKind_ = PreviousMessageWasPresence; @@ -828,7 +829,7 @@ void QtChatWindow::dropEvent(QDropEvent *event) { } void QtChatWindow::replaceLastMessage(const std::string& message) { - messageLog_->replaceLastMessage(P2QSTRING(Linkify::linkify(message))); + messageLog_->replaceLastMessage(linkimoticonify(P2QSTRING(message))); } void QtChatWindow::setAvailableOccupantActions(const std::vector& actions) { diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 1ba56be..a703818 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -183,10 +183,11 @@ namespace Swift { void beginCorrection(); void cancelCorrection(); void handleSettingChanged(const std::string& setting); - std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time); - void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style); + std::string addMessage(const QString& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time); + void replaceMessage(const QString& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style); void handleOccupantSelectionChanged(RosterItem* item); bool appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf) const; + QString linkimoticonify(const QString& message) const; int unreadCount_; bool contactIsTyping_; -- cgit v0.10.2-6-g49f6