LibreOffice Module cui (master) 1
tsaurls.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
10#include <officecfg/Office/Common.hxx>
11#include <svx/svxdlg.hxx>
14
15#include "tsaurls.hxx"
16
17using namespace ::com::sun::star;
18
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"))
26{
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);
30
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));
35
36 try
37 {
38 std::optional<css::uno::Sequence<OUString>> aUserSetTSAURLs(
39 officecfg::Office::Common::Security::Scripting::TSAURLs::get());
40 if (aUserSetTSAURLs)
41 {
42 const css::uno::Sequence<OUString>& rUserSetTSAURLs = *aUserSetTSAURLs;
43 for (auto const& userSetTSAURL : rUserSetTSAURLs)
44 {
45 AddTSAURL(userSetTSAURL);
46 }
47 }
48 }
49 catch (const uno::Exception&)
50 {
51 TOOLS_WARN_EXCEPTION("cui.options", "TSAURLsDialog::TSAURLsDialog()");
52 }
53
54 if (m_xURLListBox->get_selected_index() == -1)
55 {
56 m_xDeleteBtn->set_sensitive(false);
57 }
58}
59
61{
62 std::shared_ptr<comphelper::ConfigurationChanges> batch(
64
65 officecfg::Office::Common::Security::Scripting::TSAURLs::set(
66 comphelper::containerToSequence(m_aURLs), batch);
67 batch->commit();
68
69 m_xDialog->response(RET_OK);
70}
71
73
74void TSAURLsDialog::AddTSAURL(const OUString& rURL)
75{
76 m_aURLs.insert(rURL);
77
78 m_xURLListBox->freeze();
79 m_xURLListBox->clear();
80
81 for (auto const& url : m_aURLs)
82 {
83 m_xURLListBox->append_text(url);
84 }
85
86 m_xURLListBox->thaw();
87}
88
90{
91 OUString aURL;
92 OUString aDesc(m_xEnterAUrl->get_label());
93
96 pFact->CreateSvxNameDialog(m_xDialog.get(), aURL, aDesc));
97
98 if (pDlg->Execute() == RET_OK)
99 {
100 pDlg->GetName(aURL);
101 AddTSAURL(aURL);
102 m_xOKBtn->set_sensitive(true);
103 }
104 m_xURLListBox->unselect_all();
105 // After operations in a ListBox we have nothing selected
106 m_xDeleteBtn->set_sensitive(false);
107}
108
110{
111 m_xDeleteBtn->set_sensitive(true);
112}
113
115{
116 int nSel = m_xURLListBox->get_selected_index();
117 if (nSel == -1)
118 return;
119
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);
126}
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static SvxAbstractDialogFactory * Create()
std::unique_ptr< weld::Button > m_xOKBtn
Definition: tsaurls.hxx:21
std::set< OUString > m_aURLs
Definition: tsaurls.hxx:32
void AddTSAURL(const OUString &rURL)
Definition: tsaurls.cxx:74
virtual ~TSAURLsDialog() override
Definition: tsaurls.cxx:72
std::unique_ptr< weld::TreeView > m_xURLListBox
Definition: tsaurls.hxx:22
std::unique_ptr< weld::Button > m_xAddBtn
Definition: tsaurls.hxx:19
std::unique_ptr< weld::Button > m_xDeleteBtn
Definition: tsaurls.hxx:20
TSAURLsDialog(weld::Window *pParent)
Definition: tsaurls.cxx:19
static std::shared_ptr< ConfigurationChanges > create()
#define TOOLS_WARN_EXCEPTION(area, stream)
URL aURL
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
IMPL_LINK_NOARG(TSAURLsDialog, OKHdl_Impl, weld::Button &, void)
Definition: tsaurls.cxx:60
RET_OK