diff options
author | Mert Tumer <mert.tumer@collabora.com> | 2022-05-10 13:06:06 +0300 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2022-06-10 13:52:17 +0200 |
commit | d952df361a5e190246d7a0738ae5347b82cd57b5 (patch) | |
tree | 8ab9d944b34ea93b8cdc69494f51fd41e4636ed5 /svtools | |
parent | 044df303665606c778748fcfc0bfc47ce65ee914 (diff) |
LanguageTool Grammar Checker implementation
Signed-off-by: Mert Tumer <mert.tumer@collabora.com>
Change-Id: I275cbea668afc5beb5147370119631df8b6a2d46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135178
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/Library_svt.mk | 1 | ||||
-rw-r--r-- | svtools/source/config/languagetoolcfg.cxx | 164 |
2 files changed, 165 insertions, 0 deletions
diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index 643481368caa..5c814cfcb7e1 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -83,6 +83,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/config/extcolorcfg \ svtools/source/config/fontsubstconfig \ svtools/source/config/htmlcfg \ + svtools/source/config/languagetoolcfg \ svtools/source/config/itemholder2 \ svtools/source/config/miscopt \ svtools/source/config/slidesorterbaropt \ diff --git a/svtools/source/config/languagetoolcfg.cxx b/svtools/source/config/languagetoolcfg.cxx new file mode 100644 index 000000000000..9f81c8e787f1 --- /dev/null +++ b/svtools/source/config/languagetoolcfg.cxx @@ -0,0 +1,164 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 . + */ + +#include <sal/log.hxx> +#include <sal/config.h> +#include <svtools/languagetoolcfg.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <tools/debug.hxx> + +using namespace utl; +using namespace com::sun::star::uno; + +struct LanguageToolOptions_Impl +{ + OUString sBaseURL; + OUString sUsername; + OUString sApiKey; + bool bEnabled; +}; + +const Sequence<OUString>& SvxLanguageToolOptions::GetPropertyNames() +{ + static Sequence<OUString> const aNames{ + "LanguageTool/BaseURL", + "LanguageTool/Username", + "LanguageTool/ApiKey", + "LanguageTool/IsEnabled", + }; + return aNames; +} + +const OUString& SvxLanguageToolOptions::getBaseURL() const { return pImpl->sBaseURL; } + +void SvxLanguageToolOptions::setBaseURL(const OUString& rVal) +{ + pImpl->sBaseURL = rVal; + SetModified(); +} + +const OUString& SvxLanguageToolOptions::getUsername() const { return pImpl->sUsername; } + +void SvxLanguageToolOptions::setUsername(const OUString& rVal) +{ + pImpl->sUsername = rVal; + SetModified(); +} + +OUString SvxLanguageToolOptions::getLocaleListURL() const { return pImpl->sBaseURL + "/languages"; } + +OUString SvxLanguageToolOptions::getCheckerURL() const { return pImpl->sBaseURL + "/check"; } + +const OUString& SvxLanguageToolOptions::getApiKey() const { return pImpl->sApiKey; } + +void SvxLanguageToolOptions::setApiKey(const OUString& rVal) +{ + pImpl->sApiKey = rVal; + SetModified(); +} + +bool SvxLanguageToolOptions::getEnabled() const { return pImpl->bEnabled; } + +void SvxLanguageToolOptions::setEnabled(bool bEnabled) +{ + pImpl->bEnabled = bEnabled; + SetModified(); +} + +namespace +{ +class theSvxLanguageToolOptions + : public rtl::Static<SvxLanguageToolOptions, theSvxLanguageToolOptions> +{ +}; +} + +SvxLanguageToolOptions& SvxLanguageToolOptions::Get() { return theSvxLanguageToolOptions::get(); } + +SvxLanguageToolOptions::SvxLanguageToolOptions() + : ConfigItem("Office.Linguistic/GrammarChecking") + , pImpl(new LanguageToolOptions_Impl) +{ + Load(GetPropertyNames()); +} + +SvxLanguageToolOptions::~SvxLanguageToolOptions() {} +void SvxLanguageToolOptions::Notify(const css::uno::Sequence<OUString>&) +{ + Load(GetPropertyNames()); +} + +void SvxLanguageToolOptions::Load(const css::uno::Sequence<OUString>& aNames) +{ + Sequence<Any> aValues = GetProperties(aNames); + const Any* pValues = aValues.getConstArray(); + DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed"); + if (aValues.getLength() != aNames.getLength()) + return; + for (int nProp = 0; nProp < aNames.getLength(); nProp++) + { + if (!pValues[nProp].hasValue()) + continue; + switch (nProp) + { + case 0: + pValues[nProp] >>= pImpl->sBaseURL; + break; + case 1: + pValues[nProp] >>= pImpl->sUsername; + break; + case 2: + pValues[nProp] >>= pImpl->sApiKey; + break; + case 3: + pValues[nProp] >>= pImpl->bEnabled; + break; + default: + break; + } + } +} + +void SvxLanguageToolOptions::ImplCommit() +{ + const Sequence<OUString>& aNames = GetPropertyNames(); + Sequence<Any> aValues(aNames.getLength()); + Any* pValues = aValues.getArray(); + for (int nProp = 0; nProp < aNames.getLength(); nProp++) + { + switch (nProp) + { + case 0: + pValues[nProp] <<= pImpl->sBaseURL; + break; + case 1: + pValues[nProp] <<= pImpl->sUsername; + break; + case 2: + pValues[nProp] <<= pImpl->sApiKey; + break; + case 3: + pValues[nProp] <<= pImpl->bEnabled; + break; + default: + break; + } + } + PutProperties(aNames, aValues); +}
\ No newline at end of file |