bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / tsaurls.cxx
blob142ea656f0459d153607f99c5310c39340ecac50
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 <cuires.hrc>
14 #include "tsaurls.hxx"
16 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
18 using namespace ::com::sun::star;
20 TSAURLsDialog::TSAURLsDialog(vcl::Window* pParent)
21 : ModalDialog(pParent, "TSAURLDialog", "cui/ui/tsaurldialog.ui")
23 get(m_pAddBtn, "add");
24 get(m_pDeleteBtn, "delete");
25 get(m_pOKBtn, "ok");
26 get(m_pURLListBox, "urls");
28 m_pURLListBox->SetDropDownLineCount(8);
29 m_pURLListBox->set_width_request(m_pURLListBox->approximate_char_width() * 32);
30 m_pOKBtn->Disable();
32 m_pAddBtn->SetClickHdl( LINK( this, TSAURLsDialog, AddHdl_Impl ) );
33 m_pDeleteBtn->SetClickHdl( LINK( this, TSAURLsDialog, DeleteHdl_Impl ) );
34 m_pOKBtn->SetClickHdl( LINK( this, TSAURLsDialog, OKHdl_Impl ) );
36 try
38 css::uno::Sequence<OUString> aUserSetTSAURLs(officecfg::Office::Common::Security::Scripting::TSAURLs::get());
40 for (auto i = aUserSetTSAURLs.begin(); i != aUserSetTSAURLs.end(); ++i)
42 AddTSAURL(*i);
45 catch (const uno::Exception &e)
47 SAL_WARN("cui.options", "TSAURLsDialog::TSAURLsDialog(): caught exception" << e.Message);
51 IMPL_LINK_NOARG(TSAURLsDialog, OKHdl_Impl)
53 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
55 css::uno::Sequence<OUString> aNewValue(m_aURLs.size());
56 size_t n(0);
58 for (auto i = m_aURLs.cbegin(); i != m_aURLs.cend(); ++i)
59 aNewValue[n++] = *i;
60 officecfg::Office::Common::Security::Scripting::TSAURLs::set(aNewValue, batch);
61 batch->commit();
63 EndDialog(RET_OK);
65 return 0;
68 TSAURLsDialog::~TSAURLsDialog()
70 disposeOnce();
73 void TSAURLsDialog::dispose()
75 m_pAddBtn.clear();
76 m_pDeleteBtn.clear();
77 m_pOKBtn.clear();
78 m_pURLListBox.clear();
80 ModalDialog::dispose();
83 void TSAURLsDialog::AddTSAURL(const OUString& rURL)
85 m_aURLs.insert(rURL);
87 m_pURLListBox->SetUpdateMode(false);
88 m_pURLListBox->Clear();
90 for (auto i = m_aURLs.cbegin(); i != m_aURLs.cend(); ++i)
92 m_pURLListBox->InsertEntry(*i);
95 m_pURLListBox->SetUpdateMode(true);
98 IMPL_LINK_NOARG(TSAURLsDialog, AddHdl_Impl)
100 OUString aURL;
101 OUString aDesc( get<FixedText>("enteraurl")->GetText() );
103 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
104 boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( m_pAddBtn, aURL, aDesc));
106 if ( pDlg->Execute() == RET_OK )
108 pDlg->GetName( aURL );
110 AddTSAURL(aURL);
111 m_pOKBtn->Enable();
114 return 0;
117 IMPL_LINK_NOARG(TSAURLsDialog, DeleteHdl_Impl)
119 sal_Int32 nSel = m_pURLListBox->GetSelectEntryPos();
121 if (nSel == LISTBOX_ENTRY_NOTFOUND)
122 return 0;
124 m_aURLs.erase(m_pURLListBox->GetEntry(nSel));
125 m_pURLListBox->RemoveEntry(nSel);
126 m_pOKBtn->Enable();
128 return 0;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */