include/unotools/lingucfg.hxx | 2 lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu | 30 ------ lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx | 45 ++++++---- postprocess/CustomTarget_registry.mk | 1 sw/qa/extras/uiwriter/data/tdf148868.odt |binary sw/qa/extras/uiwriter/uiwriter3.cxx | 19 ++++ unotools/source/config/lingucfg.cxx | 21 ---- 7 files changed, 48 insertions(+), 70 deletions(-)
New commits: commit 4e8295638e68295d73b49ddb80e23c3509a49b3e Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Tue Jun 14 14:24:07 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jun 15 08:27:32 2022 +0200 tdf#148868: sw_uiwriter3: Add unittest Change-Id: I110079662cb001bbe3044138a1e7d23383cc083d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135827 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/extras/uiwriter/data/tdf148868.odt b/sw/qa/extras/uiwriter/data/tdf148868.odt new file mode 100644 index 000000000000..7ebf68a82ea3 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf148868.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 3c794a3da60e..1c7c4a87d3c5 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -352,6 +352,25 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147126) } } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf148868) +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf148868.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + pWrtShell->EndPg(/*bSelect=*/false); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false); + pWrtShell->Insert("X"); + + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf129382) { SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf129382.docx"); commit ac4719fe7365fb77c82bf5d937af069942671084 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Jun 15 06:50:48 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jun 15 08:27:18 2022 +0200 Revert "Load the locales from config file for languagetool" This reverts commit c3ed41752237a7a70c856dfb0d618f1c2eacea5a. Jenkins fails in CppunitTest_sw_core_draw on Mac and Windows Change-Id: I3e2b6359f3238a1b8af2e98d3cb5eee7aa864bae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135859 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/include/unotools/lingucfg.hxx b/include/unotools/lingucfg.hxx index 9117799c2f3a..b4a0b824e127 100644 --- a/include/unotools/lingucfg.hxx +++ b/include/unotools/lingucfg.hxx @@ -192,8 +192,6 @@ public: bool GetDictionaryEntry( const OUString &rNodeName, SvtLinguConfigDictionaryEntry &rDicEntry ) const; - bool GetLocaleListFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const; - css::uno::Sequence< OUString > GetDisabledDictionaries() const; std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat( std::u16string_view rFormatName ) const; diff --git a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu b/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu deleted file mode 100644 index ce3d6033d0c2..000000000000 --- a/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version='1.0' encoding='UTF-8'?> -<!-- - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . ---> -<oor:component-data oor:name="Linguistic" oor:package="org.openoffice.Office" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <node oor:name="ServiceManager"> - <node oor:name="GrammarCheckers"> - <node oor:name="org.openoffice.lingu.LanguageToolGrammarChecker" oor:op="fuse"> - <prop oor:name="Locales" oor:type="oor:string-list"> - <value>ar ast-ES be-BY br-FR ca-ES ca-ES-valencia zh-CN da-DK nl nl-BE en en-AU en-CA en-CA en-GB en-NZ en-ZA en-US fr gl-ES de de-AT de-DE de-DE de-CH el-GR ga-IE it ja-JP km-KH nb no fa pl-PL pt pt-AO pt-BR pt-MZ pt-PT ro-RO ru-RU de-DE-x-simple-language sk-SK sl-SI es es-AR sv tl-PH ta-IN uk-UA</value> - </prop> - </node> - </node> - </node> -</oor:component-data> - diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx index d7d53c015860..06b4fcb64175 100644 --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -35,12 +35,11 @@ #include <boost/property_tree/json_parser.hpp> #include <algorithm> #include <string_view> +#include <sal/log.hxx> #include <svtools/languagetoolcfg.hxx> #include <tools/color.hxx> #include <tools/long.hxx> #include <com/sun/star/uno/Any.hxx> -#include <unotools/lingucfg.hxx> -#include <osl/mutex.hxx> using namespace osl; using namespace com::sun::star; @@ -109,26 +108,40 @@ sal_Bool SAL_CALL LanguageToolGrammarChecker::hasLocale(const Locale& rLocale) Sequence<Locale> SAL_CALL LanguageToolGrammarChecker::getLocales() { - MutexGuard aGuard(GetLinguMutex()); - if (m_aSuppLocales.hasElements()) return m_aSuppLocales; + SvxLanguageToolOptions& rLanguageOpts = SvxLanguageToolOptions::Get(); + OString localeUrl = OUStringToOString(rLanguageOpts.getLocaleListURL(), RTL_TEXTENCODING_UTF8); + if (localeUrl.isEmpty()) + { + return m_aSuppLocales; + } + tools::Long statusCode = 0; + std::string response = makeHttpRequest(localeUrl, HTTP_METHOD::HTTP_GET, OString(), statusCode); + if (statusCode != 200) + { + return m_aSuppLocales; + } + if (response.empty()) + { + return m_aSuppLocales; + } + boost::property_tree::ptree root; + std::stringstream aStream(response); + boost::property_tree::read_json(aStream, root); - SvtLinguConfig aLinguCfg; - uno::Sequence<OUString> aLocaleList; - aLinguCfg.GetLocaleListFor("GrammarCheckers", "org.openoffice.lingu.LanguageToolGrammarChecker", - aLocaleList); - - auto nLength = aLocaleList.getLength(); - m_aSuppLocales.realloc(nLength); + size_t length = root.size(); + m_aSuppLocales.realloc(length); auto pArray = m_aSuppLocales.getArray(); - auto pLocaleList = aLocaleList.getArray(); - - for (auto i = 0; i < nLength; i++) + int i = 0; + for (auto it = root.begin(); it != root.end(); it++, i++) { - pArray[i] = LanguageTag::convertToLocale(pLocaleList[i]); + boost::property_tree::ptree& localeItem = it->second; + const std::string longCode = localeItem.get<std::string>("longCode"); + Locale aLocale = LanguageTag::convertToLocale( + OUString(longCode.c_str(), longCode.length(), RTL_TEXTENCODING_UTF8)); + pArray[i] = aLocale; } - return m_aSuppLocales; } diff --git a/postprocess/CustomTarget_registry.mk b/postprocess/CustomTarget_registry.mk index b6aba3eefcff..fa30e33ae0c7 100644 --- a/postprocess/CustomTarget_registry.mk +++ b/postprocess/CustomTarget_registry.mk @@ -116,7 +116,6 @@ postprocess_DEPS_lingucomponent := main postprocess_FILES_lingucomponent := \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-hyphenator.xcu \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-spellchecker.xcu \ - $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-grammarchecker.xcu \ $(SRCDIR)/lingucomponent/config/Linguistic-lingucomponent-thesaurus.xcu \ postprocess_FILES_main := \ diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index 03ad0747ad34..a38fb51b61b7 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -926,27 +926,6 @@ bool SvtLinguConfig::GetSupportedDictionaryFormatsFor( return bSuccess; } -bool SvtLinguConfig::GetLocaleListFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rLocaleList ) const -{ - if (rSetName.isEmpty() || rSetEntry.isEmpty()) - return false; - bool bSuccess = false; - try - { - uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW ); - xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW ); - xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW ); - xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW ); - if (xNA->getByName( "Locales" ) >>= rLocaleList) - bSuccess = true; - DBG_ASSERT( rLocaleList.hasElements(), "Locale list is empty" ); - } - catch (uno::Exception &) - { - } - return bSuccess; -} - static bool lcl_GetFileUrlFromOrigin( OUString /*out*/ &rFileUrl, const OUString &rOrigin )