Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / options / tsaurls.cxx
blobb33c76c58d43ff3380fb91f3b08ca750bd7fba45
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/.
8 */
10 #include <officecfg/Office/Common.hxx>
11 #include <svx/svxdlg.hxx>
12 #include <comphelper/sequence.hxx>
13 #include <comphelper/diagnose_ex.hxx>
15 #include "tsaurls.hxx"
17 using namespace ::com::sun::star;
19 TSAURLsDialog::TSAURLsDialog(weld::Window* pParent)
20 : GenericDialogController(pParent, "cui/ui/tsaurldialog.ui", "TSAURLDialog")
21 , m_xAddBtn(m_xBuilder->weld_button("add"))
22 , m_xDeleteBtn(m_xBuilder->weld_button("delete"))
23 , m_xOKBtn(m_xBuilder->weld_button("ok"))
24 , m_xURLListBox(m_xBuilder->weld_tree_view("urls"))
25 , m_xEnterAUrl(m_xBuilder->weld_label("enteraurl"))
27 m_xURLListBox->set_size_request(m_xURLListBox->get_approximate_digit_width() * 28,
28 m_xURLListBox->get_height_rows(8));
29 m_xOKBtn->set_sensitive(false);
31 m_xAddBtn->connect_clicked(LINK(this, TSAURLsDialog, AddHdl_Impl));
32 m_xDeleteBtn->connect_clicked(LINK(this, TSAURLsDialog, DeleteHdl_Impl));
33 m_xOKBtn->connect_clicked(LINK(this, TSAURLsDialog, OKHdl_Impl));
34 m_xURLListBox->connect_changed(LINK(this, TSAURLsDialog, SelectHdl));
36 try
38 std::optional<css::uno::Sequence<OUString>> aUserSetTSAURLs(
39 officecfg::Office::Common::Security::Scripting::TSAURLs::get());
40 if (aUserSetTSAURLs)
42 const css::uno::Sequence<OUString>& rUserSetTSAURLs = *aUserSetTSAURLs;
43 for (auto const& userSetTSAURL : rUserSetTSAURLs)
45 AddTSAURL(userSetTSAURL);
49 catch (const uno::Exception&)
51 TOOLS_WARN_EXCEPTION("cui.options", "TSAURLsDialog::TSAURLsDialog()");
54 if (m_xURLListBox->get_selected_index() == -1)
56 m_xDeleteBtn->set_sensitive(false);
60 IMPL_LINK_NOARG(TSAURLsDialog, OKHdl_Impl, weld::Button&, void)
62 std::shared_ptr<comphelper::ConfigurationChanges> batch(
63 comphelper::ConfigurationChanges::create());
65 officecfg::Office::Common::Security::Scripting::TSAURLs::set(
66 comphelper::containerToSequence(m_aURLs), batch);
67 batch->commit();
69 m_xDialog->response(RET_OK);
72 TSAURLsDialog::~TSAURLsDialog() {}
74 void TSAURLsDialog::AddTSAURL(const OUString& rURL)
76 m_aURLs.insert(rURL);
78 m_xURLListBox->freeze();
79 m_xURLListBox->clear();
81 for (auto const& url : m_aURLs)
83 m_xURLListBox->append_text(url);
86 m_xURLListBox->thaw();
89 IMPL_LINK_NOARG(TSAURLsDialog, AddHdl_Impl, weld::Button&, void)
91 OUString aURL;
92 OUString aDesc(m_xEnterAUrl->get_label());
94 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
95 ScopedVclPtr<AbstractSvxNameDialog> pDlg(
96 pFact->CreateSvxNameDialog(m_xDialog.get(), aURL, aDesc));
98 if (pDlg->Execute() == RET_OK)
100 pDlg->GetName(aURL);
101 AddTSAURL(aURL);
102 m_xOKBtn->set_sensitive(true);
104 m_xURLListBox->unselect_all();
105 // After operations in a ListBox we have nothing selected
106 m_xDeleteBtn->set_sensitive(false);
109 IMPL_LINK_NOARG(TSAURLsDialog, SelectHdl, weld::TreeView&, void)
111 m_xDeleteBtn->set_sensitive(true);
114 IMPL_LINK_NOARG(TSAURLsDialog, DeleteHdl_Impl, weld::Button&, void)
116 int nSel = m_xURLListBox->get_selected_index();
117 if (nSel == -1)
118 return;
120 m_aURLs.erase(m_xURLListBox->get_text(nSel));
121 m_xURLListBox->remove(nSel);
122 m_xURLListBox->unselect_all();
123 // After operations in a ListBox we have nothing selected
124 m_xDeleteBtn->set_sensitive(false);
125 m_xOKBtn->set_sensitive(true);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */