summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-07-16 12:37:25 (GMT)
committerSwift Review <review@swift.im>2014-07-29 08:36:54 (GMT)
commit9c5c731845881996f45b32ea6de12e0647f4634d (patch)
tree70331a822814ade469f07231ff0bf6dfbfa1fcde
parent690cb7e85ff9dadbfca3e3bc91826161011712f1 (diff)
downloadswift-contrib-9c5c731845881996f45b32ea6de12e0647f4634d.zip
swift-contrib-9c5c731845881996f45b32ea6de12e0647f4634d.tar.bz2
Prevent nick highlight rule highlighting the entire message and remove default highlight colours
Test-Information: Add a nick highlight rule. Verify that it is triggered correctly in MUCs and that only the nick text is highlighted. Added unit tests. Change-Id: I9af1c900f4767383745afd36a5eadbe08f606432
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp4
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.cpp9
-rw-r--r--Swift/Controllers/Chat/ChatMessageParser.h4
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp36
-rw-r--r--Swift/Controllers/HighlightAction.cpp2
-rw-r--r--Swift/Controllers/HighlightAction.h11
-rw-r--r--Swift/Controllers/HighlightRule.cpp12
-rw-r--r--Swift/Controllers/HighlightRule.h2
-rw-r--r--Swift/Controllers/Highlighter.h1
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp45
-rw-r--r--Swift/QtUI/QtHighlightEditor.ui7
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp8
12 files changed, 88 insertions, 53 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index 24341e6..519deda 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -207,3 +207,3 @@ std::string ChatControllerBase::addMessage(const std::string& message, const std
} else {
- return chatWindow_->addMessage(chatMessageParser_->parseMessageBody(message,senderIsSelf), senderName, senderIsSelf, label, pathToString(avatarPath), time, highlight);
+ return chatWindow_->addMessage(chatMessageParser_->parseMessageBody(message,highlighter_->getNick(),senderIsSelf), senderName, senderIsSelf, label, pathToString(avatarPath), time, highlight);
}
@@ -215,3 +215,3 @@ void ChatControllerBase::replaceMessage(const std::string& message, const std::s
} else {
- chatWindow_->replaceMessage(chatMessageParser_->parseMessageBody(message,senderIsSelf), id, time, highlight);
+ chatWindow_->replaceMessage(chatMessageParser_->parseMessageBody(message,highlighter_->getNick(),senderIsSelf), id, time, highlight);
}
diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp
index 09d93ac..5a608db 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.cpp
+++ b/Swift/Controllers/Chat/ChatMessageParser.cpp
@@ -28,3 +28,3 @@ namespace Swift {
- ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, bool senderIsSelf) {
+ ChatWindow::ChatMessage ChatMessageParser::parseMessageBody(const std::string& body, const std::string& nick, bool senderIsSelf) {
ChatWindow::ChatMessage parsedMessage;
@@ -59,3 +59,3 @@ namespace Swift {
/* do word-based color highlighting */
- parsedMessage = splitHighlight(parsedMessage);
+ parsedMessage = splitHighlight(parsedMessage, nick);
}
@@ -140,3 +140,3 @@ namespace Swift {
- ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message)
+ ChatWindow::ChatMessage ChatMessageParser::splitHighlight(const ChatWindow::ChatMessage& message, const std::string& nick)
{
@@ -151,3 +151,4 @@ namespace Swift {
}
- foreach(const boost::regex &regex, rule.getKeywordRegex()) {
+ const std::vector<boost::regex> keywordRegex = rule.getKeywordRegex(nick);
+ foreach(const boost::regex& regex, keywordRegex) {
ChatWindow::ChatMessage newMessage;
diff --git a/Swift/Controllers/Chat/ChatMessageParser.h b/Swift/Controllers/Chat/ChatMessageParser.h
index cff4ffa..2f5c171 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.h
+++ b/Swift/Controllers/Chat/ChatMessageParser.h
@@ -17,6 +17,6 @@ namespace Swift {
ChatMessageParser(const std::map<std::string, std::string>& emoticons, HighlightRulesListPtr highlightRules, bool mucMode = false);
- ChatWindow::ChatMessage parseMessageBody(const std::string& body, bool senderIsSelf = false);
+ ChatWindow::ChatMessage parseMessageBody(const std::string& body, const std::string& nick = "", bool senderIsSelf = false);
private:
ChatWindow::ChatMessage emoticonHighlight(const ChatWindow::ChatMessage& parsedMessage);
- ChatWindow::ChatMessage splitHighlight(const ChatWindow::ChatMessage& parsedMessage);
+ ChatWindow::ChatMessage splitHighlight(const ChatWindow::ChatMessage& parsedMessage, const std::string& nick);
std::map<std::string, std::string> emoticons_;
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
index 5dca63a..2a07654 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
@@ -87,2 +87,14 @@ public:
+ static HighlightRulesListPtr ruleListWithNickHighlight()
+ {
+ HighlightRule rule;
+ rule.setMatchChat(true);
+ rule.setNickIsKeyword(true);
+ rule.setMatchCase(true);
+ rule.setMatchWholeWords(true);
+ boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
+ list->addRule(rule);
+ return list;
+ }
+
void testFullBody() {
@@ -176,2 +188,26 @@ public:
assertText(result, 0, "zeroonetwothree");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Alice", "Alice");
+ assertHighlight(result, 0, "Alice");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("TextAliceText", "Alice");
+ assertText(result, 0, "TextAliceText");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Text Alice Text", "Alice");
+ assertText(result, 0, "Text ");
+ assertHighlight(result, 1, "Alice");
+ assertText(result, 2, " Text");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Alice Text", "Alice");
+ assertHighlight(result, 0, "Alice");
+ assertText(result, 1, " Text");
+
+ testling = ChatMessageParser(emoticons_, ruleListWithNickHighlight());
+ result = testling.parseMessageBody("Text Alice", "Alice");
+ assertText(result, 0, "Text ");
+ assertHighlight(result, 1, "Alice");
}
diff --git a/Swift/Controllers/HighlightAction.cpp b/Swift/Controllers/HighlightAction.cpp
index d4d199d..492d4d2 100644
--- a/Swift/Controllers/HighlightAction.cpp
+++ b/Swift/Controllers/HighlightAction.cpp
@@ -10,3 +10,3 @@ namespace Swift {
-void HighlightAction::setHighlightText(bool highlightText)
+void HighlightAction::setHighlightAllText(bool highlightText)
{
diff --git a/Swift/Controllers/HighlightAction.h b/Swift/Controllers/HighlightAction.h
index de1f201..90768a7 100644
--- a/Swift/Controllers/HighlightAction.h
+++ b/Swift/Controllers/HighlightAction.h
@@ -27,7 +27,10 @@ namespace Swift {
- bool highlightText() const { return highlightText_; }
- void setHighlightText(bool highlightText);
+ /**
+ * Gets the flag that indicates the entire message should be highlighted.
+ */
+ bool highlightAllText() const { return highlightText_; }
+ void setHighlightAllText(bool highlightText);
/**
- * Gets the foreground highlight color. If the string is empty, assume a default color.
+ * Gets the foreground highlight color.
*/
@@ -37,3 +40,3 @@ namespace Swift {
/**
- * Gets the background highlight color. If the string is empty, assume a default color.
+ * Gets the background highlight color.
*/
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp
index f1a5235..3251067 100644
--- a/Swift/Controllers/HighlightRule.cpp
+++ b/Swift/Controllers/HighlightRule.cpp
@@ -104,2 +104,14 @@ void HighlightRule::setKeywords(const std::vector<std::string>& keywords)
+std::vector<boost::regex> HighlightRule::getKeywordRegex(const std::string& nick) const {
+ if (nickIsKeyword_) {
+ std::vector<boost::regex> regex;
+ if (!nick.empty()) {
+ regex.push_back(regexFromString(nick));
+ }
+ return regex;
+ } else {
+ return keywordRegex_;
+ }
+}
+
void HighlightRule::setNickIsKeyword(bool nickIsKeyword)
diff --git a/Swift/Controllers/HighlightRule.h b/Swift/Controllers/HighlightRule.h
index ae1a3d3..c0226bc 100644
--- a/Swift/Controllers/HighlightRule.h
+++ b/Swift/Controllers/HighlightRule.h
@@ -42,3 +42,3 @@ namespace Swift {
void setKeywords(const std::vector<std::string>&);
- const std::vector<boost::regex>& getKeywordRegex() const { return keywordRegex_; }
+ std::vector<boost::regex> getKeywordRegex(const std::string& nick) const;
diff --git a/Swift/Controllers/Highlighter.h b/Swift/Controllers/Highlighter.h
index d026f29..d5d846b 100644
--- a/Swift/Controllers/Highlighter.h
+++ b/Swift/Controllers/Highlighter.h
@@ -24,2 +24,3 @@ namespace Swift {
void setNick(const std::string& nick) { nick_ = nick; }
+ std::string getNick() const { return nick_; }
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp
index ce07003..8488d7d 100644
--- a/Swift/QtUI/QtHighlightEditor.cpp
+++ b/Swift/QtUI/QtHighlightEditor.cpp
@@ -42,3 +42,2 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare
connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect()));
- connect(ui_.defaultColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect()));
connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect()));
@@ -70,3 +69,2 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare
connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
- connect(ui_.defaultColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
@@ -307,3 +305,2 @@ void QtHighlightEditor::disableDialog()
ui_.noColorRadio->setEnabled(false);
- ui_.defaultColorRadio->setEnabled(false);
ui_.customColorRadio->setEnabled(false);
@@ -401,5 +398,10 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
- rule.setNickIsKeyword(ui_.nickIsKeyword->isChecked());
- rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
- rule.setMatchCase(ui_.matchCase->isChecked());
+ if (ui_.nickIsKeyword->isChecked()) {
+ rule.setNickIsKeyword(true);
+ rule.setMatchWholeWords(true);
+ rule.setMatchCase(true);
+ } else {
+ rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
+ rule.setMatchCase(ui_.matchCase->isChecked());
+ }
@@ -408,7 +410,2 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
if (ui_.noColorRadio->isChecked()) {
- action.setHighlightText(false);
- action.setTextColor("");
- action.setTextBackground("");
- } else if (ui_.defaultColorRadio->isChecked()) {
- action.setHighlightText(true);
action.setTextColor("");
@@ -416,3 +413,2 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
} else {
- action.setHighlightText(true);
action.setTextColor(Q2PSTRING(ui_.foregroundColor->getColor().name()));
@@ -478,19 +474,4 @@ void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
ui_.noColorRadio->setEnabled(true);
- ui_.defaultColorRadio->setEnabled(true);
ui_.customColorRadio->setEnabled(true);
- if (action.highlightText()) {
- if (action.getTextColor().empty() && action.getTextBackground().empty()) {
- ui_.defaultColorRadio->setChecked(true);
- ui_.foregroundColor->setEnabled(false);
- ui_.backgroundColor->setEnabled(false);
- } else {
- ui_.foregroundColor->setEnabled(true);
- ui_.backgroundColor->setEnabled(true);
- QColor foregroundColor(P2QSTRING(action.getTextColor()));
- ui_.foregroundColor->setColor(foregroundColor);
- QColor backgroundColor(P2QSTRING(action.getTextBackground()));
- ui_.backgroundColor->setColor(backgroundColor);
- ui_.customColorRadio->setChecked(true);
- }
- } else {
+ if (action.getTextColor().empty() && action.getTextBackground().empty()) {
ui_.noColorRadio->setChecked(true);
@@ -498,2 +479,10 @@ void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
ui_.backgroundColor->setEnabled(false);
+ } else {
+ ui_.foregroundColor->setEnabled(true);
+ ui_.backgroundColor->setEnabled(true);
+ QColor foregroundColor(P2QSTRING(action.getTextColor()));
+ ui_.foregroundColor->setColor(foregroundColor);
+ QColor backgroundColor(P2QSTRING(action.getTextBackground()));
+ ui_.backgroundColor->setColor(backgroundColor);
+ ui_.customColorRadio->setChecked(true);
}
diff --git a/Swift/QtUI/QtHighlightEditor.ui b/Swift/QtUI/QtHighlightEditor.ui
index be2e99b..775771f 100644
--- a/Swift/QtUI/QtHighlightEditor.ui
+++ b/Swift/QtUI/QtHighlightEditor.ui
@@ -279,9 +279,2 @@
<item>
- <widget class="QRadioButton" name="defaultColorRadio">
- <property name="text">
- <string>Default Color</string>
- </property>
- </widget>
- </item>
- <item>
<widget class="QRadioButton" name="customColorRadio">
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index 1486293..a510e34 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -610,4 +610,4 @@ std::string QtWebKitChatView::addMessage(
QString styleSpanEnd = style == "" ? "" : "</span>";
- QString highlightSpanStart = highlight.highlightText() ? getHighlightSpanStart(highlight) : "";
- QString highlightSpanEnd = highlight.highlightText() ? "</span>" : "";
+ QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : "";
htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ;
@@ -828,4 +828,4 @@ void QtWebKitChatView::replaceMessage(const QString& message, const std::string&
QString styleSpanEnd = style == "" ? "" : "</span>";
- QString highlightSpanStart = highlight.highlightText() ? getHighlightSpanStart(highlight) : "";
- QString highlightSpanEnd = highlight.highlightText() ? "</span>" : "";
+ QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : "";
messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd;