diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-02 08:09:18 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-03-10 08:58:57 (GMT) |
commit | 2ec46186d21b0e9620e56da2430c6eadf170bf3b (patch) | |
tree | dc49c90d37710dbb3045aa17367dbaf9e26d0fda /Swift | |
parent | 4da2f1c85f2eeac9fb98d5dcc9097eeed9b34e8b (diff) | |
download | swift-2ec46186d21b0e9620e56da2430c6eadf170bf3b.zip swift-2ec46186d21b0e9620e56da2430c6eadf170bf3b.tar.bz2 |
Fix crashes in spellchecking code in case of broken backend
If Swift uses Hunspell as spellchecking backend its
configuration can fail, because a dictionary is missing
or a wrong path was specified.
Instead of crashing, spellchecking will be disabled and a
warning is printed to the terminal.
Test-Information:
Tested on Debian 8 with Qt 5.3.2.
Tested enabling/disabling of spellchecking in the UI,
selecting different dictionaries and broken dictionaries.
Change-Id: Ib6d73ed3d7a6a3701410b0f6dc983d41e807df82
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index a0188d9..adf3878 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -13,9 +13,9 @@ #include <QApplication> #include <QKeyEvent> #include <QMenu> -#include <QTime> #include <QTextDocument> +#include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> #include <Swift/Controllers/SettingConstants.h> @@ -181,15 +181,23 @@ void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) #ifdef HAVE_SPELLCHECKER void QtTextEdit::setUpSpellChecker() { + delete highlighter_; + highlighter_ = NULL; delete checker_; checker_ = NULL; if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) { std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH); std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE); checker_ = SpellCheckerFactory().createSpellChecker(dictPath + dictFile); - delete highlighter_; - highlighter_ = NULL; - highlighter_ = new QtSpellCheckHighlighter(document(), checker_); + if (checker_) { + highlighter_ = new QtSpellCheckHighlighter(document(), checker_); + } + else { + // Spellchecking is not working, as we did not get a valid checker from the factory. Disable spellchecking. + SWIFT_LOG(warning) << "Spellchecking is currently misconfigured in Swift (e.g. missing dictionary or broken dictionary file). Disable spellchecking." << std::endl; + settings_->storeSetting(SettingConstants::SPELL_CHECKER, false); + } + } } #endif @@ -213,7 +221,9 @@ void QtTextEdit::handleSettingChanged(const std::string& settings) { || settings == SettingConstants::DICT_FILE.getKey()) { #ifdef HAVE_SPELLCHECKER setUpSpellChecker(); - highlighter_->rehighlight(); + if (highlighter_) { + highlighter_->rehighlight(); + } #endif } } |