[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - comphelper/source desktop/source include/comphelper lingucomponent/source
Jan Holesovsky
kendy at collabora.com
Sat Jan 27 10:02:39 UTC 2018
comphelper/source/misc/lok.cxx | 48 +++++++++++++++++++
desktop/source/lib/init.cxx | 2
include/comphelper/lok.hxx | 2
lingucomponent/source/spellcheck/spell/sspellimp.cxx | 4 +
lingucomponent/source/thesaurus/libnth/nthesimp.cxx | 4 +
5 files changed, 59 insertions(+), 1 deletion(-)
New commits:
commit c896282fb7f38661cc9c39542d72ab3610ac990a
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Jan 26 20:28:46 2018 +0100
lok: Allow whitelisting languages that should be used by LibreOfficeKit.
LOK may get way too many languages if there are dictionaries for them
installed which blows the pre-init to >2G easily; let's allow limiting that.
Also make the preloading of languages work with the internal spell checking
dictionaries and thesauri.
Change-Id: I77119970030a7386a5cccbe4fdc89b15eab56ef1
Reviewed-on: https://gerrit.libreoffice.org/48722
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 2e8624d1e8d0..589f57b61bce 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -9,6 +9,8 @@
#include <comphelper/lok.hxx>
+#include <iostream>
+
namespace comphelper
{
@@ -112,6 +114,52 @@ const LanguageTag& getLanguageTag()
return g_aLanguageTag;
}
+bool isWhitelistedLanguage(const OUString& lang)
+{
+ if (!isActive())
+ return true;
+
+ static bool bInitialized = false;
+ static std::vector<OUString> aWhitelist;
+ if (!bInitialized)
+ {
+ const char* pWhitelist = getenv("LOK_WHITELIST_LANGUAGES");
+ if (pWhitelist)
+ {
+ std::stringstream stream(pWhitelist);
+ std::string s;
+
+ std::cerr << "Whitelisted languages: ";
+ while (getline(stream, s, ' ')) {
+ if (s.length() == 0)
+ continue;
+
+ std::cerr << s << " ";
+ aWhitelist.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8));
+ }
+ std::cerr << std::endl;
+ }
+
+ if (aWhitelist.empty())
+ std::cerr << "No language whitelisted, turning off the language support." << std::endl;
+
+ bInitialized = true;
+ }
+
+ if (aWhitelist.empty())
+ return false;
+
+ for (auto& entry : aWhitelist)
+ {
+ if (lang.startsWith(entry))
+ return true;
+ if (lang.startsWith(entry.replace('_', '-')))
+ return true;
+ }
+
+ return false;
+}
+
static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
static void *pStatusIndicatorCallbackData(nullptr);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 873ee9e85443..1de022c3fa68 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3616,7 +3616,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
if (eStage != PRE_INIT)
comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
- if (pUserProfileUrl)
+ if (pUserProfileUrl && eStage != PRE_INIT)
{
OUString url(
pUserProfileUrl, strlen(pUserProfileUrl), RTL_TEXTENCODING_UTF8);
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index e9634e77d6f9..9759bb524541 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -71,6 +71,8 @@ COMPHELPER_DLLPUBLIC bool isRangeHeaders();
COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag);
/// Get the current LOK's language.
COMPHELPER_DLLPUBLIC const LanguageTag& getLanguageTag();
+/// If the language name should be used for this LOK instance.
+COMPHELPER_DLLPUBLIC bool isWhitelistedLanguage(const OUString& lang);
// Status indicator handling. Even if in theory there could be several status indicators active at
// the same time, in practice there is only one at a time, so we don't handle any identification of
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
index 27b8f910448c..7e9916f224a3 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
#include <com/sun/star/linguistic2/SpellFailure.hpp>
+#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -168,6 +169,9 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
{
+ if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(aLocaleNames[k]))
+ continue;
+
aLocaleNamesSet.insert( aLocaleNames[k] );
}
}
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index f8a66da0d962..9fc3007078f6 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
#include <i18nlangtag/languagetag.hxx>
#include <tools/debug.hxx>
+#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/mutex.hxx>
#include <unotools/pathoptions.hxx>
@@ -172,6 +173,9 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
{
+ if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(aLocaleNames[k]))
+ continue;
+
aLocaleNamesSet.insert( aLocaleNames[k] );
}
}
More information about the Libreoffice-commits
mailing list