Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / cui / source / options / optinet2.cxx
blob95d0ec18346b3c9ebcb9ae18f6b9f48e984fbc0c
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 <unotools/securityoptions.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <comphelper/diagnose_ex.hxx>
34 #include <dialmgr.hxx>
35 #include "optinet2.hxx"
36 #include <strings.hrc>
38 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
39 #include <com/sun/star/task/InteractionHandler.hpp>
41 #include <sal/types.h>
42 #include <rtl/ustring.hxx>
43 #include <osl/file.hxx>
44 #include <com/sun/star/configuration/theDefaultProvider.hpp>
45 #include <com/sun/star/beans/NamedValue.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertyState.hpp>
48 #include <com/sun/star/util/XChangesBatch.hpp>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/string.hxx>
52 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
53 #include <com/sun/star/task/PasswordContainer.hpp>
54 #include <com/sun/star/task/XPasswordContainer2.hpp>
55 #include "securityoptions.hxx"
56 #include "webconninfo.hxx"
57 #include "certpath.hxx"
58 #include "tsaurls.hxx"
60 #include <svtools/restartdialog.hxx>
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::uno;
64 using namespace ::sfx2;
66 namespace {
68 bool isValidPort(OUString const & value) {
69 if (!comphelper::string::isdigitAsciiString(value)) {
70 return false;
72 auto const n = value.toUInt64();
73 if (n > 65535) {
74 return false;
76 if (n != 0) {
77 return true;
79 // Overflow in OUString::toUInt64 returns 0, so need to check value contains only zeroes:
80 return std::u16string_view(value).find_first_not_of(u'0') == std::u16string_view::npos;
85 IMPL_LINK(SvxProxyTabPage, PortChangedHdl, weld::Entry&, rEdit, void)
87 if (!isValidPort(rEdit.get_text()))
89 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(),
90 VclMessageType::Warning, VclButtonsType::Ok,
91 CuiResId(RID_CUISTR_OPT_PROXYPORTS)));
92 xErrorBox->run();
96 constexpr OUStringLiteral g_aProxyModePN = u"ooInetProxyType";
97 constexpr OUStringLiteral g_aHttpProxyPN = u"ooInetHTTPProxyName";
98 constexpr OUStringLiteral g_aHttpPortPN = u"ooInetHTTPProxyPort";
99 constexpr OUStringLiteral g_aHttpsProxyPN = u"ooInetHTTPSProxyName";
100 constexpr OUStringLiteral g_aHttpsPortPN = u"ooInetHTTPSProxyPort";
101 constexpr OUStringLiteral g_aFtpProxyPN = u"ooInetFTPProxyName";
102 constexpr OUStringLiteral g_aFtpPortPN = u"ooInetFTPProxyPort";
103 constexpr OUStringLiteral g_aNoProxyDescPN = u"ooInetNoProxy";
105 IMPL_STATIC_LINK(SvxProxyTabPage, NumberOnlyTextFilterHdl, OUString&, rTest, bool)
107 OUStringBuffer sAllowed;
108 for (sal_Int32 i = 0, nLen = rTest.getLength(); i < nLen; ++i)
110 if (rTest[i] >= '0' && rTest[i] <= '9')
111 sAllowed.append(rTest[i]);
113 rTest = sAllowed.makeStringAndClear();
114 return true;
117 IMPL_STATIC_LINK(SvxProxyTabPage, NoSpaceTextFilterHdl, OUString&, rTest, bool)
119 rTest = rTest.replaceAll(" ", "");
120 return true;
123 /********************************************************************/
124 /* */
125 /* SvxProxyTabPage */
126 /* */
127 /********************************************************************/
128 SvxProxyTabPage::SvxProxyTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
129 : SfxTabPage(pPage, pController, "cui/ui/optproxypage.ui", "OptProxyPage", &rSet)
130 , m_xProxyModeLB(m_xBuilder->weld_combo_box("proxymode"))
131 , m_xHttpProxyFT(m_xBuilder->weld_label("httpft"))
132 , m_xHttpProxyED(m_xBuilder->weld_entry("http"))
133 , m_xHttpPortFT(m_xBuilder->weld_label("httpportft"))
134 , m_xHttpPortED(m_xBuilder->weld_entry("httpport"))
135 , m_xHttpsProxyFT(m_xBuilder->weld_label("httpsft"))
136 , m_xHttpsProxyED(m_xBuilder->weld_entry("https"))
137 , m_xHttpsPortFT(m_xBuilder->weld_label("httpsportft"))
138 , m_xHttpsPortED(m_xBuilder->weld_entry("httpsport"))
139 , m_xFtpProxyFT(m_xBuilder->weld_label("ftpft"))
140 , m_xFtpProxyED(m_xBuilder->weld_entry("ftp"))
141 , m_xFtpPortFT(m_xBuilder->weld_label("ftpportft"))
142 , m_xFtpPortED(m_xBuilder->weld_entry("ftpport"))
143 , m_xNoProxyForFT(m_xBuilder->weld_label("noproxyft"))
144 , m_xNoProxyForED(m_xBuilder->weld_entry("noproxy"))
145 , m_xNoProxyDescFT(m_xBuilder->weld_label("noproxydesc"))
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));
153 m_xFtpProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
154 m_xFtpPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
155 m_xFtpPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
157 Link<weld::Widget&,void> aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
158 m_xHttpPortED->connect_focus_out( aLink );
159 m_xHttpsPortED->connect_focus_out( aLink );
160 m_xFtpPortED->connect_focus_out( aLink );
162 m_xProxyModeLB->connect_changed(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
164 Reference< css::lang::XMultiServiceFactory >
165 xConfigurationProvider(
166 configuration::theDefaultProvider::get(
167 comphelper::getProcessComponentContext() ) );
169 beans::NamedValue aProperty;
170 aProperty.Name = "nodepath";
171 aProperty.Value <<= OUString( "org.openoffice.Inet/Settings" );
173 Sequence< Any > aArgumentList{ Any(aProperty) };
175 m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments(
176 "com.sun.star.configuration.ConfigurationUpdateAccess",
177 aArgumentList );
180 SvxProxyTabPage::~SvxProxyTabPage()
184 std::unique_ptr<SfxTabPage> SvxProxyTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
186 return std::make_unique<SvxProxyTabPage>(pPage, pController, *rAttrSet);
189 void SvxProxyTabPage::ReadConfigData_Impl()
191 sal_Int32 nIntValue = 0;
193 std::optional<sal_Int32> x(officecfg::Inet::Settings::ooInetProxyType::get());
194 if (x)
196 nIntValue = *x;
197 m_xProxyModeLB->set_active(nIntValue);
200 m_xHttpProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPProxyName::get() );
201 x = officecfg::Inet::Settings::ooInetHTTPProxyPort::get();
202 if (x)
204 nIntValue = *x;
205 m_xHttpPortED->set_text( OUString::number( nIntValue ));
207 else
208 m_xHttpPortED->set_text( "" );
210 m_xHttpsProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPSProxyName::get() );
211 x = officecfg::Inet::Settings::ooInetHTTPSProxyPort::get();
212 if (x)
214 nIntValue = *x;
215 m_xHttpsPortED->set_text( OUString::number( nIntValue ));
217 else
218 m_xHttpsPortED->set_text( "" );
220 m_xFtpProxyED->set_text( officecfg::Inet::Settings::ooInetFTPProxyName::get() );
221 x = officecfg::Inet::Settings::ooInetFTPProxyPort::get();
222 if (x)
224 nIntValue = *x;
225 m_xFtpPortED->set_text( OUString::number( nIntValue ));
227 else
228 m_xFtpPortED->set_text( "" );
230 m_xNoProxyForED->set_text( officecfg::Inet::Settings::ooInetNoProxy::get() );
233 void SvxProxyTabPage::ReadConfigDefaults_Impl()
237 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
239 sal_Int32 nIntValue = 0;
240 OUString aStringValue;
242 if( xPropertyState->getPropertyDefault(g_aHttpProxyPN) >>= aStringValue )
244 m_xHttpProxyED->set_text( aStringValue );
247 if( xPropertyState->getPropertyDefault(g_aHttpPortPN) >>= nIntValue )
249 m_xHttpPortED->set_text( OUString::number( nIntValue ));
252 if( xPropertyState->getPropertyDefault(g_aHttpsProxyPN) >>= aStringValue )
254 m_xHttpsProxyED->set_text( aStringValue );
257 if( xPropertyState->getPropertyDefault(g_aHttpsPortPN) >>= nIntValue )
259 m_xHttpsPortED->set_text( OUString::number( nIntValue ));
262 if( xPropertyState->getPropertyDefault(g_aFtpProxyPN) >>= aStringValue )
264 m_xFtpProxyED->set_text( aStringValue );
267 if( xPropertyState->getPropertyDefault(g_aFtpPortPN) >>= nIntValue )
269 m_xFtpPortED->set_text( OUString::number( nIntValue ));
272 if( xPropertyState->getPropertyDefault(g_aNoProxyDescPN) >>= aStringValue )
274 m_xNoProxyForED->set_text( aStringValue );
277 catch (const beans::UnknownPropertyException &)
279 TOOLS_WARN_EXCEPTION("cui.options", "" );
281 catch (const css::lang::WrappedTargetException &)
283 TOOLS_WARN_EXCEPTION("cui.options", "" );
285 catch (const RuntimeException &)
287 TOOLS_WARN_EXCEPTION("cui.options", "" );
291 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
295 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
297 xPropertyState->setPropertyToDefault(g_aProxyModePN);
298 xPropertyState->setPropertyToDefault(g_aHttpProxyPN);
299 xPropertyState->setPropertyToDefault(g_aHttpPortPN);
300 xPropertyState->setPropertyToDefault(g_aHttpsProxyPN);
301 xPropertyState->setPropertyToDefault(g_aHttpsPortPN);
302 xPropertyState->setPropertyToDefault(g_aFtpProxyPN);
303 xPropertyState->setPropertyToDefault(g_aFtpPortPN);
304 xPropertyState->setPropertyToDefault(g_aNoProxyDescPN);
306 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
307 xChangesBatch->commitChanges();
309 catch (const beans::UnknownPropertyException &)
311 TOOLS_WARN_EXCEPTION("cui.options", "" );
313 catch (const css::lang::WrappedTargetException &)
315 TOOLS_WARN_EXCEPTION("cui.options", "" );
317 catch (const RuntimeException &)
319 TOOLS_WARN_EXCEPTION("cui.options", "" );
323 void SvxProxyTabPage::Reset(const SfxItemSet*)
325 ReadConfigData_Impl();
327 m_xProxyModeLB->save_value();
328 m_xHttpProxyED->save_value();
329 m_xHttpPortED->save_value();
330 m_xHttpsProxyED->save_value();
331 m_xHttpsPortED->save_value();
332 m_xFtpProxyED->save_value();
333 m_xFtpPortED->save_value();
334 m_xNoProxyForED->save_value();
336 EnableControls_Impl();
339 bool SvxProxyTabPage::FillItemSet(SfxItemSet* )
341 bool bModified = false;
343 try {
344 Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
346 sal_Int32 nSelPos = m_xProxyModeLB->get_active();
347 if(m_xProxyModeLB->get_value_changed_from_saved())
349 if( nSelPos == 1 )
351 RestoreConfigDefaults_Impl();
352 return true;
355 xPropertySet->setPropertyValue(g_aProxyModePN, Any(nSelPos));
356 bModified = true;
359 if(m_xHttpProxyED->get_value_changed_from_saved())
361 xPropertySet->setPropertyValue( g_aHttpProxyPN, Any(m_xHttpProxyED->get_text()));
362 bModified = true;
365 if ( m_xHttpPortED->get_value_changed_from_saved())
367 xPropertySet->setPropertyValue( g_aHttpPortPN, Any(m_xHttpPortED->get_text().toInt32()));
368 bModified = true;
371 if( m_xHttpsProxyED->get_value_changed_from_saved() )
373 xPropertySet->setPropertyValue( g_aHttpsProxyPN, Any(m_xHttpsProxyED->get_text()) );
374 bModified = true;
377 if ( m_xHttpsPortED->get_value_changed_from_saved() )
379 xPropertySet->setPropertyValue( g_aHttpsPortPN, Any(m_xHttpsPortED->get_text().toInt32()) );
380 bModified = true;
383 if( m_xFtpProxyED->get_value_changed_from_saved())
385 xPropertySet->setPropertyValue( g_aFtpProxyPN, Any(m_xFtpProxyED->get_text()) );
386 bModified = true;
389 if ( m_xFtpPortED->get_value_changed_from_saved() )
391 xPropertySet->setPropertyValue( g_aFtpPortPN, Any(m_xFtpPortED->get_text().toInt32()));
392 bModified = true;
395 if ( m_xNoProxyForED->get_value_changed_from_saved() )
397 xPropertySet->setPropertyValue( g_aNoProxyDescPN, Any( m_xNoProxyForED->get_text()));
398 bModified = true;
401 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
402 xChangesBatch->commitChanges();
404 catch (const css::lang::IllegalArgumentException &) {
405 TOOLS_WARN_EXCEPTION("cui.options", "" );
407 catch (const beans::UnknownPropertyException &) {
408 TOOLS_WARN_EXCEPTION("cui.options", "" );
410 catch (const beans::PropertyVetoException &) {
411 TOOLS_WARN_EXCEPTION("cui.options", "" );
413 catch (const css::lang::WrappedTargetException &) {
414 TOOLS_WARN_EXCEPTION("cui.options", "" );
416 catch (const RuntimeException &) {
417 TOOLS_WARN_EXCEPTION("cui.options", "" );
420 return bModified;
423 void SvxProxyTabPage::EnableControls_Impl()
425 m_xProxyModeLB->set_sensitive(!officecfg::Inet::Settings::ooInetNoProxy::isReadOnly());
427 const bool bManualConfig = m_xProxyModeLB->get_active() == 2;
429 const bool bHTTPProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPProxyName::isReadOnly();
430 const bool bHTTPProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPProxyPort::isReadOnly();
431 m_xHttpProxyFT->set_sensitive(bHTTPProxyNameEnabled);
432 m_xHttpProxyED->set_sensitive(bHTTPProxyNameEnabled);
433 m_xHttpPortFT->set_sensitive(bHTTPProxyPortEnabled);
434 m_xHttpPortED->set_sensitive(bHTTPProxyPortEnabled);
436 const bool bHTTPSProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPSProxyName::isReadOnly();
437 const bool bHTTPSProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPSProxyPort::isReadOnly();
438 m_xHttpsProxyFT->set_sensitive(bHTTPSProxyNameEnabled);
439 m_xHttpsProxyED->set_sensitive(bHTTPSProxyNameEnabled);
440 m_xHttpsPortFT->set_sensitive(bHTTPSProxyPortEnabled);
441 m_xHttpsPortED->set_sensitive(bHTTPSProxyPortEnabled);
443 const bool bFTPProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetFTPProxyName::isReadOnly();
444 const bool bFTPProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetFTPProxyPort::isReadOnly();
445 m_xFtpProxyFT->set_sensitive(bFTPProxyNameEnabled);
446 m_xFtpProxyED->set_sensitive(bFTPProxyNameEnabled);
447 m_xFtpPortFT->set_sensitive(bFTPProxyPortEnabled);
448 m_xFtpPortED->set_sensitive(bFTPProxyPortEnabled);
450 const bool bInetNoProxyEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetNoProxy::isReadOnly();
451 m_xNoProxyForFT->set_sensitive(bInetNoProxyEnabled);
452 m_xNoProxyForED->set_sensitive(bInetNoProxyEnabled);
453 m_xNoProxyDescFT->set_sensitive(bInetNoProxyEnabled);
456 IMPL_LINK(SvxProxyTabPage, ProxyHdl_Impl, weld::ComboBox&, rBox, void)
458 sal_Int32 nPos = rBox.get_active();
460 // Restore original system values
461 if( nPos == 1 )
463 ReadConfigDefaults_Impl();
466 EnableControls_Impl();
469 IMPL_STATIC_LINK(SvxProxyTabPage, LoseFocusHdl_Impl, weld::Widget&, rControl, void)
471 weld::Entry* pEdit = dynamic_cast<weld::Entry*>(&rControl);
472 if (pEdit && !isValidPort(pEdit->get_text()))
473 pEdit->set_text(OUString('0'));
476 /********************************************************************/
477 /* */
478 /* SvxSecurityTabPage */
479 /* */
480 /********************************************************************/
481 SvxSecurityTabPage::SvxSecurityTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
482 : SfxTabPage(pPage, pController, "cui/ui/optsecuritypage.ui", "OptSecurityPage", &rSet)
483 , m_xSecurityOptionsPB(m_xBuilder->weld_button("options"))
484 , m_xSavePasswordsCB(m_xBuilder->weld_check_button("savepassword"))
485 , m_xShowConnectionsPB(m_xBuilder->weld_button("connections"))
486 , m_xMasterPasswordCB(m_xBuilder->weld_check_button("usemasterpassword"))
487 , m_xMasterPasswordFT(m_xBuilder->weld_label("masterpasswordtext"))
488 , m_xMasterPasswordPB(m_xBuilder->weld_button("masterpassword"))
489 , m_xMacroSecFrame(m_xBuilder->weld_container("macrosecurity"))
490 , m_xMacroSecPB(m_xBuilder->weld_button("macro"))
491 , m_xCertFrame(m_xBuilder->weld_container("certificatepath"))
492 , m_xCertPathPB(m_xBuilder->weld_button("cert"))
493 , m_xTSAURLsFrame(m_xBuilder->weld_container("tsaurls"))
494 , m_xTSAURLsPB(m_xBuilder->weld_button("tsas"))
495 , m_xNoPasswordSaveFT(m_xBuilder->weld_label("nopasswordsave"))
497 //fdo#65595, we need height-for-width support here, but for now we can
498 //bodge it
499 Size aPrefSize(m_xSavePasswordsCB->get_preferred_size());
500 int nMaxWidth = m_xSavePasswordsCB->get_approximate_digit_width() * 40;
501 if (aPrefSize.Width() > nMaxWidth)
503 m_xSavePasswordsCB->set_label_wrap(true);
504 m_xSavePasswordsCB->set_size_request(nMaxWidth, -1);
507 m_sPasswordStoringDeactivateStr = m_xNoPasswordSaveFT->get_label();
509 InitControls();
511 m_xSecurityOptionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
512 m_xSavePasswordsCB->connect_toggled( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
513 m_xMasterPasswordPB->connect_clicked( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
514 m_xMasterPasswordCB->connect_toggled( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
515 m_xShowConnectionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
516 m_xMacroSecPB->connect_clicked( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
517 m_xCertPathPB->connect_clicked( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
518 m_xTSAURLsPB->connect_clicked( LINK( this, SvxSecurityTabPage, TSAURLsPBHdl ) );
520 ActivatePage( rSet );
523 SvxSecurityTabPage::~SvxSecurityTabPage()
527 IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl, weld::Button&, void)
529 if (!m_xSecOptDlg)
530 m_xSecOptDlg.reset(new svx::SecurityOptionsDialog(GetFrameWeld()));
531 m_xSecOptDlg->run();
534 IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl, weld::Toggleable&, void)
538 Reference< task::XPasswordContainer2 > xMasterPasswd(
539 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
541 if ( m_xSavePasswordsCB->get_active() )
543 bool bOldValue = xMasterPasswd->allowPersistentStoring( true );
544 xMasterPasswd->removeMasterPassword();
546 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
547 GetDialogController()->getDialog()->GetXWindow()));
549 if ( xMasterPasswd->changeMasterPassword(xTmpHandler) )
551 m_xMasterPasswordPB->set_sensitive(true);
552 m_xMasterPasswordCB->set_active(true);
553 m_xMasterPasswordCB->set_sensitive(true);
554 m_xMasterPasswordFT->set_sensitive(true);
555 m_xShowConnectionsPB->set_sensitive(true);
557 else
559 xMasterPasswd->allowPersistentStoring( bOldValue );
560 m_xSavePasswordsCB->set_active( false );
563 else
565 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
566 VclMessageType::Question, VclButtonsType::YesNo,
567 m_sPasswordStoringDeactivateStr));
568 xQueryBox->set_default_response(RET_NO);
570 sal_uInt16 nRet = xQueryBox->run();
572 if( RET_YES == nRet )
574 xMasterPasswd->allowPersistentStoring( false );
575 m_xMasterPasswordCB->set_active(true);
576 m_xMasterPasswordPB->set_sensitive( false );
577 m_xMasterPasswordCB->set_sensitive( false );
578 m_xMasterPasswordFT->set_sensitive( false );
579 m_xShowConnectionsPB->set_sensitive( false );
581 else
583 m_xSavePasswordsCB->set_active(true);
584 m_xMasterPasswordPB->set_sensitive(true);
585 m_xShowConnectionsPB->set_sensitive(true);
589 catch (const Exception&)
591 m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
595 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl, weld::Button&, void)
599 Reference< task::XPasswordContainer2 > xMasterPasswd(
600 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
602 if ( xMasterPasswd->isPersistentStoringAllowed() )
604 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
605 GetDialogController()->getDialog()->GetXWindow()));
606 xMasterPasswd->changeMasterPassword(xTmpHandler);
609 catch (const Exception&)
613 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl, weld::Toggleable&, void)
617 Reference< task::XPasswordContainer2 > xMasterPasswd(
618 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
620 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
621 GetDialogController()->getDialog()->GetXWindow()));
623 if ( m_xMasterPasswordCB->get_active() )
625 if (xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword(xTmpHandler))
627 m_xMasterPasswordPB->set_sensitive(true);
628 m_xMasterPasswordFT->set_sensitive(true);
630 else
632 m_xMasterPasswordCB->set_active( false );
633 m_xMasterPasswordPB->set_sensitive(true);
634 m_xMasterPasswordFT->set_sensitive(true);
637 else
639 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword(xTmpHandler) )
641 m_xMasterPasswordPB->set_sensitive( false );
642 m_xMasterPasswordFT->set_sensitive( false );
644 else
646 m_xMasterPasswordCB->set_active(true);
647 m_xMasterPasswordPB->set_sensitive(true);
648 m_xShowConnectionsPB->set_sensitive(true);
652 catch (const Exception&)
654 m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
658 IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl, weld::Button&, void)
662 Reference< task::XPasswordContainer2 > xMasterPasswd(
663 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
665 uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
666 GetDialogController()->getDialog()->GetXWindow()));
668 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword(xTmpHandler) )
670 svx::WebConnectionInfoDialog aDlg(GetFrameWeld());
671 aDlg.run();
674 catch (const Exception&)
678 IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl, weld::Button&, void)
680 if (!mpCertPathDlg)
681 mpCertPathDlg.reset(new CertPathDialog(GetFrameWeld()));
682 mpCertPathDlg->Init();
684 if (mpCertPathDlg->run() == RET_OK && !mpCertPathDlg->isActiveServicePath())
686 SolarMutexGuard aGuard;
687 if (svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, svtools::RESTART_REASON_ADDING_PATH))
688 GetDialogController()->response(RET_OK);
692 IMPL_LINK_NOARG(SvxSecurityTabPage, TSAURLsPBHdl, weld::Button&, void)
694 // Unlike the mpCertPathDlg, we *don't* keep the same dialog object around between
695 // invocations. Seems clearer to my little brain that way.
696 TSAURLsDialog aTSAURLsDlg(GetFrameWeld());
697 aTSAURLsDlg.run();
700 IMPL_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl, weld::Button&, void)
704 Reference< security::XDocumentDigitalSignatures > xD(
705 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
706 xD->setParentWindow(GetDialogController()->getDialog()->GetXWindow());
707 xD->manageTrustedSources();
709 catch (const Exception&)
711 TOOLS_WARN_EXCEPTION( "cui.options", "");
715 void SvxSecurityTabPage::InitControls()
717 #ifndef UNX
718 m_xCertFrame->hide();
719 #endif
721 m_xMasterPasswordPB->set_sensitive( false );
722 m_xMasterPasswordCB->set_sensitive( false );
723 m_xMasterPasswordCB->set_active(true);
724 m_xMasterPasswordFT->set_sensitive( false );
725 m_xShowConnectionsPB->set_sensitive( false );
727 // initialize the password saving checkbox
730 Reference< task::XPasswordContainer2 > xMasterPasswd(
731 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
733 if ( xMasterPasswd->isPersistentStoringAllowed() )
735 m_xMasterPasswordCB->set_sensitive(true);
736 m_xShowConnectionsPB->set_sensitive(true);
737 m_xSavePasswordsCB->set_active(true);
739 if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
740 m_xMasterPasswordCB->set_active( false );
741 else
743 m_xMasterPasswordPB->set_sensitive(true);
744 m_xMasterPasswordCB->set_active(true);
745 m_xMasterPasswordFT->set_sensitive(true);
749 catch (const Exception&)
751 m_xSavePasswordsCB->set_sensitive( false );
755 std::unique_ptr<SfxTabPage> SvxSecurityTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
757 return std::make_unique<SvxSecurityTabPage>(pPage, pController, *rAttrSet);
760 void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
764 DeactivateRC SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
766 if( _pSet )
767 FillItemSet( _pSet );
768 return DeactivateRC::LeavePage;
771 namespace
773 bool CheckAndSave( SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModified )
775 bool bModified = false;
776 if ( !SvtSecurityOptions::IsReadOnly( _eOpt ) )
778 bModified = SvtSecurityOptions::IsOptionSet( _eOpt ) != _bIsChecked;
779 if ( bModified )
781 SvtSecurityOptions::SetOption( _eOpt, _bIsChecked );
782 _rModified = true;
786 return bModified;
790 bool SvxSecurityTabPage::FillItemSet( SfxItemSet* )
792 bool bModified = false;
794 if (m_xSecOptDlg)
796 CheckAndSave( SvtSecurityOptions::EOption::DocWarnSaveOrSend, m_xSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
797 CheckAndSave( SvtSecurityOptions::EOption::DocWarnSigning, m_xSecOptDlg->IsSignDocsChecked(), bModified );
798 CheckAndSave( SvtSecurityOptions::EOption::DocWarnPrint, m_xSecOptDlg->IsPrintDocsChecked(), bModified );
799 CheckAndSave( SvtSecurityOptions::EOption::DocWarnCreatePdf, m_xSecOptDlg->IsCreatePdfChecked(), bModified );
800 CheckAndSave( SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo, m_xSecOptDlg->IsRemovePersInfoChecked(), bModified );
801 CheckAndSave( SvtSecurityOptions::EOption::DocWarnRecommendPassword, m_xSecOptDlg->IsRecommPasswdChecked(), bModified );
802 CheckAndSave( SvtSecurityOptions::EOption::CtrlClickHyperlink, m_xSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
803 CheckAndSave( SvtSecurityOptions::EOption::BlockUntrustedRefererLinks, m_xSecOptDlg->IsBlockUntrustedRefererLinksChecked(), bModified );
806 return bModified;
809 /*--------------------------------------------------------------------*/
811 void SvxSecurityTabPage::Reset( const SfxItemSet* )
815 struct SvxEMailTabPage_Impl
817 SvxEMailTabPage_Impl():
818 sProgram(officecfg::Office::Common::ExternalMailer::Program::get()),
819 bROProgram(
820 officecfg::Office::Common::ExternalMailer::Program::isReadOnly()),
821 bHideContent(
822 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get()),
823 bROHideContent(
824 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::isReadOnly())
827 OUString sProgram;
828 bool bROProgram;
829 bool bHideContent;
830 bool bROHideContent;
833 SvxEMailTabPage::SvxEMailTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
834 : SfxTabPage( pPage, pController, "cui/ui/optemailpage.ui", "OptEmailPage", &rSet)
835 , pImpl(new SvxEMailTabPage_Impl)
836 , m_xMailContainer(m_xBuilder->weld_container("program"))
837 , m_xMailerURLFI(m_xBuilder->weld_image("lockemail"))
838 , m_xMailerURLED(m_xBuilder->weld_entry("url"))
839 , m_xMailerURLPB(m_xBuilder->weld_button("browse"))
840 , m_xSuppressHiddenContainer(m_xBuilder->weld_container("suppressHiddenCont"))
841 , m_xSuppressHiddenFI(m_xBuilder->weld_image("lockSuppressHidden"))
842 , m_xSuppressHidden(m_xBuilder->weld_check_button("suppressHidden"))
843 , m_xDefaultFilterFT(m_xBuilder->weld_label("browsetitle"))
845 m_sDefaultFilterName = m_xDefaultFilterFT->get_label();
846 m_xMailerURLPB->connect_clicked( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
849 /* -------------------------------------------------------------------------*/
851 SvxEMailTabPage::~SvxEMailTabPage()
855 /* -------------------------------------------------------------------------*/
857 std::unique_ptr<SfxTabPage> SvxEMailTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
859 return std::make_unique<SvxEMailTabPage>(pPage, pController, *rAttrSet);
862 /* -------------------------------------------------------------------------*/
864 bool SvxEMailTabPage::FillItemSet( SfxItemSet* )
866 std::shared_ptr<comphelper::ConfigurationChanges> batch(
867 comphelper::ConfigurationChanges::create());
868 if (!pImpl->bROProgram && m_xMailerURLED->get_value_changed_from_saved())
870 pImpl->sProgram = m_xMailerURLED->get_text();
871 officecfg::Office::Common::ExternalMailer::Program::set(
872 pImpl->sProgram, batch);
874 if (!pImpl->bROHideContent
875 && pImpl->bHideContent != m_xSuppressHidden->get_active())
877 pImpl->bHideContent = m_xSuppressHidden->get_active();
878 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::set(
879 pImpl->bHideContent, batch);
881 batch->commit();
882 return false;
885 /* -------------------------------------------------------------------------*/
887 void SvxEMailTabPage::Reset( const SfxItemSet* )
889 m_xMailerURLED->set_sensitive(true);
890 m_xMailerURLPB->set_sensitive(true);
892 if (pImpl->bROProgram)
893 m_xMailerURLFI->show();
895 m_xMailerURLED->set_text(pImpl->sProgram);
896 m_xMailerURLED->save_value();
898 m_xMailContainer->set_sensitive(!pImpl->bROProgram);
900 if (pImpl->bROHideContent)
901 m_xSuppressHiddenFI->show();
903 m_xSuppressHidden->set_active(pImpl->bHideContent);
905 m_xSuppressHiddenContainer->set_sensitive(!pImpl->bROHideContent);
908 /* -------------------------------------------------------------------------*/
910 IMPL_LINK_NOARG(SvxEMailTabPage, FileDialogHdl_Impl, weld::Button&, void)
912 if (pImpl->bROProgram)
913 return;
915 FileDialogHelper aHelper(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, GetFrameWeld());
916 OUString sPath = m_xMailerURLED->get_text();
917 if ( sPath.isEmpty() )
918 sPath = "/usr/bin";
920 OUString sUrl;
921 osl::FileBase::getFileURLFromSystemPath(sPath, sUrl);
922 aHelper.SetDisplayDirectory(sUrl);
923 aHelper.AddFilter( m_sDefaultFilterName, "*");
925 if ( ERRCODE_NONE == aHelper.Execute() )
927 sUrl = aHelper.GetPath();
928 if (osl::FileBase::getSystemPathFromFileURL(sUrl, sPath)
929 != osl::FileBase::E_None)
931 sPath.clear();
933 m_xMailerURLED->set_text(sPath);
938 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */