OSDN Git Service

generic: port to the new spelling classes
authorIvailo Monev <xakepa10@gmail.com>
Fri, 9 Jun 2023 17:31:53 +0000 (20:31 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 9 Jun 2023 17:31:53 +0000 (20:31 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kdeplasma-addons/applets/spellcheck/SpellCheck.cpp
kdeplasma-addons/applets/spellcheck/SpellCheck.h
kdeplasma-addons/runners/spellchecker/spellcheck.cpp
kdeplasma-addons/runners/spellchecker/spellcheck.h

index 3274867..8cfe2cb 100644 (file)
@@ -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);
index 5fac5eb..564f24f 100644 (file)
@@ -29,8 +29,7 @@
 #include <Plasma/Applet>
 #include <Plasma/Dialog>
 
-#include <Sonnet/Highlighter>
-#include <Sonnet/DictionaryComboBox>
+#include <KSpellDictionaryComboBox>
 
 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;
 };
 
index a040e59..f3a0029 100644 (file)
@@ -54,12 +54,12 @@ void SpellCheckRunner::loaddata()
 {
     //Load the default speller, with the default language
     if (!m_spellers.contains("")) {
-        m_spellers[""] = QSharedPointer<Sonnet::Speller> (new Sonnet::Speller(""));
+        m_spellers[""] = QSharedPointer<KSpeller> (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<QString> 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<Sonnet::Speller> speller = m_spellers[""];
+    QSharedPointer<KSpeller> 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<Sonnet::Speller>(new Sonnet::Speller(lang));
+                    m_spellers[lang] = QSharedPointer<KSpeller>(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
index d91e35a..0f627e9 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef SPELLCHECK_H
 #define SPELLCHECK_H
 
-#include <sonnet/speller.h>
+#include <kspeller.h>
 
 #include <plasma/abstractrunner.h>
 #include <QSharedPointer>
@@ -52,7 +52,7 @@ private:
     QString m_triggerWord;
     QMap<QString, QString> m_languages;//key=language name, value=language code
     bool m_requireTriggerWord;
-    QMap<QString, QSharedPointer<Sonnet::Speller> > m_spellers; //spellers
+    QMap<QString, QSharedPointer<KSpeller> > m_spellers; //spellers
     QMutex m_spellLock; //Lock held when constructing a new speller
 };