summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-10-26 13:00:29 (GMT)
committerSwift Review <review@swift.im>2015-10-30 15:50:52 (GMT)
commit7f321edd9ada1f531b1fbc3325ef61449218f40c (patch)
treef0a1998447a41fa2cedff39edd1c179eefb4b298
parent50a3962e4d0b16fd0316be54121cfb293c3117bd (diff)
downloadswift-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.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
@@ -12,14 +12,14 @@
12 12
13#include <Swift/Controllers/HighlightAction.h> 13#include <Swift/Controllers/HighlightAction.h>
14 14
15namespace Swift { 15namespace Swift {
16 16
17void HighlightAction::setHighlightAllText(bool highlightText) 17void HighlightAction::setHighlightWholeMessage(bool highlightText)
18{ 18{
19 highlightText_ = highlightText; 19 highlightWholeMessage_ = highlightText;
20 if (!highlightText_) { 20 if (!highlightWholeMessage_) {
21 textColor_.clear(); 21 textColor_.clear();
22 textBackground_.clear(); 22 textBackground_.clear();
23 } 23 }
24} 24}
25 25
@@ -30,11 +30,11 @@ void HighlightAction::setPlaySound(bool playSound)
30 soundFile_.clear(); 30 soundFile_.clear();
31 } 31 }
32} 32}
33 33
34bool operator ==(HighlightAction const& a, HighlightAction const& b) { 34bool operator ==(HighlightAction const& a, HighlightAction const& b) {
35 if (a.highlightAllText() != b.highlightAllText()) { 35 if (a.highlightWholeMessage() != b.highlightWholeMessage()) {
36 return false; 36 return false;
37 } 37 }
38 38
39 if (a.getTextColor() != b.getTextColor()) { 39 if (a.getTextColor() != b.getTextColor()) {
40 return false; 40 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
@@ -12,26 +12,26 @@
12 12
13#pragma once 13#pragma once
14 14
15#include <string> 15#include <string>
16 16
17#include <boost/archive/text_oarchive.hpp>
18#include <boost/archive/text_iarchive.hpp> 17#include <boost/archive/text_iarchive.hpp>
18#include <boost/archive/text_oarchive.hpp>
19 19
20namespace Swift { 20namespace Swift {
21 21
22 class HighlightRule; 22 class HighlightRule;
23 23
24 class HighlightAction { 24 class HighlightAction {
25 public: 25 public:
26 HighlightAction() : highlightText_(false), playSound_(false) {} 26 HighlightAction() : highlightWholeMessage_(false), playSound_(false) {}
27 27
28 /** 28 /**
29 * Gets the flag that indicates the entire message should be highlighted. 29 * Gets the flag that indicates the entire message should be highlighted.
30 */ 30 */
31 bool highlightAllText() const { return highlightText_; } 31 bool highlightWholeMessage() const { return highlightWholeMessage_; }
32 void setHighlightAllText(bool highlightText); 32 void setHighlightWholeMessage(bool highlightText);
33 33
34 /** 34 /**
35 * Gets the foreground highlight color. 35 * Gets the foreground highlight color.
36 */ 36 */
37 const std::string& getTextColor() const { return textColor_; } 37 const std::string& getTextColor() const { return textColor_; }
@@ -50,17 +50,17 @@ namespace Swift {
50 * Gets the sound filename. If the string is empty, assume a default sound file. 50 * Gets the sound filename. If the string is empty, assume a default sound file.
51 */ 51 */
52 const std::string& getSoundFile() const { return soundFile_; } 52 const std::string& getSoundFile() const { return soundFile_; }
53 void setSoundFile(const std::string& soundFile) { soundFile_ = soundFile; } 53 void setSoundFile(const std::string& soundFile) { soundFile_ = soundFile; }
54 54
55 bool isEmpty() const { return !highlightText_ && !playSound_; } 55 bool isEmpty() const { return !highlightWholeMessage_ && !playSound_; }
56 56
57 private: 57 private:
58 friend class boost::serialization::access; 58 friend class boost::serialization::access;
59 template<class Archive> void serialize(Archive & ar, const unsigned int version); 59 template<class Archive> void serialize(Archive & ar, const unsigned int version);
60 60
61 bool highlightText_; 61 bool highlightWholeMessage_;
62 std::string textColor_; 62 std::string textColor_;
63 std::string textBackground_; 63 std::string textBackground_;
64 64
65 bool playSound_; 65 bool playSound_;
66 std::string soundFile_; 66 std::string soundFile_;
@@ -70,11 +70,11 @@ namespace Swift {
70 bool operator !=(HighlightAction const& a, HighlightAction const& b); 70 bool operator !=(HighlightAction const& a, HighlightAction const& b);
71 71
72 template<class Archive> 72 template<class Archive>
73 void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/) 73 void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/)
74 { 74 {
75 ar & highlightText_; 75 ar & highlightWholeMessage_;
76 ar & textColor_; 76 ar & textColor_;
77 ar & textBackground_; 77 ar & textBackground_;
78 ar & playSound_; 78 ar & playSound_;
79 ar & soundFile_; 79 ar & soundFile_;
80 } 80 }
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
@@ -8,25 +8,27 @@
8 * Copyright (c) 2014-2015 Isode Limited. 8 * Copyright (c) 2014-2015 Isode Limited.
9 * All rights reserved. 9 * All rights reserved.
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
12 12
13#include <Swift/Controllers/HighlightManager.h>
14
13#include <cassert> 15#include <cassert>
14 16
15#include <boost/algorithm/string.hpp> 17#include <boost/algorithm/string.hpp>
16#include <boost/regex.hpp> 18#include <boost/archive/text_iarchive.hpp>
19#include <boost/archive/text_oarchive.hpp>
17#include <boost/bind.hpp> 20#include <boost/bind.hpp>
18#include <boost/numeric/conversion/cast.hpp> 21#include <boost/numeric/conversion/cast.hpp>
22#include <boost/regex.hpp>
19#include <boost/serialization/vector.hpp> 23#include <boost/serialization/vector.hpp>
20#include <boost/archive/text_oarchive.hpp>
21#include <boost/archive/text_iarchive.hpp>
22 24
23#include <Swiften/Base/foreach.h> 25#include <Swiften/Base/foreach.h>
24#include <Swift/Controllers/HighlightManager.h> 26
25#include <Swift/Controllers/Highlighter.h> 27#include <Swift/Controllers/Highlighter.h>
26#include <Swift/Controllers/Settings/SettingsProvider.h>
27#include <Swift/Controllers/SettingConstants.h> 28#include <Swift/Controllers/SettingConstants.h>
29#include <Swift/Controllers/Settings/SettingsProvider.h>
28 30
29/* How does highlighting work? 31/* How does highlighting work?
30 * 32 *
31 * HighlightManager manages a list of if-then rules used to highlight messages. 33 * HighlightManager manages a list of if-then rules used to highlight messages.
32 * Rule is represented by HighlightRule. Action ("then" part) is HighlightAction. 34 * 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
@@ -425,20 +425,20 @@ HighlightRule QtHighlightEditor::ruleFromDialog()
425 rule.setMatchChat(false); 425 rule.setMatchChat(false);
426 rule.setMatchMUC(true); 426 rule.setMatchMUC(true);
427 } 427 }
428 428
429 if (ui_.allMsgRadio->isChecked()) { 429 if (ui_.allMsgRadio->isChecked()) {
430 action.setHighlightAllText(true); 430 action.setHighlightWholeMessage(true);
431 } 431 }
432 432
433 if (ui_.senderRadio->isChecked()) { 433 if (ui_.senderRadio->isChecked()) {
434 QString senderName = jid_->text(); 434 QString senderName = jid_->text();
435 if (!senderName.isEmpty()) { 435 if (!senderName.isEmpty()) {
436 std::vector<std::string> senders; 436 std::vector<std::string> senders;
437 senders.push_back(Q2PSTRING(senderName)); 437 senders.push_back(Q2PSTRING(senderName));
438 rule.setSenders(senders); 438 rule.setSenders(senders);
439 action.setHighlightAllText(true); 439 action.setHighlightWholeMessage(true);
440 } 440 }
441 } 441 }
442 442
443 if (ui_.keywordRadio->isChecked()) { 443 if (ui_.keywordRadio->isChecked()) {
444 QString keywordString = ui_.keyword->text(); 444 QString keywordString = ui_.keyword->text();
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
@@ -621,12 +621,14 @@ std::string QtWebKitChatView::addMessage(
621 htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking()))); 621 htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking())));
622 } 622 }
623 623
624 QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">"; 624 QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
625 QString styleSpanEnd = style == "" ? "" : "</span>"; 625 QString styleSpanEnd = style == "" ? "" : "</span>";
626 QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : ""; 626
627 QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : ""; 627 bool highlightWholeMessage = highlight.highlightWholeMessage() && highlight.getTextBackground() != "" && highlight.getTextColor() != "";
628 QString highlightSpanStart = highlightWholeMessage ? getHighlightSpanStart(highlight) : "";
629 QString highlightSpanEnd = highlightWholeMessage ? "</span>" : "";
628 htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ; 630 htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ;
629 631
630 bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf); 632 bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf);
631 633
632 QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); 634 QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
@@ -869,12 +871,12 @@ void QtWebKitChatView::replaceMessage(const QString& message, const std::string&
869 871
870 QString messageHTML(message); 872 QString messageHTML(message);
871 873
872 QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">"; 874 QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
873 QString styleSpanEnd = style == "" ? "" : "</span>"; 875 QString styleSpanEnd = style == "" ? "" : "</span>";
874 QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : ""; 876 QString highlightSpanStart = highlight.highlightWholeMessage() ? getHighlightSpanStart(highlight) : "";
875 QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : ""; 877 QString highlightSpanEnd = highlight.highlightWholeMessage() ? "</span>" : "";
876 messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd; 878 messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd;
877 879
878 replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time)); 880 replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
879 } 881 }
880 else { 882 else {