1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <officecfg/Office/Common.hxx>
#include <svx/svxdlg.hxx>
#include <comphelper/sequence.hxx>
#include <tools/diagnose_ex.h>
#include "tsaurls.hxx"
using namespace ::com::sun::star;
TSAURLsDialog::TSAURLsDialog(weld::Window* pParent)
: GenericDialogController(pParent, "cui/ui/tsaurldialog.ui", "TSAURLDialog")
, m_xAddBtn(m_xBuilder->weld_button("add"))
, m_xDeleteBtn(m_xBuilder->weld_button("delete"))
, m_xOKBtn(m_xBuilder->weld_button("ok"))
, m_xURLListBox(m_xBuilder->weld_tree_view("urls"))
, m_xEnterAUrl(m_xBuilder->weld_label("enteraurl"))
{
m_xURLListBox->set_size_request(m_xURLListBox->get_approximate_digit_width() * 28,
m_xURLListBox->get_height_rows(8));
m_xOKBtn->set_sensitive(false);
m_xAddBtn->connect_clicked(LINK(this, TSAURLsDialog, AddHdl_Impl));
m_xDeleteBtn->connect_clicked(LINK(this, TSAURLsDialog, DeleteHdl_Impl));
m_xOKBtn->connect_clicked(LINK(this, TSAURLsDialog, OKHdl_Impl));
m_xURLListBox->connect_changed(LINK(this, TSAURLsDialog, SelectHdl));
try
{
std::optional<css::uno::Sequence<OUString>> aUserSetTSAURLs(
officecfg::Office::Common::Security::Scripting::TSAURLs::get());
if (aUserSetTSAURLs)
{
const css::uno::Sequence<OUString>& rUserSetTSAURLs = *aUserSetTSAURLs;
for (auto const& userSetTSAURL : rUserSetTSAURLs)
{
AddTSAURL(userSetTSAURL);
}
}
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("cui.options", "TSAURLsDialog::TSAURLsDialog()");
}
if (m_xURLListBox->get_selected_index() == -1)
{
m_xDeleteBtn->set_sensitive(false);
}
}
IMPL_LINK_NOARG(TSAURLsDialog, OKHdl_Impl, weld::Button&, void)
{
std::shared_ptr<comphelper::ConfigurationChanges> batch(
comphelper::ConfigurationChanges::create());
officecfg::Office::Common::Security::Scripting::TSAURLs::set(
comphelper::containerToSequence(m_aURLs), batch);
batch->commit();
m_xDialog->response(RET_OK);
}
TSAURLsDialog::~TSAURLsDialog() {}
void TSAURLsDialog::AddTSAURL(const OUString& rURL)
{
m_aURLs.insert(rURL);
m_xURLListBox->freeze();
m_xURLListBox->clear();
for (auto const& url : m_aURLs)
{
m_xURLListBox->append_text(url);
}
m_xURLListBox->thaw();
}
IMPL_LINK_NOARG(TSAURLsDialog, AddHdl_Impl, weld::Button&, void)
{
OUString aURL;
OUString aDesc(m_xEnterAUrl->get_label());
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSvxNameDialog> pDlg(
pFact->CreateSvxNameDialog(m_xDialog.get(), aURL, aDesc));
if (pDlg->Execute() == RET_OK)
{
pDlg->GetName(aURL);
AddTSAURL(aURL);
m_xOKBtn->set_sensitive(true);
}
m_xURLListBox->unselect_all();
// After operations in a ListBox we have nothing selected
m_xDeleteBtn->set_sensitive(false);
}
IMPL_LINK_NOARG(TSAURLsDialog, SelectHdl, weld::TreeView&, void)
{
m_xDeleteBtn->set_sensitive(true);
}
IMPL_LINK_NOARG(TSAURLsDialog, DeleteHdl_Impl, weld::Button&, void)
{
int nSel = m_xURLListBox->get_selected_index();
if (nSel == -1)
return;
m_aURLs.erase(m_xURLListBox->get_text(nSel));
m_xURLListBox->remove(nSel);
m_xURLListBox->unselect_all();
// After operations in a ListBox we have nothing selected
m_xDeleteBtn->set_sensitive(false);
m_xOKBtn->set_sensitive(true);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|