Use correct object
[LibreOffice.git] / cui / source / options / optdeepl.cxx
blob5b51e556cc850c706b67c2d0f0a28d3883255a40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "optdeepl.hxx"
21 #include <officecfg/Office/Linguistic.hxx>
23 OptDeeplTabPage::OptDeeplTabPage(weld::Container* pPage, weld::DialogController* pController,
24 const SfxItemSet& rSet)
25 : SfxTabPage(pPage, pController, u"cui/ui/optdeeplpage.ui"_ustr, u"OptDeeplPage"_ustr, &rSet)
26 , m_xAPIUrl(m_xBuilder->weld_entry(u"apiurl"_ustr))
27 , m_xAuthKey(m_xBuilder->weld_entry(u"authkey"_ustr))
31 OptDeeplTabPage::~OptDeeplTabPage() {}
33 void OptDeeplTabPage::Reset(const SfxItemSet*)
35 std::optional<OUString> oDeeplAPIUrl
36 = officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get();
37 if (oDeeplAPIUrl && !oDeeplAPIUrl->isEmpty())
38 m_xAPIUrl->set_text(*officecfg::Office::Linguistic::Translation::Deepl::ApiURL::get());
40 std::optional<OUString> oDeeplAuthKey
41 = officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get();
42 if (oDeeplAuthKey && !oDeeplAuthKey->isEmpty())
43 m_xAuthKey->set_text(*officecfg::Office::Linguistic::Translation::Deepl::AuthKey::get());
46 OUString OptDeeplTabPage::GetAllStrings()
48 OUString sAllStrings;
49 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"label3"_ustr };
51 for (const auto& label : labels)
53 if (const auto pString = m_xBuilder->weld_label(label))
54 sAllStrings += pString->get_label() + " ";
57 if (const auto pString = m_xBuilder->weld_link_button(u"privacy"_ustr))
58 sAllStrings += pString->get_label() + " ";
60 return sAllStrings.replaceAll("_", "");
63 bool OptDeeplTabPage::FillItemSet(SfxItemSet*)
65 std::shared_ptr<comphelper::ConfigurationChanges> batch(
66 comphelper::ConfigurationChanges::create());
67 officecfg::Office::Linguistic::Translation::Deepl::ApiURL::set(m_xAPIUrl->get_text(), batch);
68 officecfg::Office::Linguistic::Translation::Deepl::AuthKey::set(m_xAuthKey->get_text(), batch);
69 batch->commit();
70 return false;
73 std::unique_ptr<SfxTabPage> OptDeeplTabPage::Create(weld::Container* pPage,
74 weld::DialogController* pController,
75 const SfxItemSet* rAttrSet)
77 return std::make_unique<OptDeeplTabPage>(pPage, pController, *rAttrSet);