Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
45 :
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
56 :
57 : // for security TP
58 : #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
59 :
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>
85 :
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"
92 :
93 : using namespace ::com::sun::star;
94 : using namespace ::com::sun::star::uno;
95 : using namespace ::sfx2;
96 : using ::rtl::OUString;
97 :
98 : // static ----------------------------------------------------------------
99 :
100 : #include <sal/config.h>
101 :
102 : // -----------------------------------------------------------------------
103 :
104 0 : void SvxNoSpaceEdit::KeyInput( const KeyEvent& rKEvent )
105 : {
106 0 : if ( bOnlyNumeric )
107 : {
108 0 : const KeyCode& rKeyCode = rKEvent.GetKeyCode();
109 0 : sal_uInt16 nGroup = rKeyCode.GetGroup();
110 0 : sal_uInt16 nKey = rKeyCode.GetCode();
111 : sal_Bool bValid = ( KEYGROUP_NUM == nGroup || KEYGROUP_CURSOR == nGroup ||
112 0 : ( KEYGROUP_MISC == nGroup && ( nKey < KEY_ADD || nKey > KEY_EQUAL ) ) );
113 0 : 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 0 : bValid = sal_True;
117 :
118 0 : if ( bValid )
119 0 : Edit::KeyInput(rKEvent);
120 : }
121 0 : else if( rKEvent.GetKeyCode().GetCode() != KEY_SPACE )
122 0 : Edit::KeyInput(rKEvent);
123 0 : }
124 :
125 : // -----------------------------------------------------------------------
126 :
127 0 : void SvxNoSpaceEdit::Modify()
128 : {
129 0 : Edit::Modify();
130 :
131 0 : if ( bOnlyNumeric )
132 : {
133 0 : rtl::OUString aValue = GetText();
134 :
135 0 : if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
136 : // the maximum value of a port number is USHRT_MAX
137 0 : ErrorBox( this, CUI_RES( RID_SVXERR_OPT_PROXYPORTS ) ).Execute();
138 : }
139 0 : }
140 :
141 : /********************************************************************/
142 : /* */
143 : /* SvxProxyTabPage */
144 : /* */
145 : /********************************************************************/
146 :
147 0 : SvxProxyTabPage::SvxProxyTabPage(Window* pParent, const SfxItemSet& rSet ) :
148 0 : SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_INET_PROXY ), rSet ),
149 0 : aOptionGB (this, CUI_RES(GB_SETTINGS)),
150 :
151 0 : aProxyModeFT (this, CUI_RES(FT_PROXYMODE)),
152 0 : aProxyModeLB (this, CUI_RES(LB_PROXYMODE)),
153 :
154 0 : aHttpProxyFT (this, CUI_RES( FT_HTTP_PROXY )),
155 0 : aHttpProxyED (this, CUI_RES( ED_HTTP_PROXY )),
156 0 : aHttpPortFT (this, CUI_RES( FT_HTTP_PORT )),
157 0 : aHttpPortED (this, CUI_RES( ED_HTTP_PORT ), sal_True),
158 :
159 0 : aHttpsProxyFT (this, CUI_RES( FT_HTTPS_PROXY )),
160 0 : aHttpsProxyED (this, CUI_RES( ED_HTTPS_PROXY )),
161 0 : aHttpsPortFT (this, CUI_RES( FT_HTTPS_PORT )),
162 0 : aHttpsPortED (this, CUI_RES( ED_HTTPS_PORT ), sal_True),
163 :
164 0 : aFtpProxyFT (this, CUI_RES( FT_FTP_PROXY )),
165 0 : aFtpProxyED (this, CUI_RES( ED_FTP_PROXY )),
166 0 : aFtpPortFT (this, CUI_RES( FT_FTP_PORT )),
167 0 : aFtpPortED (this, CUI_RES( ED_FTP_PORT ), sal_True),
168 :
169 0 : aNoProxyForFT (this, CUI_RES( FT_NOPROXYFOR )),
170 0 : aNoProxyForED (this, CUI_RES( ED_NOPROXYFOR )),
171 0 : aNoProxyDescFT (this, CUI_RES( ED_NOPROXYDESC )),
172 0 : 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 0 : aNoProxyDescPN(RTL_CONSTASCII_USTRINGPARAM("ooInetNoProxy"))
181 : {
182 0 : FreeResource();
183 :
184 0 : aHttpPortED.SetMaxTextLen(5);
185 0 : aHttpsPortED.SetMaxTextLen(5);
186 0 : aFtpPortED.SetMaxTextLen(5);
187 0 : Link aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
188 0 : aHttpPortED.SetLoseFocusHdl( aLink );
189 0 : aHttpsPortED.SetLoseFocusHdl( aLink );
190 0 : aFtpPortED.SetLoseFocusHdl( aLink );
191 :
192 0 : aProxyModeLB.SetSelectHdl(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
193 :
194 : Reference< com::sun::star::lang::XMultiServiceFactory >
195 : xConfigurationProvider(
196 : configuration::theDefaultProvider::get(
197 0 : comphelper::getProcessComponentContext() ) );
198 :
199 0 : OUString aConfigRoot(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Inet/Settings" ) );
200 :
201 0 : beans::NamedValue aProperty;
202 0 : aProperty.Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
203 0 : aProperty.Value = makeAny( aConfigRoot );
204 :
205 0 : Sequence< Any > aArgumentList( 1 );
206 0 : aArgumentList[0] = makeAny( aProperty );
207 :
208 0 : m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments( rtl::OUString(
209 : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ),
210 0 : aArgumentList );
211 :
212 0 : ArrangeControls_Impl();
213 0 : }
214 :
215 0 : SvxProxyTabPage::~SvxProxyTabPage()
216 : {
217 0 : }
218 :
219 0 : SfxTabPage* SvxProxyTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
220 : {
221 0 : return new SvxProxyTabPage(pParent, rAttrSet);
222 : }
223 :
224 0 : void SvxProxyTabPage::ReadConfigData_Impl()
225 : {
226 : try {
227 0 : Reference< container::XNameAccess > xNameAccess(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
228 :
229 0 : sal_Int32 nIntValue = 0;
230 0 : OUString aStringValue;
231 :
232 0 : if( xNameAccess->getByName(aProxyModePN) >>= nIntValue )
233 : {
234 0 : aProxyModeLB.SelectEntryPos( (sal_uInt16) nIntValue );
235 : }
236 :
237 0 : if( xNameAccess->getByName(aHttpProxyPN) >>= aStringValue )
238 : {
239 0 : aHttpProxyED.SetText( aStringValue );
240 : }
241 :
242 0 : if( xNameAccess->getByName(aHttpPortPN) >>= nIntValue )
243 : {
244 0 : aHttpPortED.SetText( String::CreateFromInt32( nIntValue ));
245 : }
246 :
247 0 : if( xNameAccess->getByName(aHttpsProxyPN) >>= aStringValue )
248 : {
249 0 : aHttpsProxyED.SetText( aStringValue );
250 : }
251 :
252 0 : if( xNameAccess->getByName(aHttpsPortPN) >>= nIntValue )
253 : {
254 0 : aHttpsPortED.SetText( String::CreateFromInt32( nIntValue ));
255 : }
256 :
257 0 : if( xNameAccess->getByName(aFtpProxyPN) >>= aStringValue )
258 : {
259 0 : aFtpProxyED.SetText( aStringValue );
260 : }
261 :
262 0 : if( xNameAccess->getByName(aFtpPortPN) >>= nIntValue )
263 : {
264 0 : aFtpPortED.SetText( String::CreateFromInt32( nIntValue ));
265 : }
266 :
267 0 : if( xNameAccess->getByName(aNoProxyDescPN) >>= aStringValue )
268 : {
269 0 : aNoProxyForED.SetText( aStringValue );
270 0 : }
271 : }
272 :
273 0 : catch (const container::NoSuchElementException&) {
274 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
275 : }
276 :
277 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
278 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
279 : }
280 :
281 0 : catch (const RuntimeException &) {
282 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
283 : }
284 :
285 0 : }
286 :
287 0 : void SvxProxyTabPage::ReadConfigDefaults_Impl()
288 : {
289 : try
290 : {
291 0 : Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
292 :
293 0 : sal_Int32 nIntValue = 0;
294 0 : OUString aStringValue;
295 :
296 0 : if( xPropertyState->getPropertyDefault(aHttpProxyPN) >>= aStringValue )
297 : {
298 0 : aHttpProxyED.SetText( aStringValue );
299 : }
300 :
301 0 : if( xPropertyState->getPropertyDefault(aHttpPortPN) >>= nIntValue )
302 : {
303 0 : aHttpPortED.SetText( String::CreateFromInt32( nIntValue ));
304 : }
305 :
306 0 : if( xPropertyState->getPropertyDefault(aHttpsProxyPN) >>= aStringValue )
307 : {
308 0 : aHttpsProxyED.SetText( aStringValue );
309 : }
310 :
311 0 : if( xPropertyState->getPropertyDefault(aHttpsPortPN) >>= nIntValue )
312 : {
313 0 : aHttpsPortED.SetText( String::CreateFromInt32( nIntValue ));
314 : }
315 :
316 0 : if( xPropertyState->getPropertyDefault(aFtpProxyPN) >>= aStringValue )
317 : {
318 0 : aFtpProxyED.SetText( aStringValue );
319 : }
320 :
321 0 : if( xPropertyState->getPropertyDefault(aFtpPortPN) >>= nIntValue )
322 : {
323 0 : aFtpPortED.SetText( String::CreateFromInt32( nIntValue ));
324 : }
325 :
326 0 : if( xPropertyState->getPropertyDefault(aNoProxyDescPN) >>= aStringValue )
327 : {
328 0 : aNoProxyForED.SetText( aStringValue );
329 0 : }
330 : }
331 0 : catch (const beans::UnknownPropertyException &)
332 : {
333 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
334 : }
335 :
336 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
337 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
338 : }
339 :
340 0 : catch (const RuntimeException &)
341 : {
342 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
343 : }
344 0 : }
345 :
346 0 : void SvxProxyTabPage::RestoreConfigDefaults_Impl()
347 : {
348 : try
349 : {
350 0 : Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
351 :
352 0 : xPropertyState->setPropertyToDefault(aProxyModePN);
353 0 : xPropertyState->setPropertyToDefault(aHttpProxyPN);
354 0 : xPropertyState->setPropertyToDefault(aHttpPortPN);
355 0 : xPropertyState->setPropertyToDefault(aHttpsProxyPN);
356 0 : xPropertyState->setPropertyToDefault(aHttpsPortPN);
357 0 : xPropertyState->setPropertyToDefault(aFtpProxyPN);
358 0 : xPropertyState->setPropertyToDefault(aFtpPortPN);
359 0 : xPropertyState->setPropertyToDefault(aNoProxyDescPN);
360 :
361 0 : Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
362 0 : xChangesBatch->commitChanges();
363 : }
364 :
365 0 : catch (const beans::UnknownPropertyException &)
366 : {
367 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
368 : }
369 :
370 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
371 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
372 : }
373 :
374 0 : catch (const RuntimeException &)
375 : {
376 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
377 : }
378 0 : }
379 :
380 0 : void SvxProxyTabPage::Reset(const SfxItemSet&)
381 : {
382 0 : ReadConfigData_Impl();
383 :
384 0 : aProxyModeLB.SaveValue();
385 0 : aHttpProxyED.SaveValue();
386 0 : aHttpPortED.SaveValue();
387 0 : aHttpsProxyED.SaveValue();
388 0 : aHttpsPortED.SaveValue();
389 0 : aFtpProxyED.SaveValue();
390 0 : aFtpPortED.SaveValue();
391 0 : aNoProxyForED.SaveValue();
392 :
393 0 : EnableControls_Impl( aProxyModeLB.GetSelectEntryPos() == 2 );
394 0 : }
395 :
396 0 : sal_Bool SvxProxyTabPage::FillItemSet(SfxItemSet& )
397 : {
398 0 : sal_Bool bModified=sal_False;
399 :
400 : try {
401 0 : Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
402 :
403 0 : sal_uInt16 nSelPos = aProxyModeLB.GetSelectEntryPos();
404 0 : if(aProxyModeLB.GetSavedValue() != nSelPos)
405 : {
406 0 : if( nSelPos == 1 )
407 : {
408 0 : RestoreConfigDefaults_Impl();
409 0 : return sal_True;
410 : }
411 :
412 0 : xPropertySet->setPropertyValue(aProxyModePN,
413 0 : makeAny((sal_Int32) nSelPos));
414 0 : bModified = sal_True;
415 : }
416 :
417 0 : if(aHttpProxyED.GetSavedValue() != aHttpProxyED.GetText())
418 : {
419 0 : xPropertySet->setPropertyValue( aHttpProxyPN,
420 0 : makeAny(rtl::OUString(aHttpProxyED.GetText())));
421 0 : bModified = sal_True;
422 : }
423 :
424 0 : if ( aHttpPortED.GetSavedValue() != aHttpPortED.GetText() )
425 : {
426 0 : xPropertySet->setPropertyValue( aHttpPortPN,
427 0 : makeAny(aHttpPortED.GetText().ToInt32()));
428 0 : bModified = sal_True;
429 : }
430 :
431 0 : if(aHttpsProxyED.GetSavedValue() != aHttpsProxyED.GetText())
432 : {
433 0 : xPropertySet->setPropertyValue( aHttpsProxyPN,
434 0 : makeAny(rtl::OUString(aHttpsProxyED.GetText())));
435 0 : bModified = sal_True;
436 : }
437 :
438 0 : if ( aHttpsPortED.GetSavedValue() != aHttpsPortED.GetText() )
439 : {
440 0 : xPropertySet->setPropertyValue( aHttpsPortPN,
441 0 : makeAny(aHttpsPortED.GetText().ToInt32()));
442 0 : bModified = sal_True;
443 : }
444 :
445 0 : if(aFtpProxyED.GetSavedValue() != aFtpProxyED.GetText())
446 : {
447 0 : xPropertySet->setPropertyValue( aFtpProxyPN,
448 0 : makeAny( rtl::OUString(aFtpProxyED.GetText())));
449 0 : bModified = sal_True;
450 : }
451 :
452 0 : if ( aFtpPortED.GetSavedValue() != aFtpPortED.GetText() )
453 : {
454 0 : xPropertySet->setPropertyValue( aFtpPortPN,
455 0 : makeAny(aFtpPortED.GetText().ToInt32()));
456 0 : bModified = sal_True;
457 : }
458 :
459 0 : if ( aNoProxyForED.GetSavedValue() != aNoProxyForED.GetText() )
460 : {
461 0 : xPropertySet->setPropertyValue( aNoProxyDescPN,
462 0 : makeAny( rtl::OUString(aNoProxyForED.GetText())));
463 0 : bModified = sal_True;
464 : }
465 :
466 0 : Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
467 0 : xChangesBatch->commitChanges();
468 : }
469 :
470 0 : catch (const com::sun::star::lang::IllegalArgumentException &) {
471 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
472 : }
473 :
474 0 : catch (const beans::UnknownPropertyException &) {
475 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
476 : }
477 :
478 0 : catch (const beans::PropertyVetoException &) {
479 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
480 : }
481 :
482 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
483 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
484 : }
485 :
486 0 : catch (const RuntimeException &) {
487 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
488 : }
489 :
490 0 : return bModified;
491 : }
492 :
493 0 : void SvxProxyTabPage::ArrangeControls_Impl()
494 : {
495 : // calculate dynamic width of controls, to not cut-off translated strings #i71445#
496 0 : long nWidth = aProxyModeFT.GetCtrlTextWidth( aProxyModeFT.GetText() );
497 0 : long nTemp = aHttpProxyFT.GetCtrlTextWidth( aHttpProxyFT.GetText() );
498 0 : if ( nTemp > nWidth )
499 0 : nWidth = nTemp;
500 0 : nTemp = aHttpsProxyFT.GetCtrlTextWidth( aHttpsProxyFT.GetText() );
501 0 : if ( nTemp > nWidth )
502 0 : nWidth = nTemp;
503 0 : nTemp = aFtpProxyFT.GetCtrlTextWidth( aFtpProxyFT.GetText() );
504 0 : if ( nTemp > nWidth )
505 0 : nWidth = nTemp;
506 0 : nTemp = aNoProxyForFT.GetCtrlTextWidth( aNoProxyForFT.GetText() );
507 0 : if ( nTemp > nWidth )
508 0 : nWidth = nTemp;
509 :
510 0 : nWidth += 10; // To be sure the length of the FixedText is enough on all platforms
511 0 : const long nFTWidth = aProxyModeFT.GetSizePixel().Width();
512 0 : if ( nWidth > nFTWidth )
513 : {
514 0 : Size aNewSize = aProxyModeFT.GetSizePixel();
515 0 : aNewSize.Width() = nWidth;
516 :
517 0 : aProxyModeFT.SetSizePixel( aNewSize );
518 0 : aHttpProxyFT.SetSizePixel( aNewSize );
519 0 : aHttpsProxyFT.SetSizePixel( aNewSize );
520 0 : aFtpProxyFT.SetSizePixel( aNewSize );
521 0 : aNoProxyForFT.SetSizePixel( aNewSize );
522 :
523 0 : const long nDelta = nWidth - nFTWidth;
524 0 : Point aNewPos = aProxyModeLB.GetPosPixel();
525 0 : aNewPos.X() += nDelta;
526 :
527 0 : aProxyModeLB.SetPosPixel( aNewPos );
528 :
529 0 : aNewSize = aHttpProxyED.GetSizePixel();
530 0 : aNewSize.Width() -= nDelta;
531 :
532 0 : aNewPos.Y() = aHttpProxyED.GetPosPixel().Y();
533 0 : aHttpProxyED.SetPosSizePixel( aNewPos, aNewSize );
534 0 : aNewPos.Y() = aHttpsProxyED.GetPosPixel().Y();
535 0 : aHttpsProxyED.SetPosSizePixel( aNewPos, aNewSize );
536 0 : aNewPos.Y() = aFtpProxyED.GetPosPixel().Y();
537 0 : aFtpProxyED.SetPosSizePixel( aNewPos, aNewSize );
538 0 : aNewPos.Y() = aNoProxyForED.GetPosPixel().Y();
539 0 : aNoProxyForED.SetPosSizePixel( aNewPos, aNewSize );
540 : }
541 0 : }
542 :
543 0 : void SvxProxyTabPage::EnableControls_Impl(sal_Bool bEnable)
544 : {
545 0 : aHttpProxyFT.Enable(bEnable);
546 0 : aHttpProxyED.Enable(bEnable);
547 0 : aHttpPortFT.Enable(bEnable);
548 0 : aHttpPortED.Enable(bEnable);
549 :
550 0 : aHttpsProxyFT.Enable(bEnable);
551 0 : aHttpsProxyED.Enable(bEnable);
552 0 : aHttpsPortFT.Enable(bEnable);
553 0 : aHttpsPortED.Enable(bEnable);
554 :
555 0 : aFtpProxyFT.Enable(bEnable);
556 0 : aFtpProxyED.Enable(bEnable);
557 0 : aFtpPortFT.Enable(bEnable);
558 0 : aFtpPortED.Enable(bEnable);
559 :
560 0 : aNoProxyForFT.Enable(bEnable);
561 0 : aNoProxyForED.Enable(bEnable);
562 0 : aNoProxyDescFT.Enable(bEnable);
563 0 : }
564 :
565 : // -----------------------------------------------------------------------
566 :
567 0 : IMPL_LINK( SvxProxyTabPage, ProxyHdl_Impl, ListBox *, pBox )
568 : {
569 0 : sal_uInt16 nPos = pBox->GetSelectEntryPos();
570 :
571 : // Restore original system values
572 0 : if( nPos == 1 )
573 : {
574 0 : ReadConfigDefaults_Impl();
575 : }
576 :
577 0 : EnableControls_Impl(nPos == 2);
578 0 : return 0;
579 : }
580 :
581 : // -----------------------------------------------------------------------
582 :
583 0 : IMPL_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Edit *, pEdit )
584 : {
585 0 : rtl::OUString aValue = pEdit->GetText();
586 :
587 0 : if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
588 0 : pEdit->SetText( rtl::OUString('0') );
589 0 : return 0;
590 : }
591 :
592 :
593 :
594 : //#98647#----------------------------------------------
595 0 : void SvxScriptExecListBox::RequestHelp( const HelpEvent& rHEvt )
596 : { // try to show tips just like as on toolbars
597 0 : sal_uInt16 nPos=LISTBOX_ENTRY_NOTFOUND;
598 0 : sal_uInt16 nTop = GetTopEntry();
599 0 : sal_uInt16 nCount = GetDisplayLineCount(); // Attention: Not GetLineCount()
600 0 : Point aPt = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
601 0 : Rectangle aItemRect;
602 0 : if( nCount > 0 ) // if there're some entries, find it.
603 0 : for( nPos = nTop ; nPos <= nTop+nCount-1 ; nPos++ ) {
604 0 : aItemRect = GetBoundingRectangle(nPos);
605 0 : if( aPt.Y() < aItemRect.Top() || aPt.Y() > aItemRect.Bottom() )
606 0 : continue;
607 : else
608 0 : break;
609 : }
610 : else // if not, nothing happens.
611 0 : return;
612 0 : String aHelpText;
613 0 : if( nPos <= nTop+nCount-1 ) // if find the matching entry, get its content.
614 0 : aHelpText = GetEntry(nPos);
615 0 : if( aHelpText.Len() && GetTextWidth(aHelpText)<GetOutputSizePixel().Width() )
616 0 : aHelpText.Erase(); // if the entry is quite short, clear the helping tip content.
617 0 : aItemRect = Rectangle(Point(0,0),GetSizePixel());
618 0 : aPt = Point(OutputToScreenPixel( aItemRect.TopLeft() ));
619 0 : aItemRect.Left() = aPt.X();
620 0 : aItemRect.Top() = aPt.Y();
621 0 : aPt = OutputToScreenPixel( aItemRect.BottomRight() );
622 0 : aItemRect.Right() = aPt.X();
623 0 : aItemRect.Bottom() = aPt.Y();
624 0 : if( rHEvt.GetMode() == HELPMODE_BALLOON )
625 0 : Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
626 : else
627 0 : Help::ShowQuickHelp( this, aItemRect, aHelpText );
628 : }
629 :
630 : /********************************************************************/
631 : /* */
632 : /* SvxSecurityTabPage */
633 : /* */
634 : /********************************************************************/
635 :
636 0 : SvxSecurityTabPage::SvxSecurityTabPage( Window* pParent, const SfxItemSet& rSet )
637 0 : :SfxTabPage ( pParent, CUI_RES( RID_SVXPAGE_INET_SECURITY ), rSet )
638 :
639 0 : ,maSecurityOptionsFL( this, CUI_RES( FL_SEC_SECURITYOPTIONS ) )
640 0 : ,maSecurityOptionsFI( this, CUI_RES( FI_SEC_SECURITYOPTIONS ) )
641 0 : ,maSecurityOptionsPB( this, CUI_RES( PB_SEC_SECURITYOPTIONS ) )
642 :
643 0 : ,maPasswordsFL ( this, CUI_RES( FL_SEC_PASSWORDS ) )
644 0 : ,maSavePasswordsCB ( this, CUI_RES( CB_SEC_SAVEPASSWORDS ) )
645 0 : ,maShowConnectionsPB( this, CUI_RES( PB_SEC_CONNECTIONS ) )
646 0 : ,maMasterPasswordCB ( this, CUI_RES( CB_SEC_MASTERPASSWORD ) )
647 0 : ,maMasterPasswordFI ( this, CUI_RES( FI_SEC_MASTERPASSWORD ) )
648 0 : ,maMasterPasswordPB ( this, CUI_RES( PB_SEC_MASTERPASSWORD ) )
649 :
650 0 : ,maMacroSecFL ( this, CUI_RES( FL_SEC_MACROSEC ) )
651 0 : ,maMacroSecFI ( this, CUI_RES( FI_SEC_MACROSEC ) )
652 0 : ,maMacroSecPB ( this, CUI_RES( PB_SEC_MACROSEC ) )
653 :
654 0 : ,m_aCertPathFL ( this, CUI_RES( FL_SEC_CERTPATH ) )
655 0 : ,m_aCertPathFI ( this, CUI_RES( FI_SEC_CERTPATH ) )
656 0 : ,m_aCertPathPB ( this, CUI_RES( PB_SEC_CERTPATH ) )
657 :
658 0 : ,mpSecOptions ( new SvtSecurityOptions )
659 : ,mpSecOptDlg ( NULL )
660 : ,mpCertPathDlg ( NULL )
661 :
662 0 : ,msPasswordStoringDeactivateStr( CUI_RES( STR_SEC_NOPASSWDSAVE ) )
663 :
664 : {
665 0 : FreeResource();
666 :
667 0 : InitControls();
668 :
669 0 : maSecurityOptionsPB.SetClickHdl( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
670 0 : maSavePasswordsCB.SetClickHdl( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
671 0 : maMasterPasswordPB.SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
672 0 : maMasterPasswordCB.SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
673 0 : maShowConnectionsPB.SetClickHdl( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
674 0 : maMacroSecPB.SetClickHdl( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
675 0 : m_aCertPathPB.SetClickHdl( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
676 :
677 0 : ActivatePage( rSet );
678 0 : }
679 :
680 0 : SvxSecurityTabPage::~SvxSecurityTabPage()
681 : {
682 0 : delete mpCertPathDlg;
683 :
684 0 : delete mpSecOptions;
685 0 : delete mpSecOptDlg;
686 0 : }
687 :
688 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl)
689 : {
690 0 : if ( !mpSecOptDlg )
691 0 : mpSecOptDlg = new svx::SecurityOptionsDialog( this, mpSecOptions );
692 0 : mpSecOptDlg->Execute();
693 0 : return 0;
694 : }
695 :
696 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl)
697 : {
698 : try
699 : {
700 : Reference< task::XPasswordContainer2 > xMasterPasswd(
701 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
702 :
703 0 : if ( maSavePasswordsCB.IsChecked() )
704 : {
705 0 : sal_Bool bOldValue = xMasterPasswd->allowPersistentStoring( sal_True );
706 0 : xMasterPasswd->removeMasterPassword();
707 0 : if ( xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
708 : {
709 0 : maMasterPasswordPB.Enable( sal_True );
710 0 : maMasterPasswordCB.Check( sal_True );
711 0 : maMasterPasswordCB.Enable( sal_True );
712 0 : maMasterPasswordFI.Enable( sal_True );
713 0 : maShowConnectionsPB.Enable( sal_True );
714 : }
715 : else
716 : {
717 0 : xMasterPasswd->allowPersistentStoring( bOldValue );
718 0 : maSavePasswordsCB.Check( sal_False );
719 : }
720 : }
721 : else
722 : {
723 0 : QueryBox aQuery( this, WB_YES_NO|WB_DEF_NO, msPasswordStoringDeactivateStr );
724 0 : sal_uInt16 nRet = aQuery.Execute();
725 :
726 0 : if( RET_YES == nRet )
727 : {
728 0 : xMasterPasswd->allowPersistentStoring( sal_False );
729 0 : maMasterPasswordCB.Check( sal_True );
730 0 : maMasterPasswordPB.Enable( sal_False );
731 0 : maMasterPasswordCB.Enable( sal_False );
732 0 : maMasterPasswordFI.Enable( sal_False );
733 0 : maShowConnectionsPB.Enable( sal_False );
734 : }
735 : else
736 : {
737 0 : maSavePasswordsCB.Check( sal_True );
738 0 : maMasterPasswordPB.Enable( sal_True );
739 0 : maShowConnectionsPB.Enable( sal_True );
740 0 : }
741 0 : }
742 : }
743 0 : catch (const Exception&)
744 : {
745 0 : maSavePasswordsCB.Check( !maSavePasswordsCB.IsChecked() );
746 : }
747 :
748 0 : return 0;
749 : }
750 :
751 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl)
752 : {
753 : try
754 : {
755 : Reference< task::XPasswordContainer2 > xMasterPasswd(
756 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
757 :
758 0 : if ( xMasterPasswd->isPersistentStoringAllowed() )
759 0 : xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() );
760 : }
761 0 : catch (const Exception&)
762 : {}
763 :
764 0 : return 0;
765 : }
766 :
767 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl)
768 : {
769 : try
770 : {
771 : Reference< task::XPasswordContainer2 > xMasterPasswd(
772 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
773 :
774 0 : if ( maMasterPasswordCB.IsChecked() )
775 : {
776 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
777 : {
778 0 : maMasterPasswordPB.Enable( sal_True );
779 0 : maMasterPasswordFI.Enable( sal_True );
780 : }
781 : else
782 : {
783 0 : maMasterPasswordCB.Check( sal_False );
784 0 : maMasterPasswordPB.Enable( sal_True );
785 0 : maMasterPasswordFI.Enable( sal_True );
786 : }
787 : }
788 : else
789 : {
790 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword( Reference< task::XInteractionHandler >() ) )
791 : {
792 0 : maMasterPasswordPB.Enable( sal_False );
793 0 : maMasterPasswordFI.Enable( sal_False );
794 : }
795 : else
796 : {
797 0 : maMasterPasswordCB.Check( sal_True );
798 0 : maMasterPasswordPB.Enable( sal_True );
799 0 : maShowConnectionsPB.Enable( sal_True );
800 : }
801 0 : }
802 : }
803 0 : catch (const Exception&)
804 : {
805 0 : maSavePasswordsCB.Check( !maSavePasswordsCB.IsChecked() );
806 : }
807 :
808 0 : return 0;
809 : }
810 :
811 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl)
812 : {
813 : try
814 : {
815 : Reference< task::XPasswordContainer2 > xMasterPasswd(
816 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
817 :
818 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword( Reference< task::XInteractionHandler>() ) )
819 : {
820 0 : svx::WebConnectionInfoDialog aDlg( this );
821 0 : aDlg.Execute();
822 0 : }
823 : }
824 0 : catch (const Exception&)
825 : {}
826 0 : return 0;
827 : }
828 :
829 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl)
830 : {
831 0 : if (!mpCertPathDlg)
832 0 : mpCertPathDlg = new CertPathDialog(this);
833 :
834 0 : rtl::OUString sOrig = mpCertPathDlg->getDirectory();
835 0 : short nRet = mpCertPathDlg->Execute();
836 :
837 0 : if (nRet == RET_OK && sOrig != mpCertPathDlg->getDirectory())
838 : {
839 0 : WarningBox aWarnBox(this, CUI_RES(RID_SVX_MSGBOX_OPTIONS_RESTART));
840 0 : aWarnBox.Execute();
841 : }
842 :
843 0 : return 0;
844 : }
845 :
846 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl)
847 : {
848 : try
849 : {
850 : Reference< security::XDocumentDigitalSignatures > xD(
851 0 : security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
852 0 : xD->manageTrustedSources();
853 : }
854 0 : catch (const Exception& e)
855 : {
856 : OSL_FAIL(rtl::OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
857 : (void)e;
858 : }
859 0 : return 0;
860 : }
861 :
862 :
863 0 : void SvxSecurityTabPage::InitControls()
864 : {
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 0 : if ( mpSecOptions->IsMacroDisabled()
871 0 : || ( mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL )
872 0 : && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS )
873 0 : && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_SECUREURLS ) ) )
874 : {
875 : //Move these up
876 0 : m_aCertPathFL.SetPosPixel(maMacroSecFL.GetPosPixel());
877 0 : m_aCertPathFI.SetPosPixel(maMacroSecFI.GetPosPixel());
878 0 : m_aCertPathPB.SetPosPixel(maMacroSecPB.GetPosPixel());
879 :
880 : //Hide these
881 0 : maMacroSecFL.Hide();
882 0 : maMacroSecFI.Hide();
883 0 : maMacroSecPB.Hide();
884 : }
885 :
886 : // one button too small for its text?
887 0 : long nBtnTextWidth = 0;
888 : Window* pButtons[] = { &maSecurityOptionsPB, &maMasterPasswordPB,
889 0 : &maShowConnectionsPB, &maMacroSecPB, &m_aCertPathPB };
890 0 : Window** pButton = pButtons;
891 0 : const sal_Int32 nBCount = SAL_N_ELEMENTS( pButtons );
892 0 : for (sal_Int32 i = 0; i < nBCount; ++i, ++pButton )
893 : {
894 0 : long nTemp = (*pButton)->GetCtrlTextWidth( (*pButton)->GetText() );
895 0 : if ( nTemp > nBtnTextWidth )
896 0 : nBtnTextWidth = nTemp;
897 : }
898 :
899 0 : nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
900 0 : const long nButtonWidth = maSecurityOptionsPB.GetSizePixel().Width();
901 0 : const long nMaxWidth = nButtonWidth * 140 / 100;
902 0 : long nExtra = ( nBtnTextWidth > nMaxWidth ) ? nBtnTextWidth - nMaxWidth : 0;
903 0 : nBtnTextWidth = std::min( nBtnTextWidth, nMaxWidth );
904 :
905 0 : if ( nBtnTextWidth > nButtonWidth )
906 : {
907 : // so make the buttons broader and its control in front of it smaller
908 0 : long nDelta = nBtnTextWidth - nButtonWidth;
909 0 : pButton = pButtons;
910 :
911 0 : if ( nExtra > 0 )
912 : {
913 0 : long nPos = (*pButton)->GetPosPixel().X() - nDelta;
914 0 : long nWidth = (*pButton)->GetSizePixel().Width() + nDelta;
915 0 : long nMaxExtra = GetOutputSizePixel().Width() - ( nPos + nWidth ) - 2;
916 0 : nExtra = ( nExtra < nMaxExtra ) ? nExtra : nMaxExtra;
917 : }
918 :
919 0 : for (sal_Int32 i = 0; i < nBCount; ++i, ++pButton )
920 : {
921 0 : Point aNewPos = (*pButton)->GetPosPixel();
922 0 : aNewPos.X() -= nDelta;
923 0 : Size aNewSize = (*pButton)->GetSizePixel();
924 0 : aNewSize.Width() += ( nDelta + nExtra );
925 0 : (*pButton)->SetPosSizePixel( aNewPos, aNewSize );
926 : }
927 :
928 : Window* pControls[] = { &maSecurityOptionsFI, &maSavePasswordsCB,
929 0 : &maMasterPasswordFI, &maMacroSecFI, &m_aCertPathFI };
930 0 : Window** pControl = pControls;
931 0 : const sal_Int32 nCCount = SAL_N_ELEMENTS( pControls );
932 0 : for (sal_Int32 i = 0; i < nCCount; ++i, ++pControl )
933 : {
934 0 : Size aNewSize = (*pControl)->GetSizePixel();
935 0 : aNewSize.Width() -= nDelta;
936 0 : (*pControl)->SetSizePixel( aNewSize );
937 : }
938 : }
939 :
940 0 : maMasterPasswordPB.Enable( sal_False );
941 0 : maMasterPasswordCB.Enable( sal_False );
942 0 : maMasterPasswordCB.Check( sal_True );
943 0 : maMasterPasswordFI.Enable( sal_False );
944 0 : maShowConnectionsPB.Enable( sal_False );
945 :
946 : // initialize the password saving checkbox
947 : try
948 : {
949 : Reference< task::XPasswordContainer2 > xMasterPasswd(
950 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
951 :
952 0 : if ( xMasterPasswd->isPersistentStoringAllowed() )
953 : {
954 0 : maMasterPasswordCB.Enable( sal_True );
955 0 : maShowConnectionsPB.Enable( sal_True );
956 0 : maSavePasswordsCB.Check( sal_True );
957 :
958 0 : if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
959 0 : maMasterPasswordCB.Check( sal_False );
960 : else
961 : {
962 0 : maMasterPasswordPB.Enable( sal_True );
963 0 : maMasterPasswordCB.Check( sal_True );
964 0 : maMasterPasswordFI.Enable( sal_True );
965 : }
966 0 : }
967 : }
968 0 : catch (const Exception&)
969 : {
970 0 : maSavePasswordsCB.Enable( sal_False );
971 : }
972 :
973 : #ifndef UNX
974 : m_aCertPathFL.Hide();
975 : m_aCertPathFI.Hide();
976 : m_aCertPathPB.Hide();
977 : #endif
978 :
979 0 : }
980 :
981 0 : SfxTabPage* SvxSecurityTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
982 : {
983 0 : return new SvxSecurityTabPage(pParent, rAttrSet);
984 : }
985 :
986 0 : void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
987 : {
988 0 : }
989 :
990 0 : int SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
991 : {
992 0 : if( _pSet )
993 0 : FillItemSet( *_pSet );
994 0 : return LEAVE_PAGE;
995 : }
996 :
997 : namespace
998 : {
999 0 : bool CheckAndSave( SvtSecurityOptions& _rOpt, SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModfied )
1000 : {
1001 0 : bool bModified = false;
1002 0 : if ( _rOpt.IsOptionEnabled( _eOpt ) )
1003 : {
1004 0 : bModified = _rOpt.IsOptionSet( _eOpt ) != _bIsChecked;
1005 0 : if ( bModified )
1006 : {
1007 0 : _rOpt.SetOption( _eOpt, _bIsChecked );
1008 0 : _rModfied = true;
1009 : }
1010 : }
1011 :
1012 0 : return bModified;
1013 : }
1014 : }
1015 :
1016 0 : sal_Bool SvxSecurityTabPage::FillItemSet( SfxItemSet& )
1017 : {
1018 0 : bool bModified = false;
1019 :
1020 0 : if ( mpSecOptDlg )
1021 : {
1022 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SAVEORSEND, mpSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
1023 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SIGNING, mpSecOptDlg->IsSignDocsChecked(), bModified );
1024 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_PRINT, mpSecOptDlg->IsPrintDocsChecked(), bModified );
1025 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_CREATEPDF, mpSecOptDlg->IsCreatePdfChecked(), bModified );
1026 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO, mpSecOptDlg->IsRemovePersInfoChecked(), bModified );
1027 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD, mpSecOptDlg->IsRecommPasswdChecked(), bModified );
1028 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_CTRLCLICK_HYPERLINK, mpSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
1029 : }
1030 :
1031 0 : return bModified;
1032 : }
1033 :
1034 : /*--------------------------------------------------------------------*/
1035 :
1036 0 : void SvxSecurityTabPage::Reset( const SfxItemSet& )
1037 : {
1038 0 : }
1039 :
1040 0 : MozPluginTabPage::MozPluginTabPage(Window* pParent, const SfxItemSet& rSet)
1041 0 : : SfxTabPage( pParent, CUI_RES( RID_SVXPAGE_INET_MOZPLUGIN ), rSet ),
1042 0 : aMSWordGB ( this, CUI_RES( GB_MOZPLUGIN ) ),
1043 0 : aWBasicCodeCB ( this, CUI_RES( CB_MOZPLUGIN_CODE ) )
1044 : {
1045 0 : FreeResource();
1046 0 : }
1047 :
1048 0 : MozPluginTabPage::~MozPluginTabPage()
1049 : {
1050 0 : }
1051 :
1052 0 : SfxTabPage* MozPluginTabPage::Create( Window* pParent,
1053 : const SfxItemSet& rAttrSet )
1054 : {
1055 0 : return new MozPluginTabPage( pParent, rAttrSet );
1056 : }
1057 0 : sal_Bool MozPluginTabPage::FillItemSet( SfxItemSet& )
1058 : {
1059 0 : sal_Bool hasInstall = isInstalled();
1060 0 : sal_Bool hasChecked = aWBasicCodeCB.IsChecked();
1061 0 : if(hasInstall && (!hasChecked)){
1062 : //try to uninstall
1063 0 : uninstallPlugin();
1064 : }
1065 0 : else if((!hasInstall) && hasChecked){
1066 : //try to install
1067 0 : installPlugin();
1068 : }
1069 : else{
1070 : // do nothing
1071 : }
1072 0 : return sal_True;
1073 : }
1074 0 : void MozPluginTabPage::Reset( const SfxItemSet& )
1075 : {
1076 0 : aWBasicCodeCB.Check( isInstalled());
1077 0 : aWBasicCodeCB.SaveValue();
1078 0 : }
1079 :
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);
1085 : }
1086 : #endif
1087 :
1088 : #define NPP_PATH_MAX 2048
1089 0 : inline bool getDllURL(rtl::OString * path)
1090 : {
1091 : OSL_ASSERT(path != NULL);
1092 0 : ::rtl::OUString dirPath/*dllPath, */;
1093 0 : if (osl_getExecutableFile(&dirPath.pData) != osl_Process_E_None) {
1094 0 : return false;
1095 : }
1096 0 : dirPath = dirPath.copy(0, dirPath.lastIndexOf('/'));
1097 0 : ::rtl::OUString sysDirPath;
1098 0 : osl::FileBase::getSystemPathFromFileURL(dirPath, sysDirPath);
1099 0 : *path = OUStringToOString(sysDirPath, RTL_TEXTENCODING_ASCII_US);
1100 0 : return true;
1101 : }
1102 :
1103 0 : sal_Bool MozPluginTabPage::isInstalled()
1104 : {
1105 : #ifdef UNIX
1106 : // get the real file referred by .so lnk file
1107 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
1108 0 : char lnkReferFilePath[NPP_PATH_MAX] = {0};
1109 0 : char* pHome = getpwuid(getuid())->pw_dir;
1110 0 : strcat(lnkFilePath, pHome);
1111 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1112 :
1113 : struct stat sBuf;
1114 0 : if (0 > lstat(lnkFilePath, &sBuf))
1115 0 : return false;
1116 0 : if (!S_ISLNK(sBuf.st_mode))
1117 0 : return false;
1118 0 : if (0 >= readlink(lnkFilePath, lnkReferFilePath, NPP_PATH_MAX))
1119 0 : return false;
1120 : // If the link is relative, then we regard it as non-standard
1121 0 : if (lnkReferFilePath[0] != '/')
1122 0 : return false;
1123 :
1124 : // get the real file path
1125 0 : char realFilePath[NPP_PATH_MAX] = {0};
1126 0 : ::rtl::OString tempString;
1127 0 : if (!getDllURL(&tempString)) {
1128 0 : return false;
1129 : }
1130 0 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1131 0 : strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1132 :
1133 0 : if (0 != strcmp(lnkReferFilePath, realFilePath))
1134 0 : return false;
1135 0 : 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;
1144 : }
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
1152 : }
1153 :
1154 0 : sal_Bool MozPluginTabPage::installPlugin()
1155 : {
1156 : #ifdef UNIX
1157 : // get the real file referred by .so lnk file
1158 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
1159 0 : char* pHome = getpwuid(getuid())->pw_dir;
1160 0 : strcat(lnkFilePath, pHome);
1161 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1162 0 : remove(lnkFilePath);
1163 :
1164 : // create the dirs if necessary
1165 : struct stat buf;
1166 0 : char tmpDir[NPP_PATH_MAX] = {0};
1167 0 : sprintf(tmpDir, "%s/.mozilla", pHome);
1168 0 : if (0 > stat(lnkFilePath, &buf))
1169 : {
1170 0 : mkdir(tmpDir, 0755);
1171 0 : strcat(tmpDir, "/plugins");
1172 0 : mkdir(tmpDir, 0755);
1173 : }
1174 :
1175 : // get the real file path
1176 0 : char realFilePath[NPP_PATH_MAX] = {0};
1177 0 : ::rtl::OString tempString;
1178 0 : if (!getDllURL(&tempString)) {
1179 0 : return false;
1180 : }
1181 0 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1182 0 : strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1183 :
1184 : // create the link
1185 0 : if (0 != symlink(realFilePath, lnkFilePath))
1186 0 : return false;
1187 0 : 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;
1194 : }
1195 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1196 : if( !lc_installPlugin(realFilePath))
1197 : return true;
1198 : else
1199 : return false;
1200 : #endif
1201 : }
1202 :
1203 0 : sal_Bool MozPluginTabPage::uninstallPlugin()
1204 : {
1205 : #ifdef UNIX
1206 : // get the real file referred by .so lnk file
1207 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
1208 0 : char* pHome = getpwuid(getuid())->pw_dir;
1209 0 : strcat(lnkFilePath, pHome);
1210 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1211 :
1212 0 : if(0 > remove(lnkFilePath))
1213 0 : return false;
1214 0 : 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;
1221 : }
1222 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1223 : if(!lc_uninstallPlugin(realFilePath))
1224 : return true;
1225 : else
1226 : return false;
1227 : #endif
1228 : }
1229 :
1230 : /* -------------------------------------------------------------------------*/
1231 :
1232 : class MailerProgramCfg_Impl : public utl::ConfigItem
1233 : {
1234 : friend class SvxEMailTabPage;
1235 : // variables
1236 : OUString sProgram;
1237 : // readonly states
1238 : sal_Bool bROProgram;
1239 :
1240 : const Sequence<OUString> GetPropertyNames();
1241 : public:
1242 : MailerProgramCfg_Impl();
1243 : virtual ~MailerProgramCfg_Impl();
1244 :
1245 : virtual void Commit();
1246 : virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames);
1247 : };
1248 :
1249 : /* -------------------------------------------------------------------------*/
1250 :
1251 0 : MailerProgramCfg_Impl::MailerProgramCfg_Impl() :
1252 : utl::ConfigItem("Office.Common/ExternalMailer"),
1253 0 : bROProgram(sal_False)
1254 : {
1255 0 : const Sequence< OUString > aNames = GetPropertyNames();
1256 0 : const Sequence< Any > aValues = GetProperties(aNames);
1257 0 : const Sequence< sal_Bool > aROStates = GetReadOnlyStates(aNames);
1258 0 : const Any* pValues = aValues.getConstArray();
1259 0 : const sal_Bool* pROStates = aROStates.getConstArray();
1260 0 : for(sal_Int32 nProp = 0; nProp < aValues.getLength(); nProp++)
1261 : {
1262 0 : if(pValues[nProp].hasValue())
1263 : {
1264 0 : switch(nProp)
1265 : {
1266 : case 0 :
1267 : {
1268 0 : pValues[nProp] >>= sProgram;
1269 0 : bROProgram = pROStates[nProp];
1270 : }
1271 0 : break;
1272 : }
1273 : }
1274 0 : }
1275 0 : }
1276 :
1277 : /* -------------------------------------------------------------------------*/
1278 :
1279 0 : MailerProgramCfg_Impl::~MailerProgramCfg_Impl()
1280 : {
1281 0 : }
1282 :
1283 : /* -------------------------------------------------------------------------*/
1284 :
1285 0 : const Sequence<OUString> MailerProgramCfg_Impl::GetPropertyNames()
1286 : {
1287 0 : Sequence<OUString> aRet(1);
1288 0 : OUString* pRet = aRet.getArray();
1289 0 : pRet[0] = "Program";
1290 0 : return aRet;
1291 : }
1292 :
1293 : /* -------------------------------------------------------------------------*/
1294 :
1295 0 : void MailerProgramCfg_Impl::Commit()
1296 : {
1297 0 : const Sequence< OUString > aOrgNames = GetPropertyNames();
1298 0 : sal_Int32 nOrgCount = aOrgNames.getLength();
1299 :
1300 0 : Sequence< OUString > aNames(nOrgCount);
1301 0 : Sequence< Any > aValues(nOrgCount);
1302 0 : sal_Int32 nRealCount = 0;
1303 :
1304 0 : for(int nProp = 0; nProp < nOrgCount; nProp++)
1305 : {
1306 0 : switch(nProp)
1307 : {
1308 : case 0:
1309 : {
1310 0 : if (!bROProgram)
1311 : {
1312 0 : aNames[nRealCount] = aOrgNames[nProp];
1313 0 : aValues[nRealCount] <<= sProgram;
1314 0 : ++nRealCount;
1315 : }
1316 : }
1317 0 : break;
1318 : }
1319 : }
1320 :
1321 0 : aNames.realloc(nRealCount);
1322 0 : aValues.realloc(nRealCount);
1323 0 : PutProperties(aNames, aValues);
1324 0 : }
1325 :
1326 0 : void MailerProgramCfg_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
1327 : {
1328 0 : }
1329 :
1330 : /* -------------------------------------------------------------------------*/
1331 :
1332 0 : struct SvxEMailTabPage_Impl
1333 : {
1334 : MailerProgramCfg_Impl aMailConfig;
1335 : };
1336 :
1337 0 : SvxEMailTabPage::SvxEMailTabPage(Window* pParent, const SfxItemSet& rSet) :
1338 0 : SfxTabPage(pParent, CUI_RES( RID_SVXPAGE_INET_MAIL ), rSet),
1339 0 : aMailFL(this, CUI_RES(FL_MAIL )),
1340 0 : aMailerURLFI(this, CUI_RES(FI_MAILERURL )),
1341 0 : aMailerURLFT(this, CUI_RES(FT_MAILERURL )),
1342 0 : aMailerURLED(this, CUI_RES(ED_MAILERURL )),
1343 0 : aMailerURLPB(this, CUI_RES(PB_MAILERURL )),
1344 0 : m_sDefaultFilterName( CUI_RES(STR_DEFAULT_FILENAME )),
1345 0 : pImpl(new SvxEMailTabPage_Impl)
1346 : {
1347 0 : FreeResource();
1348 :
1349 0 : aMailerURLPB.SetClickHdl( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
1350 :
1351 : // FixedText not wide enough?
1352 0 : long nTxtW = aMailerURLFT.GetCtrlTextWidth( aMailerURLFT.GetText() );
1353 0 : long nCtrlW = aMailerURLFT.GetSizePixel().Width();
1354 0 : if ( nTxtW >= nCtrlW )
1355 : {
1356 0 : long nDelta = Max( (long)10, nTxtW - nCtrlW );
1357 : // so FixedText wider
1358 0 : Size aNewSz = aMailerURLFT.GetSizePixel();
1359 0 : aNewSz.Width() += nDelta;
1360 0 : aMailerURLFT.SetSizePixel( aNewSz );
1361 : // and Edit smaller
1362 0 : aNewSz = aMailerURLED.GetSizePixel();
1363 0 : aNewSz.Width() -= nDelta;
1364 0 : Point aNewPt = aMailerURLED.GetPosPixel();
1365 0 : aNewPt.X() += nDelta;
1366 0 : aMailerURLED.SetPosSizePixel( aNewPt, aNewSz );
1367 : }
1368 0 : }
1369 :
1370 : /* -------------------------------------------------------------------------*/
1371 :
1372 0 : SvxEMailTabPage::~SvxEMailTabPage()
1373 : {
1374 0 : delete pImpl;
1375 0 : }
1376 :
1377 : /* -------------------------------------------------------------------------*/
1378 :
1379 0 : SfxTabPage* SvxEMailTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1380 : {
1381 0 : return new SvxEMailTabPage(pParent, rAttrSet);
1382 : }
1383 :
1384 : /* -------------------------------------------------------------------------*/
1385 :
1386 0 : sal_Bool SvxEMailTabPage::FillItemSet( SfxItemSet& )
1387 : {
1388 0 : sal_Bool bMailModified = sal_False;
1389 0 : if(!pImpl->aMailConfig.bROProgram && aMailerURLED.GetSavedValue() != aMailerURLED.GetText())
1390 : {
1391 0 : pImpl->aMailConfig.sProgram = aMailerURLED.GetText();
1392 0 : bMailModified = sal_True;
1393 : }
1394 0 : if ( bMailModified )
1395 0 : pImpl->aMailConfig.Commit();
1396 :
1397 0 : return sal_False;
1398 : }
1399 :
1400 : /* -------------------------------------------------------------------------*/
1401 :
1402 0 : void SvxEMailTabPage::Reset( const SfxItemSet& )
1403 : {
1404 0 : aMailerURLED.Enable(sal_True );
1405 0 : aMailerURLPB.Enable(sal_True );
1406 :
1407 0 : if(pImpl->aMailConfig.bROProgram)
1408 0 : aMailerURLFI.Show();
1409 :
1410 0 : aMailerURLED.SetText(pImpl->aMailConfig.sProgram);
1411 0 : aMailerURLED.SaveValue();
1412 0 : aMailerURLED.Enable(!pImpl->aMailConfig.bROProgram);
1413 0 : aMailerURLPB.Enable(!pImpl->aMailConfig.bROProgram);
1414 0 : aMailerURLFT.Enable(!pImpl->aMailConfig.bROProgram);
1415 :
1416 0 : aMailFL.Enable(aMailerURLFT.IsEnabled() ||
1417 0 : aMailerURLED.IsEnabled() ||
1418 0 : aMailerURLPB.IsEnabled());
1419 0 : }
1420 :
1421 : /* -------------------------------------------------------------------------*/
1422 :
1423 0 : IMPL_LINK( SvxEMailTabPage, FileDialogHdl_Impl, PushButton*, pButton )
1424 : {
1425 0 : if ( &aMailerURLPB == pButton && !pImpl->aMailConfig.bROProgram )
1426 : {
1427 : FileDialogHelper aHelper(
1428 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
1429 0 : 0 );
1430 0 : rtl::OUString sPath = aMailerURLED.GetText();
1431 0 : if ( sPath.isEmpty() )
1432 0 : sPath = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/usr/bin"));
1433 :
1434 0 : rtl::OUString sUrl;
1435 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sPath, sUrl);
1436 0 : aHelper.SetDisplayDirectory(sUrl);
1437 0 : aHelper.AddFilter( m_sDefaultFilterName, rtl::OUString("*"));
1438 :
1439 0 : if ( ERRCODE_NONE == aHelper.Execute() )
1440 : {
1441 0 : sUrl = aHelper.GetPath();
1442 0 : ::utl::LocalFileHelper::ConvertURLToPhysicalName(sUrl, sPath);
1443 0 : aMailerURLED.SetText(sPath);
1444 0 : }
1445 : }
1446 0 : return 0;
1447 3 : }
1448 :
1449 : // -----------------------------------------------------------------------------
1450 :
1451 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|