Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / cui / source / options / optinet2.cxx
blob240cb876684aff56c3a88b6d4cf5ab4dd48d7b00
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 <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 #define _SVX_OPTINET2_CXX
47 #include <dialmgr.hxx>
48 #include "optinet2.hxx"
49 #include <svx/svxdlg.hxx>
50 #include <cuires.hrc>
51 #include "optinet2.hrc"
52 #include "helpid.hrc"
53 #include <svx/ofaitem.hxx>
54 #include <svx/htmlmode.hxx>
55 #include <svx/svxids.hrc> // slot ids, mostly for changetracking
57 // for security TP
58 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
60 #ifdef UNX
61 #include <sys/stat.h>
62 #include <unistd.h>
63 #include <fcntl.h>
64 #include <pwd.h>
65 #include <sys/types.h>
66 #include <string.h>
67 #include <rtl/textenc.h>
68 #include <rtl/locale.h>
69 #include <osl/nlsupport.h>
70 #endif
71 #include <sal/types.h>
72 #include <sal/macros.h>
73 #include <rtl/ustring.hxx>
74 #include <osl/file.hxx>
75 #include <osl/process.h>
76 #include <com/sun/star/configuration/theDefaultProvider.hpp>
77 #include <com/sun/star/container/XNameReplace.hpp>
78 #include <com/sun/star/container/XNameAccess.hpp>
79 #include <com/sun/star/beans/NamedValue.hpp>
80 #include <com/sun/star/beans/XPropertySet.hpp>
81 #include <com/sun/star/beans/XPropertyState.hpp>
82 #include <com/sun/star/util/XChangesBatch.hpp>
83 #include <comphelper/processfactory.hxx>
84 #include <comphelper/string.hxx>
86 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
87 #include "com/sun/star/task/PasswordContainer.hpp"
88 #include "com/sun/star/task/XPasswordContainer2.hpp"
89 #include "securityoptions.hxx"
90 #include "webconninfo.hxx"
91 #include "certpath.hxx"
93 using namespace ::com::sun::star;
94 using namespace ::com::sun::star::uno;
95 using namespace ::sfx2;
96 using ::rtl::OUString;
98 // static ----------------------------------------------------------------
100 #include <sal/config.h>
102 // -----------------------------------------------------------------------
104 void SvxNoSpaceEdit::KeyInput( const KeyEvent& rKEvent )
106 if ( bOnlyNumeric )
108 const KeyCode& rKeyCode = rKEvent.GetKeyCode();
109 sal_uInt16 nGroup = rKeyCode.GetGroup();
110 sal_uInt16 nKey = rKeyCode.GetCode();
111 sal_Bool bValid = ( KEYGROUP_NUM == nGroup || KEYGROUP_CURSOR == nGroup ||
112 ( KEYGROUP_MISC == nGroup && ( nKey < KEY_ADD || nKey > KEY_EQUAL ) ) );
113 if ( !bValid && ( rKeyCode.IsMod1() && (
114 KEY_A == nKey || KEY_C == nKey || KEY_V == nKey || KEY_X == nKey || KEY_Z == nKey ) ) )
115 // Erase, Copy, Paste, Select All und Undo soll funktionieren
116 bValid = sal_True;
118 if ( bValid )
119 Edit::KeyInput(rKEvent);
121 else if( rKEvent.GetKeyCode().GetCode() != KEY_SPACE )
122 Edit::KeyInput(rKEvent);
125 // -----------------------------------------------------------------------
127 void SvxNoSpaceEdit::Modify()
129 Edit::Modify();
131 if ( bOnlyNumeric )
133 rtl::OUString aValue = GetText();
135 if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
136 // the maximum value of a port number is USHRT_MAX
137 ErrorBox( this, CUI_RES( RID_SVXERR_OPT_PROXYPORTS ) ).Execute();
141 /********************************************************************/
142 /* */
143 /* SvxProxyTabPage */
144 /* */
145 /********************************************************************/
147 SvxProxyTabPage::SvxProxyTabPage(Window* pParent, const SfxItemSet& rSet ) :
148 SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_INET_PROXY ), rSet ),
149 aOptionGB (this, CUI_RES(GB_SETTINGS)),
151 aProxyModeFT (this, CUI_RES(FT_PROXYMODE)),
152 aProxyModeLB (this, CUI_RES(LB_PROXYMODE)),
154 aHttpProxyFT (this, CUI_RES( FT_HTTP_PROXY )),
155 aHttpProxyED (this, CUI_RES( ED_HTTP_PROXY )),
156 aHttpPortFT (this, CUI_RES( FT_HTTP_PORT )),
157 aHttpPortED (this, CUI_RES( ED_HTTP_PORT ), sal_True),
159 aHttpsProxyFT (this, CUI_RES( FT_HTTPS_PROXY )),
160 aHttpsProxyED (this, CUI_RES( ED_HTTPS_PROXY )),
161 aHttpsPortFT (this, CUI_RES( FT_HTTPS_PORT )),
162 aHttpsPortED (this, CUI_RES( ED_HTTPS_PORT ), sal_True),
164 aFtpProxyFT (this, CUI_RES( FT_FTP_PROXY )),
165 aFtpProxyED (this, CUI_RES( ED_FTP_PROXY )),
166 aFtpPortFT (this, CUI_RES( FT_FTP_PORT )),
167 aFtpPortED (this, CUI_RES( ED_FTP_PORT ), sal_True),
169 aNoProxyForFT (this, CUI_RES( FT_NOPROXYFOR )),
170 aNoProxyForED (this, CUI_RES( ED_NOPROXYFOR )),
171 aNoProxyDescFT (this, CUI_RES( ED_NOPROXYDESC )),
172 sFromBrowser ( CUI_RES( ST_PROXY_FROM_BROWSER ) ),
173 aProxyModePN(RTL_CONSTASCII_USTRINGPARAM("ooInetProxyType")),
174 aHttpProxyPN(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyName")),
175 aHttpPortPN(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyPort")),
176 aHttpsProxyPN(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyName")),
177 aHttpsPortPN(RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyPort")),
178 aFtpProxyPN(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyName")),
179 aFtpPortPN(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyPort")),
180 aNoProxyDescPN(RTL_CONSTASCII_USTRINGPARAM("ooInetNoProxy"))
182 FreeResource();
184 aHttpPortED.SetMaxTextLen(5);
185 aHttpsPortED.SetMaxTextLen(5);
186 aFtpPortED.SetMaxTextLen(5);
187 Link aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
188 aHttpPortED.SetLoseFocusHdl( aLink );
189 aHttpsPortED.SetLoseFocusHdl( aLink );
190 aFtpPortED.SetLoseFocusHdl( aLink );
192 aProxyModeLB.SetSelectHdl(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
194 Reference< com::sun::star::lang::XMultiServiceFactory >
195 xConfigurationProvider(
196 configuration::theDefaultProvider::get(
197 comphelper::getProcessComponentContext() ) );
199 OUString aConfigRoot(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings" ) );
201 beans::NamedValue aProperty;
202 aProperty.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
203 aProperty.Value = makeAny( aConfigRoot );
205 Sequence< Any > aArgumentList( 1 );
206 aArgumentList[0] = makeAny( aProperty );
208 m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments( rtl::OUString(
209 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ),
210 aArgumentList );
212 ArrangeControls_Impl();
215 SvxProxyTabPage::~SvxProxyTabPage()
219 SfxTabPage* SvxProxyTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
221 return new SvxProxyTabPage(pParent, rAttrSet);
224 void SvxProxyTabPage::ReadConfigData_Impl()
226 try {
227 Reference< container::XNameAccess > xNameAccess(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
229 sal_Int32 nIntValue = 0;
230 OUString aStringValue;
232 if( xNameAccess->getByName(aProxyModePN) >>= nIntValue )
234 aProxyModeLB.SelectEntryPos( (sal_uInt16) nIntValue );
237 if( xNameAccess->getByName(aHttpProxyPN) >>= aStringValue )
239 aHttpProxyED.SetText( aStringValue );
242 if( xNameAccess->getByName(aHttpPortPN) >>= nIntValue )
244 aHttpPortED.SetText( String::CreateFromInt32( nIntValue ));
247 if( xNameAccess->getByName(aHttpsProxyPN) >>= aStringValue )
249 aHttpsProxyED.SetText( aStringValue );
252 if( xNameAccess->getByName(aHttpsPortPN) >>= nIntValue )
254 aHttpsPortED.SetText( String::CreateFromInt32( nIntValue ));
257 if( xNameAccess->getByName(aFtpProxyPN) >>= aStringValue )
259 aFtpProxyED.SetText( aStringValue );
262 if( xNameAccess->getByName(aFtpPortPN) >>= nIntValue )
264 aFtpPortED.SetText( String::CreateFromInt32( nIntValue ));
267 if( xNameAccess->getByName(aNoProxyDescPN) >>= aStringValue )
269 aNoProxyForED.SetText( aStringValue );
273 catch (const container::NoSuchElementException&) {
274 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
277 catch (const com::sun::star::lang::WrappedTargetException &) {
278 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
281 catch (const RuntimeException &) {
282 OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
287 void SvxProxyTabPage::ReadConfigDefaults_Impl()
291 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
293 sal_Int32 nIntValue = 0;
294 OUString aStringValue;
296 if( xPropertyState->getPropertyDefault(aHttpProxyPN) >>= aStringValue )
298 aHttpProxyED.SetText( aStringValue );
301 if( xPropertyState->getPropertyDefault(aHttpPortPN) >>= nIntValue )
303 aHttpPortED.SetText( String::CreateFromInt32( nIntValue ));
306 if( xPropertyState->getPropertyDefault(aHttpsProxyPN) >>= aStringValue )
308 aHttpsProxyED.SetText( aStringValue );
311 if( xPropertyState->getPropertyDefault(aHttpsPortPN) >>= nIntValue )
313 aHttpsPortED.SetText( String::CreateFromInt32( nIntValue ));
316 if( xPropertyState->getPropertyDefault(aFtpProxyPN) >>= aStringValue )
318 aFtpProxyED.SetText( aStringValue );
321 if( xPropertyState->getPropertyDefault(aFtpPortPN) >>= nIntValue )
323 aFtpPortED.SetText( String::CreateFromInt32( nIntValue ));
326 if( xPropertyState->getPropertyDefault(aNoProxyDescPN) >>= aStringValue )
328 aNoProxyForED.SetText( aStringValue );
331 catch (const beans::UnknownPropertyException &)
333 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
336 catch (const com::sun::star::lang::WrappedTargetException &) {
337 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
340 catch (const RuntimeException &)
342 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
346 void SvxProxyTabPage::RestoreConfigDefaults_Impl()
350 Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
352 xPropertyState->setPropertyToDefault(aProxyModePN);
353 xPropertyState->setPropertyToDefault(aHttpProxyPN);
354 xPropertyState->setPropertyToDefault(aHttpPortPN);
355 xPropertyState->setPropertyToDefault(aHttpsProxyPN);
356 xPropertyState->setPropertyToDefault(aHttpsPortPN);
357 xPropertyState->setPropertyToDefault(aFtpProxyPN);
358 xPropertyState->setPropertyToDefault(aFtpPortPN);
359 xPropertyState->setPropertyToDefault(aNoProxyDescPN);
361 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
362 xChangesBatch->commitChanges();
365 catch (const beans::UnknownPropertyException &)
367 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
370 catch (const com::sun::star::lang::WrappedTargetException &) {
371 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
374 catch (const RuntimeException &)
376 OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
380 void SvxProxyTabPage::Reset(const SfxItemSet&)
382 ReadConfigData_Impl();
384 aProxyModeLB.SaveValue();
385 aHttpProxyED.SaveValue();
386 aHttpPortED.SaveValue();
387 aHttpsProxyED.SaveValue();
388 aHttpsPortED.SaveValue();
389 aFtpProxyED.SaveValue();
390 aFtpPortED.SaveValue();
391 aNoProxyForED.SaveValue();
393 EnableControls_Impl( aProxyModeLB.GetSelectEntryPos() == 2 );
396 sal_Bool SvxProxyTabPage::FillItemSet(SfxItemSet& )
398 sal_Bool bModified=sal_False;
400 try {
401 Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
403 sal_uInt16 nSelPos = aProxyModeLB.GetSelectEntryPos();
404 if(aProxyModeLB.GetSavedValue() != nSelPos)
406 if( nSelPos == 1 )
408 RestoreConfigDefaults_Impl();
409 return sal_True;
412 xPropertySet->setPropertyValue(aProxyModePN,
413 makeAny((sal_Int32) nSelPos));
414 bModified = sal_True;
417 if(aHttpProxyED.GetSavedValue() != aHttpProxyED.GetText())
419 xPropertySet->setPropertyValue( aHttpProxyPN,
420 makeAny(rtl::OUString(aHttpProxyED.GetText())));
421 bModified = sal_True;
424 if ( aHttpPortED.GetSavedValue() != aHttpPortED.GetText() )
426 xPropertySet->setPropertyValue( aHttpPortPN,
427 makeAny(aHttpPortED.GetText().ToInt32()));
428 bModified = sal_True;
431 if(aHttpsProxyED.GetSavedValue() != aHttpsProxyED.GetText())
433 xPropertySet->setPropertyValue( aHttpsProxyPN,
434 makeAny(rtl::OUString(aHttpsProxyED.GetText())));
435 bModified = sal_True;
438 if ( aHttpsPortED.GetSavedValue() != aHttpsPortED.GetText() )
440 xPropertySet->setPropertyValue( aHttpsPortPN,
441 makeAny(aHttpsPortED.GetText().ToInt32()));
442 bModified = sal_True;
445 if(aFtpProxyED.GetSavedValue() != aFtpProxyED.GetText())
447 xPropertySet->setPropertyValue( aFtpProxyPN,
448 makeAny( rtl::OUString(aFtpProxyED.GetText())));
449 bModified = sal_True;
452 if ( aFtpPortED.GetSavedValue() != aFtpPortED.GetText() )
454 xPropertySet->setPropertyValue( aFtpPortPN,
455 makeAny(aFtpPortED.GetText().ToInt32()));
456 bModified = sal_True;
459 if ( aNoProxyForED.GetSavedValue() != aNoProxyForED.GetText() )
461 xPropertySet->setPropertyValue( aNoProxyDescPN,
462 makeAny( rtl::OUString(aNoProxyForED.GetText())));
463 bModified = sal_True;
466 Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
467 xChangesBatch->commitChanges();
470 catch (const com::sun::star::lang::IllegalArgumentException &) {
471 OSL_TRACE( "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
474 catch (const beans::UnknownPropertyException &) {
475 OSL_TRACE( "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
478 catch (const beans::PropertyVetoException &) {
479 OSL_TRACE( "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
482 catch (const com::sun::star::lang::WrappedTargetException &) {
483 OSL_TRACE( "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
486 catch (const RuntimeException &) {
487 OSL_TRACE( "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
490 return bModified;
493 void SvxProxyTabPage::ArrangeControls_Impl()
495 // calculate dynamic width of controls, to not cut-off translated strings #i71445#
496 long nWidth = aProxyModeFT.GetCtrlTextWidth( aProxyModeFT.GetText() );
497 long nTemp = aHttpProxyFT.GetCtrlTextWidth( aHttpProxyFT.GetText() );
498 if ( nTemp > nWidth )
499 nWidth = nTemp;
500 nTemp = aHttpsProxyFT.GetCtrlTextWidth( aHttpsProxyFT.GetText() );
501 if ( nTemp > nWidth )
502 nWidth = nTemp;
503 nTemp = aFtpProxyFT.GetCtrlTextWidth( aFtpProxyFT.GetText() );
504 if ( nTemp > nWidth )
505 nWidth = nTemp;
506 nTemp = aNoProxyForFT.GetCtrlTextWidth( aNoProxyForFT.GetText() );
507 if ( nTemp > nWidth )
508 nWidth = nTemp;
510 nWidth += 10; // To be sure the length of the FixedText is enough on all platforms
511 const long nFTWidth = aProxyModeFT.GetSizePixel().Width();
512 if ( nWidth > nFTWidth )
514 Size aNewSize = aProxyModeFT.GetSizePixel();
515 aNewSize.Width() = nWidth;
517 aProxyModeFT.SetSizePixel( aNewSize );
518 aHttpProxyFT.SetSizePixel( aNewSize );
519 aHttpsProxyFT.SetSizePixel( aNewSize );
520 aFtpProxyFT.SetSizePixel( aNewSize );
521 aNoProxyForFT.SetSizePixel( aNewSize );
523 const long nDelta = nWidth - nFTWidth;
524 Point aNewPos = aProxyModeLB.GetPosPixel();
525 aNewPos.X() += nDelta;
527 aProxyModeLB.SetPosPixel( aNewPos );
529 aNewSize = aHttpProxyED.GetSizePixel();
530 aNewSize.Width() -= nDelta;
532 aNewPos.Y() = aHttpProxyED.GetPosPixel().Y();
533 aHttpProxyED.SetPosSizePixel( aNewPos, aNewSize );
534 aNewPos.Y() = aHttpsProxyED.GetPosPixel().Y();
535 aHttpsProxyED.SetPosSizePixel( aNewPos, aNewSize );
536 aNewPos.Y() = aFtpProxyED.GetPosPixel().Y();
537 aFtpProxyED.SetPosSizePixel( aNewPos, aNewSize );
538 aNewPos.Y() = aNoProxyForED.GetPosPixel().Y();
539 aNoProxyForED.SetPosSizePixel( aNewPos, aNewSize );
543 void SvxProxyTabPage::EnableControls_Impl(sal_Bool bEnable)
545 aHttpProxyFT.Enable(bEnable);
546 aHttpProxyED.Enable(bEnable);
547 aHttpPortFT.Enable(bEnable);
548 aHttpPortED.Enable(bEnable);
550 aHttpsProxyFT.Enable(bEnable);
551 aHttpsProxyED.Enable(bEnable);
552 aHttpsPortFT.Enable(bEnable);
553 aHttpsPortED.Enable(bEnable);
555 aFtpProxyFT.Enable(bEnable);
556 aFtpProxyED.Enable(bEnable);
557 aFtpPortFT.Enable(bEnable);
558 aFtpPortED.Enable(bEnable);
560 aNoProxyForFT.Enable(bEnable);
561 aNoProxyForED.Enable(bEnable);
562 aNoProxyDescFT.Enable(bEnable);
565 // -----------------------------------------------------------------------
567 IMPL_LINK( SvxProxyTabPage, ProxyHdl_Impl, ListBox *, pBox )
569 sal_uInt16 nPos = pBox->GetSelectEntryPos();
571 // Restore original system values
572 if( nPos == 1 )
574 ReadConfigDefaults_Impl();
577 EnableControls_Impl(nPos == 2);
578 return 0;
581 // -----------------------------------------------------------------------
583 IMPL_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Edit *, pEdit )
585 rtl::OUString aValue = pEdit->GetText();
587 if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
588 pEdit->SetText( rtl::OUString('0') );
589 return 0;
594 //#98647#----------------------------------------------
595 void SvxScriptExecListBox::RequestHelp( const HelpEvent& rHEvt )
596 { // try to show tips just like as on toolbars
597 sal_uInt16 nPos=LISTBOX_ENTRY_NOTFOUND;
598 sal_uInt16 nTop = GetTopEntry();
599 sal_uInt16 nCount = GetDisplayLineCount(); // Attention: Not GetLineCount()
600 Point aPt = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
601 Rectangle aItemRect;
602 if( nCount > 0 ) // if there're some entries, find it.
603 for( nPos = nTop ; nPos <= nTop+nCount-1 ; nPos++ ) {
604 aItemRect = GetBoundingRectangle(nPos);
605 if( aPt.Y() < aItemRect.Top() || aPt.Y() > aItemRect.Bottom() )
606 continue;
607 else
608 break;
610 else // if not, nothing happens.
611 return;
612 String aHelpText;
613 if( nPos <= nTop+nCount-1 ) // if find the matching entry, get its content.
614 aHelpText = GetEntry(nPos);
615 if( aHelpText.Len() && GetTextWidth(aHelpText)<GetOutputSizePixel().Width() )
616 aHelpText.Erase(); // if the entry is quite short, clear the helping tip content.
617 aItemRect = Rectangle(Point(0,0),GetSizePixel());
618 aPt = Point(OutputToScreenPixel( aItemRect.TopLeft() ));
619 aItemRect.Left() = aPt.X();
620 aItemRect.Top() = aPt.Y();
621 aPt = OutputToScreenPixel( aItemRect.BottomRight() );
622 aItemRect.Right() = aPt.X();
623 aItemRect.Bottom() = aPt.Y();
624 if( rHEvt.GetMode() == HELPMODE_BALLOON )
625 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
626 else
627 Help::ShowQuickHelp( this, aItemRect, aHelpText );
630 /********************************************************************/
631 /* */
632 /* SvxSecurityTabPage */
633 /* */
634 /********************************************************************/
636 SvxSecurityTabPage::SvxSecurityTabPage( Window* pParent, const SfxItemSet& rSet )
637 :SfxTabPage ( pParent, CUI_RES( RID_SVXPAGE_INET_SECURITY ), rSet )
639 ,maSecurityOptionsFL( this, CUI_RES( FL_SEC_SECURITYOPTIONS ) )
640 ,maSecurityOptionsFI( this, CUI_RES( FI_SEC_SECURITYOPTIONS ) )
641 ,maSecurityOptionsPB( this, CUI_RES( PB_SEC_SECURITYOPTIONS ) )
643 ,maPasswordsFL ( this, CUI_RES( FL_SEC_PASSWORDS ) )
644 ,maSavePasswordsCB ( this, CUI_RES( CB_SEC_SAVEPASSWORDS ) )
645 ,maShowConnectionsPB( this, CUI_RES( PB_SEC_CONNECTIONS ) )
646 ,maMasterPasswordCB ( this, CUI_RES( CB_SEC_MASTERPASSWORD ) )
647 ,maMasterPasswordFI ( this, CUI_RES( FI_SEC_MASTERPASSWORD ) )
648 ,maMasterPasswordPB ( this, CUI_RES( PB_SEC_MASTERPASSWORD ) )
650 ,maMacroSecFL ( this, CUI_RES( FL_SEC_MACROSEC ) )
651 ,maMacroSecFI ( this, CUI_RES( FI_SEC_MACROSEC ) )
652 ,maMacroSecPB ( this, CUI_RES( PB_SEC_MACROSEC ) )
654 ,m_aCertPathFL ( this, CUI_RES( FL_SEC_CERTPATH ) )
655 ,m_aCertPathFI ( this, CUI_RES( FI_SEC_CERTPATH ) )
656 ,m_aCertPathPB ( this, CUI_RES( PB_SEC_CERTPATH ) )
658 ,mpSecOptions ( new SvtSecurityOptions )
659 ,mpSecOptDlg ( NULL )
660 ,mpCertPathDlg ( NULL )
662 ,msPasswordStoringDeactivateStr( CUI_RES( STR_SEC_NOPASSWDSAVE ) )
665 FreeResource();
667 InitControls();
669 maSecurityOptionsPB.SetClickHdl( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
670 maSavePasswordsCB.SetClickHdl( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
671 maMasterPasswordPB.SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
672 maMasterPasswordCB.SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
673 maShowConnectionsPB.SetClickHdl( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
674 maMacroSecPB.SetClickHdl( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
675 m_aCertPathPB.SetClickHdl( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
677 ActivatePage( rSet );
680 SvxSecurityTabPage::~SvxSecurityTabPage()
682 delete mpCertPathDlg;
684 delete mpSecOptions;
685 delete mpSecOptDlg;
688 IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl)
690 if ( !mpSecOptDlg )
691 mpSecOptDlg = new svx::SecurityOptionsDialog( this, mpSecOptions );
692 mpSecOptDlg->Execute();
693 return 0;
696 IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl)
700 Reference< task::XPasswordContainer2 > xMasterPasswd(
701 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
703 if ( maSavePasswordsCB.IsChecked() )
705 sal_Bool bOldValue = xMasterPasswd->allowPersistentStoring( sal_True );
706 xMasterPasswd->removeMasterPassword();
707 if ( xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
709 maMasterPasswordPB.Enable( sal_True );
710 maMasterPasswordCB.Check( sal_True );
711 maMasterPasswordCB.Enable( sal_True );
712 maMasterPasswordFI.Enable( sal_True );
713 maShowConnectionsPB.Enable( sal_True );
715 else
717 xMasterPasswd->allowPersistentStoring( bOldValue );
718 maSavePasswordsCB.Check( sal_False );
721 else
723 QueryBox aQuery( this, WB_YES_NO|WB_DEF_NO, msPasswordStoringDeactivateStr );
724 sal_uInt16 nRet = aQuery.Execute();
726 if( RET_YES == nRet )
728 xMasterPasswd->allowPersistentStoring( sal_False );
729 maMasterPasswordCB.Check( sal_True );
730 maMasterPasswordPB.Enable( sal_False );
731 maMasterPasswordCB.Enable( sal_False );
732 maMasterPasswordFI.Enable( sal_False );
733 maShowConnectionsPB.Enable( sal_False );
735 else
737 maSavePasswordsCB.Check( sal_True );
738 maMasterPasswordPB.Enable( sal_True );
739 maShowConnectionsPB.Enable( sal_True );
743 catch (const Exception&)
745 maSavePasswordsCB.Check( !maSavePasswordsCB.IsChecked() );
748 return 0;
751 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl)
755 Reference< task::XPasswordContainer2 > xMasterPasswd(
756 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
758 if ( xMasterPasswd->isPersistentStoringAllowed() )
759 xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() );
761 catch (const Exception&)
764 return 0;
767 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl)
771 Reference< task::XPasswordContainer2 > xMasterPasswd(
772 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
774 if ( maMasterPasswordCB.IsChecked() )
776 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
778 maMasterPasswordPB.Enable( sal_True );
779 maMasterPasswordFI.Enable( sal_True );
781 else
783 maMasterPasswordCB.Check( sal_False );
784 maMasterPasswordPB.Enable( sal_True );
785 maMasterPasswordFI.Enable( sal_True );
788 else
790 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword( Reference< task::XInteractionHandler >() ) )
792 maMasterPasswordPB.Enable( sal_False );
793 maMasterPasswordFI.Enable( sal_False );
795 else
797 maMasterPasswordCB.Check( sal_True );
798 maMasterPasswordPB.Enable( sal_True );
799 maShowConnectionsPB.Enable( sal_True );
803 catch (const Exception&)
805 maSavePasswordsCB.Check( !maSavePasswordsCB.IsChecked() );
808 return 0;
811 IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl)
815 Reference< task::XPasswordContainer2 > xMasterPasswd(
816 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
818 if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword( Reference< task::XInteractionHandler>() ) )
820 svx::WebConnectionInfoDialog aDlg( this );
821 aDlg.Execute();
824 catch (const Exception&)
826 return 0;
829 IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl)
831 if (!mpCertPathDlg)
832 mpCertPathDlg = new CertPathDialog(this);
834 rtl::OUString sOrig = mpCertPathDlg->getDirectory();
835 short nRet = mpCertPathDlg->Execute();
837 if (nRet == RET_OK && sOrig != mpCertPathDlg->getDirectory())
839 WarningBox aWarnBox(this, CUI_RES(RID_SVX_MSGBOX_OPTIONS_RESTART));
840 aWarnBox.Execute();
843 return 0;
846 IMPL_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl)
850 Reference< security::XDocumentDigitalSignatures > xD(
851 security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
852 xD->manageTrustedSources();
854 catch (const Exception& e)
856 OSL_FAIL(rtl::OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
857 (void)e;
859 return 0;
863 void SvxSecurityTabPage::InitControls()
865 // Hide all controls which belong to the macro security button in case the macro
866 // security settings managed by the macro security dialog opened via the button
867 // are all readonly or if the macros are disabled in general.
868 // @@@ Better would be to query the dialog whether it is 'useful' or not. Exposing
869 // macro security dialog implementations here, which is bad.
870 if ( mpSecOptions->IsMacroDisabled()
871 || ( mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL )
872 && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS )
873 && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_SECUREURLS ) ) )
875 //Move these up
876 m_aCertPathFL.SetPosPixel(maMacroSecFL.GetPosPixel());
877 m_aCertPathFI.SetPosPixel(maMacroSecFI.GetPosPixel());
878 m_aCertPathPB.SetPosPixel(maMacroSecPB.GetPosPixel());
880 //Hide these
881 maMacroSecFL.Hide();
882 maMacroSecFI.Hide();
883 maMacroSecPB.Hide();
886 // one button too small for its text?
887 long nBtnTextWidth = 0;
888 Window* pButtons[] = { &maSecurityOptionsPB, &maMasterPasswordPB,
889 &maShowConnectionsPB, &maMacroSecPB, &m_aCertPathPB };
890 Window** pButton = pButtons;
891 const sal_Int32 nBCount = SAL_N_ELEMENTS( pButtons );
892 for (sal_Int32 i = 0; i < nBCount; ++i, ++pButton )
894 long nTemp = (*pButton)->GetCtrlTextWidth( (*pButton)->GetText() );
895 if ( nTemp > nBtnTextWidth )
896 nBtnTextWidth = nTemp;
899 nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
900 const long nButtonWidth = maSecurityOptionsPB.GetSizePixel().Width();
901 const long nMaxWidth = nButtonWidth * 140 / 100;
902 long nExtra = ( nBtnTextWidth > nMaxWidth ) ? nBtnTextWidth - nMaxWidth : 0;
903 nBtnTextWidth = std::min( nBtnTextWidth, nMaxWidth );
905 if ( nBtnTextWidth > nButtonWidth )
907 // so make the buttons broader and its control in front of it smaller
908 long nDelta = nBtnTextWidth - nButtonWidth;
909 pButton = pButtons;
911 if ( nExtra > 0 )
913 long nPos = (*pButton)->GetPosPixel().X() - nDelta;
914 long nWidth = (*pButton)->GetSizePixel().Width() + nDelta;
915 long nMaxExtra = GetOutputSizePixel().Width() - ( nPos + nWidth ) - 2;
916 nExtra = ( nExtra < nMaxExtra ) ? nExtra : nMaxExtra;
919 for (sal_Int32 i = 0; i < nBCount; ++i, ++pButton )
921 Point aNewPos = (*pButton)->GetPosPixel();
922 aNewPos.X() -= nDelta;
923 Size aNewSize = (*pButton)->GetSizePixel();
924 aNewSize.Width() += ( nDelta + nExtra );
925 (*pButton)->SetPosSizePixel( aNewPos, aNewSize );
928 Window* pControls[] = { &maSecurityOptionsFI, &maSavePasswordsCB,
929 &maMasterPasswordFI, &maMacroSecFI, &m_aCertPathFI };
930 Window** pControl = pControls;
931 const sal_Int32 nCCount = SAL_N_ELEMENTS( pControls );
932 for (sal_Int32 i = 0; i < nCCount; ++i, ++pControl )
934 Size aNewSize = (*pControl)->GetSizePixel();
935 aNewSize.Width() -= nDelta;
936 (*pControl)->SetSizePixel( aNewSize );
940 maMasterPasswordPB.Enable( sal_False );
941 maMasterPasswordCB.Enable( sal_False );
942 maMasterPasswordCB.Check( sal_True );
943 maMasterPasswordFI.Enable( sal_False );
944 maShowConnectionsPB.Enable( sal_False );
946 // initialize the password saving checkbox
949 Reference< task::XPasswordContainer2 > xMasterPasswd(
950 task::PasswordContainer::create(comphelper::getProcessComponentContext()));
952 if ( xMasterPasswd->isPersistentStoringAllowed() )
954 maMasterPasswordCB.Enable( sal_True );
955 maShowConnectionsPB.Enable( sal_True );
956 maSavePasswordsCB.Check( sal_True );
958 if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
959 maMasterPasswordCB.Check( sal_False );
960 else
962 maMasterPasswordPB.Enable( sal_True );
963 maMasterPasswordCB.Check( sal_True );
964 maMasterPasswordFI.Enable( sal_True );
968 catch (const Exception&)
970 maSavePasswordsCB.Enable( sal_False );
973 #ifndef UNX
974 m_aCertPathFL.Hide();
975 m_aCertPathFI.Hide();
976 m_aCertPathPB.Hide();
977 #endif
981 SfxTabPage* SvxSecurityTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
983 return new SvxSecurityTabPage(pParent, rAttrSet);
986 void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
990 int SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
992 if( _pSet )
993 FillItemSet( *_pSet );
994 return LEAVE_PAGE;
997 namespace
999 bool CheckAndSave( SvtSecurityOptions& _rOpt, SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModfied )
1001 bool bModified = false;
1002 if ( _rOpt.IsOptionEnabled( _eOpt ) )
1004 bModified = _rOpt.IsOptionSet( _eOpt ) != _bIsChecked;
1005 if ( bModified )
1007 _rOpt.SetOption( _eOpt, _bIsChecked );
1008 _rModfied = true;
1012 return bModified;
1016 sal_Bool SvxSecurityTabPage::FillItemSet( SfxItemSet& )
1018 bool bModified = false;
1020 if ( mpSecOptDlg )
1022 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SAVEORSEND, mpSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
1023 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SIGNING, mpSecOptDlg->IsSignDocsChecked(), bModified );
1024 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_PRINT, mpSecOptDlg->IsPrintDocsChecked(), bModified );
1025 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_CREATEPDF, mpSecOptDlg->IsCreatePdfChecked(), bModified );
1026 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO, mpSecOptDlg->IsRemovePersInfoChecked(), bModified );
1027 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD, mpSecOptDlg->IsRecommPasswdChecked(), bModified );
1028 CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_CTRLCLICK_HYPERLINK, mpSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
1031 return bModified;
1034 /*--------------------------------------------------------------------*/
1036 void SvxSecurityTabPage::Reset( const SfxItemSet& )
1040 MozPluginTabPage::MozPluginTabPage(Window* pParent, const SfxItemSet& rSet)
1041 : SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_INET_MOZPLUGIN ), rSet ),
1042 aMSWordGB ( this, CUI_RES( GB_MOZPLUGIN ) ),
1043 aWBasicCodeCB ( this, CUI_RES( CB_MOZPLUGIN_CODE ) )
1045 FreeResource();
1048 MozPluginTabPage::~MozPluginTabPage()
1052 SfxTabPage* MozPluginTabPage::Create( Window* pParent,
1053 const SfxItemSet& rAttrSet )
1055 return new MozPluginTabPage( pParent, rAttrSet );
1057 sal_Bool MozPluginTabPage::FillItemSet( SfxItemSet& )
1059 sal_Bool hasInstall = isInstalled();
1060 sal_Bool hasChecked = aWBasicCodeCB.IsChecked();
1061 if(hasInstall && (!hasChecked)){
1062 //try to uninstall
1063 uninstallPlugin();
1065 else if((!hasInstall) && hasChecked){
1066 //try to install
1067 installPlugin();
1069 else{
1070 // do nothing
1072 return sal_True;
1074 void MozPluginTabPage::Reset( const SfxItemSet& )
1076 aWBasicCodeCB.Check( isInstalled());
1077 aWBasicCodeCB.SaveValue();
1080 #ifdef WNT
1081 extern "C" {
1082 int lc_isInstalled(const char* realFilePath);
1083 int lc_installPlugin(const char* realFilePath);
1084 int lc_uninstallPlugin(const char* realFilePath);
1086 #endif
1088 #define NPP_PATH_MAX 2048
1089 inline bool getDllURL(rtl::OString * path)
1091 OSL_ASSERT(path != NULL);
1092 ::rtl::OUString dirPath/*dllPath, */;
1093 if (osl_getExecutableFile(&dirPath.pData) != osl_Process_E_None) {
1094 return false;
1096 dirPath = dirPath.copy(0, dirPath.lastIndexOf('/'));
1097 ::rtl::OUString sysDirPath;
1098 osl::FileBase::getSystemPathFromFileURL(dirPath, sysDirPath);
1099 *path = OUStringToOString(sysDirPath, RTL_TEXTENCODING_ASCII_US);
1100 return true;
1103 sal_Bool MozPluginTabPage::isInstalled()
1105 #ifdef UNIX
1106 // get the real file referred by .so lnk file
1107 char lnkFilePath[NPP_PATH_MAX] = {0};
1108 char lnkReferFilePath[NPP_PATH_MAX] = {0};
1109 char* pHome = getpwuid(getuid())->pw_dir;
1110 strcat(lnkFilePath, pHome);
1111 strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1113 struct stat sBuf;
1114 if (0 > lstat(lnkFilePath, &sBuf))
1115 return false;
1116 if (!S_ISLNK(sBuf.st_mode))
1117 return false;
1118 if (0 >= readlink(lnkFilePath, lnkReferFilePath, NPP_PATH_MAX))
1119 return false;
1120 // If the link is relative, then we regard it as non-standard
1121 if (lnkReferFilePath[0] != '/')
1122 return false;
1124 // get the real file path
1125 char realFilePath[NPP_PATH_MAX] = {0};
1126 ::rtl::OString tempString;
1127 if (!getDllURL(&tempString)) {
1128 return false;
1130 strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1131 strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1133 if (0 != strcmp(lnkReferFilePath, realFilePath))
1134 return false;
1135 return true;
1136 #endif
1137 #ifdef WNT
1138 // get the value from registry
1139 sal_Bool ret = true;
1140 ::rtl::OString tempString;
1141 char realFilePath[NPP_PATH_MAX] = {0};
1142 if (!getDllURL(&tempString)){
1143 return false;
1145 strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1146 if(! lc_isInstalled(realFilePath))
1147 ret =true;
1148 else
1149 ret = false;
1150 return ret;
1151 #endif
1154 sal_Bool MozPluginTabPage::installPlugin()
1156 #ifdef UNIX
1157 // get the real file referred by .so lnk file
1158 char lnkFilePath[NPP_PATH_MAX] = {0};
1159 char* pHome = getpwuid(getuid())->pw_dir;
1160 strcat(lnkFilePath, pHome);
1161 strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1162 remove(lnkFilePath);
1164 // create the dirs if necessary
1165 struct stat buf;
1166 char tmpDir[NPP_PATH_MAX] = {0};
1167 sprintf(tmpDir, "%s/.mozilla", pHome);
1168 if (0 > stat(lnkFilePath, &buf))
1170 mkdir(tmpDir, 0755);
1171 strcat(tmpDir, "/plugins");
1172 mkdir(tmpDir, 0755);
1175 // get the real file path
1176 char realFilePath[NPP_PATH_MAX] = {0};
1177 ::rtl::OString tempString;
1178 if (!getDllURL(&tempString)) {
1179 return false;
1181 strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1182 strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1184 // create the link
1185 if (0 != symlink(realFilePath, lnkFilePath))
1186 return false;
1187 return true;
1188 #endif
1189 #ifdef WNT
1190 ::rtl::OString tempString;
1191 char realFilePath[NPP_PATH_MAX] = {0};
1192 if (!getDllURL(&tempString)) {
1193 return false;
1195 strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1196 if( !lc_installPlugin(realFilePath))
1197 return true;
1198 else
1199 return false;
1200 #endif
1203 sal_Bool MozPluginTabPage::uninstallPlugin()
1205 #ifdef UNIX
1206 // get the real file referred by .so lnk file
1207 char lnkFilePath[NPP_PATH_MAX] = {0};
1208 char* pHome = getpwuid(getuid())->pw_dir;
1209 strcat(lnkFilePath, pHome);
1210 strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1212 if(0 > remove(lnkFilePath))
1213 return false;
1214 return true;
1215 #endif
1216 #ifdef WNT
1217 ::rtl::OString tempString;
1218 char realFilePath[NPP_PATH_MAX] = {0};
1219 if (!getDllURL(&tempString)) {
1220 return false;
1222 strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1223 if(!lc_uninstallPlugin(realFilePath))
1224 return true;
1225 else
1226 return false;
1227 #endif
1230 /* -------------------------------------------------------------------------*/
1232 class MailerProgramCfg_Impl : public utl::ConfigItem
1234 friend class SvxEMailTabPage;
1235 // variables
1236 OUString sProgram;
1237 // readonly states
1238 sal_Bool bROProgram;
1240 const Sequence<OUString> GetPropertyNames();
1241 public:
1242 MailerProgramCfg_Impl();
1243 virtual ~MailerProgramCfg_Impl();
1245 virtual void Commit();
1246 virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames);
1249 /* -------------------------------------------------------------------------*/
1251 MailerProgramCfg_Impl::MailerProgramCfg_Impl() :
1252 utl::ConfigItem("Office.Common/ExternalMailer"),
1253 bROProgram(sal_False)
1255 const Sequence< OUString > aNames = GetPropertyNames();
1256 const Sequence< Any > aValues = GetProperties(aNames);
1257 const Sequence< sal_Bool > aROStates = GetReadOnlyStates(aNames);
1258 const Any* pValues = aValues.getConstArray();
1259 const sal_Bool* pROStates = aROStates.getConstArray();
1260 for(sal_Int32 nProp = 0; nProp < aValues.getLength(); nProp++)
1262 if(pValues[nProp].hasValue())
1264 switch(nProp)
1266 case 0 :
1268 pValues[nProp] >>= sProgram;
1269 bROProgram = pROStates[nProp];
1271 break;
1277 /* -------------------------------------------------------------------------*/
1279 MailerProgramCfg_Impl::~MailerProgramCfg_Impl()
1283 /* -------------------------------------------------------------------------*/
1285 const Sequence<OUString> MailerProgramCfg_Impl::GetPropertyNames()
1287 Sequence<OUString> aRet(1);
1288 OUString* pRet = aRet.getArray();
1289 pRet[0] = "Program";
1290 return aRet;
1293 /* -------------------------------------------------------------------------*/
1295 void MailerProgramCfg_Impl::Commit()
1297 const Sequence< OUString > aOrgNames = GetPropertyNames();
1298 sal_Int32 nOrgCount = aOrgNames.getLength();
1300 Sequence< OUString > aNames(nOrgCount);
1301 Sequence< Any > aValues(nOrgCount);
1302 sal_Int32 nRealCount = 0;
1304 for(int nProp = 0; nProp < nOrgCount; nProp++)
1306 switch(nProp)
1308 case 0:
1310 if (!bROProgram)
1312 aNames[nRealCount] = aOrgNames[nProp];
1313 aValues[nRealCount] <<= sProgram;
1314 ++nRealCount;
1317 break;
1321 aNames.realloc(nRealCount);
1322 aValues.realloc(nRealCount);
1323 PutProperties(aNames, aValues);
1326 void MailerProgramCfg_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
1330 /* -------------------------------------------------------------------------*/
1332 struct SvxEMailTabPage_Impl
1334 MailerProgramCfg_Impl aMailConfig;
1337 SvxEMailTabPage::SvxEMailTabPage(Window* pParent, const SfxItemSet& rSet) :
1338 SfxTabPage(pParent, CUI_RES( RID_SVXPAGE_INET_MAIL ), rSet),
1339 aMailFL(this, CUI_RES(FL_MAIL )),
1340 aMailerURLFI(this, CUI_RES(FI_MAILERURL )),
1341 aMailerURLFT(this, CUI_RES(FT_MAILERURL )),
1342 aMailerURLED(this, CUI_RES(ED_MAILERURL )),
1343 aMailerURLPB(this, CUI_RES(PB_MAILERURL )),
1344 m_sDefaultFilterName( CUI_RES(STR_DEFAULT_FILENAME )),
1345 pImpl(new SvxEMailTabPage_Impl)
1347 FreeResource();
1349 aMailerURLPB.SetClickHdl( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
1351 // FixedText not wide enough?
1352 long nTxtW = aMailerURLFT.GetCtrlTextWidth( aMailerURLFT.GetText() );
1353 long nCtrlW = aMailerURLFT.GetSizePixel().Width();
1354 if ( nTxtW >= nCtrlW )
1356 long nDelta = Max( (long)10, nTxtW - nCtrlW );
1357 // so FixedText wider
1358 Size aNewSz = aMailerURLFT.GetSizePixel();
1359 aNewSz.Width() += nDelta;
1360 aMailerURLFT.SetSizePixel( aNewSz );
1361 // and Edit smaller
1362 aNewSz = aMailerURLED.GetSizePixel();
1363 aNewSz.Width() -= nDelta;
1364 Point aNewPt = aMailerURLED.GetPosPixel();
1365 aNewPt.X() += nDelta;
1366 aMailerURLED.SetPosSizePixel( aNewPt, aNewSz );
1370 /* -------------------------------------------------------------------------*/
1372 SvxEMailTabPage::~SvxEMailTabPage()
1374 delete pImpl;
1377 /* -------------------------------------------------------------------------*/
1379 SfxTabPage* SvxEMailTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1381 return new SvxEMailTabPage(pParent, rAttrSet);
1384 /* -------------------------------------------------------------------------*/
1386 sal_Bool SvxEMailTabPage::FillItemSet( SfxItemSet& )
1388 sal_Bool bMailModified = sal_False;
1389 if(!pImpl->aMailConfig.bROProgram && aMailerURLED.GetSavedValue() != aMailerURLED.GetText())
1391 pImpl->aMailConfig.sProgram = aMailerURLED.GetText();
1392 bMailModified = sal_True;
1394 if ( bMailModified )
1395 pImpl->aMailConfig.Commit();
1397 return sal_False;
1400 /* -------------------------------------------------------------------------*/
1402 void SvxEMailTabPage::Reset( const SfxItemSet& )
1404 aMailerURLED.Enable(sal_True );
1405 aMailerURLPB.Enable(sal_True );
1407 if(pImpl->aMailConfig.bROProgram)
1408 aMailerURLFI.Show();
1410 aMailerURLED.SetText(pImpl->aMailConfig.sProgram);
1411 aMailerURLED.SaveValue();
1412 aMailerURLED.Enable(!pImpl->aMailConfig.bROProgram);
1413 aMailerURLPB.Enable(!pImpl->aMailConfig.bROProgram);
1414 aMailerURLFT.Enable(!pImpl->aMailConfig.bROProgram);
1416 aMailFL.Enable(aMailerURLFT.IsEnabled() ||
1417 aMailerURLED.IsEnabled() ||
1418 aMailerURLPB.IsEnabled());
1421 /* -------------------------------------------------------------------------*/
1423 IMPL_LINK( SvxEMailTabPage, FileDialogHdl_Impl, PushButton*, pButton )
1425 if ( &aMailerURLPB == pButton && !pImpl->aMailConfig.bROProgram )
1427 FileDialogHelper aHelper(
1428 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
1429 0 );
1430 rtl::OUString sPath = aMailerURLED.GetText();
1431 if ( sPath.isEmpty() )
1432 sPath = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/usr/bin"));
1434 rtl::OUString sUrl;
1435 ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sPath, sUrl);
1436 aHelper.SetDisplayDirectory(sUrl);
1437 aHelper.AddFilter( m_sDefaultFilterName, rtl::OUString("*"));
1439 if ( ERRCODE_NONE == aHelper.Execute() )
1441 sUrl = aHelper.GetPath();
1442 ::utl::LocalFileHelper::ConvertURLToPhysicalName(sUrl, sPath);
1443 aMailerURLED.SetText(sPath);
1446 return 0;
1449 // -----------------------------------------------------------------------------
1451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */