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 <tools/shl.hxx>
21 #include <tools/config.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <svl/intitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/eitem.hxx>
26 #include <svl/slstitm.hxx>
27 #include <sfx2/fcontnr.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/viewsh.hxx>
31 #include <sfx2/sfxsids.hrc>
32 #include <sfx2/filedlghelper.hxx>
33 #include <svl/urihelper.hxx>
34 #include <svl/cntwids.hrc>
35 #include <sfx2/app.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <unotools/bootstrap.hxx>
38 #include <vcl/help.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <unotools/pathoptions.hxx>
41 #include <unotools/securityoptions.hxx>
42 #include <unotools/localfilehelper.hxx>
43 #include <unotools/extendedsecurityoptions.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
46 #include <dialmgr.hxx>
47 #include "optinet2.hxx"
48 #include <svx/svxdlg.hxx>
50 #include "optinet2.hrc"
52 #include <svx/ofaitem.hxx>
53 #include <sfx2/htmlmode.hxx>
54 #include <svx/svxids.hrc> // slot ids, mostly for changetracking
57 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
64 #include <sys/types.h>
66 #include <rtl/textenc.h>
67 #include <rtl/locale.h>
68 #include <osl/nlsupport.h>
70 #include <sal/types.h>
71 #include <sal/macros.h>
72 #include <rtl/ustring.hxx>
73 #include <osl/file.hxx>
74 #include <osl/process.h>
75 #include <com/sun/star/configuration/theDefaultProvider.hpp>
76 #include <com/sun/star/container/XNameReplace.hpp>
77 #include <com/sun/star/container/XNameAccess.hpp>
78 #include <com/sun/star/beans/NamedValue.hpp>
79 #include <com/sun/star/beans/XPropertySet.hpp>
80 #include <com/sun/star/beans/XPropertyState.hpp>
81 #include <com/sun/star/util/XChangesBatch.hpp>
82 #include <comphelper/processfactory.hxx>
83 #include <comphelper/string.hxx>
85 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
86 #include "com/sun/star/task/PasswordContainer.hpp"
87 #include "com/sun/star/task/XPasswordContainer2.hpp"
88 #include "securityoptions.hxx"
89 #include "webconninfo.hxx"
90 #include "certpath.hxx"
92 using namespace ::com::sun::star
;
93 using namespace ::com::sun::star::uno
;
94 using namespace ::sfx2
;
96 // static ----------------------------------------------------------------
98 #include <sal/config.h>
100 // -----------------------------------------------------------------------
102 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvxNoSpaceEdit(Window
*pParent
, VclBuilder::stringmap
&)
104 return new SvxNoSpaceEdit(pParent
, WB_LEFT
|WB_VCENTER
|WB_BORDER
|WB_3DLOOK
);
107 void SvxNoSpaceEdit::KeyInput( const KeyEvent
& rKEvent
)
109 bool bValid
= rKEvent
.GetKeyCode().GetCode() != KEY_SPACE
;
110 if (bValid
&& bOnlyNumeric
)
112 const KeyCode
& rKeyCode
= rKEvent
.GetKeyCode();
113 sal_uInt16 nGroup
= rKeyCode
.GetGroup();
114 sal_uInt16 nKey
= rKeyCode
.GetCode();
115 bValid
= ( KEYGROUP_NUM
== nGroup
|| KEYGROUP_CURSOR
== nGroup
||
116 ( KEYGROUP_MISC
== nGroup
&& ( nKey
< KEY_ADD
|| nKey
> KEY_EQUAL
) ) );
117 if ( !bValid
&& ( rKeyCode
.IsMod1() && (
118 KEY_A
== nKey
|| KEY_C
== nKey
|| KEY_V
== nKey
|| KEY_X
== nKey
|| KEY_Z
== nKey
) ) )
119 // Erase, Copy, Paste, Select All und Undo soll funktionieren
123 Edit::KeyInput(rKEvent
);
126 // -----------------------------------------------------------------------
128 void SvxNoSpaceEdit::Modify()
134 OUString aValue
= GetText();
136 if ( !comphelper::string::isdigitAsciiString(aValue
) || (long)aValue
.toInt32() > USHRT_MAX
)
137 // the maximum value of a port number is USHRT_MAX
138 ErrorBox( this, CUI_RES( RID_SVXERR_OPT_PROXYPORTS
) ).Execute();
142 bool SvxNoSpaceEdit::set_property(const OString
&rKey
, const OString
&rValue
)
144 if (rKey
== "only-numeric")
145 bOnlyNumeric
= toBool(rValue
);
147 return Edit::set_property(rKey
, rValue
);
152 /********************************************************************/
154 /* SvxProxyTabPage */
156 /********************************************************************/
158 SvxProxyTabPage::SvxProxyTabPage(Window
* pParent
, const SfxItemSet
& rSet
)
159 : SfxTabPage(pParent
, "OptProxyPage","cui/ui/optproxypage.ui", rSet
)
160 , aProxyModePN("ooInetProxyType")
161 , aHttpProxyPN("ooInetHTTPProxyName")
162 , aHttpPortPN("ooInetHTTPProxyPort")
163 , aHttpsProxyPN("ooInetHTTPSProxyName")
164 , aHttpsPortPN("ooInetHTTPSProxyPort")
165 , aFtpProxyPN("ooInetFTPProxyName")
166 , aFtpPortPN("ooInetFTPProxyPort")
167 , aNoProxyDescPN("ooInetNoProxy")
169 get(m_pProxyModeLB
, "proxymode");
171 get(m_pHttpProxyFT
, "httpft");
172 get(m_pHttpProxyED
, "http");
173 get(m_pHttpPortFT
, "httpportft");
174 get(m_pHttpPortED
, "httpport");
176 get(m_pHttpsProxyFT
, "httpsft");
177 get(m_pHttpsProxyED
, "https");
178 get(m_pHttpsPortFT
, "httpsportft");
179 get(m_pHttpsPortED
, "httpsport");
181 get(m_pFtpProxyFT
, "ftpft");
182 get(m_pFtpProxyED
, "ftp");
183 get(m_pFtpPortFT
, "ftpportft");
184 get(m_pFtpPortED
, "ftpport");
186 get(m_pNoProxyForFT
, "noproxyft");
187 get(m_pNoProxyForED
, "noproxy");
188 get(m_pNoProxyDescFT
, "noproxydesc");
190 Link aLink
= LINK( this, SvxProxyTabPage
, LoseFocusHdl_Impl
);
191 m_pHttpPortED
->SetLoseFocusHdl( aLink
);
192 m_pHttpsPortED
->SetLoseFocusHdl( aLink
);
193 m_pFtpPortED
->SetLoseFocusHdl( aLink
);
195 m_pProxyModeLB
->SetSelectHdl(LINK( this, SvxProxyTabPage
, ProxyHdl_Impl
));
197 Reference
< com::sun::star::lang::XMultiServiceFactory
>
198 xConfigurationProvider(
199 configuration::theDefaultProvider::get(
200 comphelper::getProcessComponentContext() ) );
202 OUString
aConfigRoot( "org.openoffice.Inet/Settings" );
204 beans::NamedValue aProperty
;
205 aProperty
.Name
= OUString( "nodepath" );
206 aProperty
.Value
= makeAny( aConfigRoot
);
208 Sequence
< Any
> aArgumentList( 1 );
209 aArgumentList
[0] = makeAny( aProperty
);
211 m_xConfigurationUpdateAccess
= xConfigurationProvider
->createInstanceWithArguments(
212 OUString( "com.sun.star.configuration.ConfigurationUpdateAccess" ),
216 SvxProxyTabPage::~SvxProxyTabPage()
220 SfxTabPage
* SvxProxyTabPage::Create(Window
* pParent
, const SfxItemSet
& rAttrSet
)
222 return new SvxProxyTabPage(pParent
, rAttrSet
);
225 void SvxProxyTabPage::ReadConfigData_Impl()
228 Reference
< container::XNameAccess
> xNameAccess(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
230 sal_Int32 nIntValue
= 0;
231 OUString aStringValue
;
233 if( xNameAccess
->getByName(aProxyModePN
) >>= nIntValue
)
235 m_pProxyModeLB
->SelectEntryPos( (sal_uInt16
) nIntValue
);
238 if( xNameAccess
->getByName(aHttpProxyPN
) >>= aStringValue
)
240 m_pHttpProxyED
->SetText( aStringValue
);
243 if( xNameAccess
->getByName(aHttpPortPN
) >>= nIntValue
)
245 m_pHttpPortED
->SetText( OUString::number( nIntValue
));
248 if( xNameAccess
->getByName(aHttpsProxyPN
) >>= aStringValue
)
250 m_pHttpsProxyED
->SetText( aStringValue
);
253 if( xNameAccess
->getByName(aHttpsPortPN
) >>= nIntValue
)
255 m_pHttpsPortED
->SetText( OUString::number( nIntValue
));
258 if( xNameAccess
->getByName(aFtpProxyPN
) >>= aStringValue
)
260 m_pFtpProxyED
->SetText( aStringValue
);
263 if( xNameAccess
->getByName(aFtpPortPN
) >>= nIntValue
)
265 m_pFtpPortED
->SetText( OUString::number( nIntValue
));
268 if( xNameAccess
->getByName(aNoProxyDescPN
) >>= aStringValue
)
270 m_pNoProxyForED
->SetText( aStringValue
);
274 catch (const container::NoSuchElementException
&) {
275 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
278 catch (const com::sun::star::lang::WrappedTargetException
&) {
279 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
282 catch (const RuntimeException
&) {
283 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
288 void SvxProxyTabPage::ReadConfigDefaults_Impl()
292 Reference
< beans::XPropertyState
> xPropertyState(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
294 sal_Int32 nIntValue
= 0;
295 OUString aStringValue
;
297 if( xPropertyState
->getPropertyDefault(aHttpProxyPN
) >>= aStringValue
)
299 m_pHttpProxyED
->SetText( aStringValue
);
302 if( xPropertyState
->getPropertyDefault(aHttpPortPN
) >>= nIntValue
)
304 m_pHttpPortED
->SetText( OUString::number( nIntValue
));
307 if( xPropertyState
->getPropertyDefault(aHttpsProxyPN
) >>= aStringValue
)
309 m_pHttpsProxyED
->SetText( aStringValue
);
312 if( xPropertyState
->getPropertyDefault(aHttpsPortPN
) >>= nIntValue
)
314 m_pHttpsPortED
->SetText( OUString::number( nIntValue
));
317 if( xPropertyState
->getPropertyDefault(aFtpProxyPN
) >>= aStringValue
)
319 m_pFtpProxyED
->SetText( aStringValue
);
322 if( xPropertyState
->getPropertyDefault(aFtpPortPN
) >>= nIntValue
)
324 m_pFtpPortED
->SetText( OUString::number( nIntValue
));
327 if( xPropertyState
->getPropertyDefault(aNoProxyDescPN
) >>= aStringValue
)
329 m_pNoProxyForED
->SetText( aStringValue
);
332 catch (const beans::UnknownPropertyException
&)
334 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
337 catch (const com::sun::star::lang::WrappedTargetException
&) {
338 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
341 catch (const RuntimeException
&)
343 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
347 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
351 Reference
< beans::XPropertyState
> xPropertyState(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
353 xPropertyState
->setPropertyToDefault(aProxyModePN
);
354 xPropertyState
->setPropertyToDefault(aHttpProxyPN
);
355 xPropertyState
->setPropertyToDefault(aHttpPortPN
);
356 xPropertyState
->setPropertyToDefault(aHttpsProxyPN
);
357 xPropertyState
->setPropertyToDefault(aHttpsPortPN
);
358 xPropertyState
->setPropertyToDefault(aFtpProxyPN
);
359 xPropertyState
->setPropertyToDefault(aFtpPortPN
);
360 xPropertyState
->setPropertyToDefault(aNoProxyDescPN
);
362 Reference
< util::XChangesBatch
> xChangesBatch(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
363 xChangesBatch
->commitChanges();
366 catch (const beans::UnknownPropertyException
&)
368 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
371 catch (const com::sun::star::lang::WrappedTargetException
&) {
372 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
375 catch (const RuntimeException
&)
377 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
381 void SvxProxyTabPage::Reset(const SfxItemSet
&)
383 ReadConfigData_Impl();
385 m_pProxyModeLB
->SaveValue();
386 m_pHttpProxyED
->SaveValue();
387 m_pHttpPortED
->SaveValue();
388 m_pHttpsProxyED
->SaveValue();
389 m_pHttpsPortED
->SaveValue();
390 m_pFtpProxyED
->SaveValue();
391 m_pFtpPortED
->SaveValue();
392 m_pNoProxyForED
->SaveValue();
394 EnableControls_Impl( m_pProxyModeLB
->GetSelectEntryPos() == 2 );
397 sal_Bool
SvxProxyTabPage::FillItemSet(SfxItemSet
& )
399 sal_Bool bModified
=sal_False
;
402 Reference
< beans::XPropertySet
> xPropertySet(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
404 sal_uInt16 nSelPos
= m_pProxyModeLB
->GetSelectEntryPos();
405 if(m_pProxyModeLB
->GetSavedValue() != nSelPos
)
409 RestoreConfigDefaults_Impl();
413 xPropertySet
->setPropertyValue(aProxyModePN
,
414 makeAny((sal_Int32
) nSelPos
));
415 bModified
= sal_True
;
418 if(m_pHttpProxyED
->GetSavedValue() != m_pHttpProxyED
->GetText())
420 xPropertySet
->setPropertyValue( aHttpProxyPN
, makeAny(m_pHttpProxyED
->GetText()));
421 bModified
= sal_True
;
424 if ( m_pHttpPortED
->GetSavedValue() != m_pHttpPortED
->GetText() )
426 xPropertySet
->setPropertyValue( aHttpPortPN
, makeAny(m_pHttpPortED
->GetText().toInt32()));
427 bModified
= sal_True
;
430 if( m_pHttpsProxyED
->GetSavedValue() != m_pHttpsProxyED
->GetText() )
432 xPropertySet
->setPropertyValue( aHttpsProxyPN
, makeAny(m_pHttpsProxyED
->GetText()) );
433 bModified
= sal_True
;
436 if ( m_pHttpsPortED
->GetSavedValue() != m_pHttpsPortED
->GetText() )
438 xPropertySet
->setPropertyValue( aHttpsPortPN
, makeAny(m_pHttpsPortED
->GetText().toInt32()) );
439 bModified
= sal_True
;
442 if( m_pFtpProxyED
->GetSavedValue() != m_pFtpProxyED
->GetText())
444 xPropertySet
->setPropertyValue( aFtpProxyPN
, makeAny(m_pFtpProxyED
->GetText()) );
445 bModified
= sal_True
;
448 if ( m_pFtpPortED
->GetSavedValue() != m_pFtpPortED
->GetText() )
450 xPropertySet
->setPropertyValue( aFtpPortPN
, makeAny(m_pFtpPortED
->GetText().toInt32()));
451 bModified
= sal_True
;
454 if ( m_pNoProxyForED
->GetSavedValue() != m_pNoProxyForED
->GetText() )
456 xPropertySet
->setPropertyValue( aNoProxyDescPN
, makeAny( m_pNoProxyForED
->GetText()));
457 bModified
= sal_True
;
460 Reference
< util::XChangesBatch
> xChangesBatch(m_xConfigurationUpdateAccess
, UNO_QUERY_THROW
);
461 xChangesBatch
->commitChanges();
464 catch (const com::sun::star::lang::IllegalArgumentException
&) {
465 OSL_TRACE( "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
468 catch (const beans::UnknownPropertyException
&) {
469 OSL_TRACE( "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
472 catch (const beans::PropertyVetoException
&) {
473 OSL_TRACE( "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
476 catch (const com::sun::star::lang::WrappedTargetException
&) {
477 OSL_TRACE( "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
480 catch (const RuntimeException
&) {
481 OSL_TRACE( "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
487 void SvxProxyTabPage::EnableControls_Impl(sal_Bool bEnable
)
489 m_pHttpProxyFT
->Enable(bEnable
);
490 m_pHttpProxyED
->Enable(bEnable
);
491 m_pHttpPortFT
->Enable(bEnable
);
492 m_pHttpPortED
->Enable(bEnable
);
494 m_pHttpsProxyFT
->Enable(bEnable
);
495 m_pHttpsProxyED
->Enable(bEnable
);
496 m_pHttpsPortFT
->Enable(bEnable
);
497 m_pHttpsPortED
->Enable(bEnable
);
499 m_pFtpProxyFT
->Enable(bEnable
);
500 m_pFtpProxyED
->Enable(bEnable
);
501 m_pFtpPortFT
->Enable(bEnable
);
502 m_pFtpPortED
->Enable(bEnable
);
504 m_pNoProxyForFT
->Enable(bEnable
);
505 m_pNoProxyForED
->Enable(bEnable
);
506 m_pNoProxyDescFT
->Enable(bEnable
);
509 // -----------------------------------------------------------------------
511 IMPL_LINK( SvxProxyTabPage
, ProxyHdl_Impl
, ListBox
*, pBox
)
513 sal_uInt16 nPos
= pBox
->GetSelectEntryPos();
515 // Restore original system values
518 ReadConfigDefaults_Impl();
521 EnableControls_Impl(nPos
== 2);
525 // -----------------------------------------------------------------------
527 IMPL_LINK( SvxProxyTabPage
, LoseFocusHdl_Impl
, Edit
*, pEdit
)
529 OUString aValue
= pEdit
->GetText();
531 if ( !comphelper::string::isdigitAsciiString(aValue
) || (long)aValue
.toInt32() > USHRT_MAX
)
532 pEdit
->SetText( OUString('0') );
538 //#98647#----------------------------------------------
539 void SvxScriptExecListBox::RequestHelp( const HelpEvent
& rHEvt
)
540 { // try to show tips just like as on toolbars
541 sal_uInt16 nPos
=LISTBOX_ENTRY_NOTFOUND
;
542 sal_uInt16 nTop
= GetTopEntry();
543 sal_uInt16 nCount
= GetDisplayLineCount(); // Attention: Not GetLineCount()
544 Point aPt
= ScreenToOutputPixel( rHEvt
.GetMousePosPixel() );
546 if( nCount
> 0 ) // if there're some entries, find it.
547 for( nPos
= nTop
; nPos
<= nTop
+nCount
-1 ; nPos
++ ) {
548 aItemRect
= GetBoundingRectangle(nPos
);
549 if( aPt
.Y() < aItemRect
.Top() || aPt
.Y() > aItemRect
.Bottom() )
554 else // if not, nothing happens.
557 if( nPos
<= nTop
+nCount
-1 ) // if find the matching entry, get its content.
558 aHelpText
= GetEntry(nPos
);
559 if( aHelpText
.getLength() && GetTextWidth(aHelpText
)<GetOutputSizePixel().Width() )
560 aHelpText
= OUString(); // if the entry is quite short, clear the helping tip content.
561 aItemRect
= Rectangle(Point(0,0),GetSizePixel());
562 aPt
= Point(OutputToScreenPixel( aItemRect
.TopLeft() ));
563 aItemRect
.Left() = aPt
.X();
564 aItemRect
.Top() = aPt
.Y();
565 aPt
= OutputToScreenPixel( aItemRect
.BottomRight() );
566 aItemRect
.Right() = aPt
.X();
567 aItemRect
.Bottom() = aPt
.Y();
568 if( rHEvt
.GetMode() == HELPMODE_BALLOON
)
569 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, aHelpText
);
571 Help::ShowQuickHelp( this, aItemRect
, aHelpText
);
574 /********************************************************************/
576 /* SvxSecurityTabPage */
578 /********************************************************************/
580 SvxSecurityTabPage::SvxSecurityTabPage(Window
* pParent
, const SfxItemSet
& rSet
)
581 : SfxTabPage(pParent
, "OptSecurityPage", "cui/ui/optsecuritypage.ui", rSet
)
582 , mpSecOptions(new SvtSecurityOptions
)
584 , mpCertPathDlg(NULL
)
586 get(m_pSecurityOptionsPB
, "options");
587 get(m_pSavePasswordsCB
, "savepassword");
589 //fdo#65595, we height-for-width support here, but for now we can
591 Size
aSize(m_pSavePasswordsCB
->CalcMinimumSize(56*approximate_char_width()));
592 m_pSavePasswordsCB
->set_width_request(aSize
.Width());
593 m_pSavePasswordsCB
->set_height_request(aSize
.Height());
595 get(m_pShowConnectionsPB
, "connections");
596 get(m_pMasterPasswordCB
, "usemasterpassword");
597 get(m_pMasterPasswordFT
, "masterpasswordtext");
598 get(m_pMasterPasswordPB
, "masterpassword");
599 get(m_pMacroSecFrame
, "macrosecurity");
600 get(m_pMacroSecPB
, "macro");
601 get(m_pCertFrame
, "certificatepath");
602 get(m_pCertPathPB
, "cert");
603 m_sPasswordStoringDeactivateStr
= get
<FixedText
>("nopasswordsave")->GetText();
607 m_pSecurityOptionsPB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, SecurityOptionsHdl
) );
608 m_pSavePasswordsCB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, SavePasswordHdl
) );
609 m_pMasterPasswordPB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, MasterPasswordHdl
) );
610 m_pMasterPasswordCB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, MasterPasswordCBHdl
) );
611 m_pShowConnectionsPB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, ShowPasswordsHdl
) );
612 m_pMacroSecPB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, MacroSecPBHdl
) );
613 m_pCertPathPB
->SetClickHdl( LINK( this, SvxSecurityTabPage
, CertPathPBHdl
) );
615 ActivatePage( rSet
);
618 SvxSecurityTabPage::~SvxSecurityTabPage()
620 delete mpCertPathDlg
;
626 IMPL_LINK_NOARG(SvxSecurityTabPage
, SecurityOptionsHdl
)
629 mpSecOptDlg
= new svx::SecurityOptionsDialog( this, mpSecOptions
);
630 mpSecOptDlg
->Execute();
634 IMPL_LINK_NOARG(SvxSecurityTabPage
, SavePasswordHdl
)
638 Reference
< task::XPasswordContainer2
> xMasterPasswd(
639 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
641 if ( m_pSavePasswordsCB
->IsChecked() )
643 sal_Bool bOldValue
= xMasterPasswd
->allowPersistentStoring( sal_True
);
644 xMasterPasswd
->removeMasterPassword();
645 if ( xMasterPasswd
->changeMasterPassword( Reference
< task::XInteractionHandler
>() ) )
647 m_pMasterPasswordPB
->Enable( sal_True
);
648 m_pMasterPasswordCB
->Check( sal_True
);
649 m_pMasterPasswordCB
->Enable( sal_True
);
650 m_pMasterPasswordFT
->Enable( sal_True
);
651 m_pShowConnectionsPB
->Enable( sal_True
);
655 xMasterPasswd
->allowPersistentStoring( bOldValue
);
656 m_pSavePasswordsCB
->Check( sal_False
);
661 QueryBox
aQuery( this, WB_YES_NO
|WB_DEF_NO
, m_sPasswordStoringDeactivateStr
);
662 sal_uInt16 nRet
= aQuery
.Execute();
664 if( RET_YES
== nRet
)
666 xMasterPasswd
->allowPersistentStoring( sal_False
);
667 m_pMasterPasswordCB
->Check( sal_True
);
668 m_pMasterPasswordPB
->Enable( sal_False
);
669 m_pMasterPasswordCB
->Enable( sal_False
);
670 m_pMasterPasswordFT
->Enable( sal_False
);
671 m_pShowConnectionsPB
->Enable( sal_False
);
675 m_pSavePasswordsCB
->Check( sal_True
);
676 m_pMasterPasswordPB
->Enable( sal_True
);
677 m_pShowConnectionsPB
->Enable( sal_True
);
681 catch (const Exception
&)
683 m_pSavePasswordsCB
->Check( !m_pSavePasswordsCB
->IsChecked() );
689 IMPL_LINK_NOARG(SvxSecurityTabPage
, MasterPasswordHdl
)
693 Reference
< task::XPasswordContainer2
> xMasterPasswd(
694 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
696 if ( xMasterPasswd
->isPersistentStoringAllowed() )
697 xMasterPasswd
->changeMasterPassword( Reference
< task::XInteractionHandler
>() );
699 catch (const Exception
&)
705 IMPL_LINK_NOARG(SvxSecurityTabPage
, MasterPasswordCBHdl
)
709 Reference
< task::XPasswordContainer2
> xMasterPasswd(
710 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
712 if ( m_pMasterPasswordCB
->IsChecked() )
714 if ( xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->changeMasterPassword( Reference
< task::XInteractionHandler
>() ) )
716 m_pMasterPasswordPB
->Enable( sal_True
);
717 m_pMasterPasswordFT
->Enable( sal_True
);
721 m_pMasterPasswordCB
->Check( sal_False
);
722 m_pMasterPasswordPB
->Enable( sal_True
);
723 m_pMasterPasswordFT
->Enable( sal_True
);
728 if ( xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->useDefaultMasterPassword( Reference
< task::XInteractionHandler
>() ) )
730 m_pMasterPasswordPB
->Enable( sal_False
);
731 m_pMasterPasswordFT
->Enable( sal_False
);
735 m_pMasterPasswordCB
->Check( sal_True
);
736 m_pMasterPasswordPB
->Enable( sal_True
);
737 m_pShowConnectionsPB
->Enable( sal_True
);
741 catch (const Exception
&)
743 m_pSavePasswordsCB
->Check( !m_pSavePasswordsCB
->IsChecked() );
749 IMPL_LINK_NOARG(SvxSecurityTabPage
, ShowPasswordsHdl
)
753 Reference
< task::XPasswordContainer2
> xMasterPasswd(
754 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
756 if ( xMasterPasswd
->isPersistentStoringAllowed() && xMasterPasswd
->authorizateWithMasterPassword( Reference
< task::XInteractionHandler
>() ) )
758 svx::WebConnectionInfoDialog
aDlg( this );
762 catch (const Exception
&)
767 IMPL_LINK_NOARG(SvxSecurityTabPage
, CertPathPBHdl
)
770 mpCertPathDlg
= new CertPathDialog(this);
772 OUString sOrig
= mpCertPathDlg
->getDirectory();
773 short nRet
= mpCertPathDlg
->Execute();
775 if (nRet
== RET_OK
&& sOrig
!= mpCertPathDlg
->getDirectory())
777 WarningBox
aWarnBox(this, CUI_RES(RID_SVX_MSGBOX_OPTIONS_RESTART
));
784 IMPL_LINK_NOARG(SvxSecurityTabPage
, MacroSecPBHdl
)
788 Reference
< security::XDocumentDigitalSignatures
> xD(
789 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
790 xD
->manageTrustedSources();
792 catch (const Exception
& e
)
794 OSL_FAIL(OUStringToOString(e
.Message
, osl_getThreadTextEncoding()).getStr());
801 void SvxSecurityTabPage::InitControls()
803 // Hide all controls which belong to the macro security button in case the macro
804 // security settings managed by the macro security dialog opened via the button
805 // are all readonly or if the macros are disabled in general.
806 // @@@ Better would be to query the dialog whether it is 'useful' or not. Exposing
807 // macro security dialog implementations here, which is bad.
808 if ( mpSecOptions
->IsMacroDisabled()
809 || ( mpSecOptions
->IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL
)
810 && mpSecOptions
->IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS
)
811 && mpSecOptions
->IsReadOnly( SvtSecurityOptions::E_SECUREURLS
) ) )
814 m_pMacroSecFrame
->Hide();
818 m_pCertFrame
->Hide();
821 m_pMasterPasswordPB
->Enable( sal_False
);
822 m_pMasterPasswordCB
->Enable( sal_False
);
823 m_pMasterPasswordCB
->Check( sal_True
);
824 m_pMasterPasswordFT
->Enable( sal_False
);
825 m_pShowConnectionsPB
->Enable( sal_False
);
827 // initialize the password saving checkbox
830 Reference
< task::XPasswordContainer2
> xMasterPasswd(
831 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
833 if ( xMasterPasswd
->isPersistentStoringAllowed() )
835 m_pMasterPasswordCB
->Enable( sal_True
);
836 m_pShowConnectionsPB
->Enable( sal_True
);
837 m_pSavePasswordsCB
->Check( sal_True
);
839 if ( xMasterPasswd
->isDefaultMasterPasswordUsed() )
840 m_pMasterPasswordCB
->Check( sal_False
);
843 m_pMasterPasswordPB
->Enable( sal_True
);
844 m_pMasterPasswordCB
->Check( sal_True
);
845 m_pMasterPasswordFT
->Enable( sal_True
);
849 catch (const Exception
&)
851 m_pSavePasswordsCB
->Enable( sal_False
);
855 SfxTabPage
* SvxSecurityTabPage::Create(Window
* pParent
, const SfxItemSet
& rAttrSet
)
857 return new SvxSecurityTabPage(pParent
, rAttrSet
);
860 void SvxSecurityTabPage::ActivatePage( const SfxItemSet
& )
864 int SvxSecurityTabPage::DeactivatePage( SfxItemSet
* _pSet
)
867 FillItemSet( *_pSet
);
873 bool CheckAndSave( SvtSecurityOptions
& _rOpt
, SvtSecurityOptions::EOption _eOpt
, const bool _bIsChecked
, bool& _rModfied
)
875 bool bModified
= false;
876 if ( _rOpt
.IsOptionEnabled( _eOpt
) )
878 bModified
= _rOpt
.IsOptionSet( _eOpt
) != _bIsChecked
;
881 _rOpt
.SetOption( _eOpt
, _bIsChecked
);
890 sal_Bool
SvxSecurityTabPage::FillItemSet( SfxItemSet
& )
892 bool bModified
= false;
896 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_SAVEORSEND
, mpSecOptDlg
->IsSaveOrSendDocsChecked(), bModified
);
897 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_SIGNING
, mpSecOptDlg
->IsSignDocsChecked(), bModified
);
898 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_PRINT
, mpSecOptDlg
->IsPrintDocsChecked(), bModified
);
899 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_CREATEPDF
, mpSecOptDlg
->IsCreatePdfChecked(), bModified
);
900 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO
, mpSecOptDlg
->IsRemovePersInfoChecked(), bModified
);
901 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD
, mpSecOptDlg
->IsRecommPasswdChecked(), bModified
);
902 CheckAndSave( *mpSecOptions
, SvtSecurityOptions::E_CTRLCLICK_HYPERLINK
, mpSecOptDlg
->IsCtrlHyperlinkChecked(), bModified
);
908 /*--------------------------------------------------------------------*/
910 void SvxSecurityTabPage::Reset( const SfxItemSet
& )
914 MozPluginTabPage::MozPluginTabPage(Window
* pParent
, const SfxItemSet
& rSet
)
915 : SfxTabPage(pParent
, "OptBrowserPage", "cui/ui/optbrowserpage.ui", rSet
)
917 get(m_pWBasicCodeCB
, "display");
920 MozPluginTabPage::~MozPluginTabPage()
924 SfxTabPage
* MozPluginTabPage::Create( Window
* pParent
,
925 const SfxItemSet
& rAttrSet
)
927 return new MozPluginTabPage( pParent
, rAttrSet
);
929 sal_Bool
MozPluginTabPage::FillItemSet( SfxItemSet
& )
931 sal_Bool hasInstall
= isInstalled();
932 sal_Bool hasChecked
= m_pWBasicCodeCB
->IsChecked();
933 if(hasInstall
&& (!hasChecked
)){
937 else if((!hasInstall
) && hasChecked
){
946 void MozPluginTabPage::Reset( const SfxItemSet
& )
948 m_pWBasicCodeCB
->Check( isInstalled());
949 m_pWBasicCodeCB
->SaveValue();
954 int lc_isInstalled(const char* realFilePath
);
955 int lc_installPlugin(const char* realFilePath
);
956 int lc_uninstallPlugin(const char* realFilePath
);
960 #define NPP_PATH_MAX 2048
961 inline bool getDllURL(OString
* path
)
963 OSL_ASSERT(path
!= NULL
);
964 OUString dirPath
/*dllPath, */;
965 if (osl_getExecutableFile(&dirPath
.pData
) != osl_Process_E_None
) {
968 dirPath
= dirPath
.copy(0, dirPath
.lastIndexOf('/'));
970 osl::FileBase::getSystemPathFromFileURL(dirPath
, sysDirPath
);
971 *path
= OUStringToOString(sysDirPath
, RTL_TEXTENCODING_ASCII_US
);
975 sal_Bool
MozPluginTabPage::isInstalled()
978 // get the real file referred by .so lnk file
979 char lnkFilePath
[NPP_PATH_MAX
] = {0};
980 char lnkReferFilePath
[NPP_PATH_MAX
] = {0};
981 char* pHome
= getpwuid(getuid())->pw_dir
;
982 strcat(lnkFilePath
, pHome
);
983 strcat(lnkFilePath
, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION
);
986 if (0 > lstat(lnkFilePath
, &sBuf
))
988 if (!S_ISLNK(sBuf
.st_mode
))
990 if (0 >= readlink(lnkFilePath
, lnkReferFilePath
, NPP_PATH_MAX
))
992 // If the link is relative, then we regard it as non-standard
993 if (lnkReferFilePath
[0] != '/')
996 // get the real file path
997 char realFilePath
[NPP_PATH_MAX
] = {0};
999 if (!getDllURL(&tempString
)) {
1002 strncpy(realFilePath
, tempString
.getStr(), NPP_PATH_MAX
- 1);
1003 strcat(realFilePath
, "/libnpsoplugin" SAL_DLLEXTENSION
);
1005 if (0 != strcmp(lnkReferFilePath
, realFilePath
))
1010 // get the value from registry
1011 sal_Bool ret
= true;
1013 char realFilePath
[NPP_PATH_MAX
] = {0};
1014 if (!getDllURL(&tempString
)){
1017 strncpy(realFilePath
, tempString
.getStr(), NPP_PATH_MAX
);
1018 if(! lc_isInstalled(realFilePath
))
1026 sal_Bool
MozPluginTabPage::installPlugin()
1029 // get the real file referred by .so lnk file
1030 char lnkFilePath
[NPP_PATH_MAX
] = {0};
1031 char* pHome
= getpwuid(getuid())->pw_dir
;
1032 strcat(lnkFilePath
, pHome
);
1033 strcat(lnkFilePath
, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION
);
1034 remove(lnkFilePath
);
1036 // create the dirs if necessary
1038 char tmpDir
[NPP_PATH_MAX
] = {0};
1039 sprintf(tmpDir
, "%s/.mozilla", pHome
);
1040 if (0 > stat(lnkFilePath
, &buf
))
1042 mkdir(tmpDir
, 0755);
1043 strcat(tmpDir
, "/plugins");
1044 mkdir(tmpDir
, 0755);
1047 // get the real file path
1048 char realFilePath
[NPP_PATH_MAX
] = {0};
1050 if (!getDllURL(&tempString
)) {
1053 strncpy(realFilePath
, tempString
.getStr(), NPP_PATH_MAX
- 1);
1054 strcat(realFilePath
, "/libnpsoplugin" SAL_DLLEXTENSION
);
1057 if (0 != symlink(realFilePath
, lnkFilePath
))
1063 char realFilePath
[NPP_PATH_MAX
] = {0};
1064 if (!getDllURL(&tempString
)) {
1067 strncpy(realFilePath
, tempString
.getStr(), NPP_PATH_MAX
);
1068 if( !lc_installPlugin(realFilePath
))
1075 sal_Bool
MozPluginTabPage::uninstallPlugin()
1078 // get the real file referred by .so lnk file
1079 char lnkFilePath
[NPP_PATH_MAX
] = {0};
1080 char* pHome
= getpwuid(getuid())->pw_dir
;
1081 strcat(lnkFilePath
, pHome
);
1082 strcat(lnkFilePath
, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION
);
1084 if(0 > remove(lnkFilePath
))
1090 char realFilePath
[NPP_PATH_MAX
] = {0};
1091 if (!getDllURL(&tempString
)) {
1094 strncpy(realFilePath
, tempString
.getStr(), NPP_PATH_MAX
);
1095 if(!lc_uninstallPlugin(realFilePath
))
1102 /* -------------------------------------------------------------------------*/
1104 class MailerProgramCfg_Impl
: public utl::ConfigItem
1106 friend class SvxEMailTabPage
;
1110 sal_Bool bROProgram
;
1112 const Sequence
<OUString
> GetPropertyNames();
1114 MailerProgramCfg_Impl();
1115 virtual ~MailerProgramCfg_Impl();
1117 virtual void Commit();
1118 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& _rPropertyNames
);
1121 /* -------------------------------------------------------------------------*/
1123 MailerProgramCfg_Impl::MailerProgramCfg_Impl() :
1124 utl::ConfigItem("Office.Common/ExternalMailer"),
1125 bROProgram(sal_False
)
1127 const Sequence
< OUString
> aNames
= GetPropertyNames();
1128 const Sequence
< Any
> aValues
= GetProperties(aNames
);
1129 const Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates(aNames
);
1130 const Any
* pValues
= aValues
.getConstArray();
1131 const sal_Bool
* pROStates
= aROStates
.getConstArray();
1132 for(sal_Int32 nProp
= 0; nProp
< aValues
.getLength(); nProp
++)
1134 if(pValues
[nProp
].hasValue())
1140 pValues
[nProp
] >>= sProgram
;
1141 bROProgram
= pROStates
[nProp
];
1149 /* -------------------------------------------------------------------------*/
1151 MailerProgramCfg_Impl::~MailerProgramCfg_Impl()
1155 /* -------------------------------------------------------------------------*/
1157 const Sequence
<OUString
> MailerProgramCfg_Impl::GetPropertyNames()
1159 Sequence
<OUString
> aRet(1);
1160 OUString
* pRet
= aRet
.getArray();
1161 pRet
[0] = "Program";
1165 /* -------------------------------------------------------------------------*/
1167 void MailerProgramCfg_Impl::Commit()
1169 const Sequence
< OUString
> aOrgNames
= GetPropertyNames();
1170 sal_Int32 nOrgCount
= aOrgNames
.getLength();
1172 Sequence
< OUString
> aNames(nOrgCount
);
1173 Sequence
< Any
> aValues(nOrgCount
);
1174 sal_Int32 nRealCount
= 0;
1176 for(int nProp
= 0; nProp
< nOrgCount
; nProp
++)
1184 aNames
[nRealCount
] = aOrgNames
[nProp
];
1185 aValues
[nRealCount
] <<= sProgram
;
1193 aNames
.realloc(nRealCount
);
1194 aValues
.realloc(nRealCount
);
1195 PutProperties(aNames
, aValues
);
1198 void MailerProgramCfg_Impl::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
1202 /* -------------------------------------------------------------------------*/
1204 struct SvxEMailTabPage_Impl
1206 MailerProgramCfg_Impl aMailConfig
;
1209 SvxEMailTabPage::SvxEMailTabPage(Window
* pParent
, const SfxItemSet
& rSet
)
1210 : SfxTabPage( pParent
, "OptEmailPage", "cui/ui/optemailpage.ui", rSet
)
1211 , pImpl(new SvxEMailTabPage_Impl
)
1213 get(m_pMailContainer
, "OptEmailPage");
1214 get(m_pMailerURLFI
, "lockemail");
1215 get(m_pMailerURLED
, "url");
1216 get(m_pMailerURLPB
, "browse");
1217 m_sDefaultFilterName
= get
<FixedText
>("browsetitle")->GetText();
1218 m_pMailerURLPB
->SetClickHdl( LINK( this, SvxEMailTabPage
, FileDialogHdl_Impl
) );
1221 /* -------------------------------------------------------------------------*/
1223 SvxEMailTabPage::~SvxEMailTabPage()
1228 /* -------------------------------------------------------------------------*/
1230 SfxTabPage
* SvxEMailTabPage::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
1232 return new SvxEMailTabPage(pParent
, rAttrSet
);
1235 /* -------------------------------------------------------------------------*/
1237 sal_Bool
SvxEMailTabPage::FillItemSet( SfxItemSet
& )
1239 sal_Bool bMailModified
= sal_False
;
1240 if(!pImpl
->aMailConfig
.bROProgram
&& m_pMailerURLED
->GetSavedValue() != m_pMailerURLED
->GetText())
1242 pImpl
->aMailConfig
.sProgram
= m_pMailerURLED
->GetText();
1243 bMailModified
= sal_True
;
1245 if ( bMailModified
)
1246 pImpl
->aMailConfig
.Commit();
1251 /* -------------------------------------------------------------------------*/
1253 void SvxEMailTabPage::Reset( const SfxItemSet
& )
1255 m_pMailerURLED
->Enable(sal_True
);
1256 m_pMailerURLPB
->Enable(sal_True
);
1258 if (pImpl
->aMailConfig
.bROProgram
)
1259 m_pMailerURLFI
->Show();
1261 m_pMailerURLED
->SetText(pImpl
->aMailConfig
.sProgram
);
1262 m_pMailerURLED
->SaveValue();
1264 m_pMailContainer
->Enable(!pImpl
->aMailConfig
.bROProgram
);
1267 /* -------------------------------------------------------------------------*/
1269 IMPL_LINK( SvxEMailTabPage
, FileDialogHdl_Impl
, PushButton
*, pButton
)
1271 if (m_pMailerURLPB
== pButton
&& !pImpl
->aMailConfig
.bROProgram
)
1273 FileDialogHelper
aHelper(
1274 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
1276 OUString sPath
= m_pMailerURLED
->GetText();
1277 if ( sPath
.isEmpty() )
1278 sPath
= OUString("/usr/bin");
1281 ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sPath
, sUrl
);
1282 aHelper
.SetDisplayDirectory(sUrl
);
1283 aHelper
.AddFilter( m_sDefaultFilterName
, OUString("*"));
1285 if ( ERRCODE_NONE
== aHelper
.Execute() )
1287 sUrl
= aHelper
.GetPath();
1288 ::utl::LocalFileHelper::ConvertURLToPhysicalName(sUrl
, sPath
);
1289 m_pMailerURLED
->SetText(sPath
);
1295 // -----------------------------------------------------------------------------
1297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */