summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-01-31 14:57:22 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2017-02-27 14:07:13 (GMT)
commitfc8f5b31c22ed7af4f0e2473f269601a87a0438c (patch)
tree0c59a9debf72247c7409947a3a4cccb6c616dd06 /Swift/Controllers/HighlightManager.cpp
parentabd81d4a3cf08ffaa1e5265d204cdd80c8c0583b (diff)
downloadswift-fc8f5b31c22ed7af4f0e2473f269601a87a0438c.zip
swift-fc8f5b31c22ed7af4f0e2473f269601a87a0438c.tar.bz2
Redesign highlight logic and processing
The new highlight logic follows a simpler model. It supports: * highlighting of whole words in a message * highlighting messages by sender name * highlighting if the user’s name is mentioned Possible actions for these highlights are text colouring, sound playback of WAV files, and system notifications. In addition the user can decide to receive sound and system notification on general incoming direct and group messages. Redesigned the highlight configuration UI dialog for this new model. ChatMessageParser class now deals with all parsing and marking up the chat message with the matching HighlightActions. Highlighter class has been extended to deal with all sound and system notification highlights that should be emitted by a specified chat message. Moved some tests over to gtest in the process. Test-Information: Tested UI on macOS 10.12.3 with Qt 5.7.1. Manually tested that correct system notification are emitted on mentions, keyword highlights and general messages. Added new unit tests to cover new highlighting behaviour. Change-Id: I1c89e29d81022174187fb44af0d384036ec51594
Diffstat (limited to 'Swift/Controllers/HighlightManager.cpp')
-rw-r--r--Swift/Controllers/HighlightManager.cpp148
1 files changed, 0 insertions, 148 deletions
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp
deleted file mode 100644
index 9176301..0000000
--- a/Swift/Controllers/HighlightManager.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2012 Maciej Niedzielski
- * Licensed under the simplified BSD license.
- * See Documentation/Licenses/BSD-simplified.txt for more information.
- */
-
-/*
- * Copyright (c) 2014-2016 Isode Limited.
- * All rights reserved.
- * See the COPYING file for more information.
- */
-
-#include <Swift/Controllers/HighlightManager.h>
-
-#include <cassert>
-#include <sstream>
-
-#include <boost/algorithm/string.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 <Swift/Controllers/Highlighter.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.
- * Highligher may be customized by using setNick(), etc.
- *
- * ChatControllerBase passes incoming messages to Highlighter and gets HighlightAction in return
- * (first matching rule is returned).
- * If needed, HighlightAction is then passed back to Highlighter for further handling.
- * This results in HighlightManager emiting onHighlight event,
- * which is handled by SoundController to play sound notification
- */
-
-namespace Swift {
-
-HighlightManager::HighlightManager(SettingsProvider* settings)
- : settings_(settings)
- , storingSettings_(false) {
- rules_ = std::make_shared<HighlightRulesList>();
- loadSettings();
- handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1));
-}
-
-void HighlightManager::handleSettingChanged(const std::string& settingPath) {
- if (!storingSettings_ && SettingConstants::HIGHLIGHT_RULES.getKey() == settingPath) {
- loadSettings();
- }
-}
-
-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> rules;
-
- HighlightRule chatNotificationRule;
- chatNotificationRule.setMatchChat(true);
- chatNotificationRule.getAction().setPlaySound(true);
- chatNotificationRule.setMatchWholeWords(true);
- rules.push_back(chatNotificationRule);
-
- HighlightRule selfMentionMUCRule;
- selfMentionMUCRule.setMatchMUC(true);
- selfMentionMUCRule.getAction().setPlaySound(true);
- selfMentionMUCRule.setNickIsKeyword(true);
- selfMentionMUCRule.setMatchCase(true);
- selfMentionMUCRule.setMatchWholeWords(true);
- rules.push_back(selfMentionMUCRule);
-
- return rules;
-}
-
-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) {
- 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) {
- 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) {
- assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) < rules_->getSize());
- rules_->list_.erase(rules_->list_.begin() + index);
-}
-
-void HighlightManager::swapRules(const size_t first, const size_t second) {
- assert(first < rules_->getSize());
- assert(second < rules_->getSize());
- const HighlightRule swap = rules_->getRule(first);
- rules_->setRule(first, rules_->getRule(second));
- rules_->setRule(second, swap);
-}
-
-void HighlightManager::storeSettings() {
- storingSettings_ = true; // don't reload settings while saving
- settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString());
- storingSettings_ = false;
-}
-
-void HighlightManager::loadSettings() {
- std::string rulesString = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES);
- std::stringstream stream;
- stream << rulesString;
- try {
- boost::archive::text_iarchive archive(stream);
- archive >> rules_->list_;
- } catch (boost::archive::archive_exception&) {
- rules_->list_ = getDefaultRules();
- }
-}
-
-Highlighter* HighlightManager::createHighlighter() {
- return new Highlighter(this);
-}
-
-bool HighlightManager::isDefaultRulesList() const {
- return getDefaultRules() == rules_->list_;
-}
-
-void HighlightManager::resetToDefaultRulesList() {
- rules_->list_ = getDefaultRules();
-}
-
-}