Use correct object
[LibreOffice.git] / cui / source / options / optinet2.cxx
blobd2196cd1b80d8ce8f22eca4a2498b6e6fc090ed5
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 <sal/config.h>
22 #include <string_view>
24 #include <officecfg/Inet.hxx>
25 #include <officecfg/Office/Common.hxx>
26 #include <officecfg/Office/Security.hxx>
27 #include <vcl/weld.hxx>
28 #include <sfx2/filedlghelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <comphelper/diagnose_ex.hxx>
33 #include <dialmgr.hxx>
34 #include "optinet2.hxx"
35 #include <strings.hrc>
37 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
38 #include <com/sun/star/task/InteractionHandler.hpp>
40 #include <sal/types.h>
41 #include <rtl/ustring.hxx>
42 #include <osl/file.hxx>
43 #include <com/sun/star/configuration/theDefaultProvider.hpp>
44 #include <com/sun/star/beans/NamedValue.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include <com/sun/star/beans/XPropertyState.hpp>
47 #include <com/sun/star/util/XChangesBatch.hpp>
48 #include <comphelper/processfactory.hxx>
49 #include <comphelper/string.hxx>
51 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
52 #include <com/sun/star/task/PasswordContainer.hpp>
53 #include <com/sun/star/task/XPasswordContainer2.hpp>
54 #include <securityoptions.hxx>
55 #include "webconninfo.hxx"
56 #include "certpath.hxx"
57 #include "tsaurls.hxx"
59 #include <svtools/restartdialog.hxx>
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::sfx2;
65 namespace {
67 bool isValidPort(OUString const & value) {
68 if (!comphelper::string::isdigitAsciiString(value)) {
69 return false;
71 auto const n = value.toUInt64();
72 if (n > 65535) {
73 return false;
75 if (n != 0) {
76 return true;
78 // Overflow in OUString::toUInt64 returns 0, so need to check value contains only zeroes:
79 return std::u16string_view(value).find_first_not_of(u'0') == std::u16string_view::npos;
84 IMPL_LINK(SvxProxyTabPage, PortChangedHdl, weld::Entry&, rEdit, void)
86 if (!isValidPort(rEdit.get_text()))
88 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(),
89 VclMessageType::Warning, VclButtonsType::Ok,
90 CuiResId(RID_CUISTR_OPT_PROXYPORTS)));
91 xErrorBox->run();
95 constexpr OUString g_aProxyModePN = u"ooInetProxyType"_ustr;
96 constexpr OUString g_aHttpProxyPN = u"ooInetHTTPProxyName"_ustr;
97 constexpr OUString g_aHttpPortPN = u"ooInetHTTPProxyPort"_ustr;
98 constexpr OUString g_aHttpsProxyPN = u"ooInetHTTPSProxyName"_ustr;
99 constexpr OUString g_aHttpsPortPN = u"ooInetHTTPSProxyPort"_ustr;
100 constexpr OUString g_aNoProxyDescPN = u"ooInetNoProxy"_ustr;
102 IMPL_STATIC_LINK(SvxProxyTabPage, NumberOnlyTextFilterHdl, OUString&, rTest, bool)
104 OUStringBuffer sAllowed;
105 for (sal_Int32 i = 0, nLen = rTest.getLength(); i < nLen; ++i)
107 if (rTest[i] >= '0' && rTest[i] <= '9')
108 sAllowed.append(rTest[i]);
110 rTest = sAllowed.makeStringAndClear();
111 return true;
114 IMPL_STATIC_LINK(SvxProxyTabPage, NoSpaceTextFilterHdl, OUString&, rTest, bool)
116 rTest = rTest.replaceAll(" ", "");
117 return true;
120 /********************************************************************/
121 /* */
122 /* SvxProxyTabPage */
123 /* */
124 /********************************************************************/
125 SvxProxyTabPage::SvxProxyTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
126 : SfxTabPage(pPage, pController, u"cui/ui/optproxypage.ui"_ustr, u"OptProxyPage"_ustr, &rSet)
127 , m_xProxyModeFT(m_xBuilder->weld_label(u"label2"_ustr))
128 , m_xProxyModeLB(m_xBuilder->weld_combo_box(u"proxymode"_ustr))
129 , m_xProxyModeImg(m_xBuilder->weld_widget(u"lockproxymode"_ustr))
130 , m_xHttpProxyFT(m_xBuilder->weld_label(u"httpft"_ustr))
131 , m_xHttpProxyED(m_xBuilder->weld_entry(u"http"_ustr))
132 , m_xHttpProxyImg(m_xBuilder->weld_widget(u"lockhttp"_ustr))
133 , m_xHttpPortFT(m_xBuilder->weld_label(u"httpportft"_ustr))
134 , m_xHttpPortED(m_xBuilder->weld_entry(u"httpport"_ustr))
135 , m_xHttpPortImg(m_xBuilder->weld_widget(u"lockhttpport"_ustr))
136 , m_xHttpsProxyFT(m_xBuilder->weld_label(u"httpsft"_ustr))
137 , m_xHttpsProxyED(m_xBuilder->weld_entry(u"https"_ustr))
138 , m_xHttpsProxyImg(m_xBuilder->weld_widget(u"lockhttps"_ustr))
139 , m_xHttpsPortFT(m_xBuilder->weld_label(u"httpsportft"_ustr))
140 , m_xHttpsPortED(m_xBuilder->weld_entry(u"httpsport"_ustr))
141 , m_xHttpsPortImg(m_xBuilder->weld_widget(u"lockhttpsport"_ustr))
142 , m_xNoProxyForFT(m_xBuilder->weld_label(u"noproxyft"_ustr))
143 , m_xNoProxyForED(m_xBuilder->weld_entry(u"noproxy"_ustr))
144 , m_xNoProxyForImg(m_xBuilder->weld_widget(u"locknoproxy"_ustr))
145 , m_xNoProxyDescFT(m_xBuilder->weld_label(u"noproxydesc"_ustr))
147 m_xHttpProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
148 m_xHttpPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
149 m_xHttpPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
150 m_xHttpsProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
151 m_xHttpsPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
152 m_xHttpsPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
154 Link<weld::Widget&,void> aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
155 m_xHttpPortED->connect_focus_out( aLink );
156 m_xHttpsPortED->connect_focus_out( aLink );
158 m_xProxyModeLB->connect_changed(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
160 Reference< css::lang::XMultiServiceFactory >
161 xConfigurationProvider(
162 configuration::theDefaultProvider::get(
163 comphelper::getProcessComponentContext() ) );
165 beans::NamedValue aProperty;
166 aProperty.Name = "nodepath";
167 aProperty.Value <<= u"org.openoffice.Inet/Settings"_ustr;
169 Sequence< Any > aArgumentList{ Any(aProperty) };
171 m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments(
172 u"com.sun.star.configuration.ConfigurationUpdateAccess"_ustr,
173 aArgumentList );
176 SvxProxyTabPage::~SvxProxyTabPage()
180 std::unique_ptr<SfxTabPage> SvxProxyTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
182 return std::make_unique<SvxProxyTabPage>(pPage, pController, *rAttrSet);
185 void SvxProxyTabPage::ReadConfigData_Impl()
187 sal_Int32 nIntValue = 0;
189 std::optional<sal_Int32> x(officecfg::Inet::Settings::ooInetProxyType::get());
190 if (x)
192 nIntValue = *x;
193 m_xProxyModeLB->set_active(nIntValue);
196 m_xHttpProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPProxyName::get() );
197 x = officecfg::Inet::Settings::ooInetHTTPProxyPort::get();
198 if (x)
200 nIntValue = *x;
201 m_xHttpPortED->set_text( OUString::number( nIntValue ));
203 else
204 m_xHttpPortED->set_text( u""_ustr );
206 m_xHttpsProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPSProxyName::get() );
207 x = officecfg::Inet::Settings::ooInetHTTPSProxyPort::get();
208 if (x)
210 nIntValue = *x;
211 m_xHttpsPortED->set_text( OUString::number( nIntValue ));
213 else
214 m_xHttpsPortED->set_text( u""_ustr );
216 m_xNoProxyForED->set_text( officecfg::Inet::Settings::ooInetNoProxy::get() );
219 void SvxProxyTabPage::ReadConfigDefaults_Impl()
223 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
225 sal_Int32 nIntValue = 0;
226 OUString aStringValue;
228 if( xPropertyState->getPropertyDefault(g_aHttpProxyPN) >>= aStringValue )
230 m_xHttpProxyED->set_text( aStringValue );
233 if( xPropertyState->getPropertyDefault(g_aHttpPortPN) >>= nIntValue )
235 m_xHttpPortED->set_text( OUString::number( nIntValue ));
238 if( xPropertyState->getPropertyDefault(g_aHttpsProxyPN) >>= aStringValue )
240 m_xHttpsProxyED->set_text( aStringValue );
243 if( xPropertyState->getPropertyDefault(g_aHttpsPortPN) >>= nIntValue )
245 m_xHttpsPortED->set_text( OUString::number( nIntValue ));
248 if( xPropertyState->getPropertyDefault(g_aNoProxyDescPN) >>= aStringValue )
250 m_xNoProxyForED->set_text( aStringValue );
253 catch (const beans::UnknownPropertyException &)
255 TOOLS_WARN_EXCEPTION("cui.options", "" );
257 catch (const css::lang::WrappedTargetException &)
259 TOOLS_WARN_EXCEPTION("cui.options", "" );
261 catch (const RuntimeException &)
263 TOOLS_WARN_EXCEPTION("cui.options", "" );
267 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
271 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
273 xPropertyState->setPropertyToDefault(g_aProxyModePN);
274 xPropertyState->setPropertyToDefault(g_aHttpProxyPN);
275 xPropertyState->setPropertyToDefault(g_aHttpPortPN);
276 xPropertyState->setPropertyToDefault(g_aHttpsProxyPN);
277 xPropertyState->setPropertyToDefault(g_aHttpsPortPN);
278 xPropertyState->setPropertyToDefault(g_aNoProxyDescPN);
280 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
281 xChangesBatch->commitChanges();
283 catch (const beans::UnknownPropertyException &)
285 TOOLS_WARN_EXCEPTION("cui.options", "" );
287 catch (const css::lang::WrappedTargetException &)
289 TOOLS_WARN_EXCEPTION("cui.options", "" );
291 catch (const RuntimeException &)
293 TOOLS_WARN_EXCEPTION("cui.options", "" );
297 void SvxProxyTabPage::Reset(const SfxItemSet*)
299 ReadConfigData_Impl();
301 m_xProxyModeLB->save_value();
302 m_xHttpProxyED->save_value();
303 m_xHttpPortED->save_value();
304 m_xHttpsProxyED->save_value();
305 m_xHttpsPortED->save_value();
306 m_xNoProxyForED->save_value();
308 EnableControls_Impl();
311 OUString SvxProxyTabPage::GetAllStrings()
313 OUString sAllStrings;
314 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"httpft"_ustr, u"httpsft"_ustr,
315 u"noproxyft"_ustr, u"httpportft"_ustr, u"httpsportft"_ustr, u"noproxydesc"_ustr };
317 for (const auto& label : labels)
319 if (const auto pString = m_xBuilder->weld_label(label))
320 sAllStrings += pString->get_label() + " ";
323 return sAllStrings.replaceAll("_", "");
326 bool SvxProxyTabPage::FillItemSet(SfxItemSet* )
328 bool bModified = false;
330 try {
331 Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
333 sal_Int32 nSelPos = m_xProxyModeLB->get_active();
334 if(m_xProxyModeLB->get_value_changed_from_saved())
336 if( nSelPos == 1 )
338 RestoreConfigDefaults_Impl();
339 return true;
342 xPropertySet->setPropertyValue(g_aProxyModePN, Any(nSelPos));
343 bModified = true;
346 if(m_xHttpProxyED->get_value_changed_from_saved())
348 xPropertySet->setPropertyValue( g_aHttpProxyPN, Any(m_xHttpProxyED->get_text()));
349 bModified = true;
352 if ( m_xHttpPortED->get_value_changed_from_saved())
354 xPropertySet->setPropertyValue( g_aHttpPortPN, Any(m_xHttpPortED->get_text().toInt32()));
355 bModified = true;
358 if( m_xHttpsProxyED->get_value_changed_from_saved() )
360 xPropertySet->setPropertyValue( g_aHttpsProxyPN, Any(m_xHttpsProxyED->get_text()) );
361 bModified = true;
364 if ( m_xHttpsPortED->get_value_changed_from_saved() )
366 xPropertySet->setPropertyValue( g_aHttpsPortPN, Any(m_xHttpsPortED->get_text().toInt32()) );
367 bModified = true;
370 if ( m_xNoProxyForED->get_value_changed_from_saved() )
372 xPropertySet->setPropertyValue( g_aNoProxyDescPN, Any( m_xNoProxyForED->get_text()));
373 bModified = true;
376 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
377 xChangesBatch->commitChanges();
379 catch (const css::lang::IllegalArgumentException &) {
380 TOOLS_WARN_EXCEPTION("cui.options", "" );
382 catch (const beans::UnknownPropertyException &) {
383 TOOLS_WARN_EXCEPTION("cui.options", "" );
385 catch (const beans::PropertyVetoException &) {
386 TOOLS_WARN_EXCEPTION("cui.options", "" );
388 catch (const css::lang::WrappedTargetException &) {
389 TOOLS_WARN_EXCEPTION("cui.options", "" );
391 catch (const RuntimeException &) {
392 TOOLS_WARN_EXCEPTION("cui.options", "" );
395 return bModified;
398 void SvxProxyTabPage::EnableControls_Impl()
400 bool bEnable = !officecfg::Inet::Settings::ooInetNoProxy::isReadOnly();
401 m_xProxyModeFT->set_sensitive(bEnable);
402 m_xProxyModeLB->set_sensitive(bEnable);
403 m_xProxyModeImg->set_visible(!bEnable);
405 const bool bManualConfig = m_xProxyModeLB->get_active() == 2;
407 bEnable = !officecfg::Inet::Settings::ooInetHTTPProxyName::isReadOnly();
408 const bool bHTTPProxyNameEnabled = bManualConfig && bEnable;
409 const bool bHTTPProxyPortEnabled = bManualConfig && bEnable;
410 m_xHttpProxyFT->set_sensitive(bHTTPProxyNameEnabled);
411 m_xHttpProxyED->set_sensitive(bHTTPProxyNameEnabled);
412 m_xHttpProxyImg->set_visible(!bEnable);
413 m_xHttpPortFT->set_sensitive(bHTTPProxyPortEnabled);
414 m_xHttpPortED->set_sensitive(bHTTPProxyPortEnabled);
415 m_xHttpPortImg->set_visible(!bEnable);
417 bEnable = !officecfg::Inet::Settings::ooInetHTTPSProxyName::isReadOnly();
418 const bool bHTTPSProxyNameEnabled = bManualConfig && bEnable;
419 const bool bHTTPSProxyPortEnabled = bManualConfig && bEnable;
420 m_xHttpsProxyFT->set_sensitive(bHTTPSProxyNameEnabled);
421 m_xHttpsProxyED->set_sensitive(bHTTPSProxyNameEnabled);
422 m_xHttpsProxyImg->set_visible(!bEnable);
423 m_xHttpsPortFT->set_sensitive(bHTTPSProxyPortEnabled);
424 m_xHttpsPortED->set_sensitive(bHTTPSProxyPortEnabled);
425 m_xHttpsPortImg->set_visible(!bEnable);
427 bEnable = !officecfg::Inet::Settings::ooInetNoProxy::isReadOnly();
428 const bool bInetNoProxyEnabled = bManualConfig && bEnable;
429 m_xNoProxyForFT->set_sensitive(bInetNoProxyEnabled);
430 m_xNoProxyForED->set_sensitive(bInetNoProxyEnabled);
431 m_xNoProxyForImg->set_visible(!bEnable);
432 m_xNoProxyDescFT->set_sensitive(bInetNoProxyEnabled);
435 IMPL_LINK(SvxProxyTabPage, ProxyHdl_Impl, weld::ComboBox&, rBox, void)
437 sal_Int32 nPos = rBox.get_active();
439 // Restore original system values
440 if( nPos == 1 )
442 ReadConfigDefaults_Impl();
445 EnableControls_Impl();
448 IMPL_STATIC_LINK(SvxProxyTabPage, LoseFocusHdl_Impl, weld::Widget&, rControl, void)
450 weld::Entry* pEdit = dynamic_cast<weld::Entry*>(&rControl);
451 if (pEdit && !isValidPort(pEdit->get_text()))
452 pEdit->set_text(OUString('0'));
455 /********************************************************************/
456 /* */
457 /* SvxSecurityTabPage */
458 /* */
459 /********************************************************************/
460 SvxSecurityTabPage::SvxSecurityTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
461 : SfxTabPage(pPage, pController, u"cui/ui/optsecuritypage.ui"_ustr, u"OptSecurityPage"_ustr, &rSet)
462 , m_xSecurityOptionsPB(m_xBuilder->weld_button(u"options"_ustr))
463 , m_xSavePasswordsCB(m_xBuilder->weld_check_button(u"savepassword"_ustr))
464 , m_xSavePasswordsImg(m_xBuilder->weld_widget(u"locksavepassword"_ustr))
465 , m_xShowConnectionsPB(m_xBuilder->weld_button(u"connections"_ustr))
466 , m_xMasterPasswordCB(m_xBuilder->weld_check_button(u"usemasterpassword"_ustr))
467 , m_xMasterPasswordImg(m_xBuilder->weld_widget(u"lockusemasterpassword"_ustr))
468 , m_xMasterPasswordFT(m_xBuilder->weld_label(u"masterpasswordtext"_ustr))
469 , m_xMasterPasswordPB(m_xBuilder->weld_button(u"masterpassword"_ustr))
470 , m_xMacroSecFrame(m_xBuilder->weld_container(u"macrosecurity"_ustr))
471 , m_xMacroSecPB(m_xBuilder->weld_button(u"macro"_ustr))
472 , m_xCertFrame(m_xBuilder->weld_container(u"certificatepath"_ustr))
473 , m_xCertPathPB(m_xBuilder->weld_button(u"cert"_ustr))
474 , m_xCertPathImg(m_xBuilder->weld_widget(u"lockcertipath"_ustr))
475 , m_xCertPathLabel(m_xBuilder->weld_label(u"label7"_ustr))
476 , m_xTSAURLsFrame(m_xBuilder->weld_container(u"tsaurls"_ustr))
477 , m_xTSAURLsPB(m_xBuilder->weld_button(u"tsas"_ustr))
478 , m_xTSAURLsImg(m_xBuilder->weld_widget(u"locktsas"_ustr))
479 , m_xTSAURLsLabel(m_xBuilder->weld_label(u"label9"_ustr))
480 , m_xNoPasswordSaveFT(m_xBuilder->weld_label(u"nopasswordsave"_ustr))
481 , m_xCertMgrPathLB(m_xBuilder->weld_button(u"browse"_ustr))
482 , m_xParameterEdit(m_xBuilder->weld_entry(u"parameterfield"_ustr))
483 , m_xCertMgrPathImg(m_xBuilder->weld_widget(u"lockcertimanager"_ustr))
484 , m_xCertMgrPathLabel(m_xBuilder->weld_label(u"label11"_ustr))
486 //fdo#65595, we need height-for-width support here, but for now we can
487 //bodge it
488 Size aPrefSize(m_xSavePasswordsCB->get_preferred_size());
489 int nMaxWidth = m_xSavePasswordsCB->get_approximate_digit_width() * 40;
490 if (aPrefSize.Width() > nMaxWidth)
492 m_xSavePasswordsCB->set_label_wrap(true);
493 m_xSavePasswordsCB->set_size_request(nMaxWidth, -1);
496 m_sPasswordStoringDeactivateStr = m_xNoPasswordSaveFT->get_label();
498 InitControls();
500 m_xSecurityOptionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
501 m_xSavePasswordsCB->connect_toggled( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
502 m_xMasterPasswordPB->connect_clicked( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
503 m_xMasterPasswordCB->connect_toggled( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
504 m_xShowConnectionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
505 m_xMacroSecPB->connect_clicked( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
506 m_xCertPathPB->connect_clicked( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
507 m_xTSAURLsPB->connect_clicked( LINK( this, SvxSecurityTabPage, TSAURLsPBHdl ) );
508 m_xCertMgrPathLB->connect_clicked( LINK( this, SvxSecurityTabPage, CertMgrPBHdl ) );
510 ActivatePage( rSet );
513 IMPL_LINK_NOARG(SvxSecurityTabPage, CertMgrPBHdl, weld::Button&, void)
517 FileDialogHelper aHelper(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
518 FileDialogFlags::NONE, nullptr);
519 OUString sPath = m_xParameterEdit->get_text();
520 if (sPath.isEmpty())
521 sPath = "/usr/bin";
523 OUString sUrl;
524 osl::FileBase::getFileURLFromSystemPath(sPath, sUrl);
525 aHelper.SetDisplayDirectory(sUrl);
527 if (ERRCODE_NONE == aHelper.Execute())
529 sUrl = aHelper.GetPath();
530 if (osl::FileBase::getSystemPathFromFileURL(sUrl, sPath) != osl::FileBase::E_None)
532 sPath.clear();
534 m_xParameterEdit->set_text(sPath);
536 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
537 comphelper::ConfigurationChanges::create());
538 OUString sCurCertMgr = m_xParameterEdit->get_text();
539 officecfg::Office::Common::Security::Scripting::CertMgrPath::set(sCurCertMgr, pBatch);
540 pBatch->commit();
542 catch (const uno::Exception&)
544 TOOLS_WARN_EXCEPTION("cui.options", "CertMgrPBHdl");
548 SvxSecurityTabPage::~SvxSecurityTabPage()
552 IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl, weld::Button&, void)
554 if (!m_xSecOptDlg)
555 m_xSecOptDlg.reset(new svx::SecurityOptionsDialog(GetFrameWeld()));
556 m_xSecOptDlg->run();
559 IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl, weld::Toggleable&, void)
563 Reference< task::XPasswordContainer2 > xMasterPasswd(
564 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
566 if ( m_xSavePasswordsCB->get_active() )
568 bool bOldValue = xMasterPasswd->allowPersistentStoring( true );
569 xMasterPasswd->removeMasterPassword();
571 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
572 GetDialogController()->getDialog()->GetXWindow()));
574 if ( xMasterPasswd->changeMasterPassword(xTmpHandler) )
576 m_xMasterPasswordPB->set_sensitive(true);
577 m_xMasterPasswordCB->set_active(true);
578 m_xMasterPasswordCB->set_sensitive(true);
579 m_xMasterPasswordFT->set_sensitive(true);
580 m_xShowConnectionsPB->set_sensitive(true);
582 else
584 xMasterPasswd->allowPersistentStoring( bOldValue );
585 m_xSavePasswordsCB->set_active( false );
588 else
590 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
591 VclMessageType::Question, VclButtonsType::YesNo,
592 m_sPasswordStoringDeactivateStr));
593 xQueryBox->set_default_response(RET_NO);
595 sal_uInt16 nRet = xQueryBox->run();
597 if( RET_YES == nRet )
599 xMasterPasswd->allowPersistentStoring( false );
600 m_xMasterPasswordCB->set_active(true);
601 m_xMasterPasswordPB->set_sensitive( false );
602 m_xMasterPasswordCB->set_sensitive( false );
603 m_xMasterPasswordFT->set_sensitive( false );
604 m_xShowConnectionsPB->set_sensitive( false );
606 else
608 m_xSavePasswordsCB->set_active(true);
609 m_xMasterPasswordPB->set_sensitive(true);
610 m_xShowConnectionsPB->set_sensitive(true);
614 catch (const Exception&)
616 m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
620 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl, weld::Button&, void)
624 Reference< task::XPasswordContainer2 > xMasterPasswd(
625 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
627 if ( xMasterPasswd->isPersistentStoringAllowed() )
629 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
630 GetDialogController()->getDialog()->GetXWindow()));
631 xMasterPasswd->changeMasterPassword(xTmpHandler);
634 catch (const Exception&)
638 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl, weld::Toggleable&, void)
642 Reference< task::XPasswordContainer2 > xMasterPasswd(
643 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
645 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
646 GetDialogController()->getDialog()->GetXWindow()));
648 if ( m_xMasterPasswordCB->get_active() )
650 if (xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword(xTmpHandler))
652 m_xMasterPasswordPB->set_sensitive(true);
653 m_xMasterPasswordFT->set_sensitive(true);
655 else
657 m_xMasterPasswordCB->set_active( false );
658 m_xMasterPasswordPB->set_sensitive(true);
659 m_xMasterPasswordFT->set_sensitive(true);
662 else
664 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword(xTmpHandler) )
666 m_xMasterPasswordPB->set_sensitive( false );
667 m_xMasterPasswordFT->set_sensitive( false );
669 else
671 m_xMasterPasswordCB->set_active(true);
672 m_xMasterPasswordPB->set_sensitive(true);
673 m_xShowConnectionsPB->set_sensitive(true);
677 catch (const Exception&)
679 m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
683 IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl, weld::Button&, void)
687 Reference< task::XPasswordContainer2 > xMasterPasswd(
688 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
690 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
691 GetDialogController()->getDialog()->GetXWindow()));
693 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword(xTmpHandler) )
695 svx::WebConnectionInfoDialog aDlg(GetFrameWeld());
696 aDlg.run();
699 catch (const Exception&)
703 IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl, weld::Button&, void)
705 if (!mpCertPathDlg)
706 mpCertPathDlg.reset(new CertPathDialog(GetFrameWeld()));
707 mpCertPathDlg->Init();
709 if (mpCertPathDlg->run() == RET_OK && !mpCertPathDlg->isActiveServicePath())
711 SolarMutexGuard aGuard;
712 if (svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, svtools::RESTART_REASON_ADDING_PATH))
713 GetDialogController()->response(RET_OK);
717 IMPL_LINK_NOARG(SvxSecurityTabPage, TSAURLsPBHdl, weld::Button&, void)
719 // Unlike the mpCertPathDlg, we *don't* keep the same dialog object around between
720 // invocations. Seems clearer to my little brain that way.
721 TSAURLsDialog aTSAURLsDlg(GetFrameWeld());
722 aTSAURLsDlg.run();
725 IMPL_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl, weld::Button&, void)
729 Reference< security::XDocumentDigitalSignatures > xD(
730 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
731 xD->setParentWindow(GetDialogController()->getDialog()->GetXWindow());
732 xD->manageTrustedSources();
734 catch (const Exception&)
736 TOOLS_WARN_EXCEPTION( "cui.options", "");
740 void SvxSecurityTabPage::InitControls()
742 #ifndef UNX
743 m_xCertFrame->hide();
744 #endif
746 m_xMasterPasswordPB->set_sensitive( false );
747 m_xMasterPasswordCB->set_sensitive( false );
748 m_xMasterPasswordCB->set_active(true);
749 m_xMasterPasswordFT->set_sensitive( false );
750 m_xShowConnectionsPB->set_sensitive( false );
752 // initialize the password saving checkbox
755 Reference< task::XPasswordContainer2 > xMasterPasswd(
756 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
758 if ( xMasterPasswd->isPersistentStoringAllowed() )
760 m_xMasterPasswordCB->set_sensitive(true);
761 m_xShowConnectionsPB->set_sensitive(true);
762 m_xSavePasswordsCB->set_active(true);
764 if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
765 m_xMasterPasswordCB->set_active( false );
766 else
768 m_xMasterPasswordPB->set_sensitive(true);
769 m_xMasterPasswordCB->set_active(true);
770 m_xMasterPasswordFT->set_sensitive(true);
774 if (officecfg::Office::Common::Passwords::UseStorage::isReadOnly())
776 m_xSavePasswordsCB->set_sensitive(false);
777 m_xShowConnectionsPB->set_sensitive(false);
778 m_xSavePasswordsImg->set_visible(true);
779 m_xMasterPasswordCB->set_sensitive(false);
780 m_xMasterPasswordPB->set_sensitive(false);
781 m_xMasterPasswordImg->set_visible(true);
784 catch (const Exception&)
786 m_xSavePasswordsCB->set_sensitive( false );
791 OUString sCurCertMgr = officecfg::Office::Common::Security::Scripting::CertMgrPath::get();
793 if (!sCurCertMgr.isEmpty())
794 m_xParameterEdit->set_text(sCurCertMgr);
796 bool bEnable = !officecfg::Office::Common::Security::Scripting::CertMgrPath::isReadOnly();
797 m_xCertMgrPathLB->set_sensitive(bEnable);
798 m_xParameterEdit->set_sensitive(bEnable);
799 m_xCertMgrPathLabel->set_sensitive(bEnable);
800 m_xCertMgrPathImg->set_visible(!bEnable);
802 bEnable = !officecfg::Office::Common::Security::Scripting::TSAURLs::isReadOnly();
803 m_xTSAURLsPB->set_sensitive(bEnable);
804 m_xTSAURLsLabel->set_sensitive(bEnable);
805 m_xTSAURLsImg->set_visible(!bEnable);
807 #ifndef UNX
808 bEnable = !officecfg::Office::Common::Security::Scripting::CertDir::isReadOnly() ||
809 !officecfg::Office::Common::Security::Scripting::ManualCertDir::isReadOnly();
810 m_xCertPathPB->set_sensitive(bEnable);
811 m_xCertPathLabel->set_sensitive(bEnable);
812 m_xCertPathImg->set_visible(!bEnable);
813 #endif
815 catch (const uno::Exception&)
820 std::unique_ptr<SfxTabPage> SvxSecurityTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
822 return std::make_unique<SvxSecurityTabPage>(pPage, pController, *rAttrSet);
825 void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
829 DeactivateRC SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
831 if( _pSet )
832 FillItemSet( _pSet );
833 return DeactivateRC::LeavePage;
836 OUString SvxSecurityTabPage::GetAllStrings()
838 OUString sAllStrings;
839 OUString labels[] = { u"label1"_ustr, u"label4"_ustr, u"label2"_ustr, u"masterpasswordtext"_ustr,
840 u"nopasswordsave"_ustr, u"label3"_ustr, u"label5"_ustr, u"label8"_ustr,
841 u"label7"_ustr, u"label10"_ustr, u"label9"_ustr, u"label12"_ustr,
842 u"label11"_ustr };
844 for (const auto& label : labels)
846 if (const auto pString = m_xBuilder->weld_label(label))
847 sAllStrings += pString->get_label() + " ";
850 OUString checkButton[] = { u"savepassword"_ustr, u"usemasterpassword"_ustr };
852 for (const auto& check : checkButton)
854 if (const auto pString = m_xBuilder->weld_check_button(check))
855 sAllStrings += pString->get_label() + " ";
858 // TODO: Should we exclude button strings from the search?
859 // button id: "browse" is excluded
860 OUString buttons[] = { u"options"_ustr, u"connections"_ustr, u"masterpassword"_ustr, u"macro"_ustr, u"cert"_ustr, u"tsas"_ustr };
862 for (const auto& btn : buttons)
864 if (const auto pString = m_xBuilder->weld_button(btn))
865 sAllStrings += pString->get_label() + " ";
868 return sAllStrings.replaceAll("_", "");
871 bool SvxSecurityTabPage::FillItemSet( SfxItemSet* )
873 bool bModified = false;
875 if (m_xSecOptDlg) {
876 bModified = m_xSecOptDlg->SetSecurityOptions();
879 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
880 comphelper::ConfigurationChanges::create());
881 if (m_xParameterEdit->get_value_changed_from_saved())
883 OUString sCurCertMgr = m_xParameterEdit->get_text();
884 officecfg::Office::Common::Security::Scripting::CertMgrPath::set(sCurCertMgr, pBatch);
885 pBatch->commit();
888 return bModified;
891 /*--------------------------------------------------------------------*/
893 void SvxSecurityTabPage::Reset( const SfxItemSet* )
897 struct SvxEMailTabPage_Impl
899 SvxEMailTabPage_Impl():
900 sProgram(officecfg::Office::Common::ExternalMailer::Program::get()),
901 bROProgram(
902 officecfg::Office::Common::ExternalMailer::Program::isReadOnly()),
903 bHideContent(
904 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get()),
905 bROHideContent(
906 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::isReadOnly())
909 OUString sProgram;
910 bool bROProgram;
911 bool bHideContent;
912 bool bROHideContent;
915 SvxEMailTabPage::SvxEMailTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
916 : SfxTabPage( pPage, pController, u"cui/ui/optemailpage.ui"_ustr, u"OptEmailPage"_ustr, &rSet)
917 , pImpl(new SvxEMailTabPage_Impl)
918 , m_xMailContainer(m_xBuilder->weld_container(u"program"_ustr))
919 , m_xMailerURLFI(m_xBuilder->weld_image(u"lockemail"_ustr))
920 , m_xMailerURLED(m_xBuilder->weld_entry(u"url"_ustr))
921 , m_xMailerURLPB(m_xBuilder->weld_button(u"browse"_ustr))
922 , m_xSuppressHiddenContainer(m_xBuilder->weld_container(u"suppressHiddenCont"_ustr))
923 , m_xSuppressHiddenFI(m_xBuilder->weld_image(u"lockSuppressHidden"_ustr))
924 , m_xSuppressHidden(m_xBuilder->weld_check_button(u"suppressHidden"_ustr))
925 , m_xDefaultFilterFT(m_xBuilder->weld_label(u"browsetitle"_ustr))
927 m_sDefaultFilterName = m_xDefaultFilterFT->get_label();
928 m_xMailerURLPB->connect_clicked( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
931 /* -------------------------------------------------------------------------*/
933 SvxEMailTabPage::~SvxEMailTabPage()
937 /* -------------------------------------------------------------------------*/
939 std::unique_ptr<SfxTabPage> SvxEMailTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
941 return std::make_unique<SvxEMailTabPage>(pPage, pController, *rAttrSet);
944 /* -------------------------------------------------------------------------*/
946 OUString SvxEMailTabPage::GetAllStrings()
948 OUString sAllStrings;
949 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"browsetitle"_ustr, u"suppress"_ustr };
951 for (const auto& label : labels)
953 if (const auto pString = m_xBuilder->weld_label(label))
954 sAllStrings += pString->get_label() + " ";
957 return sAllStrings.replaceAll("_", "");
960 /* -------------------------------------------------------------------------*/
962 bool SvxEMailTabPage::FillItemSet( SfxItemSet* )
964 std::shared_ptr<comphelper::ConfigurationChanges> batch(
965 comphelper::ConfigurationChanges::create());
966 if (!pImpl->bROProgram && m_xMailerURLED->get_value_changed_from_saved())
968 pImpl->sProgram = m_xMailerURLED->get_text();
969 officecfg::Office::Common::ExternalMailer::Program::set(
970 pImpl->sProgram, batch);
972 if (!pImpl->bROHideContent
973 && pImpl->bHideContent != m_xSuppressHidden->get_active())
975 pImpl->bHideContent = m_xSuppressHidden->get_active();
976 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::set(
977 pImpl->bHideContent, batch);
979 batch->commit();
980 return false;
983 /* -------------------------------------------------------------------------*/
985 void SvxEMailTabPage::Reset( const SfxItemSet* )
987 m_xMailerURLED->set_sensitive(true);
988 m_xMailerURLPB->set_sensitive(true);
990 if (pImpl->bROProgram)
991 m_xMailerURLFI->show();
993 m_xMailerURLED->set_text(pImpl->sProgram);
994 m_xMailerURLED->save_value();
996 m_xMailContainer->set_sensitive(!pImpl->bROProgram);
998 if (pImpl->bROHideContent)
999 m_xSuppressHiddenFI->show();
1001 m_xSuppressHidden->set_active(pImpl->bHideContent);
1003 m_xSuppressHiddenContainer->set_sensitive(!pImpl->bROHideContent);
1006 /* -------------------------------------------------------------------------*/
1008 IMPL_LINK_NOARG(SvxEMailTabPage, FileDialogHdl_Impl, weld::Button&, void)
1010 if (pImpl->bROProgram)
1011 return;
1013 FileDialogHelper aHelper(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, GetFrameWeld());
1014 OUString sPath = m_xMailerURLED->get_text();
1015 if ( sPath.isEmpty() )
1016 sPath = "/usr/bin";
1018 OUString sUrl;
1019 osl::FileBase::getFileURLFromSystemPath(sPath, sUrl);
1020 aHelper.SetDisplayDirectory(sUrl);
1021 aHelper.AddFilter( m_sDefaultFilterName, u"*"_ustr);
1023 if ( ERRCODE_NONE == aHelper.Execute() )
1025 sUrl = aHelper.GetPath();
1026 if (osl::FileBase::getSystemPathFromFileURL(sUrl, sPath)
1027 != osl::FileBase::E_None)
1029 sPath.clear();
1031 m_xMailerURLED->set_text(sPath);
1036 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */