summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-08-06 19:57:37 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-08-06 19:58:33 (GMT)
commitd1281fa275f9d419682f0fbb0b414f92e7b667ee (patch)
tree5f5e7c854146b5441f7e383e5d89a54e9908e890
parent6f26d9aa86f0909af13b23b1a925b8d492e74154 (diff)
downloadswift-contrib-d1281fa275f9d419682f0fbb0b414f92e7b667ee.zip
swift-contrib-d1281fa275f9d419682f0fbb0b414f92e7b667ee.tar.bz2
More consistent linkification and emoticonification.
Resolves: #959
-rw-r--r--Swift/QtUI/QtChatWindow.cpp55
-rw-r--r--Swift/QtUI/QtChatWindow.h5
2 files changed, 31 insertions, 29 deletions
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<SecurityLabel> 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<SecurityLabel> 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("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \" class='swift_label'>").arg(Qt::escape(P2QSTRING(label->getForegroundColor()))).arg(Qt::escape(P2QSTRING(label->getBackgroundColor())));
- htmlString += QString("%1</span> ").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<QString, QString> 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","<br/>");
+ return messageHTML;
+}
+
+std::string QtChatWindow::addMessage(const QString &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> 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("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \" class='swift_label'>").arg(Qt::escape(P2QSTRING(label->getForegroundColor()))).arg(Qt::escape(P2QSTRING(label->getBackgroundColor())));
+ htmlString += QString("%1</span> ").arg(Qt::escape(P2QSTRING(label->getDisplayMarking())));
+ }
+ QString messageHTML(message);
QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
QString styleSpanEnd = style == "" ? "" : "</span>";
htmlString += "<span class='swift_inner_message'>" + styleSpanStart + messageHTML + styleSpanEnd + "</span>" ;
@@ -565,7 +570,7 @@ int QtChatWindow::getCount() {
}
std::string QtChatWindow::addAction(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> 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","<br/>");
+ QString messageHTML(P2QSTRING(message));
+ messageHTML = linkimoticonify(messageHTML);
messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(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","<br/>");
+ QString messageHTML(message);
QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
QString styleSpanEnd = style == "" ? "" : "</span>";
@@ -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","<br/>");
+ QString messageHTML(P2QSTRING(message));
+ messageHTML = linkimoticonify(messageHTML);
messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(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<OccupantAction>& 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<SecurityLabel> 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<SecurityLabel> 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_;