diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-08 13:36:27 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-03-29 14:13:20 (GMT) |
commit | 74e51310d27e9d9a66d2d790360549c48abec8d1 (patch) | |
tree | d350bf7cd62c144e561841b4a228b0f60cb76957 /Swift/Controllers/HighlightManager.cpp | |
parent | c26314684cd4e6140e5ea882285c2076505bd53d (diff) | |
download | swift-74e51310d27e9d9a66d2d790360549c48abec8d1.zip swift-74e51310d27e9d9a66d2d790360549c48abec8d1.tar.bz2 |
Refactored keyword highlighting
This commit changes the ChatWindow/ChatView APIs to not pass
highlights actions as additional parameters but instead they
are now part of the ChatWindow::ChatMessage and its parts.
This allows the controllers to do highlighting in one single
place and play sound actions on the highlighted message in
a single place.
On a highlighted message only unique sounds are played and
they are played in sequence of the rules that matched
the message.
Test-Information:
Adjusted the existing unit tests accordingly. Added unit
tests that check reduplication of highlight action sounds
and that the sound actions are emitted correctly.
Manually verified that highlight sound actions with and
without duplicated sounds are audible on OS X 10.11.3.
Change-Id: I68c88e0d285d79d87b2997ed29d92b140480b394
Diffstat (limited to 'Swift/Controllers/HighlightManager.cpp')
-rw-r--r-- | Swift/Controllers/HighlightManager.cpp | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index e5c8cef..07f8e54 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2014-2015 Isode Limited. + * Copyright (c) 2014-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -49,30 +49,26 @@ namespace Swift { HighlightManager::HighlightManager(SettingsProvider* settings) : settings_(settings) - , storingSettings_(false) -{ + , storingSettings_(false) { rules_ = boost::make_shared<HighlightRulesList>(); loadSettings(); handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1)); } -void HighlightManager::handleSettingChanged(const std::string& settingPath) -{ +void HighlightManager::handleSettingChanged(const std::string& settingPath) { if (!storingSettings_ && SettingConstants::HIGHLIGHT_RULES.getKey() == settingPath) { loadSettings(); } } -std::string HighlightManager::rulesToString() const -{ +std::string HighlightManager::rulesToString() const { std::stringstream stream; boost::archive::text_oarchive archive(stream); archive << rules_->list_; return stream.str(); } -std::vector<HighlightRule> HighlightManager::getDefaultRules() -{ +std::vector<HighlightRule> HighlightManager::getDefaultRules() { std::vector<HighlightRule> rules; HighlightRule chatNotificationRule; @@ -92,26 +88,22 @@ std::vector<HighlightRule> HighlightManager::getDefaultRules() return rules; } -HighlightRule HighlightManager::getRule(int index) const -{ +HighlightRule HighlightManager::getRule(int index) const { assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize()); return rules_->getRule(static_cast<size_t>(index)); } -void HighlightManager::setRule(int index, const HighlightRule& rule) -{ +void HighlightManager::setRule(int index, const HighlightRule& rule) { assert(index >= 0 && static_cast<size_t>(index) < rules_->getSize()); rules_->list_[static_cast<size_t>(index)] = rule; } -void HighlightManager::insertRule(int index, const HighlightRule& rule) -{ +void HighlightManager::insertRule(int index, const HighlightRule& rule) { assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) <= rules_->getSize()); rules_->list_.insert(rules_->list_.begin() + index, rule); } -void HighlightManager::removeRule(int index) -{ +void HighlightManager::removeRule(int index) { assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) < rules_->getSize()); rules_->list_.erase(rules_->list_.begin() + index); } @@ -124,15 +116,13 @@ void HighlightManager::swapRules(const size_t first, const size_t second) { rules_->setRule(second, swap); } -void HighlightManager::storeSettings() -{ +void HighlightManager::storeSettings() { storingSettings_ = true; // don't reload settings while saving settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString()); storingSettings_ = false; } -void HighlightManager::loadSettings() -{ +void HighlightManager::loadSettings() { std::string rulesString = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES); std::stringstream stream; stream << rulesString; @@ -144,8 +134,7 @@ void HighlightManager::loadSettings() } } -Highlighter* HighlightManager::createHighlighter() -{ +Highlighter* HighlightManager::createHighlighter() { return new Highlighter(this); } |