1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <toolkit/helper/vclunohelper.hxx>
28 #include <vcl/weld.hxx>
29 #include <sfx2/filedlghelper.hxx>
30 #include <vcl/svapp.hxx>
31 #include <unotools/securityoptions.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <tools/diagnose_ex.h>
35 #include <dialmgr.hxx>
36 #include "optinet2.hxx"
37 #include <strings.hrc>
39 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
40 #include <com/sun/star/task/InteractionHandler.hpp>
42 #include <sal/types.h>
43 #include <sal/log.hxx>
44 #include <rtl/ustring.hxx>
45 #include <osl/file.hxx>
46 #include <com/sun/star/configuration/theDefaultProvider.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/beans/NamedValue.hpp>
49 #include <com/sun/star/beans/XPropertySet.hpp>
50 #include <com/sun/star/beans/XPropertyState.hpp>
51 #include <com/sun/star/util/XChangesBatch.hpp>
52 #include <comphelper/processfactory.hxx>
53 #include <comphelper/string.hxx>
55 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
56 #include <com/sun/star/task/PasswordContainer.hpp>
57 #include <com/sun/star/task/XPasswordContainer2.hpp>
58 #include "securityoptions.hxx"
59 #include "webconninfo.hxx"
60 #include "certpath.hxx"
61 #include "tsaurls.hxx"
63 #include <svtools/restartdialog.hxx>
65 using namespace ::com::sun::star
;
66 using namespace ::com::sun::star::uno
;
67 using namespace ::sfx2
;
71 bool isValidPort(OUString
const & value
) {
72 if (!comphelper::string::isdigitAsciiString(value
)) {
75 auto const n
= value
.toUInt64();
82 // Overflow in OUString::toUInt64 returns 0, so need to check value contains only zeroes:
83 return std::u16string_view(value
).find_first_not_of(u
'0') == std::u16string_view::npos
;
88 IMPL_LINK(SvxProxyTabPage
, PortChangedHdl
, weld::Entry
&, rEdit
, void)
90 if (!isValidPort(rEdit
.get_text()))
92 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(),
93 VclMessageType::Warning
, VclButtonsType::Ok
,
94 CuiResId( RID_SVXSTR_OPT_PROXYPORTS
)));
99 static const char g_aProxyModePN
[] = "ooInetProxyType";
100 static const char g_aHttpProxyPN
[] = "ooInetHTTPProxyName";
101 static const char g_aHttpPortPN
[] = "ooInetHTTPProxyPort";
102 static const char g_aHttpsProxyPN
[] = "ooInetHTTPSProxyName";
103 static const char g_aHttpsPortPN
[] = "ooInetHTTPSProxyPort";
104 static const char g_aFtpProxyPN
[] = "ooInetFTPProxyName";
105 static const char g_aFtpPortPN
[] = "ooInetFTPProxyPort";
106 static const char g_aNoProxyDescPN
[] = "ooInetNoProxy";
108 IMPL_STATIC_LINK(SvxProxyTabPage
, NumberOnlyTextFilterHdl
, OUString
&, rTest
, bool)
110 OUStringBuffer sAllowed
;
111 for (sal_Int32 i
= 0, nLen
= rTest
.getLength(); i
< nLen
; ++i
)
113 if (rTest
[i
] >= '0' && rTest
[i
] <= '9')
114 sAllowed
.append(rTest
[i
]);
116 rTest
= sAllowed
.makeStringAndClear();
120 IMPL_STATIC_LINK(SvxProxyTabPage
, NoSpaceTextFilterHdl
, OUString
&, rTest
, bool)
122 rTest
= rTest
.replaceAll(" ", "");
126 /********************************************************************/
128 /* SvxProxyTabPage */
130 /********************************************************************/
131 SvxProxyTabPage::SvxProxyTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
132 : SfxTabPage(pPage
, pController
, "cui/ui/optproxypage.ui", "OptProxyPage", &rSet
)
133 , m_xProxyModeLB(m_xBuilder
->weld_combo_box("proxymode"))
134 , m_xHttpProxyFT(m_xBuilder
->weld_label("httpft"))
135 , m_xHttpProxyED(m_xBuilder
->weld_entry("http"))
136 , m_xHttpPortFT(m_xBuilder
->weld_label("httpportft"))
137 , m_xHttpPortED(m_xBuilder
->weld_entry("httpport"))
138 , m_xHttpsProxyFT(m_xBuilder
->weld_label("httpsft"))
139 , m_xHttpsProxyED(m_xBuilder
->weld_entry("https"))
140 , m_xHttpsPortFT(m_xBuilder
->weld_label("httpsportft"))
141 , m_xHttpsPortED(m_xBuilder
->weld_entry("httpsport"))
142 , m_xFtpProxyFT(m_xBuilder
->weld_label("ftpft"))
143 , m_xFtpProxyED(m_xBuilder
->weld_entry("ftp"))
144 , m_xFtpPortFT(m_xBuilder
->weld_label("ftpportft"))
145 , m_xFtpPortED(m_xBuilder
->weld_entry("ftpport"))
146 , m_xNoProxyForFT(m_xBuilder
->weld_label("noproxyft"))
147 , m_xNoProxyForED(m_xBuilder
->weld_entry("noproxy"))
148 , m_xNoProxyDescFT(m_xBuilder
->weld_label("noproxydesc"))
150 m_xHttpProxyED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NoSpaceTextFilterHdl
));
151 m_xHttpPortED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NumberOnlyTextFilterHdl
));
152 m_xHttpPortED
->connect_changed(LINK(this, SvxProxyTabPage
, PortChangedHdl
));
153 m_xHttpsProxyED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NoSpaceTextFilterHdl
));
154 m_xHttpsPortED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NumberOnlyTextFilterHdl
));
155 m_xHttpsPortED
->connect_changed(LINK(this, SvxProxyTabPage
, PortChangedHdl
));
156 m_xFtpProxyED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NoSpaceTextFilterHdl
));
157 m_xFtpPortED
->connect_insert_text(LINK(this, SvxProxyTabPage
, NumberOnlyTextFilterHdl
));
158 m_xFtpPortED
->connect_changed(LINK(this, SvxProxyTabPage
, PortChangedHdl
));
160 Link
<weld::Widget
&,void> aLink
= LINK( this, SvxProxyTabPage
, LoseFocusHdl_Impl
);
161 m_xHttpPortED
->connect_focus_out( aLink
);
162 m_xHttpsPortED
->connect_focus_out( aLink
);
163 m_xFtpPortED
->connect_focus_out( aLink
);
165 m_xProxyModeLB
->connect_changed(LINK( this, SvxProxyTabPage
, ProxyHdl_Impl
));
167 Reference
< css::lang::XMultiServiceFactory
>
168 xConfigurationProvider(
169 configuration::theDefaultProvider::get(
170 comphelper::getProcessComponentContext() ) );
172 beans::NamedValue aProperty
;
173 aProperty
.Name
= "nodepath";
174 aProperty
.Value
<<= OUString( "org.openoffice.Inet/Settings" );
176 Sequence
< Any
> aArgumentList( 1 );
177 aArgumentList
[0] <<= aProperty
;
179 m_xConfigurationUpdateAccess
= xConfigurationProvider
->createInstanceWithArguments(
180 "com.sun.star.configuration.ConfigurationUpdateAccess",
184 SvxProxyTabPage::~SvxProxyTabPage()
188 std::unique_ptr
<SfxTabPage
> SvxProxyTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
190 return std::make_unique
<SvxProxyTabPage
>(pPage
, pController
, *rAttrSet
);
193 void SvxProxyTabPage::ReadConfigData_Impl()
196 Reference
< container::XNameAccess
> xNameAccess(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
198 sal_Int32 nIntValue
= 0;
199 OUString aStringValue
;
201 if( xNameAccess
->getByName(g_aProxyModePN
) >>= nIntValue
)
203 m_xProxyModeLB
->set_active(nIntValue
);
206 if( xNameAccess
->getByName(g_aHttpProxyPN
) >>= aStringValue
)
208 m_xHttpProxyED
->set_text( aStringValue
);
211 if( xNameAccess
->getByName(g_aHttpPortPN
) >>= nIntValue
)
213 m_xHttpPortED
->set_text( OUString::number( nIntValue
));
216 if( xNameAccess
->getByName(g_aHttpsProxyPN
) >>= aStringValue
)
218 m_xHttpsProxyED
->set_text( aStringValue
);
221 if( xNameAccess
->getByName(g_aHttpsPortPN
) >>= nIntValue
)
223 m_xHttpsPortED
->set_text( OUString::number( nIntValue
));
226 if( xNameAccess
->getByName(g_aFtpProxyPN
) >>= aStringValue
)
228 m_xFtpProxyED
->set_text( aStringValue
);
231 if( xNameAccess
->getByName(g_aFtpPortPN
) >>= nIntValue
)
233 m_xFtpPortED
->set_text( OUString::number( nIntValue
));
236 if( xNameAccess
->getByName(g_aNoProxyDescPN
) >>= aStringValue
)
238 m_xNoProxyForED
->set_text( aStringValue
);
241 catch (const container::NoSuchElementException
&) {
242 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
244 catch (const css::lang::WrappedTargetException
&) {
245 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
247 catch (const RuntimeException
&) {
248 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
252 void SvxProxyTabPage::ReadConfigDefaults_Impl()
256 Reference
< beans::XPropertyState
> xPropertyState(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
258 sal_Int32 nIntValue
= 0;
259 OUString aStringValue
;
261 if( xPropertyState
->getPropertyDefault(g_aHttpProxyPN
) >>= aStringValue
)
263 m_xHttpProxyED
->set_text( aStringValue
);
266 if( xPropertyState
->getPropertyDefault(g_aHttpPortPN
) >>= nIntValue
)
268 m_xHttpPortED
->set_text( OUString::number( nIntValue
));
271 if( xPropertyState
->getPropertyDefault(g_aHttpsProxyPN
) >>= aStringValue
)
273 m_xHttpsProxyED
->set_text( aStringValue
);
276 if( xPropertyState
->getPropertyDefault(g_aHttpsPortPN
) >>= nIntValue
)
278 m_xHttpsPortED
->set_text( OUString::number( nIntValue
));
281 if( xPropertyState
->getPropertyDefault(g_aFtpProxyPN
) >>= aStringValue
)
283 m_xFtpProxyED
->set_text( aStringValue
);
286 if( xPropertyState
->getPropertyDefault(g_aFtpPortPN
) >>= nIntValue
)
288 m_xFtpPortED
->set_text( OUString::number( nIntValue
));
291 if( xPropertyState
->getPropertyDefault(g_aNoProxyDescPN
) >>= aStringValue
)
293 m_xNoProxyForED
->set_text( aStringValue
);
296 catch (const beans::UnknownPropertyException
&)
298 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: UnknownPropertyException caught" );
300 catch (const css::lang::WrappedTargetException
&) {
301 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: WrappedTargetException caught" );
303 catch (const RuntimeException
&)
305 SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: RuntimeException caught" );
309 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
313 Reference
< beans::XPropertyState
> xPropertyState(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
315 xPropertyState
->setPropertyToDefault(g_aProxyModePN
);
316 xPropertyState
->setPropertyToDefault(g_aHttpProxyPN
);
317 xPropertyState
->setPropertyToDefault(g_aHttpPortPN
);
318 xPropertyState
->setPropertyToDefault(g_aHttpsProxyPN
);
319 xPropertyState
->setPropertyToDefault(g_aHttpsPortPN
);
320 xPropertyState
->setPropertyToDefault(g_aFtpProxyPN
);
321 xPropertyState
->setPropertyToDefault(g_aFtpPortPN
);
322 xPropertyState
->setPropertyToDefault(g_aNoProxyDescPN
);
324 Reference
< util::XChangesBatch
> xChangesBatch(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
325 xChangesBatch
->commitChanges();
327 catch (const beans::UnknownPropertyException
&)
329 SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
331 catch (const css::lang::WrappedTargetException
&) {
332 SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
334 catch (const RuntimeException
&)
336 SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
340 void SvxProxyTabPage::Reset(const SfxItemSet
*)
342 ReadConfigData_Impl();
344 m_xProxyModeLB
->save_value();
345 m_xHttpProxyED
->save_value();
346 m_xHttpPortED
->save_value();
347 m_xHttpsProxyED
->save_value();
348 m_xHttpsPortED
->save_value();
349 m_xFtpProxyED
->save_value();
350 m_xFtpPortED
->save_value();
351 m_xNoProxyForED
->save_value();
353 EnableControls_Impl();
356 bool SvxProxyTabPage::FillItemSet(SfxItemSet
* )
358 bool bModified
= false;
361 Reference
< beans::XPropertySet
> xPropertySet(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
363 sal_Int32 nSelPos
= m_xProxyModeLB
->get_active();
364 if(m_xProxyModeLB
->get_value_changed_from_saved())
368 RestoreConfigDefaults_Impl();
372 xPropertySet
->setPropertyValue(g_aProxyModePN
, Any(nSelPos
));
376 if(m_xHttpProxyED
->get_value_changed_from_saved())
378 xPropertySet
->setPropertyValue( g_aHttpProxyPN
, Any(m_xHttpProxyED
->get_text()));
382 if ( m_xHttpPortED
->get_value_changed_from_saved())
384 xPropertySet
->setPropertyValue( g_aHttpPortPN
, Any(m_xHttpPortED
->get_text().toInt32()));
388 if( m_xHttpsProxyED
->get_value_changed_from_saved() )
390 xPropertySet
->setPropertyValue( g_aHttpsProxyPN
, Any(m_xHttpsProxyED
->get_text()) );
394 if ( m_xHttpsPortED
->get_value_changed_from_saved() )
396 xPropertySet
->setPropertyValue( g_aHttpsPortPN
, Any(m_xHttpsPortED
->get_text().toInt32()) );
400 if( m_xFtpProxyED
->get_value_changed_from_saved())
402 xPropertySet
->setPropertyValue( g_aFtpProxyPN
, Any(m_xFtpProxyED
->get_text()) );
406 if ( m_xFtpPortED
->get_value_changed_from_saved() )
408 xPropertySet
->setPropertyValue( g_aFtpPortPN
, Any(m_xFtpPortED
->get_text().toInt32()));
412 if ( m_xNoProxyForED
->get_value_changed_from_saved() )
414 xPropertySet
->setPropertyValue( g_aNoProxyDescPN
, Any( m_xNoProxyForED
->get_text()));
418 Reference
< util::XChangesBatch
> xChangesBatch(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
419 xChangesBatch
->commitChanges();
421 catch (const css::lang::IllegalArgumentException
&) {
422 SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
424 catch (const beans::UnknownPropertyException
&) {
425 SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
427 catch (const beans::PropertyVetoException
&) {
428 SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
430 catch (const css::lang::WrappedTargetException
&) {
431 SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
433 catch (const RuntimeException
&) {
434 SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
440 void SvxProxyTabPage::EnableControls_Impl()
442 m_xProxyModeLB
->set_sensitive(!officecfg::Inet::Settings::ooInetNoProxy::isReadOnly());
444 const bool bManualConfig
= m_xProxyModeLB
->get_active() == 2;
446 const bool bHTTPProxyNameEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetHTTPProxyName::isReadOnly();
447 const bool bHTTPProxyPortEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetHTTPProxyPort::isReadOnly();
448 m_xHttpProxyFT
->set_sensitive(bHTTPProxyNameEnabled
);
449 m_xHttpProxyED
->set_sensitive(bHTTPProxyNameEnabled
);
450 m_xHttpPortFT
->set_sensitive(bHTTPProxyPortEnabled
);
451 m_xHttpPortED
->set_sensitive(bHTTPProxyPortEnabled
);
453 const bool bHTTPSProxyNameEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetHTTPSProxyName::isReadOnly();
454 const bool bHTTPSProxyPortEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetHTTPSProxyPort::isReadOnly();
455 m_xHttpsProxyFT
->set_sensitive(bHTTPSProxyNameEnabled
);
456 m_xHttpsProxyED
->set_sensitive(bHTTPSProxyNameEnabled
);
457 m_xHttpsPortFT
->set_sensitive(bHTTPSProxyPortEnabled
);
458 m_xHttpsPortED
->set_sensitive(bHTTPSProxyPortEnabled
);
460 const bool bFTPProxyNameEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetFTPProxyName::isReadOnly();
461 const bool bFTPProxyPortEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetFTPProxyPort::isReadOnly();
462 m_xFtpProxyFT
->set_sensitive(bFTPProxyNameEnabled
);
463 m_xFtpProxyED
->set_sensitive(bFTPProxyNameEnabled
);
464 m_xFtpPortFT
->set_sensitive(bFTPProxyPortEnabled
);
465 m_xFtpPortED
->set_sensitive(bFTPProxyPortEnabled
);
467 const bool bInetNoProxyEnabled
= bManualConfig
&& !officecfg::Inet::Settings::ooInetNoProxy::isReadOnly();
468 m_xNoProxyForFT
->set_sensitive(bInetNoProxyEnabled
);
469 m_xNoProxyForED
->set_sensitive(bInetNoProxyEnabled
);
470 m_xNoProxyDescFT
->set_sensitive(bInetNoProxyEnabled
);
473 IMPL_LINK(SvxProxyTabPage
, ProxyHdl_Impl
, weld::ComboBox
&, rBox
, void)
475 sal_Int32 nPos
= rBox
.get_active();
477 // Restore original system values
480 ReadConfigDefaults_Impl();
483 EnableControls_Impl();
486 IMPL_STATIC_LINK(SvxProxyTabPage
, LoseFocusHdl_Impl
, weld::Widget
&, rControl
, void)
488 weld::Entry
* pEdit
= dynamic_cast<weld::Entry
*>(&rControl
);
489 if (pEdit
&& !isValidPort(pEdit
->get_text()))
490 pEdit
->set_text(OUString('0'));
493 /********************************************************************/
495 /* SvxSecurityTabPage */
497 /********************************************************************/
498 SvxSecurityTabPage::SvxSecurityTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
499 : SfxTabPage(pPage
, pController
, "cui/ui/optsecuritypage.ui", "OptSecurityPage", &rSet
)
500 , mpSecOptions(new SvtSecurityOptions
)
501 , m_xSecurityOptionsPB(m_xBuilder
->weld_button("options"))
502 , m_xSavePasswordsCB(m_xBuilder
->weld_check_button("savepassword"))
503 , m_xShowConnectionsPB(m_xBuilder
->weld_button("connections"))
504 , m_xMasterPasswordCB(m_xBuilder
->weld_check_button("usemasterpassword"))
505 , m_xMasterPasswordFT(m_xBuilder
->weld_label("masterpasswordtext"))
506 , m_xMasterPasswordPB(m_xBuilder
->weld_button("masterpassword"))
507 , m_xMacroSecFrame(m_xBuilder
->weld_container("macrosecurity"))
508 , m_xMacroSecPB(m_xBuilder
->weld_button("macro"))
509 , m_xCertFrame(m_xBuilder
->weld_container("certificatepath"))
510 , m_xCertPathPB(m_xBuilder
->weld_button("cert"))
511 , m_xTSAURLsFrame(m_xBuilder
->weld_container("tsaurls"))
512 , m_xTSAURLsPB(m_xBuilder
->weld_button("tsas"))
513 , m_xNoPasswordSaveFT(m_xBuilder
->weld_label("nopasswordsave"))
515 //fdo#65595, we need height-for-width support here, but for now we can
517 Size
aPrefSize(m_xSavePasswordsCB
->get_preferred_size());
518 int nMaxWidth
= m_xSavePasswordsCB
->get_approximate_digit_width() * 40;
519 if (aPrefSize
.Width() > nMaxWidth
)
521 m_xSavePasswordsCB
->set_label_line_wrap(true);
522 m_xSavePasswordsCB
->set_size_request(nMaxWidth
, -1);
525 m_sPasswordStoringDeactivateStr
= m_xNoPasswordSaveFT
->get_label();
529 m_xSecurityOptionsPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, SecurityOptionsHdl
) );
530 m_xSavePasswordsCB
->connect_clicked( LINK( this, SvxSecurityTabPage
, SavePasswordHdl
) );
531 m_xMasterPasswordPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, MasterPasswordHdl
) );
532 m_xMasterPasswordCB
->connect_clicked( LINK( this, SvxSecurityTabPage
, MasterPasswordCBHdl
) );
533 m_xShowConnectionsPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, ShowPasswordsHdl
) );
534 m_xMacroSecPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, MacroSecPBHdl
) );
535 m_xCertPathPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, CertPathPBHdl
) );
536 m_xTSAURLsPB
->connect_clicked( LINK( this, SvxSecurityTabPage
, TSAURLsPBHdl
) );
538 ActivatePage( rSet
);
541 SvxSecurityTabPage::~SvxSecurityTabPage()
545 IMPL_LINK_NOARG(SvxSecurityTabPage
, SecurityOptionsHdl
, weld::Button
&, void)
548 m_xSecOptDlg
.reset(new svx::SecurityOptionsDialog(GetFrameWeld(), mpSecOptions
.get()));
552 IMPL_LINK_NOARG(SvxSecurityTabPage
, SavePasswordHdl
, weld::Button
&, void)
556 Reference
< task::XPasswordContainer2
> xMasterPasswd(
557 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
559 if ( m_xSavePasswordsCB
->get_active() )
561 bool bOldValue
= xMasterPasswd
->allowPersistentStoring( true );
562 xMasterPasswd
->removeMasterPassword();
564 uno::Reference
<task::XInteractionHandler
> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
565 GetDialogController()->getDialog()->GetXWindow()));
567 if ( xMasterPasswd
->changeMasterPassword(xTmpHandler
) )
569 m_xMasterPasswordPB
->set_sensitive(true);
570 m_xMasterPasswordCB
->set_active(true);
571 m_xMasterPasswordCB
->set_sensitive(true);
572 m_xMasterPasswordFT
->set_sensitive(true);
573 m_xShowConnectionsPB
->set_sensitive(true);
577 xMasterPasswd
->allowPersistentStoring( bOldValue
);
578 m_xSavePasswordsCB
->set_active( false );
583 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
584 VclMessageType::Question
, VclButtonsType::YesNo
,
585 m_sPasswordStoringDeactivateStr
));
586 xQueryBox
->set_default_response(RET_NO
);
588 sal_uInt16 nRet
= xQueryBox
->run();
590 if( RET_YES
== nRet
)
592 xMasterPasswd
->allowPersistentStoring( false );
593 m_xMasterPasswordCB
->set_active(true);
594 m_xMasterPasswordPB
->set_sensitive( false );
595 m_xMasterPasswordCB
->set_sensitive( false );
596 m_xMasterPasswordFT
->set_sensitive( false );
597 m_xShowConnectionsPB
->set_sensitive( false );
601 m_xSavePasswordsCB
->set_active(true);
602 m_xMasterPasswordPB
->set_sensitive(true);
603 m_xShowConnectionsPB
->set_sensitive(true);
607 catch (const Exception
&)
609 m_xSavePasswordsCB
->set_active( !m_xSavePasswordsCB
->get_active() );
613 IMPL_LINK_NOARG(SvxSecurityTabPage
, MasterPasswordHdl
, weld::Button
&, void)
617 Reference
< task::XPasswordContainer2
> xMasterPasswd(
618 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
620 if ( xMasterPasswd
->isPersistentStoringAllowed() )
622 uno::Reference
<task::XInteractionHandler
> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
623 GetDialogController()->getDialog()->GetXWindow()));
624 xMasterPasswd
->changeMasterPassword(xTmpHandler
);
627 catch (const Exception
&)
631 IMPL_LINK_NOARG(SvxSecurityTabPage
, MasterPasswordCBHdl
, weld::Button
&, void)
635 Reference
< task::XPasswordContainer2
> xMasterPasswd(
636 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
638 uno::Reference
<task::XInteractionHandler
> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
639 GetDialogController()->getDialog()->GetXWindow()));
641 if ( m_xMasterPasswordCB
->get_active() )
643 if (xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->changeMasterPassword(xTmpHandler
))
645 m_xMasterPasswordPB
->set_sensitive(true);
646 m_xMasterPasswordFT
->set_sensitive(true);
650 m_xMasterPasswordCB
->set_active( false );
651 m_xMasterPasswordPB
->set_sensitive(true);
652 m_xMasterPasswordFT
->set_sensitive(true);
657 if ( xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->useDefaultMasterPassword(xTmpHandler
) )
659 m_xMasterPasswordPB
->set_sensitive( false );
660 m_xMasterPasswordFT
->set_sensitive( false );
664 m_xMasterPasswordCB
->set_active(true);
665 m_xMasterPasswordPB
->set_sensitive(true);
666 m_xShowConnectionsPB
->set_sensitive(true);
670 catch (const Exception
&)
672 m_xSavePasswordsCB
->set_active( !m_xSavePasswordsCB
->get_active() );
676 IMPL_LINK_NOARG(SvxSecurityTabPage
, ShowPasswordsHdl
, weld::Button
&, void)
680 Reference
< task::XPasswordContainer2
> xMasterPasswd(
681 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
683 uno::Reference
<task::XInteractionHandler
> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
684 GetDialogController()->getDialog()->GetXWindow()));
686 if ( xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->authorizateWithMasterPassword(xTmpHandler
) )
688 svx::WebConnectionInfoDialog
aDlg(GetFrameWeld());
692 catch (const Exception
&)
696 IMPL_LINK_NOARG(SvxSecurityTabPage
, CertPathPBHdl
, weld::Button
&, void)
699 mpCertPathDlg
.reset(new CertPathDialog(GetFrameWeld()));
701 OUString sOrig
= mpCertPathDlg
->getDirectory();
702 short nRet
= mpCertPathDlg
->run();
704 if (nRet
== RET_OK
&& sOrig
!= mpCertPathDlg
->getDirectory())
706 SolarMutexGuard aGuard
;
707 if (svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr, svtools::RESTART_REASON_ADDING_PATH
))
708 GetDialogController()->response(RET_OK
);
712 IMPL_LINK_NOARG(SvxSecurityTabPage
, TSAURLsPBHdl
, weld::Button
&, void)
714 // Unlike the mpCertPathDlg, we *don't* keep the same dialog object around between
715 // invocations. Seems clearer to my little brain that way.
716 TSAURLsDialog
aTSAURLsDlg(GetFrameWeld());
720 IMPL_LINK_NOARG(SvxSecurityTabPage
, MacroSecPBHdl
, weld::Button
&, void)
724 Reference
< security::XDocumentDigitalSignatures
> xD(
725 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
726 xD
->setParentWindow(GetDialogController()->getDialog()->GetXWindow());
727 xD
->manageTrustedSources();
729 catch (const Exception
&)
731 TOOLS_WARN_EXCEPTION( "cui.options", "");
735 void SvxSecurityTabPage::InitControls()
737 // Hide all controls which belong to the macro security button in case the macro
738 // security settings managed by the macro security dialog opened via the button
739 // are all readonly or if the macros are disabled in general.
740 // @@@ Better would be to query the dialog whether it is 'useful' or not. Exposing
741 // macro security dialog implementations here, which is bad.
742 if ( mpSecOptions
->IsMacroDisabled()
743 || ( mpSecOptions
->IsReadOnly( SvtSecurityOptions::EOption::MacroSecLevel
)
744 && mpSecOptions
->IsReadOnly( SvtSecurityOptions::EOption::MacroTrustedAuthors
)
745 && mpSecOptions
->IsReadOnly( SvtSecurityOptions::EOption::SecureUrls
) ) )
748 m_xMacroSecFrame
->hide();
752 m_xCertFrame
->hide();
755 m_xMasterPasswordPB
->set_sensitive( false );
756 m_xMasterPasswordCB
->set_sensitive( false );
757 m_xMasterPasswordCB
->set_active(true);
758 m_xMasterPasswordFT
->set_sensitive( false );
759 m_xShowConnectionsPB
->set_sensitive( false );
761 // initialize the password saving checkbox
764 Reference
< task::XPasswordContainer2
> xMasterPasswd(
765 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
767 if ( xMasterPasswd
->isPersistentStoringAllowed() )
769 m_xMasterPasswordCB
->set_sensitive(true);
770 m_xShowConnectionsPB
->set_sensitive(true);
771 m_xSavePasswordsCB
->set_active(true);
773 if ( xMasterPasswd
->isDefaultMasterPasswordUsed() )
774 m_xMasterPasswordCB
->set_active( false );
777 m_xMasterPasswordPB
->set_sensitive(true);
778 m_xMasterPasswordCB
->set_active(true);
779 m_xMasterPasswordFT
->set_sensitive(true);
783 catch (const Exception
&)
785 m_xSavePasswordsCB
->set_sensitive( false );
789 std::unique_ptr
<SfxTabPage
> SvxSecurityTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
791 return std::make_unique
<SvxSecurityTabPage
>(pPage
, pController
, *rAttrSet
);
794 void SvxSecurityTabPage::ActivatePage( const SfxItemSet
& )
798 DeactivateRC
SvxSecurityTabPage::DeactivatePage( SfxItemSet
* _pSet
)
801 FillItemSet( _pSet
);
802 return DeactivateRC::LeavePage
;
807 bool CheckAndSave( SvtSecurityOptions
& _rOpt
, SvtSecurityOptions::EOption _eOpt
, const bool _bIsChecked
, bool& _rModfied
)
809 bool bModified
= false;
810 if ( _rOpt
.IsOptionEnabled( _eOpt
) )
812 bModified
= _rOpt
.IsOptionSet( _eOpt
) != _bIsChecked
;
815 _rOpt
.SetOption( _eOpt
, _bIsChecked
);
824 bool SvxSecurityTabPage::FillItemSet( SfxItemSet
* )
826 bool bModified
= false;
830 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnSaveOrSend
, m_xSecOptDlg
->IsSaveOrSendDocsChecked(), bModified
);
831 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnSigning
, m_xSecOptDlg
->IsSignDocsChecked(), bModified
);
832 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnPrint
, m_xSecOptDlg
->IsPrintDocsChecked(), bModified
);
833 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnCreatePdf
, m_xSecOptDlg
->IsCreatePdfChecked(), bModified
);
834 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo
, m_xSecOptDlg
->IsRemovePersInfoChecked(), bModified
);
835 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::DocWarnRecommendPassword
, m_xSecOptDlg
->IsRecommPasswdChecked(), bModified
);
836 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::CtrlClickHyperlink
, m_xSecOptDlg
->IsCtrlHyperlinkChecked(), bModified
);
837 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::EOption::BlockUntrustedRefererLinks
, m_xSecOptDlg
->IsBlockUntrustedRefererLinksChecked(), bModified
);
843 /*--------------------------------------------------------------------*/
845 void SvxSecurityTabPage::Reset( const SfxItemSet
* )
849 struct SvxEMailTabPage_Impl
851 SvxEMailTabPage_Impl():
852 sProgram(officecfg::Office::Common::ExternalMailer::Program::get()),
854 officecfg::Office::Common::ExternalMailer::Program::isReadOnly()),
856 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get()),
858 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::isReadOnly())
867 SvxEMailTabPage::SvxEMailTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
868 : SfxTabPage( pPage
, pController
, "cui/ui/optemailpage.ui", "OptEmailPage", &rSet
)
869 , pImpl(new SvxEMailTabPage_Impl
)
870 , m_xMailContainer(m_xBuilder
->weld_container("program"))
871 , m_xMailerURLFI(m_xBuilder
->weld_image("lockemail"))
872 , m_xMailerURLED(m_xBuilder
->weld_entry("url"))
873 , m_xMailerURLPB(m_xBuilder
->weld_button("browse"))
874 , m_xSuppressHiddenContainer(m_xBuilder
->weld_container("suppressHiddenCont"))
875 , m_xSuppressHiddenFI(m_xBuilder
->weld_image("lockSuppressHidden"))
876 , m_xSuppressHidden(m_xBuilder
->weld_check_button("suppressHidden"))
877 , m_xDefaultFilterFT(m_xBuilder
->weld_label("browsetitle"))
879 m_sDefaultFilterName
= m_xDefaultFilterFT
->get_label();
880 m_xMailerURLPB
->connect_clicked( LINK( this, SvxEMailTabPage
, FileDialogHdl_Impl
) );
883 /* -------------------------------------------------------------------------*/
885 SvxEMailTabPage::~SvxEMailTabPage()
889 /* -------------------------------------------------------------------------*/
891 std::unique_ptr
<SfxTabPage
> SvxEMailTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrSet
)
893 return std::make_unique
<SvxEMailTabPage
>(pPage
, pController
, *rAttrSet
);
896 /* -------------------------------------------------------------------------*/
898 bool SvxEMailTabPage::FillItemSet( SfxItemSet
* )
900 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(
901 comphelper::ConfigurationChanges::create());
902 if (!pImpl
->bROProgram
&& m_xMailerURLED
->get_value_changed_from_saved())
904 pImpl
->sProgram
= m_xMailerURLED
->get_text();
905 officecfg::Office::Common::ExternalMailer::Program::set(
906 pImpl
->sProgram
, batch
);
908 if (!pImpl
->bROHideContent
909 && pImpl
->bHideContent
!= m_xSuppressHidden
->get_active())
911 pImpl
->bHideContent
= m_xSuppressHidden
->get_active();
912 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::set(
913 pImpl
->bHideContent
, batch
);
919 /* -------------------------------------------------------------------------*/
921 void SvxEMailTabPage::Reset( const SfxItemSet
* )
923 m_xMailerURLED
->set_sensitive(true);
924 m_xMailerURLPB
->set_sensitive(true);
926 if (pImpl
->bROProgram
)
927 m_xMailerURLFI
->show();
929 m_xMailerURLED
->set_text(pImpl
->sProgram
);
930 m_xMailerURLED
->save_value();
932 m_xMailContainer
->set_sensitive(!pImpl
->bROProgram
);
934 if (pImpl
->bROHideContent
)
935 m_xSuppressHiddenFI
->show();
937 m_xSuppressHidden
->set_active(pImpl
->bHideContent
);
939 m_xSuppressHiddenContainer
->set_sensitive(!pImpl
->bROHideContent
);
942 /* -------------------------------------------------------------------------*/
944 IMPL_LINK_NOARG(SvxEMailTabPage
, FileDialogHdl_Impl
, weld::Button
&, void)
946 if (!pImpl
->bROProgram
)
948 FileDialogHelper
aHelper(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, FileDialogFlags::NONE
, GetFrameWeld());
949 OUString sPath
= m_xMailerURLED
->get_text();
950 if ( sPath
.isEmpty() )
954 osl::FileBase::getFileURLFromSystemPath(sPath
, sUrl
);
955 aHelper
.SetDisplayDirectory(sUrl
);
956 aHelper
.AddFilter( m_sDefaultFilterName
, "*");
958 if ( ERRCODE_NONE
== aHelper
.Execute() )
960 sUrl
= aHelper
.GetPath();
961 if (osl::FileBase::getSystemPathFromFileURL(sUrl
, sPath
)
962 != osl::FileBase::E_None
)
966 m_xMailerURLED
->set_text(sPath
);
972 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */