From 3391e8f1b7463ae3d5ce95267f1fabd0305eceae Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 9 Jun 2023 20:31:53 +0300 Subject: [PATCH] generic: port to the new spelling classes Signed-off-by: Ivailo Monev --- kdeplasma-addons/applets/spellcheck/SpellCheck.cpp | 2 +- kdeplasma-addons/applets/spellcheck/SpellCheck.h | 5 ++--- .../runners/spellchecker/spellcheck.cpp | 25 +++++++++++----------- kdeplasma-addons/runners/spellchecker/spellcheck.h | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/kdeplasma-addons/applets/spellcheck/SpellCheck.cpp b/kdeplasma-addons/applets/spellcheck/SpellCheck.cpp index 32748674..8cfe2cb3 100644 --- a/kdeplasma-addons/applets/spellcheck/SpellCheck.cpp +++ b/kdeplasma-addons/applets/spellcheck/SpellCheck.cpp @@ -199,7 +199,7 @@ void SpellCheck::toggleDialog(bool pasteText, bool preferSelection) m_textEdit->setCheckSpellingEnabled(true); m_textEdit->createHighlighter(); - m_dictionaryComboBox = new Sonnet::DictionaryComboBox(m_spellingDialog); + m_dictionaryComboBox = new KSpellDictionaryComboBox(m_spellingDialog); m_dictionaryComboBox->setToolTip(i18n("Language")); KAction *spellingAction = new KAction(KIcon("tools-check-spelling"), i18n("Spell checking"), m_spellingDialog); diff --git a/kdeplasma-addons/applets/spellcheck/SpellCheck.h b/kdeplasma-addons/applets/spellcheck/SpellCheck.h index 5fac5eb6..564f24ff 100644 --- a/kdeplasma-addons/applets/spellcheck/SpellCheck.h +++ b/kdeplasma-addons/applets/spellcheck/SpellCheck.h @@ -29,8 +29,7 @@ #include #include -#include -#include +#include class SpellCheck : public Plasma::Applet { @@ -62,7 +61,7 @@ protected slots: private: KTextEdit *m_textEdit; Plasma::Dialog *m_spellingDialog; - Sonnet::DictionaryComboBox *m_dictionaryComboBox; + KSpellDictionaryComboBox *m_dictionaryComboBox; int m_dragTimer; }; diff --git a/kdeplasma-addons/runners/spellchecker/spellcheck.cpp b/kdeplasma-addons/runners/spellchecker/spellcheck.cpp index a040e598..f3a0029f 100644 --- a/kdeplasma-addons/runners/spellchecker/spellcheck.cpp +++ b/kdeplasma-addons/runners/spellchecker/spellcheck.cpp @@ -54,12 +54,12 @@ void SpellCheckRunner::loaddata() { //Load the default speller, with the default language if (!m_spellers.contains("")) { - m_spellers[""] = QSharedPointer (new Sonnet::Speller("")); + m_spellers[""] = QSharedPointer (new KSpeller(KGlobal::config().data())); } //store all language names, makes it possible to type "spell german TERM" if english locale is set //Need to construct a map between natual language names and names the spell-check recognises. KLocale *locale = KGlobal::locale(); - const QStringList avail = m_spellers[""]->availableLanguages(); + const QStringList avail = m_spellers[""]->dictionaries(); //We need to filter the available languages so that we associate the natural language //name (eg. 'german') with one sub-code. QSet families; @@ -73,8 +73,8 @@ void SpellCheckRunner::loaddata() QString code; //If we only have one code, use it. //If a string is the default language, use it - if (family.contains(m_spellers[""]->language())) { - code = m_spellers[""]->language(); + if (family.contains(m_spellers[""]->dictionary())) { + code = m_spellers[""]->dictionary(); } else if (fcode == QLatin1String("en")) { //If the family is english, default to en_US. if (family.contains("en_US")) { @@ -130,7 +130,7 @@ void SpellCheckRunner::reloadConfiguration() QString SpellCheckRunner::findlang(const QStringList& terms) { //If first term is a language code (like en_GB), set it as the spell-check language - if (terms.count() >= 1 && m_spellers[""]->availableLanguages().contains(terms[0])) { + if (terms.count() >= 1 && m_spellers[""]->dictionaries().contains(terms[0])) { return terms[0]; } //If we have two terms and the first is a language name (eg 'french'), @@ -154,7 +154,7 @@ QString SpellCheckRunner::findlang(const QStringList& terms) if (!code.isEmpty()) { //We found a valid language! Check still available - const QStringList avail = m_spellers[""]->availableLanguages(); + const QStringList avail = m_spellers[""]->dictionaries(); //Does the spell-checker like it? if (avail.contains(code)) { return code; @@ -183,9 +183,9 @@ void SpellCheckRunner::match(Plasma::RunnerContext &context) } //Pointer to speller object with our chosen language - QSharedPointer speller = m_spellers[""]; + QSharedPointer speller = m_spellers[""]; - if (speller->isValid()) { + if (!speller->dictionary().isEmpty()) { QStringList terms = query.split(' ', QString::SkipEmptyParts); QString lang = findlang(terms); //If we found a language, create a new speller object using it. @@ -197,7 +197,8 @@ void SpellCheckRunner::match(Plasma::RunnerContext &context) QMutexLocker lock (&m_spellLock); //Check nothing happened while we were acquiring the lock if (!m_spellers.contains(lang)) { - m_spellers[lang] = QSharedPointer(new Sonnet::Speller(lang)); + m_spellers[lang] = QSharedPointer(new KSpeller(KGlobal::config().data())); + m_spellers[lang]->setDictionary(lang); } } speller = m_spellers[lang]; @@ -213,13 +214,13 @@ void SpellCheckRunner::match(Plasma::RunnerContext &context) Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::InformationalMatch); - if (speller->isValid()) { - QStringList suggestions; - const bool correct = speller->checkAndSuggest(query,suggestions); + if (!speller->dictionary().isEmpty()) { + const bool correct = speller->check(query); if (correct) { match.setIcon(KIcon(QLatin1String( "checkbox" ))); match.setText(i18n("Correct")+QLatin1String(": ")+query); } else { + QStringList suggestions = speller->suggest(query); match.setIcon(KIcon(QLatin1String( "edit-delete" ))); const QString recommended = i18n("Suggested words: %1", suggestions.join(i18nc("seperator for a list of words", ", "))); //TODO: try setting a text and a subtext, with the subtext being the suggestions diff --git a/kdeplasma-addons/runners/spellchecker/spellcheck.h b/kdeplasma-addons/runners/spellchecker/spellcheck.h index d91e35ad..0f627e93 100644 --- a/kdeplasma-addons/runners/spellchecker/spellcheck.h +++ b/kdeplasma-addons/runners/spellchecker/spellcheck.h @@ -19,7 +19,7 @@ #ifndef SPELLCHECK_H #define SPELLCHECK_H -#include +#include #include #include @@ -52,7 +52,7 @@ private: QString m_triggerWord; QMap m_languages;//key=language name, value=language code bool m_requireTriggerWord; - QMap > m_spellers; //spellers + QMap > m_spellers; //spellers QMutex m_spellLock; //Lock held when constructing a new speller }; -- 2.11.0