[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sonnet] src/core: Don't impose using the default client
From:       R.J.V. Bertin <null () kde ! org>
Date:       2018-04-07 17:41:00
Message-ID: E1f4rpk-0006qc-EY () code ! kde ! org
[Download RAW message or body]

Git commit e63a234d55d90502500b4913c6ecb813c97d8235 by R.J.V. Bertin.
Committed on 07/04/2018 at 17:40.
Pushed by rjvbb into branch 'master'.

Don't impose using the default client

With this change, Sonnet's default client concept and the actual
behaviour are in better correspondence. The backend defined by the
defaultClient key in the Sonnet settings file will now be used only
if it supports the requested language. If not, Sonnet will fall back
to whatever backend is most reliable for that language.

Differential Revision: https://phabricator.kde.org/D11183

M  +19   -4    src/core/loader.cpp

https://commits.kde.org/sonnet/e63a234d55d90502500b4913c6ecb813c97d8235

diff --git a/src/core/loader.cpp b/src/core/loader.cpp
index f41c1e7..13c5c25 100644
--- a/src/core/loader.cpp
+++ b/src/core/loader.cpp
@@ -31,6 +31,8 @@
 #include "core_debug.h"
 #include <QDir>
 
+#include <algorithm>
+
 #ifdef SONNET_STATIC
 #include "../plugins/hunspell/hunspellclient.h"
 #ifdef Q_OS_MACOS
@@ -84,13 +86,9 @@ SpellerPlugin *Loader::createSpeller(const QString &language, \
const QString &cli  QString backend = clientName;
     QString plang = language;
 
-    if (backend.isEmpty()) {
-        backend = d->settings->defaultClient();
-    }
     if (plang.isEmpty()) {
         plang = d->settings->defaultLanguage();
     }
-
     const QVector<Client *> lClients = d->languageClients[plang];
 
     if (lClients.isEmpty()) {
@@ -98,22 +96,39 @@ SpellerPlugin *Loader::createSpeller(const QString &language, \
const QString &cli  return nullptr;
     }
 
+    if (backend.isEmpty()) {
+        backend = d->settings->defaultClient();
+        if (!backend.isEmpty()) {
+            // check if the default client supports the requested language;
+            // if it does it will be an element of lClients.
+            bool unknown = !std::any_of(lClients.constBegin(), lClients.constEnd(), \
[backend] (const Client *client) { +                    return client->name() == \
backend; }); +            if (unknown) {
+                qCWarning(SONNET_LOG_CORE) << "Default client" << backend << \
"doesn't support language:" << plang; +                backend = QString();
+            }
+        }
+    }
+
     QVectorIterator<Client *> itr(lClients);
     while (itr.hasNext()) {
         Client *item = itr.next();
         if (!backend.isEmpty()) {
             if (backend == item->name()) {
                 SpellerPlugin *dict = item->createSpeller(plang);
+                qCDebug(SONNET_LOG_CORE) << "Using the" << item->name() << "plugin \
for language" << plang;  return dict;
             }
         } else {
             //the first one is the one with the highest
             //reliability
             SpellerPlugin *dict = item->createSpeller(plang);
+            qCDebug(SONNET_LOG_CORE) << "Using the" << item->name() << "plugin for \
language" << plang;  return dict;
         }
     }
 
+    qCWarning(SONNET_LOG_CORE) << "The default client" << backend << "has no \
language dictionaries for the language:" << plang;  return nullptr;
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic