diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-10-26 13:00:29 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2015-10-30 15:50:52 (GMT) |
| commit | 7f321edd9ada1f531b1fbc3325ef61449218f40c (patch) | |
| tree | f0a1998447a41fa2cedff39edd1c179eefb4b298 | |
| parent | 50a3962e4d0b16fd0316be54121cfb293c3117bd (diff) | |
| download | swift-7f321edd9ada1f531b1fbc3325ef61449218f40c.zip swift-7f321edd9ada1f531b1fbc3325ef61449218f40c.tar.bz2 | |
Only highlight text if a highlight color is set
This commit has the default rule set the default color and
changes HighlightAction::highlightText_ symbol to
HighlightAction::highlightWholeMessage_ as it is more
descriptive of its use.
Test-Information:
Tested highlighting with the default rule set, and one with
a highlight color set for the chat rule.
Change-Id: Ic638e6347bdf6623ab5959341486233494f005f0
| -rw-r--r-- | Swift/Controllers/HighlightAction.cpp | 8 | ||||
| -rw-r--r-- | Swift/Controllers/HighlightAction.h | 14 | ||||
| -rw-r--r-- | Swift/Controllers/HighlightManager.cpp | 12 | ||||
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 4 | ||||
| -rw-r--r-- | Swift/QtUI/QtWebKitChatView.cpp | 10 |
5 files changed, 26 insertions, 22 deletions
diff --git a/Swift/Controllers/HighlightAction.cpp b/Swift/Controllers/HighlightAction.cpp index 80d9d85..4603408 100644 --- a/Swift/Controllers/HighlightAction.cpp +++ b/Swift/Controllers/HighlightAction.cpp @@ -8,37 +8,37 @@ * Copyright (c) 2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/HighlightAction.h> namespace Swift { -void HighlightAction::setHighlightAllText(bool highlightText) +void HighlightAction::setHighlightWholeMessage(bool highlightText) { - highlightText_ = highlightText; - if (!highlightText_) { + highlightWholeMessage_ = highlightText; + if (!highlightWholeMessage_) { textColor_.clear(); textBackground_.clear(); } } void HighlightAction::setPlaySound(bool playSound) { playSound_ = playSound; if (!playSound_) { soundFile_.clear(); } } bool operator ==(HighlightAction const& a, HighlightAction const& b) { - if (a.highlightAllText() != b.highlightAllText()) { + if (a.highlightWholeMessage() != b.highlightWholeMessage()) { return false; } if (a.getTextColor() != b.getTextColor()) { return false; } if (a.getTextBackground() != b.getTextBackground()) { return false; diff --git a/Swift/Controllers/HighlightAction.h b/Swift/Controllers/HighlightAction.h index a9e0cee..3930eee 100644 --- a/Swift/Controllers/HighlightAction.h +++ b/Swift/Controllers/HighlightAction.h @@ -8,34 +8,34 @@ * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include <string> -#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> +#include <boost/archive/text_oarchive.hpp> namespace Swift { class HighlightRule; class HighlightAction { public: - HighlightAction() : highlightText_(false), playSound_(false) {} + HighlightAction() : highlightWholeMessage_(false), playSound_(false) {} /** * Gets the flag that indicates the entire message should be highlighted. */ - bool highlightAllText() const { return highlightText_; } - void setHighlightAllText(bool highlightText); + bool highlightWholeMessage() const { return highlightWholeMessage_; } + void setHighlightWholeMessage(bool highlightText); /** * Gets the foreground highlight color. */ const std::string& getTextColor() const { return textColor_; } void setTextColor(const std::string& textColor) { textColor_ = textColor; } /** * Gets the background highlight color. @@ -46,37 +46,37 @@ namespace Swift { bool playSound() const { return playSound_; } void setPlaySound(bool playSound); /** * Gets the sound filename. If the string is empty, assume a default sound file. */ const std::string& getSoundFile() const { return soundFile_; } void setSoundFile(const std::string& soundFile) { soundFile_ = soundFile; } - bool isEmpty() const { return !highlightText_ && !playSound_; } + bool isEmpty() const { return !highlightWholeMessage_ && !playSound_; } private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version); - bool highlightText_; + bool highlightWholeMessage_; std::string textColor_; std::string textBackground_; bool playSound_; std::string soundFile_; }; bool operator ==(HighlightAction const& a, HighlightAction const& b); bool operator !=(HighlightAction const& a, HighlightAction const& b); template<class Archive> void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/) { - ar & highlightText_; + ar & highlightWholeMessage_; ar & textColor_; ar & textBackground_; ar & playSound_; ar & soundFile_; } } diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index ed49e72..e5c8cef 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -4,33 +4,35 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2014-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <Swift/Controllers/HighlightManager.h> + #include <cassert> #include <boost/algorithm/string.hpp> -#include <boost/regex.hpp> +#include <boost/archive/text_iarchive.hpp> +#include <boost/archive/text_oarchive.hpp> #include <boost/bind.hpp> #include <boost/numeric/conversion/cast.hpp> +#include <boost/regex.hpp> #include <boost/serialization/vector.hpp> -#include <boost/archive/text_oarchive.hpp> -#include <boost/archive/text_iarchive.hpp> #include <Swiften/Base/foreach.h> -#include <Swift/Controllers/HighlightManager.h> + #include <Swift/Controllers/Highlighter.h> -#include <Swift/Controllers/Settings/SettingsProvider.h> #include <Swift/Controllers/SettingConstants.h> +#include <Swift/Controllers/Settings/SettingsProvider.h> /* How does highlighting work? * * HighlightManager manages a list of if-then rules used to highlight messages. * Rule is represented by HighlightRule. Action ("then" part) is HighlightAction. * * * HighlightManager is also used as a factory for Highlighter objects. * Each ChatControllerBase has its own Highlighter. diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 50d1f78..1d47c4e 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -421,28 +421,28 @@ HighlightRule QtHighlightEditor::ruleFromDialog() if (ui_.chatRadio->isChecked()) { rule.setMatchChat(true); rule.setMatchMUC(false); } else { rule.setMatchChat(false); rule.setMatchMUC(true); } if (ui_.allMsgRadio->isChecked()) { - action.setHighlightAllText(true); + action.setHighlightWholeMessage(true); } if (ui_.senderRadio->isChecked()) { QString senderName = jid_->text(); if (!senderName.isEmpty()) { std::vector<std::string> senders; senders.push_back(Q2PSTRING(senderName)); rule.setSenders(senders); - action.setHighlightAllText(true); + action.setHighlightWholeMessage(true); } } if (ui_.keywordRadio->isChecked()) { QString keywordString = ui_.keyword->text(); if (!keywordString.isEmpty()) { std::vector<std::string> keywords; keywords.push_back(Q2PSTRING(keywordString)); rule.setKeywords(keywords); diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp index f1278b8..7e0e505 100644 --- a/Swift/QtUI/QtWebKitChatView.cpp +++ b/Swift/QtUI/QtWebKitChatView.cpp @@ -617,20 +617,22 @@ std::string QtWebKitChatView::addMessage( 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(QtUtilities::htmlEscape(P2QSTRING(label->getForegroundColor()))).arg(QtUtilities::htmlEscape(P2QSTRING(label->getBackgroundColor()))); htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking()))); } QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">"; QString styleSpanEnd = style == "" ? "" : "</span>"; - QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : ""; - QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : ""; + + bool highlightWholeMessage = highlight.highlightWholeMessage() && highlight.getTextBackground() != "" && highlight.getTextColor() != ""; + QString highlightSpanStart = highlightWholeMessage ? getHighlightSpanStart(highlight) : ""; + QString highlightSpanEnd = highlightWholeMessage ? "</span>" : ""; htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ; bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf); QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++); addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), direction)); previousMessageWasSelf_ = senderIsSelf; @@ -865,20 +867,20 @@ void QtWebKitChatView::replaceMessage(const QString& message, const std::string& if (!id.empty()) { if (window_->isWidgetSelected()) { window_->onAllMessagesRead(); } QString messageHTML(message); QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">"; QString styleSpanEnd = style == "" ? "" : "</span>"; - QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : ""; - QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : ""; + QString highlightSpanStart = highlight.highlightWholeMessage() ? getHighlightSpanStart(highlight) : ""; + QString highlightSpanEnd = highlight.highlightWholeMessage() ? "</span>" : ""; messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd; replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time)); } else { std::cerr << "Trying to replace a message with no id"; } } |
Swift