summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2023-01-11 16:14:57 -0400
committerHenry Castro <hcastro@collabora.com>2023-02-03 12:32:24 +0000
commitf74031d4eaeb289f062f77209da10d464c09c2a6 (patch)
treed0dafe2b4e867eab597c4d2a855229164bfc74e0 /desktop
parent52ebc632b3cfa122dcb178cf28d8dbc7c7c57007 (diff)
lok: add function getDocLanguages
If the spell checker is disabled to use a remote spelling feature, the getLanguages function is obsolete. In order to not break stable functions, introduce the getDocLanguages for the remote spelling feature. Signed-off-by: Henry Castro <hcastro@collabora.com> Change-Id: Ic210f31eddd3208b29d073ff35ba4fa2d98ea772 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145363 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com> (cherry picked from commit bb0c63cc73998a0f67ae4c3e59acea3827a6e11c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146399 Tested-by: Jenkins
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx129
1 files changed, 127 insertions, 2 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 71c53f2d097a..d19d2717ffaa 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -77,6 +77,7 @@
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/document/XDocumentLanguages.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/DispatchResultEvent.hpp>
#include <com/sun/star/frame/DispatchResultState.hpp>
@@ -102,6 +103,7 @@
#include <com/sun/star/xml/crypto/XCertificateCreator.hpp>
#include <com/sun/star/security/XCertificate.hpp>
+#include <com/sun/star/linguistic2/LanguageGuessing.hpp>
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
#include <com/sun/star/linguistic2/XSpellChecker.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
@@ -5384,6 +5386,119 @@ static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, in
pDoc->setGraphicSelection(nType, nX, nY);
}
+static void getDocLanguages(LibreOfficeKitDocument* pThis, uno::Sequence<lang::Locale>& rSeq)
+{
+ SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if (!pViewFrame)
+ return;
+
+ SfxDispatcher* pDispatcher = pViewFrame->GetBindings().GetDispatcher();
+ if (!pDispatcher)
+ return;
+
+ css::uno::Any aLangStatus;
+ pDispatcher->QueryState(SID_LANGUAGE_STATUS, aLangStatus);
+
+ Sequence<OUString> aSeqLang;
+ if (!(aLangStatus >>= aSeqLang))
+ return;
+
+ // (aSeqLang[0] == "Current Language", aSeqLang[1] == "Script Type",
+ // aSeqLang[2] == "Keyboard Language", aSeqLang[3] == "Guess Text Lang")
+ if (aSeqLang.getLength() != 4)
+ return;
+
+ LanguageType nLangType;
+ std::set<LanguageType> aLangItems;
+ SvtScriptType eScriptType = static_cast<SvtScriptType>(aSeqLang[1].toInt32());
+
+ if (!aSeqLang[0].isEmpty())
+ {
+ nLangType = SvtLanguageTable::GetLanguageType(aSeqLang[0]);
+ if (nLangType != LANGUAGE_DONTKNOW)
+ {
+ aLangItems.insert(nLangType);
+ }
+ }
+
+ const AllSettings& rAllSettings = Application::GetSettings();
+ nLangType = rAllSettings.GetLanguageTag().getLanguageType();
+ if (nLangType != LANGUAGE_DONTKNOW &&
+ (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+ {
+ aLangItems.insert(nLangType);
+ }
+
+ nLangType = rAllSettings.GetUILanguageTag().getLanguageType();
+ if (nLangType != LANGUAGE_DONTKNOW &&
+ (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+ {
+ aLangItems.insert(nLangType);
+ }
+
+ if (!aSeqLang[2].isEmpty())
+ {
+ nLangType = SvtLanguageTable::GetLanguageType(aSeqLang[2]);
+ if (nLangType != LANGUAGE_DONTKNOW &&
+ (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+ {
+ aLangItems.insert(nLangType);
+ }
+ }
+
+ if (!aSeqLang[3].isEmpty())
+ {
+ Reference<linguistic2::XLanguageGuessing> xLangGuesser;
+ try
+ {
+ xLangGuesser = linguistic2::LanguageGuessing::create(xContext);
+ }
+ catch(...)
+ {
+ }
+
+ if (xLangGuesser.is())
+ {
+ lang::Locale aLocale = xLangGuesser->guessPrimaryLanguage(aSeqLang[3], 0,
+ aSeqLang[3].getLength());
+ nLangType = LanguageTag(aLocale).makeFallback().getLanguageType();
+ if (nLangType != LANGUAGE_DONTKNOW &&
+ (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+ {
+ aLangItems.insert(nLangType);
+ }
+ }
+ }
+
+ LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+ Reference<document::XDocumentLanguages> xDocumentLanguages(pDocument->mxComponent, UNO_QUERY);
+ if (xDocumentLanguages.is())
+ {
+ const Sequence<lang::Locale> aLocales(xDocumentLanguages->getDocumentLanguages(
+ static_cast<sal_Int16>(eScriptType), 64));
+
+ for (const lang::Locale& aLocale : aLocales)
+ {
+ nLangType = SvtLanguageTable::GetLanguageType(aLocale.Language);
+ if (nLangType != LANGUAGE_DONTKNOW &&
+ (eScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType)))
+ {
+ aLangItems.insert(nLangType);
+ }
+ }
+ }
+
+ int nLocale = 0;
+ Sequence<lang::Locale> aLocales(aLangItems.size());
+ auto pLocales = aLocales.getArray();
+ for (const LanguageType& itLang : aLangItems)
+ {
+ pLocales[nLocale++] = LanguageTag::convertToLocale(itLang);
+ }
+
+ rSeq = aLocales;
+}
+
static void doc_resetSelection(LibreOfficeKitDocument* pThis)
{
comphelper::ProfileZone aZone("doc_resetSelection");
@@ -5401,7 +5516,7 @@ static void doc_resetSelection(LibreOfficeKitDocument* pThis)
pDoc->resetSelection();
}
-static char* getLanguages(const char* pCommand)
+static char* getLanguages(LibreOfficeKitDocument* pThis, const char* pCommand)
{
css::uno::Sequence< css::lang::Locale > aLocales;
@@ -5414,6 +5529,16 @@ static char* getLanguages(const char* pCommand)
if (xSpell.is())
aLocales = xSpell->getLocales();
}
+
+ /* FIXME: To obtain the document languages the spell checker can be disabled,
+ so a future re-work of the getLanguages function is needed in favor to use
+ getDocLanguages */
+ if (!aLocales.hasElements())
+ {
+ uno::Sequence< css::lang::Locale > aSeq;
+ getDocLanguages(pThis, aSeq);
+ aLocales = aSeq;
+ }
}
boost::property_tree::ptree aTree;
@@ -5770,7 +5895,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
if (!strcmp(pCommand, ".uno:LanguageStatus"))
{
- return getLanguages(pCommand);
+ return getLanguages(pThis, pCommand);
}
else if (!strcmp(pCommand, ".uno:CharFontName"))
{