From 69b0fa8a6267a1fa77e77405000f42e8aeba5fa0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 14 Mar 2023 16:24:09 +0200 Subject: [PATCH] Use officecfg instead of SvxDeeplOptions Change-Id: I977d9be45fa17b960cccb0915c5f2762bf11288f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148885 Tested-by: Jenkins Reviewed-by: Noel Grandin --- cui/source/options/optdeepl.cxx | 15 +-- desktop/source/lib/init.cxx | 8 +- include/svtools/deeplcfg.hxx | 50 --------- svtools/Library_svt.mk | 1 - svtools/source/config/deeplcfg.cxx | 124 ---------------------- sw/source/ui/misc/translatelangselect.cxx | 14 +-- sw/source/uibase/shells/textsh1.cxx | 16 +-- 7 files changed, 29 insertions(+), 199 deletions(-) delete mode 100644 include/svtools/deeplcfg.hxx delete mode 100644 svtools/source/config/deeplcfg.cxx diff --git a/cui/source/options/optdeepl.cxx b/cui/source/options/optdeepl.cxx index 5343f72a59c9..6544a8fbc645 100644 --- a/cui/source/options/optdeepl.cxx +++ b/cui/source/options/optdeepl.cxx @@ -18,7 +18,7 @@ */ #include "optdeepl.hxx" -#include +#include OptDeeplTabPage::OptDeeplTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet) @@ -32,16 +32,17 @@ OptDeeplTabPage::~OptDeeplTabPage() {} void OptDeeplTabPage::Reset(const SfxItemSet*) { - SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - m_xAPIUrl->set_text(rDeeplOptions.getAPIUrl()); - m_xAuthKey->set_text(rDeeplOptions.getAuthKey()); + m_xAPIUrl->set_text(*officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get()); + m_xAuthKey->set_text(*officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get()); } bool OptDeeplTabPage::FillItemSet(SfxItemSet*) { - SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - rDeeplOptions.setAPIUrl(m_xAPIUrl->get_text()); - rDeeplOptions.setAuthKey(m_xAuthKey->get_text()); + std::shared_ptr batch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Linguistic::Translation::Deepl::ApiURL::set(m_xAPIUrl->get_text(), batch); + officecfg::Office::Linguistic::Translation::Deepl::AuthKey::set(m_xAuthKey->get_text(), batch); + batch->commit(); return false; } diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 1a29cdd4ce05..bdab0c035563 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -143,7 +143,6 @@ #include #include #include -#include #include #ifdef IOS #include @@ -7351,9 +7350,10 @@ void setDeeplConfig() OUString aAuthKey = OStringToOUString(pAuthKeyString, RTL_TEXTENCODING_UTF8); try { - SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - rDeeplOptions.setAPIUrl(aAPIUrl); - rDeeplOptions.setAuthKey(aAuthKey); + std::shared_ptr batch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Linguistic::Translation::Deepl::ApiURL::set(aAPIUrl, batch); + officecfg::Office::Linguistic::Translation::Deepl::AuthKey::set(aAuthKey, batch); + batch->commit(); } catch(uno::Exception const& rException) { diff --git a/include/svtools/deeplcfg.hxx b/include/svtools/deeplcfg.hxx deleted file mode 100644 index a943d72d4d7e..000000000000 --- a/include/svtools/deeplcfg.hxx +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- 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 . - */ - -#pragma once -#include -#include -#include - -using namespace utl; -using namespace com::sun::star::uno; - -struct DeeplOptions_Impl; - -class SVT_DLLPUBLIC SvxDeeplOptions final : public utl::ConfigItem -{ -public: - SvxDeeplOptions(); - virtual ~SvxDeeplOptions() override; - - virtual void Notify(const css::uno::Sequence& _rPropertyNames) override; - static SvxDeeplOptions& Get(); - - const OUString& getAPIUrl() const; - void setAPIUrl(const OUString& rVal); - - const OUString& getAuthKey() const; - void setAuthKey(const OUString& rVal); - -private: - std::unique_ptr pImpl; - void Load(const css::uno::Sequence& rPropertyNames); - virtual void ImplCommit() override; - static const Sequence& GetPropertyNames(); -}; diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index 96714fdcfea1..46b68fb149e6 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -84,7 +84,6 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/config/extcolorcfg \ svtools/source/config/fontsubstconfig \ svtools/source/config/htmlcfg \ - svtools/source/config/deeplcfg \ svtools/source/config/itemholder2 \ svtools/source/config/miscopt \ svtools/source/config/slidesorterbaropt \ diff --git a/svtools/source/config/deeplcfg.cxx b/svtools/source/config/deeplcfg.cxx deleted file mode 100644 index 3b022b70804b..000000000000 --- a/svtools/source/config/deeplcfg.cxx +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- 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 -#include -#include -#include -#include - -using namespace utl; -using namespace com::sun::star::uno; - -struct DeeplOptions_Impl -{ - OUString sAPIUrl; - OUString sAuthKey; -}; - -const Sequence& SvxDeeplOptions::GetPropertyNames() -{ - static Sequence const aNames{ - "Deepl/ApiURL", - "Deepl/AuthKey", - }; - return aNames; -} - -const OUString& SvxDeeplOptions::getAPIUrl() const { return pImpl->sAPIUrl; } - -void SvxDeeplOptions::setAPIUrl(const OUString& rVal) -{ - pImpl->sAPIUrl = rVal; - SetModified(); -} - -const OUString& SvxDeeplOptions::getAuthKey() const { return pImpl->sAuthKey; } - -void SvxDeeplOptions::setAuthKey(const OUString& rVal) -{ - pImpl->sAuthKey = rVal; - SetModified(); -} - -namespace -{ -class theSvxDeeplOptions : public rtl::Static -{ -}; -} - -SvxDeeplOptions& SvxDeeplOptions::Get() { return theSvxDeeplOptions::get(); } - -SvxDeeplOptions::SvxDeeplOptions() - : ConfigItem("Office.Linguistic/Translation") - , pImpl(new DeeplOptions_Impl) -{ - Load(GetPropertyNames()); -} - -SvxDeeplOptions::~SvxDeeplOptions() {} -void SvxDeeplOptions::Notify(const css::uno::Sequence&) { Load(GetPropertyNames()); } - -void SvxDeeplOptions::Load(const css::uno::Sequence& aNames) -{ - Sequence 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->sAPIUrl; - break; - case 1: - pValues[nProp] >>= pImpl->sAuthKey; - break; - default: - break; - } - } -} - -void SvxDeeplOptions::ImplCommit() -{ - const Sequence& aNames = GetPropertyNames(); - Sequence aValues(aNames.getLength()); - Any* pValues = aValues.getArray(); - for (int nProp = 0; nProp < aNames.getLength(); nProp++) - { - switch (nProp) - { - case 0: - pValues[nProp] <<= pImpl->sAPIUrl; - break; - case 1: - pValues[nProp] <<= pImpl->sAuthKey; - break; - default: - break; - } - } - PutProperties(aNames, aValues); -} \ No newline at end of file diff --git a/sw/source/ui/misc/translatelangselect.cxx b/sw/source/ui/misc/translatelangselect.cxx index 2d438edf59d1..8036cd11dec3 100644 --- a/sw/source/ui/misc/translatelangselect.cxx +++ b/sw/source/ui/misc/translatelangselect.cxx @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include static const std::vector& getLanguageVec() { @@ -133,8 +133,11 @@ IMPL_LINK_NOARG(SwTranslateLangSelectDlg, LangSelectTranslateHdl, weld::Button&, return; } - SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - if (rDeeplOptions.getAPIUrl().isEmpty() || rDeeplOptions.getAuthKey().isEmpty()) + std::optional oDeeplAPIUrl + = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get(); + std::optional oDeeplKey + = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get(); + if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty()) { SAL_WARN("sw.ui", "SwTranslateLangSelectDlg: API options are not set"); m_xDialog->response(RET_CANCEL); @@ -142,11 +145,10 @@ IMPL_LINK_NOARG(SwTranslateLangSelectDlg, LangSelectTranslateHdl, weld::Button&, } const OString aAPIUrl - = OUStringToOString(rtl::Concat2View(rDeeplOptions.getAPIUrl() + "?tag_handling=html"), + = OUStringToOString(rtl::Concat2View(*oDeeplAPIUrl + "?tag_handling=html"), RTL_TEXTENCODING_UTF8) .trim(); - const OString aAuthKey - = OUStringToOString(rDeeplOptions.getAuthKey(), RTL_TEXTENCODING_UTF8).trim(); + const OString aAuthKey = OUStringToOString(*oDeeplKey, RTL_TEXTENCODING_UTF8).trim(); const auto aTargetLang = getLanguageVec().at(SwTranslateLangSelectDlg::selectedLangIdx).getLanguage(); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index b52e26778388..c79d2bec1fbe 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -108,9 +108,9 @@ #include #if !ENABLE_WASM_STRIP_EXTRA #include +#include #include #include -#include #endif // ENABLE_WASM_STRIP_EXTRA #include #include @@ -1940,14 +1940,15 @@ void SwTextShell::Execute(SfxRequest &rReq) const SfxPoolItem* pTargetLangStringItem = nullptr; if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TARGETLANG_STR, false, &pTargetLangStringItem)) { - SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - if (rDeeplOptions.getAPIUrl().isEmpty() || rDeeplOptions.getAuthKey().isEmpty()) + std::optional oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get(); + std::optional oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get(); + if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty()) { SAL_WARN("sw.ui", "SID_FM_TRANSLATE: API options are not set"); break; } - const OString aAPIUrl = OUStringToOString(rtl::Concat2View(rDeeplOptions.getAPIUrl() + "?tag_handling=html"), RTL_TEXTENCODING_UTF8).trim(); - const OString aAuthKey = OUStringToOString(rDeeplOptions.getAuthKey(), RTL_TEXTENCODING_UTF8).trim(); + const OString aAPIUrl = OUStringToOString(rtl::Concat2View(*oDeeplAPIUrl + "?tag_handling=html"), RTL_TEXTENCODING_UTF8).trim(); + const OString aAuthKey = OUStringToOString(*oDeeplKey, RTL_TEXTENCODING_UTF8).trim(); OString aTargetLang = OUStringToOString(static_cast(pTargetLangStringItem)->GetValue(), RTL_TEXTENCODING_UTF8); SwTranslateHelper::TranslateAPIConfig aConfig({aAPIUrl, aAuthKey, aTargetLang}); SwTranslateHelper::TranslateDocument(rWrtSh, aConfig); @@ -2474,8 +2475,9 @@ void SwTextShell::GetState( SfxItemSet &rSet ) rSet.Put(SfxVisibilityItem(nWhich, false)); break; } - const SvxDeeplOptions& rDeeplOptions = SvxDeeplOptions::Get(); - if (rDeeplOptions.getAPIUrl().isEmpty() || rDeeplOptions.getAuthKey().isEmpty()) + std::optional oDeeplAPIUrl = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get(); + std::optional oDeeplKey = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get(); + if (!oDeeplAPIUrl || oDeeplAPIUrl->isEmpty() || !oDeeplKey || oDeeplKey->isEmpty()) { rSet.DisableItem(nWhich); }