diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-01-13 15:26:24 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-07-09 14:01:41 (GMT) |
commit | f2bcc401477dcb5ca52b5d9d5e85f4bf7bae9285 (patch) | |
tree | 01cf807b2ad59f5ea6504fd28d12e0f994e2f907 /Swift/Controllers/HighlightRule.cpp | |
parent | 8e03583fe21bcd5e0025da81d8f4a34ed05cd058 (diff) | |
download | swift-contrib-f2bcc401477dcb5ca52b5d9d5e85f4bf7bae9285.zip swift-contrib-f2bcc401477dcb5ca52b5d9d5e85f4bf7bae9285.tar.bz2 |
Reworked highlight rules dialog. Added support for highlighting individual words in messages.
Change-Id: I378fa69077c29008db4ef7c2265e5212924bc2ce
Diffstat (limited to 'Swift/Controllers/HighlightRule.cpp')
-rw-r--r-- | Swift/Controllers/HighlightRule.cpp | 64 |
1 files changed, 6 insertions, 58 deletions
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp index 9ca7d86..f1a5235 100644 --- a/Swift/Controllers/HighlightRule.cpp +++ b/Swift/Controllers/HighlightRule.cpp @@ -4,6 +4,12 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + #include <algorithm> #include <boost/algorithm/string.hpp> #include <boost/lambda/lambda.hpp> @@ -56,57 +62,6 @@ bool HighlightRule::boolFromString(const std::string& s) return s == "1"; } -std::string HighlightRule::toString() const -{ - std::vector<std::string> v; - v.push_back(boost::join(senders_, "\t")); - v.push_back(boost::join(keywords_, "\t")); - v.push_back(boolToString(nickIsKeyword_)); - v.push_back(boolToString(matchChat_)); - v.push_back(boolToString(matchMUC_)); - v.push_back(boolToString(matchCase_)); - v.push_back(boolToString(matchWholeWords_)); - v.push_back(boolToString(action_.highlightText())); - v.push_back(action_.getTextColor()); - v.push_back(action_.getTextBackground()); - v.push_back(boolToString(action_.playSound())); - v.push_back(action_.getSoundFile()); - return boost::join(v, "\n"); -} - -HighlightRule HighlightRule::fromString(const std::string& s) -{ - std::vector<std::string> v; - boost::split(v, s, boost::is_any_of("\n")); - - HighlightRule r; - size_t i = 0; - try { - boost::split(r.senders_, v.at(i++), boost::is_any_of("\t")); - r.senders_.erase(std::remove_if(r.senders_.begin(), r.senders_.end(), boost::lambda::_1 == ""), r.senders_.end()); - boost::split(r.keywords_, v.at(i++), boost::is_any_of("\t")); - r.keywords_.erase(std::remove_if(r.keywords_.begin(), r.keywords_.end(), boost::lambda::_1 == ""), r.keywords_.end()); - r.nickIsKeyword_ = boolFromString(v.at(i++)); - r.matchChat_ = boolFromString(v.at(i++)); - r.matchMUC_ = boolFromString(v.at(i++)); - r.matchCase_ = boolFromString(v.at(i++)); - r.matchWholeWords_ = boolFromString(v.at(i++)); - r.action_.setHighlightText(boolFromString(v.at(i++))); - r.action_.setTextColor(v.at(i++)); - r.action_.setTextBackground(v.at(i++)); - r.action_.setPlaySound(boolFromString(v.at(i++))); - r.action_.setSoundFile(v.at(i++)); - } - catch (std::out_of_range) { - // this may happen if more properties are added to HighlightRule object, etc... - // in such case, default values (set by default constructor) will be used - } - - r.updateRegex(); - - return r; -} - bool HighlightRule::isMatch(const std::string& body, const std::string& sender, const std::string& nick, MessageType messageType) const { if ((messageType == HighlightRule::ChatMessage && matchChat_) || (messageType == HighlightRule::MUCMessage && matchMUC_)) { @@ -114,13 +69,6 @@ bool HighlightRule::isMatch(const std::string& body, const std::string& sender, bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_); bool matchesSender = senders_.empty(); - foreach (const boost::regex & rx, keywordRegex_) { - if (boost::regex_search(body, rx)) { - matchesKeyword = true; - break; - } - } - if (!matchesKeyword && nickIsKeyword_ && !nick.empty()) { if (boost::regex_search(body, regexFromString(nick))) { matchesKeyword = true; |