From ff4b006a565f2a945903a131f46d637d8b77188e Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git@the-compiler.org>
Date: Tue, 1 Aug 2017 16:52:02 +0200
Subject: [PATCH] Add a QTWEBENGINE_DICTIONARIES_PATH environment variable

On a Linux system with an installed application, the only places dictionaries
are searched currently are /usr/bin/qtwebengine_dictionaries and
/usr/share/qt/qtwebengine_dictionaries (or similar, depending on the
distribution).

This adds an environment variable which makes it possible to customize the
location dictionaries are in (e.g. to something user-writable).

Documentation is added in the next commit, as it was duplicated in four
different locations and I cleaned it up a bit.

[ChangeLog] New QTWEBENGINE_DICTIONARIES_PATH environment variable to customize
the location for spell checking dictionaries.

Task-number: QTBUG-62236
Change-Id: Iefc90451c537656025abb785291fe55f6a82d50c
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Reviewed-by: Viktor Engelmann <viktor.engelmann@qt.io>
---
 src/core/web_engine_library_info.cpp | 34 ++++++++++++++++------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/core/web_engine_library_info.cpp b/src/core/web_engine_library_info.cpp
index f46f8f425..35b139602 100644
--- a/src/core/web_engine_library_info.cpp
+++ b/src/core/web_engine_library_info.cpp
@@ -216,26 +216,32 @@ QString dictionariesPath()
     if (!initialized) {
         initialized = true;
 
-        // First try to find dictionaries near the application.
+        const QByteArray fromEnv = qgetenv("QTWEBENGINE_DICTIONARIES_PATH");
+        if (!fromEnv.isEmpty()) {
+            // Only search in QTWEBENGINE_DICTIONARIES_PATH if set
+            candidatePaths << QString::fromLocal8Bit(fromEnv);
+        } else {
+            // First try to find dictionaries near the application.
 #ifdef OS_MACOSX
-        QString resourcesDictionariesPath = getMainApplicationResourcesPath()
-                % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
-        candidatePaths << resourcesDictionariesPath;
+            QString resourcesDictionariesPath = getMainApplicationResourcesPath()
+                    % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
+            candidatePaths << resourcesDictionariesPath;
 #endif
-        QString applicationDictionariesPath = QCoreApplication::applicationDirPath()
-                % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
-        candidatePaths << applicationDictionariesPath;
+            QString applicationDictionariesPath = QCoreApplication::applicationDirPath()
+                    % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
+            candidatePaths << applicationDictionariesPath;
 
-        // Then try to find dictionaries near the installed library.
+            // Then try to find dictionaries near the installed library.
 #if defined(OS_MACOSX) && defined(QT_MAC_FRAMEWORK_BUILD)
-        QString frameworkDictionariesPath = getResourcesPath(frameworkBundle())
-                % QLatin1String("/qtwebengine_dictionaries");
-        candidatePaths << frameworkDictionariesPath;
+            QString frameworkDictionariesPath = getResourcesPath(frameworkBundle())
+                    % QLatin1String("/qtwebengine_dictionaries");
+            candidatePaths << frameworkDictionariesPath;
 #endif
 
-        QString libraryDictionariesPath = QLibraryInfo::location(QLibraryInfo::DataPath)
-                % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
-        candidatePaths << libraryDictionariesPath;
+            QString libraryDictionariesPath = QLibraryInfo::location(QLibraryInfo::DataPath)
+                    % QDir::separator() % QLatin1String("qtwebengine_dictionaries");
+            candidatePaths << libraryDictionariesPath;
+        }
 
         Q_FOREACH (const QString &candidate, candidatePaths) {
             if (QFileInfo::exists(candidate)) {
-- 
GitLab