summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/HighlightAction.cpp8
-rw-r--r--Swift/Controllers/HighlightAction.h14
-rw-r--r--Swift/Controllers/HighlightManager.cpp12
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp4
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp10
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
@@ -11,16 +11,16 @@
*/
#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)
@@ -29,13 +29,13 @@ void HighlightAction::setPlaySound(bool 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;
}
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
@@ -11,28 +11,28 @@
*/
#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; }
@@ -49,19 +49,19 @@ namespace Swift {
/**
* 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_;
};
@@ -69,13 +69,13 @@ namespace Swift {
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
@@ -7,27 +7,29 @@
/*
* 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.
*
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
@@ -424,22 +424,22 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
} 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()) {
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
@@ -620,14 +620,16 @@ std::string QtWebKitChatView::addMessage(
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_++);
@@ -868,14 +870,14 @@ void QtWebKitChatView::replaceMessage(const QString& message, const std::string&
}
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";