bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / options / optinet2.cxx
bloba3c72ff37eef905a07592d5299e88fe1b87db08c
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 <officecfg/Office/Common.hxx>
23 #include <officecfg/Office/Security.hxx>
24 #include <tools/config.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/stritem.hxx>
28 #include <svl/eitem.hxx>
29 #include <svl/slstitm.hxx>
30 #include <sfx2/fcontnr.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/docfilt.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <sfx2/sfxsids.hrc>
35 #include <sfx2/filedlghelper.hxx>
36 #include <svl/urihelper.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <unotools/bootstrap.hxx>
40 #include <vcl/help.hxx>
41 #include <vcl/layout.hxx>
42 #include <vcl/builderfactory.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <unotools/pathoptions.hxx>
45 #include <unotools/securityoptions.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include <unotools/extendedsecurityoptions.hxx>
48 #include <com/sun/star/uno/Sequence.hxx>
50 #include <dialmgr.hxx>
51 #include "optinet2.hxx"
52 #include <svx/svxdlg.hxx>
53 #include <cuires.hrc>
54 #include "helpid.hrc"
55 #include <svx/ofaitem.hxx>
56 #include <sfx2/htmlmode.hxx>
57 #include <svx/svxids.hrc>
59 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
61 #ifdef UNX
62 #include <sys/stat.h>
63 #include <unistd.h>
64 #include <fcntl.h>
65 #include <pwd.h>
66 #include <sys/types.h>
67 #include <string.h>
68 #include <rtl/textenc.h>
69 #include <rtl/locale.h>
70 #include <osl/nlsupport.h>
71 #endif
72 #include <sal/types.h>
73 #include <sal/macros.h>
74 #include <rtl/ustring.hxx>
75 #include <osl/file.hxx>
76 #include <osl/process.h>
77 #include <com/sun/star/configuration/theDefaultProvider.hpp>
78 #include <com/sun/star/container/XNameReplace.hpp>
79 #include <com/sun/star/container/XNameAccess.hpp>
80 #include <com/sun/star/beans/NamedValue.hpp>
81 #include <com/sun/star/beans/XPropertySet.hpp>
82 #include <com/sun/star/beans/XPropertyState.hpp>
83 #include <com/sun/star/util/XChangesBatch.hpp>
84 #include <comphelper/processfactory.hxx>
85 #include <comphelper/string.hxx>
87 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
88 #include "com/sun/star/task/PasswordContainer.hpp"
89 #include "com/sun/star/task/XPasswordContainer2.hpp"
90 #include "securityoptions.hxx"
91 #include "webconninfo.hxx"
92 #include "certpath.hxx"
93 #include "tsaurls.hxx"
95 using namespace ::com::sun::star;
96 using namespace ::com::sun::star::uno;
97 using namespace ::sfx2;
99 // static ----------------------------------------------------------------
101 #include <sal/config.h>
103 VCL_BUILDER_FACTORY_ARGS(SvxNoSpaceEdit, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK)
105 void SvxNoSpaceEdit::KeyInput( const KeyEvent& rKEvent )
107 bool bValid = rKEvent.GetKeyCode().GetCode() != KEY_SPACE;
108 if (bValid && bOnlyNumeric)
110 const vcl::KeyCode& rKeyCode = rKEvent.GetKeyCode();
111 sal_uInt16 nGroup = rKeyCode.GetGroup();
112 sal_uInt16 nKey = rKeyCode.GetCode();
113 bValid = ( KEYGROUP_NUM == nGroup || KEYGROUP_CURSOR == nGroup ||
114 ( KEYGROUP_MISC == nGroup && ( nKey < KEY_ADD || nKey > KEY_EQUAL ) ) );
115 if ( !bValid && ( rKeyCode.IsMod1() && (
116 KEY_A == nKey || KEY_C == nKey || KEY_V == nKey || KEY_X == nKey || KEY_Z == nKey ) ) )
117 // Erase, Copy, Paste, Select All und Undo soll funktionieren
118 bValid = true;
120 if (bValid)
121 Edit::KeyInput(rKEvent);
126 void SvxNoSpaceEdit::Modify()
128 Edit::Modify();
130 if ( bOnlyNumeric )
132 OUString aValue = GetText();
134 if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
135 // the maximum value of a port number is USHRT_MAX
136 ScopedVclPtrInstance<MessageDialog>::Create( this, CUI_RES( RID_SVXSTR_OPT_PROXYPORTS ) )->Execute();
140 bool SvxNoSpaceEdit::set_property(const OString &rKey, const OString &rValue)
142 if (rKey == "only-numeric")
143 bOnlyNumeric = toBool(rValue);
144 else
145 return Edit::set_property(rKey, rValue);
146 return true;
150 /********************************************************************/
151 /* */
152 /* SvxProxyTabPage */
153 /* */
154 /********************************************************************/
156 SvxProxyTabPage::SvxProxyTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
157 : SfxTabPage(pParent, "OptProxyPage","cui/ui/optproxypage.ui", &rSet)
158 , aProxyModePN("ooInetProxyType")
159 , aHttpProxyPN("ooInetHTTPProxyName")
160 , aHttpPortPN("ooInetHTTPProxyPort")
161 , aHttpsProxyPN("ooInetHTTPSProxyName")
162 , aHttpsPortPN("ooInetHTTPSProxyPort")
163 , aFtpProxyPN("ooInetFTPProxyName")
164 , aFtpPortPN("ooInetFTPProxyPort")
165 , aNoProxyDescPN("ooInetNoProxy")
167 get(m_pProxyModeLB, "proxymode");
169 get(m_pHttpProxyFT, "httpft");
170 get(m_pHttpProxyED, "http");
171 get(m_pHttpPortFT, "httpportft");
172 get(m_pHttpPortED, "httpport");
174 get(m_pHttpsProxyFT, "httpsft");
175 get(m_pHttpsProxyED, "https");
176 get(m_pHttpsPortFT, "httpsportft");
177 get(m_pHttpsPortED, "httpsport");
179 get(m_pFtpProxyFT, "ftpft");
180 get(m_pFtpProxyED, "ftp");
181 get(m_pFtpPortFT, "ftpportft");
182 get(m_pFtpPortED, "ftpport");
184 get(m_pNoProxyForFT, "noproxyft");
185 get(m_pNoProxyForED, "noproxy");
186 get(m_pNoProxyDescFT, "noproxydesc");
188 Link<> aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
189 m_pHttpPortED->SetLoseFocusHdl( aLink );
190 m_pHttpsPortED->SetLoseFocusHdl( aLink );
191 m_pFtpPortED->SetLoseFocusHdl( aLink );
193 m_pProxyModeLB->SetSelectHdl(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
195 Reference< com::sun::star::lang::XMultiServiceFactory >
196 xConfigurationProvider(
197 configuration::theDefaultProvider::get(
198 comphelper::getProcessComponentContext() ) );
200 OUString aConfigRoot( "org.openoffice.Inet/Settings" );
202 beans::NamedValue aProperty;
203 aProperty.Name = "nodepath";
204 aProperty.Value = makeAny( aConfigRoot );
206 Sequence< Any > aArgumentList( 1 );
207 aArgumentList[0] = makeAny( aProperty );
209 m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments(
210 OUString( "com.sun.star.configuration.ConfigurationUpdateAccess" ),
211 aArgumentList );
214 SvxProxyTabPage::~SvxProxyTabPage()
216 disposeOnce();
219 void SvxProxyTabPage::dispose()
221 m_pProxyModeLB.clear();
222 m_pHttpProxyFT.clear();
223 m_pHttpProxyED.clear();
224 m_pHttpPortFT.clear();
225 m_pHttpPortED.clear();
226 m_pHttpsProxyFT.clear();
227 m_pHttpsProxyED.clear();
228 m_pHttpsPortFT.clear();
229 m_pHttpsPortED.clear();
230 m_pFtpProxyFT.clear();
231 m_pFtpProxyED.clear();
232 m_pFtpPortFT.clear();
233 m_pFtpPortED.clear();
234 m_pNoProxyForFT.clear();
235 m_pNoProxyForED.clear();
236 m_pNoProxyDescFT.clear();
237 SfxTabPage::dispose();
240 VclPtr<SfxTabPage> SvxProxyTabPage::Create(vcl::Window* pParent, const SfxItemSet* rAttrSet )
242 return VclPtr<SvxProxyTabPage>::Create(pParent, *rAttrSet);
245 void SvxProxyTabPage::ReadConfigData_Impl()
247 try {
248 Reference< container::XNameAccess > xNameAccess(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
250 sal_Int32 nIntValue = 0;
251 OUString aStringValue;
253 if( xNameAccess->getByName(aProxyModePN) >>= nIntValue )
255 m_pProxyModeLB->SelectEntryPos( nIntValue );
258 if( xNameAccess->getByName(aHttpProxyPN) >>= aStringValue )
260 m_pHttpProxyED->SetText( aStringValue );
263 if( xNameAccess->getByName(aHttpPortPN) >>= nIntValue )
265 m_pHttpPortED->SetText( OUString::number( nIntValue ));
268 if( xNameAccess->getByName(aHttpsProxyPN) >>= aStringValue )
270 m_pHttpsProxyED->SetText( aStringValue );
273 if( xNameAccess->getByName(aHttpsPortPN) >>= nIntValue )
275 m_pHttpsPortED->SetText( OUString::number( nIntValue ));
278 if( xNameAccess->getByName(aFtpProxyPN) >>= aStringValue )
280 m_pFtpProxyED->SetText( aStringValue );
283 if( xNameAccess->getByName(aFtpPortPN) >>= nIntValue )
285 m_pFtpPortED->SetText( OUString::number( nIntValue ));
288 if( xNameAccess->getByName(aNoProxyDescPN) >>= aStringValue )
290 m_pNoProxyForED->SetText( aStringValue );
294 catch (const container::NoSuchElementException&) {
295 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
298 catch (const com::sun::star::lang::WrappedTargetException &) {
299 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
302 catch (const RuntimeException &) {
303 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
308 void SvxProxyTabPage::ReadConfigDefaults_Impl()
312 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
314 sal_Int32 nIntValue = 0;
315 OUString aStringValue;
317 if( xPropertyState->getPropertyDefault(aHttpProxyPN) >>= aStringValue )
319 m_pHttpProxyED->SetText( aStringValue );
322 if( xPropertyState->getPropertyDefault(aHttpPortPN) >>= nIntValue )
324 m_pHttpPortED->SetText( OUString::number( nIntValue ));
327 if( xPropertyState->getPropertyDefault(aHttpsProxyPN) >>= aStringValue )
329 m_pHttpsProxyED->SetText( aStringValue );
332 if( xPropertyState->getPropertyDefault(aHttpsPortPN) >>= nIntValue )
334 m_pHttpsPortED->SetText( OUString::number( nIntValue ));
337 if( xPropertyState->getPropertyDefault(aFtpProxyPN) >>= aStringValue )
339 m_pFtpProxyED->SetText( aStringValue );
342 if( xPropertyState->getPropertyDefault(aFtpPortPN) >>= nIntValue )
344 m_pFtpPortED->SetText( OUString::number( nIntValue ));
347 if( xPropertyState->getPropertyDefault(aNoProxyDescPN) >>= aStringValue )
349 m_pNoProxyForED->SetText( aStringValue );
352 catch (const beans::UnknownPropertyException &)
354 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
357 catch (const com::sun::star::lang::WrappedTargetException &) {
358 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
361 catch (const RuntimeException &)
363 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
367 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
371 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
373 xPropertyState->setPropertyToDefault(aProxyModePN);
374 xPropertyState->setPropertyToDefault(aHttpProxyPN);
375 xPropertyState->setPropertyToDefault(aHttpPortPN);
376 xPropertyState->setPropertyToDefault(aHttpsProxyPN);
377 xPropertyState->setPropertyToDefault(aHttpsPortPN);
378 xPropertyState->setPropertyToDefault(aFtpProxyPN);
379 xPropertyState->setPropertyToDefault(aFtpPortPN);
380 xPropertyState->setPropertyToDefault(aNoProxyDescPN);
382 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
383 xChangesBatch->commitChanges();
386 catch (const beans::UnknownPropertyException &)
388 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
391 catch (const com::sun::star::lang::WrappedTargetException &) {
392 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
395 catch (const RuntimeException &)
397 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
401 void SvxProxyTabPage::Reset(const SfxItemSet*)
403 ReadConfigData_Impl();
405 m_pProxyModeLB->SaveValue();
406 m_pHttpProxyED->SaveValue();
407 m_pHttpPortED->SaveValue();
408 m_pHttpsProxyED->SaveValue();
409 m_pHttpsPortED->SaveValue();
410 m_pFtpProxyED->SaveValue();
411 m_pFtpPortED->SaveValue();
412 m_pNoProxyForED->SaveValue();
414 EnableControls_Impl( m_pProxyModeLB->GetSelectEntryPos() == 2 );
417 bool SvxProxyTabPage::FillItemSet(SfxItemSet* )
419 bool bModified = false;
421 try {
422 Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
424 sal_Int32 nSelPos = m_pProxyModeLB->GetSelectEntryPos();
425 if(m_pProxyModeLB->IsValueChangedFromSaved())
427 if( nSelPos == 1 )
429 RestoreConfigDefaults_Impl();
430 return true;
433 xPropertySet->setPropertyValue(aProxyModePN,
434 makeAny((sal_Int32) nSelPos));
435 bModified = true;
438 if(m_pHttpProxyED->IsValueChangedFromSaved())
440 xPropertySet->setPropertyValue( aHttpProxyPN, makeAny(m_pHttpProxyED->GetText()));
441 bModified = true;
444 if ( m_pHttpPortED->IsValueChangedFromSaved())
446 xPropertySet->setPropertyValue( aHttpPortPN, makeAny(m_pHttpPortED->GetText().toInt32()));
447 bModified = true;
450 if( m_pHttpsProxyED->IsValueChangedFromSaved() )
452 xPropertySet->setPropertyValue( aHttpsProxyPN, makeAny(m_pHttpsProxyED->GetText()) );
453 bModified = true;
456 if ( m_pHttpsPortED->IsValueChangedFromSaved() )
458 xPropertySet->setPropertyValue( aHttpsPortPN, makeAny(m_pHttpsPortED->GetText().toInt32()) );
459 bModified = true;
462 if( m_pFtpProxyED->IsValueChangedFromSaved())
464 xPropertySet->setPropertyValue( aFtpProxyPN, makeAny(m_pFtpProxyED->GetText()) );
465 bModified = true;
468 if ( m_pFtpPortED->IsValueChangedFromSaved() )
470 xPropertySet->setPropertyValue( aFtpPortPN, makeAny(m_pFtpPortED->GetText().toInt32()));
471 bModified = true;
474 if ( m_pNoProxyForED->IsValueChangedFromSaved() )
476 xPropertySet->setPropertyValue( aNoProxyDescPN, makeAny( m_pNoProxyForED->GetText()));
477 bModified = true;
480 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
481 xChangesBatch->commitChanges();
484 catch (const com::sun::star::lang::IllegalArgumentException &) {
485 OSL_TRACE( "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
488 catch (const beans::UnknownPropertyException &) {
489 OSL_TRACE( "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
492 catch (const beans::PropertyVetoException &) {
493 OSL_TRACE( "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
496 catch (const com::sun::star::lang::WrappedTargetException &) {
497 OSL_TRACE( "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
500 catch (const RuntimeException &) {
501 OSL_TRACE( "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
504 return bModified;
507 void SvxProxyTabPage::EnableControls_Impl(bool bEnable)
509 m_pHttpProxyFT->Enable(bEnable);
510 m_pHttpProxyED->Enable(bEnable);
511 m_pHttpPortFT->Enable(bEnable);
512 m_pHttpPortED->Enable(bEnable);
514 m_pHttpsProxyFT->Enable(bEnable);
515 m_pHttpsProxyED->Enable(bEnable);
516 m_pHttpsPortFT->Enable(bEnable);
517 m_pHttpsPortED->Enable(bEnable);
519 m_pFtpProxyFT->Enable(bEnable);
520 m_pFtpProxyED->Enable(bEnable);
521 m_pFtpPortFT->Enable(bEnable);
522 m_pFtpPortED->Enable(bEnable);
524 m_pNoProxyForFT->Enable(bEnable);
525 m_pNoProxyForED->Enable(bEnable);
526 m_pNoProxyDescFT->Enable(bEnable);
531 IMPL_LINK( SvxProxyTabPage, ProxyHdl_Impl, ListBox *, pBox )
533 sal_Int32 nPos = pBox->GetSelectEntryPos();
535 // Restore original system values
536 if( nPos == 1 )
538 ReadConfigDefaults_Impl();
541 EnableControls_Impl(nPos == 2);
542 return 0;
547 IMPL_STATIC_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Edit *, pEdit )
549 OUString aValue = pEdit->GetText();
551 if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
552 pEdit->SetText( OUString('0') );
553 return 0;
558 //#98647#----------------------------------------------
559 void SvxScriptExecListBox::RequestHelp( const HelpEvent& rHEvt )
560 { // try to show tips just like as on toolbars
561 sal_Int32 nPos=LISTBOX_ENTRY_NOTFOUND;
562 sal_Int32 nTop = GetTopEntry();
563 sal_uInt16 nCount = GetDisplayLineCount(); // Attention: Not GetLineCount()
564 Point aPt = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
565 Rectangle aItemRect;
566 if( nCount > 0 ) // if there're some entries, find it.
567 for( nPos = nTop ; nPos <= nTop+nCount-1 ; nPos++ ) {
568 aItemRect = GetBoundingRectangle(nPos);
569 if( aPt.Y() < aItemRect.Top() || aPt.Y() > aItemRect.Bottom() )
570 continue;
571 else
572 break;
574 else // if not, nothing happens.
575 return;
576 OUString aHelpText;
577 if( nPos <= nTop+nCount-1 ) // if find the matching entry, get its content.
578 aHelpText = GetEntry(nPos);
579 if( aHelpText.getLength() && GetTextWidth(aHelpText)<GetOutputSizePixel().Width() )
580 aHelpText.clear(); // if the entry is quite short, clear the helping tip content.
581 aItemRect = Rectangle(Point(0,0),GetSizePixel());
582 aPt = Point(OutputToScreenPixel( aItemRect.TopLeft() ));
583 aItemRect.Left() = aPt.X();
584 aItemRect.Top() = aPt.Y();
585 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
586 aItemRect.Right() = aPt.X();
587 aItemRect.Bottom() = aPt.Y();
588 if( rHEvt.GetMode() == HelpEventMode::BALLOON )
589 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
590 else
591 Help::ShowQuickHelp( this, aItemRect, aHelpText );
594 /********************************************************************/
595 /* */
596 /* SvxSecurityTabPage */
597 /* */
598 /********************************************************************/
600 SvxSecurityTabPage::SvxSecurityTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
601 : SfxTabPage(pParent, "OptSecurityPage", "cui/ui/optsecuritypage.ui", &rSet)
602 , mpSecOptions(new SvtSecurityOptions)
603 , mpSecOptDlg(NULL)
604 , mpCertPathDlg(NULL)
606 get(m_pSecurityOptionsPB, "options");
607 get(m_pSavePasswordsCB, "savepassword");
609 //fdo#65595, we need height-for-width support here, but for now we can
610 //bodge it
611 Size aPrefSize(m_pSavePasswordsCB->get_preferred_size());
612 Size aSize(m_pSavePasswordsCB->CalcMinimumSize(56*approximate_char_width()));
613 if (aPrefSize.Width() > aSize.Width())
615 m_pSavePasswordsCB->set_width_request(aSize.Width());
616 m_pSavePasswordsCB->set_height_request(aSize.Height());
619 get(m_pShowConnectionsPB, "connections");
620 get(m_pMasterPasswordCB, "usemasterpassword");
621 get(m_pMasterPasswordFT, "masterpasswordtext");
622 get(m_pMasterPasswordPB, "masterpassword");
623 get(m_pMacroSecFrame, "macrosecurity");
624 get(m_pMacroSecPB, "macro");
625 get(m_pCertFrame, "certificatepath");
626 get(m_pCertPathPB, "cert");
627 get(m_pTSAURLsFrame, "tsaurls");
628 get(m_pTSAURLsPB, "tsas");
629 m_sPasswordStoringDeactivateStr = get<FixedText>("nopasswordsave")->GetText();
631 InitControls();
633 m_pSecurityOptionsPB->SetClickHdl( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
634 m_pSavePasswordsCB->SetClickHdl( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
635 m_pMasterPasswordPB->SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
636 m_pMasterPasswordCB->SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
637 m_pShowConnectionsPB->SetClickHdl( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
638 m_pMacroSecPB->SetClickHdl( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
639 m_pCertPathPB->SetClickHdl( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
640 m_pTSAURLsPB->SetClickHdl( LINK( this, SvxSecurityTabPage, TSAURLsPBHdl ) );
642 ActivatePage( rSet );
645 SvxSecurityTabPage::~SvxSecurityTabPage()
647 disposeOnce();
650 void SvxSecurityTabPage::dispose()
652 delete mpSecOptions;
653 mpSecOptions = NULL;
654 mpCertPathDlg.disposeAndClear();
655 mpSecOptDlg.clear();
656 m_pSecurityOptionsPB.clear();
657 m_pSavePasswordsCB.clear();
658 m_pShowConnectionsPB.clear();
659 m_pMasterPasswordCB.clear();
660 m_pMasterPasswordFT.clear();
661 m_pMasterPasswordPB.clear();
662 m_pMacroSecFrame.clear();
663 m_pMacroSecPB.clear();
664 m_pCertFrame.clear();
665 m_pCertPathPB.clear();
666 m_pTSAURLsFrame.clear();
667 m_pTSAURLsPB.clear();
669 SfxTabPage::dispose();
672 IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl)
674 if ( !mpSecOptDlg )
675 mpSecOptDlg = VclPtr<svx::SecurityOptionsDialog>::Create( this, mpSecOptions );
676 mpSecOptDlg->Execute();
677 return 0;
680 IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl)
684 Reference< task::XPasswordContainer2 > xMasterPasswd(
685 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
687 if ( m_pSavePasswordsCB->IsChecked() )
689 bool bOldValue = xMasterPasswd->allowPersistentStoring( sal_True );
690 xMasterPasswd->removeMasterPassword();
691 if ( xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
693 m_pMasterPasswordPB->Enable( true );
694 m_pMasterPasswordCB->Check( true );
695 m_pMasterPasswordCB->Enable( true );
696 m_pMasterPasswordFT->Enable( true );
697 m_pShowConnectionsPB->Enable( true );
699 else
701 xMasterPasswd->allowPersistentStoring( bOldValue );
702 m_pSavePasswordsCB->Check( false );
705 else
707 ScopedVclPtrInstance< QueryBox > aQuery( this, WB_YES_NO|WB_DEF_NO, m_sPasswordStoringDeactivateStr );
708 sal_uInt16 nRet = aQuery->Execute();
710 if( RET_YES == nRet )
712 xMasterPasswd->allowPersistentStoring( sal_False );
713 m_pMasterPasswordCB->Check( true );
714 m_pMasterPasswordPB->Enable( false );
715 m_pMasterPasswordCB->Enable( false );
716 m_pMasterPasswordFT->Enable( false );
717 m_pShowConnectionsPB->Enable( false );
719 else
721 m_pSavePasswordsCB->Check( true );
722 m_pMasterPasswordPB->Enable( true );
723 m_pShowConnectionsPB->Enable( true );
727 catch (const Exception&)
729 m_pSavePasswordsCB->Check( !m_pSavePasswordsCB->IsChecked() );
732 return 0;
735 IMPL_STATIC_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl)
739 Reference< task::XPasswordContainer2 > xMasterPasswd(
740 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
742 if ( xMasterPasswd->isPersistentStoringAllowed() )
743 xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() );
745 catch (const Exception&)
748 return 0;
751 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl)
755 Reference< task::XPasswordContainer2 > xMasterPasswd(
756 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
758 if ( m_pMasterPasswordCB->IsChecked() )
760 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
762 m_pMasterPasswordPB->Enable( true );
763 m_pMasterPasswordFT->Enable( true );
765 else
767 m_pMasterPasswordCB->Check( false );
768 m_pMasterPasswordPB->Enable( true );
769 m_pMasterPasswordFT->Enable( true );
772 else
774 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword( Reference< task::XInteractionHandler >() ) )
776 m_pMasterPasswordPB->Enable( false );
777 m_pMasterPasswordFT->Enable( false );
779 else
781 m_pMasterPasswordCB->Check( true );
782 m_pMasterPasswordPB->Enable( true );
783 m_pShowConnectionsPB->Enable( true );
787 catch (const Exception&)
789 m_pSavePasswordsCB->Check( !m_pSavePasswordsCB->IsChecked() );
792 return 0;
795 IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl)
799 Reference< task::XPasswordContainer2 > xMasterPasswd(
800 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
802 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword( Reference< task::XInteractionHandler>() ) )
804 ScopedVclPtrInstance< svx::WebConnectionInfoDialog > aDlg(this);
805 aDlg->Execute();
808 catch (const Exception&)
810 return 0;
813 IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl)
815 if (!mpCertPathDlg)
816 mpCertPathDlg = VclPtr<CertPathDialog>::Create(this);
818 OUString sOrig = mpCertPathDlg->getDirectory();
819 short nRet = mpCertPathDlg->Execute();
821 if (nRet == RET_OK && sOrig != mpCertPathDlg->getDirectory())
823 ScopedVclPtrInstance< MessageDialog > aWarnBox(this, CUI_RES(RID_SVXSTR_OPTIONS_RESTART), VCL_MESSAGE_INFO);
824 aWarnBox->Execute();
827 return 0;
830 IMPL_LINK_NOARG(SvxSecurityTabPage, TSAURLsPBHdl)
832 // Unlike the mpCertPathDlg, we *don't* keep the same dialog object around between
833 // invocations. Seems clearer to my little brain that way.
835 ScopedVclPtrInstance<TSAURLsDialog> pTSAURLsDlg(this);
837 pTSAURLsDlg->Execute();
839 return 0;
842 IMPL_STATIC_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl)
846 Reference< security::XDocumentDigitalSignatures > xD(
847 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
848 xD->manageTrustedSources();
850 catch (const Exception& e)
852 OSL_FAIL(OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
853 (void)e;
855 return 0;
859 void SvxSecurityTabPage::InitControls()
861 // Hide all controls which belong to the macro security button in case the macro
862 // security settings managed by the macro security dialog opened via the button
863 // are all readonly or if the macros are disabled in general.
864 // @@@ Better would be to query the dialog whether it is 'useful' or not. Exposing
865 // macro security dialog implementations here, which is bad.
866 if ( mpSecOptions->IsMacroDisabled()
867 || ( mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL )
868 && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS )
869 && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_SECUREURLS ) ) )
871 //Hide these
872 m_pMacroSecFrame->Hide();
875 #ifndef UNX
876 m_pCertFrame->Hide();
877 #endif
879 m_pMasterPasswordPB->Enable( false );
880 m_pMasterPasswordCB->Enable( false );
881 m_pMasterPasswordCB->Check( true );
882 m_pMasterPasswordFT->Enable( false );
883 m_pShowConnectionsPB->Enable( false );
885 // initialize the password saving checkbox
888 Reference< task::XPasswordContainer2 > xMasterPasswd(
889 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
891 if ( xMasterPasswd->isPersistentStoringAllowed() )
893 m_pMasterPasswordCB->Enable( true );
894 m_pShowConnectionsPB->Enable( true );
895 m_pSavePasswordsCB->Check( true );
897 if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
898 m_pMasterPasswordCB->Check( false );
899 else
901 m_pMasterPasswordPB->Enable( true );
902 m_pMasterPasswordCB->Check( true );
903 m_pMasterPasswordFT->Enable( true );
907 catch (const Exception&)
909 m_pSavePasswordsCB->Enable( false );
913 VclPtr<SfxTabPage> SvxSecurityTabPage::Create(vcl::Window* pParent, const SfxItemSet* rAttrSet )
915 return VclPtr<SvxSecurityTabPage>::Create(pParent, *rAttrSet);
918 void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
922 SfxTabPage::sfxpg SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
924 if( _pSet )
925 FillItemSet( _pSet );
926 return LEAVE_PAGE;
929 namespace
931 bool CheckAndSave( SvtSecurityOptions& _rOpt, SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModfied )
933 bool bModified = false;
934 if ( _rOpt.IsOptionEnabled( _eOpt ) )
936 bModified = _rOpt.IsOptionSet( _eOpt ) != _bIsChecked;
937 if ( bModified )
939 _rOpt.SetOption( _eOpt, _bIsChecked );
940 _rModfied = true;
944 return bModified;
948 bool SvxSecurityTabPage::FillItemSet( SfxItemSet* )
950 bool bModified = false;
952 if ( mpSecOptDlg )
954 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SAVEORSEND, mpSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
955 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SIGNING, mpSecOptDlg->IsSignDocsChecked(), bModified );
956 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_PRINT, mpSecOptDlg->IsPrintDocsChecked(), bModified );
957 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_CREATEPDF, mpSecOptDlg->IsCreatePdfChecked(), bModified );
958 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO, mpSecOptDlg->IsRemovePersInfoChecked(), bModified );
959 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD, mpSecOptDlg->IsRecommPasswdChecked(), bModified );
960 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_CTRLCLICK_HYPERLINK, mpSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
961 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_BLOCKUNTRUSTEDREFERERLINKS, mpSecOptDlg->IsBlockUntrustedRefererLinksChecked(), bModified );
964 return bModified;
967 /*--------------------------------------------------------------------*/
969 void SvxSecurityTabPage::Reset( const SfxItemSet* )
973 struct SvxEMailTabPage_Impl
975 SvxEMailTabPage_Impl():
976 sProgram(officecfg::Office::Common::ExternalMailer::Program::get()),
977 bROProgram(
978 officecfg::Office::Common::ExternalMailer::Program::isReadOnly()),
979 bHideContent(
980 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get()),
981 bROHideContent(
982 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::isReadOnly())
985 OUString sProgram;
986 bool bROProgram;
987 bool bHideContent;
988 bool bROHideContent;
991 SvxEMailTabPage::SvxEMailTabPage(vcl::Window* pParent, const SfxItemSet& rSet)
992 : SfxTabPage( pParent, "OptEmailPage", "cui/ui/optemailpage.ui", &rSet)
993 , pImpl(new SvxEMailTabPage_Impl)
995 get(m_pMailContainer, "program");
996 get(m_pMailerURLFI, "lockemail");
997 get(m_pMailerURLED, "url");
998 get(m_pMailerURLPB, "browse");
999 get(m_pSuppressHiddenContainer, "suppressHiddenCont");
1000 get(m_pSuppressHiddenFI, "lockSuppressHidden");
1001 get(m_pSuppressHidden, "suppressHidden");
1002 m_sDefaultFilterName = get<FixedText>("browsetitle")->GetText();
1003 m_pMailerURLPB->SetClickHdl( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
1006 /* -------------------------------------------------------------------------*/
1008 SvxEMailTabPage::~SvxEMailTabPage()
1010 disposeOnce();
1013 void SvxEMailTabPage::dispose()
1015 delete pImpl;
1016 pImpl = NULL;
1017 m_pMailContainer.clear();
1018 m_pMailerURLFI.clear();
1019 m_pMailerURLED.clear();
1020 m_pMailerURLPB.clear();
1021 m_pSuppressHiddenContainer.clear();
1022 m_pSuppressHiddenFI.clear();
1023 m_pSuppressHidden.clear();
1024 SfxTabPage::dispose();
1027 /* -------------------------------------------------------------------------*/
1029 VclPtr<SfxTabPage> SvxEMailTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
1031 return VclPtr<SvxEMailTabPage>::Create(pParent, *rAttrSet);
1034 /* -------------------------------------------------------------------------*/
1036 bool SvxEMailTabPage::FillItemSet( SfxItemSet* )
1038 std::shared_ptr<comphelper::ConfigurationChanges> batch(
1039 comphelper::ConfigurationChanges::create());
1040 if (!pImpl->bROProgram && m_pMailerURLED->IsValueChangedFromSaved())
1042 pImpl->sProgram = m_pMailerURLED->GetText();
1043 officecfg::Office::Common::ExternalMailer::Program::set(
1044 pImpl->sProgram, batch);
1046 if (!pImpl->bROHideContent
1047 && pImpl->bHideContent != m_pSuppressHidden->IsChecked())
1049 pImpl->bHideContent = m_pSuppressHidden->IsChecked();
1050 officecfg::Office::Security::HiddenContent::RemoveHiddenContent::set(
1051 pImpl->bHideContent, batch);
1053 batch->commit();
1054 return false;
1057 /* -------------------------------------------------------------------------*/
1059 void SvxEMailTabPage::Reset( const SfxItemSet* )
1061 m_pMailerURLED->Enable(true );
1062 m_pMailerURLPB->Enable(true );
1064 if (pImpl->bROProgram)
1065 m_pMailerURLFI->Show();
1067 m_pMailerURLED->SetText(pImpl->sProgram);
1068 m_pMailerURLED->SaveValue();
1070 m_pMailContainer->Enable(!pImpl->bROProgram);
1072 if (pImpl->bROHideContent)
1073 m_pSuppressHiddenFI->Show();
1075 m_pSuppressHidden->Check(pImpl->bHideContent);
1077 m_pSuppressHiddenContainer->Enable(!pImpl->bROHideContent);
1080 /* -------------------------------------------------------------------------*/
1082 IMPL_LINK( SvxEMailTabPage, FileDialogHdl_Impl, PushButton*, pButton )
1084 if (m_pMailerURLPB == pButton && !pImpl->bROProgram)
1086 FileDialogHelper aHelper(
1087 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
1088 0 );
1089 OUString sPath = m_pMailerURLED->GetText();
1090 if ( sPath.isEmpty() )
1091 sPath = "/usr/bin";
1093 OUString sUrl;
1094 ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sPath, sUrl);
1095 aHelper.SetDisplayDirectory(sUrl);
1096 aHelper.AddFilter( m_sDefaultFilterName, OUString("*"));
1098 if ( ERRCODE_NONE == aHelper.Execute() )
1100 sUrl = aHelper.GetPath();
1101 ::utl::LocalFileHelper::ConvertURLToPhysicalName(sUrl, sPath);
1102 m_pMailerURLED->SetText(sPath);
1105 return 0;
1110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */