From 9c0049cfae49c8e4ddef9125a69db2ad134c10c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 13:48:25 +0200 Subject: Merging upstream version 4:24.2.4. Signed-off-by: Daniel Baumann --- cui/source/options/optlanguagetool.cxx | 35 +++++++++++++++++++++------------- cui/source/options/treeopt.cxx | 22 +++------------------ 2 files changed, 25 insertions(+), 32 deletions(-) (limited to 'cui/source/options') diff --git a/cui/source/options/optlanguagetool.cxx b/cui/source/options/optlanguagetool.cxx index 8c56a40e72..3979b42c05 100644 --- a/cui/source/options/optlanguagetool.cxx +++ b/cui/source/options/optlanguagetool.cxx @@ -25,6 +25,7 @@ using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool; constexpr OUString LANGUAGETOOL_DEFAULT_URL = u"https://api.languagetool.org/v2"_ustr; +constexpr OUString LANGUAGETOOLPLUS_DEFAULT_URL = u"https://api.languagetoolplus.com/v2"_ustr; OptLanguageToolTabPage::OptLanguageToolTabPage(weld::Container* pPage, weld::DialogController* pController, @@ -81,20 +82,21 @@ IMPL_LINK_NOARG(OptLanguageToolTabPage, CheckHdl, weld::Toggleable&, void) void OptLanguageToolTabPage::Reset(const SfxItemSet*) { // tdf#150494 If no URL has been set, use the default URL - OUString aBaseURL = LanguageToolCfg::BaseURL::get().value_or(""); - if (aBaseURL.isEmpty()) - m_xBaseURLED->set_text(LANGUAGETOOL_DEFAULT_URL); - else - m_xBaseURLED->set_text(aBaseURL); + OUString aUsername = LanguageToolCfg::Username::get().value_or(""); + OUString aApiKey = LanguageToolCfg::ApiKey::get().value_or(""); + OUString aBaseURL = LanguageToolCfg::BaseURL::get().value_or( + (aUsername.isEmpty() && aApiKey.isEmpty()) ? LANGUAGETOOL_DEFAULT_URL + : LANGUAGETOOLPLUS_DEFAULT_URL); + m_xBaseURLED->set_text(aBaseURL); m_xBaseURLED->set_sensitive(!LanguageToolCfg::BaseURL::isReadOnly()); m_xBaseURLImg->set_visible(LanguageToolCfg::BaseURL::isReadOnly()); - m_xUsernameED->set_text(LanguageToolCfg::Username::get().value_or("")); + m_xUsernameED->set_text(aUsername); m_xUsernameED->set_sensitive(!LanguageToolCfg::Username::isReadOnly()); m_xUsernameImg->set_visible(LanguageToolCfg::Username::isReadOnly()); - m_xApiKeyED->set_text(LanguageToolCfg::ApiKey::get().value_or("")); + m_xApiKeyED->set_text(aApiKey); m_xApiKeyED->set_sensitive(!LanguageToolCfg::ApiKey::isReadOnly()); m_xApiKeyImg->set_visible(LanguageToolCfg::ApiKey::isReadOnly()); @@ -139,14 +141,21 @@ bool OptLanguageToolTabPage::FillItemSet(SfxItemSet*) auto batch(comphelper::ConfigurationChanges::create()); // tdf#150494 If no URL has been set, then save the default URL + // tdf#159395 If Username and ApiKey are set, then save the default URL for paid service OUString aBaseURL = m_xBaseURLED->get_text(); - if (aBaseURL.isEmpty()) - LanguageToolCfg::BaseURL::set(LANGUAGETOOL_DEFAULT_URL, batch); - else - LanguageToolCfg::BaseURL::set(aBaseURL, batch); + OUString aUsername = m_xUsernameED->get_text(); + OUString aApiKey = m_xApiKeyED->get_text(); - LanguageToolCfg::Username::set(m_xUsernameED->get_text(), batch); - LanguageToolCfg::ApiKey::set(m_xApiKeyED->get_text(), batch); + if (aBaseURL.isEmpty() + || (aUsername.isEmpty() && aApiKey.isEmpty() && aBaseURL == LANGUAGETOOLPLUS_DEFAULT_URL)) + aBaseURL = LANGUAGETOOL_DEFAULT_URL; + + if (!aUsername.isEmpty() && !aApiKey.isEmpty() && aBaseURL == LANGUAGETOOL_DEFAULT_URL) + aBaseURL = LANGUAGETOOLPLUS_DEFAULT_URL; + + LanguageToolCfg::BaseURL::set(aBaseURL, batch); + LanguageToolCfg::Username::set(aUsername, batch); + LanguageToolCfg::ApiKey::set(aApiKey, batch); LanguageToolCfg::RestProtocol::set(m_xRestProtocol->get_text(), batch); LanguageToolCfg::SSLCertVerify::set(!m_xSSLDisableVerificationBox->get_active(), batch); batch->commit(); diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx index d8fe793e10..029c5f773f 100644 --- a/cui/source/options/treeopt.cxx +++ b/cui/source/options/treeopt.cxx @@ -790,7 +790,7 @@ IMPL_LINK_NOARG(OfaTreeOptionsDialog, SearchUpdateHdl, weld::Entry&, void) IMPL_LINK_NOARG(OfaTreeOptionsDialog, ImplUpdateDataHdl, Timer*, void) { - // initializeFirstNDialog() can take a long time, show wait cursor and disable input + // initializeAllDialogs() can take a long time, show wait cursor and disable input std::unique_ptr xWait(m_pParent ? new weld::WaitObject(m_pParent) : nullptr); // Pause redraw @@ -801,7 +801,7 @@ IMPL_LINK_NOARG(OfaTreeOptionsDialog, ImplUpdateDataHdl, Timer*, void) m_xSearchEdit->freeze(); xTreeLB->hide(); - initializeFirstNDialog(); + initializeAllDialogs(); m_xSearchEdit->thaw(); xTreeLB->show(); @@ -847,10 +847,9 @@ void OfaTreeOptionsDialog::selectFirstEntry() } } -void OfaTreeOptionsDialog::initializeFirstNDialog(sal_Int16 nNumberOfNode) +void OfaTreeOptionsDialog::initializeAllDialogs() { std::unique_ptr xEntry; - sal_Int16 nCount = 0; std::unique_ptr xTemp = xTreeLB->make_iterator(); bool bTemp = xTreeLB->get_iter_first(*xTemp); @@ -877,12 +876,6 @@ void OfaTreeOptionsDialog::initializeFirstNDialog(sal_Int16 nNumberOfNode) } } - /* if nNumberOfNode is -1 (which is the default value if no parameter provided), - this function will initialize all dialogs since nCount always greater than -1 */ - if (nCount == nNumberOfNode) - break; - - ++nCount; bTemp = xTreeLB->iter_next(*xTemp); } } @@ -1187,15 +1180,6 @@ void OfaTreeOptionsDialog::ActivateLastSelection() xTreeLB->select(*xEntry); m_xSearchEdit->grab_focus(); SelectHdl_Impl(); - - // initializeFirstNDialog() can take a long time, show wait cursor - std::unique_ptr xWait(m_pParent ? new weld::WaitObject(m_pParent) : nullptr); - - /* initialize first 25 dialogs which are almost half of the dialogs - in a row while Options dialog opens. then clear&reselect to avoid UI test failures. */ - initializeFirstNDialog(25); - clearOptionsDialog(); - SelectHdl_Impl(); } void OfaTreeOptionsDialog::InitItemSets(OptionsGroupInfo& rGroupInfo) -- cgit v1.2.3