summaryrefslogtreecommitdiff
path: root/desktop/source/lib
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-09-16 13:20:28 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-09-17 17:17:30 +0200
commit0bf27ee5226496f844361e2c8cc0fbf625ec1466 (patch)
treefb5c82f701b587fd4a08c6cc8af98b5603e7fc86 /desktop/source/lib
parentb9a70d822ce54fc6976542a48ff938a1adc6661d (diff)
move setLanguageToolConfig out of extern "C" zone
no logic change here Change-Id: I29153a11e1b841fa078d29a6431cd5af1179672e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173450 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit 26e433e0e3c6dfbf2569c3b6f0a14249dc4d0c1f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173537 Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'desktop/source/lib')
-rw-r--r--desktop/source/lib/init.cxx160
1 files changed, 79 insertions, 81 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 9cc65b4b9e68..cf6088164730 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -796,6 +796,11 @@ static int lcl_getViewId(std::string_view payload)
return 0;
}
+// Wonder global state ...
+static uno::Reference<css::uno::XComponentContext> xContext;
+static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
+static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
+
namespace {
std::string extractCertificate(const std::string & certificate)
@@ -1015,6 +1020,80 @@ void hideSidebar()
SetLastExceptionMsg(u"No view shell or sidebar"_ustr);
}
+void setLanguageToolConfig()
+{
+ const char* pEnabled = ::getenv("LANGUAGETOOL_ENABLED");
+ const char* pBaseUrlString = ::getenv("LANGUAGETOOL_BASEURL");
+
+ if (pEnabled && pBaseUrlString)
+ {
+ const char* pUsername = ::getenv("LANGUAGETOOL_USERNAME");
+ const char* pApikey = ::getenv("LANGUAGETOOL_APIKEY");
+ const char* pSSLVerification = ::getenv("LANGUAGETOOL_SSL_VERIFICATION");
+ const char* pRestProtocol = ::getenv("LANGUAGETOOL_RESTPROTOCOL");
+
+ OUString aEnabled = OStringToOUString(pEnabled, RTL_TEXTENCODING_UTF8);
+ if (aEnabled != "true")
+ return;
+ OUString aBaseUrl = OStringToOUString(pBaseUrlString, RTL_TEXTENCODING_UTF8);
+ try
+ {
+ using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
+ auto batch(comphelper::ConfigurationChanges::create());
+
+ LanguageToolCfg::BaseURL::set(aBaseUrl, batch);
+ LanguageToolCfg::IsEnabled::set(true, batch);
+ if (pSSLVerification)
+ {
+ OUString aSSLVerification = OStringToOUString(pSSLVerification, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::SSLCertVerify::set(aSSLVerification == "true", batch);
+ }
+ if (pRestProtocol)
+ {
+ OUString aRestProtocol = OStringToOUString(pRestProtocol, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::RestProtocol::set(aRestProtocol, batch);
+ }
+ if (pUsername && pApikey)
+ {
+ OUString aUsername = OStringToOUString(pUsername, RTL_TEXTENCODING_UTF8);
+ OUString aApiKey = OStringToOUString(pApikey, RTL_TEXTENCODING_UTF8);
+ LanguageToolCfg::Username::set(aUsername, batch);
+ LanguageToolCfg::ApiKey::set(aApiKey, batch);
+ }
+ batch->commit();
+
+ css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv =
+ css::linguistic2::LinguServiceManager::create(xContext);
+ if (xLangSrv.is())
+ {
+ css::uno::Reference<css::linguistic2::XSpellChecker> xSpell = xLangSrv->getSpellChecker();
+ if (xSpell.is())
+ {
+ Sequence<OUString> aEmpty;
+ Sequence<css::lang::Locale> aLocales = xSpell->getLocales();
+
+ uno::Reference<linguistic2::XProofreader> xGC(
+ xContext->getServiceManager()->createInstanceWithContext(u"org.openoffice.lingu.LanguageToolGrammarChecker"_ustr, xContext),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<linguistic2::XSupportedLocales> xSuppLoc(xGC, uno::UNO_QUERY_THROW);
+
+ for (int itLocale = 0; itLocale < aLocales.getLength(); itLocale++)
+ {
+ // turn off spell checker if LanguageTool supports the locale already
+ if (xSuppLoc->hasLocale(aLocales[itLocale]))
+ xLangSrv->setConfiguredServices(
+ SN_SPELLCHECKER, aLocales[itLocale], aEmpty);
+ }
+ }
+ }
+ }
+ catch(uno::Exception const& rException)
+ {
+ SAL_WARN("lok", "Failed to set LanguageTool API settings: " << rException.Message);
+ }
+ }
+}
+
} // end anonymous namespace
// Could be anonymous in principle, but for the unit testing purposes, we
@@ -2704,11 +2783,6 @@ void setFormatSpecificFilterData(std::u16string_view sFormat, comphelper::Sequen
} // anonymous namespace
-// Wonder global state ...
-static uno::Reference<css::uno::XComponentContext> xContext;
-static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
-static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
-
static LibreOfficeKitDocument* lo_documentLoad(LibreOfficeKit* pThis, const char* pURL)
{
return lo_documentLoadWithOptions(pThis, pURL, nullptr);
@@ -7798,8 +7872,6 @@ static void preLoadShortCutAccelerators()
batch->commit();
}
-void setLanguageToolConfig();
-
/// Used only by LibreOfficeKit when used by Online to pre-initialize
static void preloadData()
{
@@ -8057,80 +8129,6 @@ void setDeeplConfig()
}
}
-void setLanguageToolConfig()
-{
- const char* pEnabled = ::getenv("LANGUAGETOOL_ENABLED");
- const char* pBaseUrlString = ::getenv("LANGUAGETOOL_BASEURL");
-
- if (pEnabled && pBaseUrlString)
- {
- const char* pUsername = ::getenv("LANGUAGETOOL_USERNAME");
- const char* pApikey = ::getenv("LANGUAGETOOL_APIKEY");
- const char* pSSLVerification = ::getenv("LANGUAGETOOL_SSL_VERIFICATION");
- const char* pRestProtocol = ::getenv("LANGUAGETOOL_RESTPROTOCOL");
-
- OUString aEnabled = OStringToOUString(pEnabled, RTL_TEXTENCODING_UTF8);
- if (aEnabled != "true")
- return;
- OUString aBaseUrl = OStringToOUString(pBaseUrlString, RTL_TEXTENCODING_UTF8);
- try
- {
- using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
- auto batch(comphelper::ConfigurationChanges::create());
-
- LanguageToolCfg::BaseURL::set(aBaseUrl, batch);
- LanguageToolCfg::IsEnabled::set(true, batch);
- if (pSSLVerification)
- {
- OUString aSSLVerification = OStringToOUString(pSSLVerification, RTL_TEXTENCODING_UTF8);
- LanguageToolCfg::SSLCertVerify::set(aSSLVerification == "true", batch);
- }
- if (pRestProtocol)
- {
- OUString aRestProtocol = OStringToOUString(pRestProtocol, RTL_TEXTENCODING_UTF8);
- LanguageToolCfg::RestProtocol::set(aRestProtocol, batch);
- }
- if (pUsername && pApikey)
- {
- OUString aUsername = OStringToOUString(pUsername, RTL_TEXTENCODING_UTF8);
- OUString aApiKey = OStringToOUString(pApikey, RTL_TEXTENCODING_UTF8);
- LanguageToolCfg::Username::set(aUsername, batch);
- LanguageToolCfg::ApiKey::set(aApiKey, batch);
- }
- batch->commit();
-
- css::uno::Reference<css::linguistic2::XLinguServiceManager2> xLangSrv =
- css::linguistic2::LinguServiceManager::create(xContext);
- if (xLangSrv.is())
- {
- css::uno::Reference<css::linguistic2::XSpellChecker> xSpell = xLangSrv->getSpellChecker();
- if (xSpell.is())
- {
- Sequence<OUString> aEmpty;
- Sequence<css::lang::Locale> aLocales = xSpell->getLocales();
-
- uno::Reference<linguistic2::XProofreader> xGC(
- xContext->getServiceManager()->createInstanceWithContext(u"org.openoffice.lingu.LanguageToolGrammarChecker"_ustr, xContext),
- uno::UNO_QUERY_THROW);
- uno::Reference<linguistic2::XSupportedLocales> xSuppLoc(xGC, uno::UNO_QUERY_THROW);
-
- for (int itLocale = 0; itLocale < aLocales.getLength(); itLocale++)
- {
- // turn off spell checker if LanguageTool supports the locale already
- if (xSuppLoc->hasLocale(aLocales[itLocale]))
- xLangSrv->setConfiguredServices(
- SN_SPELLCHECKER, aLocales[itLocale], aEmpty);
- }
- }
- }
- }
- catch(uno::Exception const& rException)
- {
- SAL_WARN("lok", "Failed to set LanguageTool API settings: " << rException.Message);
- }
- }
-}
-
}
static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfileUrl)