LibreOffice Module cui (master) 1
optlanguagetool.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "optlanguagetool.hxx"
21#include <officecfg/Office/Linguistic.hxx>
22#include <sal/log.hxx>
23#include <dialmgr.hxx>
24#include <strings.hrc>
25
26using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
27constexpr OUStringLiteral LANGUAGETOOL_DEFAULT_URL = u"https://api.languagetool.org/v2";
28
30 weld::DialogController* pController,
31 const SfxItemSet& rSet)
32 : SfxTabPage(pPage, pController, "cui/ui/langtoolconfigpage.ui", "OptLangToolPage", &rSet)
33 , m_xBaseURLED(m_xBuilder->weld_entry("baseurl"))
34 , m_xUsernameED(m_xBuilder->weld_entry("username"))
35 , m_xApiKeyED(m_xBuilder->weld_entry("apikey"))
36 , m_xRestProtocol(m_xBuilder->weld_entry("restprotocol"))
37 , m_xActivateBox(m_xBuilder->weld_check_button("activate"))
38 , m_xSSLDisableVerificationBox(m_xBuilder->weld_check_button("verifyssl"))
39 , m_xApiSettingsFrame(m_xBuilder->weld_frame("apisettings"))
40{
41 m_xActivateBox->connect_toggled(LINK(this, OptLanguageToolTabPage, CheckHdl));
42 EnableControls(LanguageToolCfg::IsEnabled::get());
43
44 // tdf#150494 Set default values as placeholder text
45 m_xBaseURLED->set_placeholder_text(CuiResId(RID_LANGUAGETOOL_LEAVE_EMPTY));
46 m_xUsernameED->set_placeholder_text(CuiResId(RID_LANGUAGETOOL_LEAVE_EMPTY));
47 m_xApiKeyED->set_placeholder_text(CuiResId(RID_LANGUAGETOOL_LEAVE_EMPTY));
48 m_xRestProtocol->set_placeholder_text(CuiResId(RID_LANGUAGETOOL_REST_LEAVE_EMPTY));
49}
50
52
54{
55 if (bEnable != LanguageToolCfg::IsEnabled::get())
56 {
58 LanguageToolCfg::IsEnabled::set(bEnable, batch);
59 batch->commit();
60 }
61 m_xApiSettingsFrame->set_visible(bEnable);
62 m_xActivateBox->set_active(bEnable);
63 m_xSSLDisableVerificationBox->set_active(!LanguageToolCfg::SSLCertVerify::get());
64}
65
67{
68 EnableControls(m_xActivateBox->get_active());
69}
70
72{
73 // tdf#150494 If no URL has been set, use the default URL
74 OUString aBaseURL = LanguageToolCfg::BaseURL::get().value_or("");
75 if (aBaseURL.isEmpty())
77 else
78 m_xBaseURLED->set_text(aBaseURL);
79
80 m_xUsernameED->set_text(LanguageToolCfg::Username::get().value_or(""));
81 m_xApiKeyED->set_text(LanguageToolCfg::ApiKey::get().value_or(""));
82 m_xRestProtocol->set_text(LanguageToolCfg::RestProtocol::get().value_or(""));
83 m_xSSLDisableVerificationBox->set_active(!LanguageToolCfg::SSLCertVerify::get());
84}
85
87{
89
90 // tdf#150494 If no URL has been set, then save the default URL
91 OUString aBaseURL = m_xBaseURLED->get_text();
92 if (aBaseURL.isEmpty())
93 LanguageToolCfg::BaseURL::set(LANGUAGETOOL_DEFAULT_URL, batch);
94 else
95 LanguageToolCfg::BaseURL::set(aBaseURL, batch);
96
97 LanguageToolCfg::Username::set(m_xUsernameED->get_text(), batch);
98 LanguageToolCfg::ApiKey::set(m_xApiKeyED->get_text(), batch);
99 LanguageToolCfg::RestProtocol::set(m_xRestProtocol->get_text(), batch);
100 LanguageToolCfg::SSLCertVerify::set(!m_xSSLDisableVerificationBox->get_active(), batch);
101 batch->commit();
102 return false;
103}
104
105std::unique_ptr<SfxTabPage> OptLanguageToolTabPage::Create(weld::Container* pPage,
106 weld::DialogController* pController,
107 const SfxItemSet* rAttrSet)
108{
109 return std::make_unique<OptLanguageToolTabPage>(pPage, pController, *rAttrSet);
110}
std::unique_ptr< weld::CheckButton > m_xActivateBox
std::unique_ptr< weld::Entry > m_xRestProtocol
virtual ~OptLanguageToolTabPage() override
std::unique_ptr< weld::CheckButton > m_xSSLDisableVerificationBox
std::unique_ptr< weld::Frame > m_xApiSettingsFrame
OptLanguageToolTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
std::unique_ptr< weld::Entry > m_xBaseURLED
virtual void Reset(const SfxItemSet *rSet) override
std::unique_ptr< weld::Entry > m_xUsernameED
void EnableControls(bool bEnable)
virtual bool FillItemSet(SfxItemSet *rSet) override
std::unique_ptr< weld::Entry > m_xApiKeyED
static std::shared_ptr< ConfigurationChanges > create()
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
float u
officecfg::Office::Linguistic::GrammarChecking::LanguageTool LanguageToolCfg
IMPL_LINK_NOARG(OptLanguageToolTabPage, CheckHdl, weld::Toggleable &, void)
constexpr OUStringLiteral LANGUAGETOOL_DEFAULT_URL
static SfxItemSet & rSet