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 : #include <dialmgr.hxx>
47 : #include "optinet2.hxx"
48 : #include <svx/svxdlg.hxx>
49 : #include <cuires.hrc>
50 : #include "optinet2.hrc"
51 : #include "helpid.hrc"
52 : #include <svx/ofaitem.hxx>
53 : #include <sfx2/htmlmode.hxx>
54 : #include <svx/svxids.hrc> // slot ids, mostly for changetracking
55 :
56 : // for security TP
57 : #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
58 :
59 : #ifdef UNX
60 : #include <sys/stat.h>
61 : #include <unistd.h>
62 : #include <fcntl.h>
63 : #include <pwd.h>
64 : #include <sys/types.h>
65 : #include <string.h>
66 : #include <rtl/textenc.h>
67 : #include <rtl/locale.h>
68 : #include <osl/nlsupport.h>
69 : #endif
70 : #include <sal/types.h>
71 : #include <sal/macros.h>
72 : #include <rtl/ustring.hxx>
73 : #include <osl/file.hxx>
74 : #include <osl/process.h>
75 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
76 : #include <com/sun/star/container/XNameReplace.hpp>
77 : #include <com/sun/star/container/XNameAccess.hpp>
78 : #include <com/sun/star/beans/NamedValue.hpp>
79 : #include <com/sun/star/beans/XPropertySet.hpp>
80 : #include <com/sun/star/beans/XPropertyState.hpp>
81 : #include <com/sun/star/util/XChangesBatch.hpp>
82 : #include <comphelper/processfactory.hxx>
83 : #include <comphelper/string.hxx>
84 :
85 : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
86 : #include "com/sun/star/task/PasswordContainer.hpp"
87 : #include "com/sun/star/task/XPasswordContainer2.hpp"
88 : #include "securityoptions.hxx"
89 : #include "webconninfo.hxx"
90 : #include "certpath.hxx"
91 :
92 : using namespace ::com::sun::star;
93 : using namespace ::com::sun::star::uno;
94 : using namespace ::sfx2;
95 :
96 : // static ----------------------------------------------------------------
97 :
98 : #include <sal/config.h>
99 :
100 : // -----------------------------------------------------------------------
101 :
102 0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxNoSpaceEdit(Window *pParent, VclBuilder::stringmap &)
103 : {
104 0 : return new SvxNoSpaceEdit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK);
105 : }
106 :
107 0 : void SvxNoSpaceEdit::KeyInput( const KeyEvent& rKEvent )
108 : {
109 0 : bool bValid = rKEvent.GetKeyCode().GetCode() != KEY_SPACE;
110 0 : if (bValid && bOnlyNumeric)
111 : {
112 0 : const KeyCode& rKeyCode = rKEvent.GetKeyCode();
113 0 : sal_uInt16 nGroup = rKeyCode.GetGroup();
114 0 : sal_uInt16 nKey = rKeyCode.GetCode();
115 0 : bValid = ( KEYGROUP_NUM == nGroup || KEYGROUP_CURSOR == nGroup ||
116 0 : ( KEYGROUP_MISC == nGroup && ( nKey < KEY_ADD || nKey > KEY_EQUAL ) ) );
117 0 : if ( !bValid && ( rKeyCode.IsMod1() && (
118 0 : KEY_A == nKey || KEY_C == nKey || KEY_V == nKey || KEY_X == nKey || KEY_Z == nKey ) ) )
119 : // Erase, Copy, Paste, Select All und Undo soll funktionieren
120 0 : bValid = sal_True;
121 : }
122 0 : if (bValid)
123 0 : Edit::KeyInput(rKEvent);
124 0 : }
125 :
126 : // -----------------------------------------------------------------------
127 :
128 0 : void SvxNoSpaceEdit::Modify()
129 : {
130 0 : Edit::Modify();
131 :
132 0 : if ( bOnlyNumeric )
133 : {
134 0 : OUString aValue = GetText();
135 :
136 0 : if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
137 : // the maximum value of a port number is USHRT_MAX
138 0 : ErrorBox( this, CUI_RES( RID_SVXERR_OPT_PROXYPORTS ) ).Execute();
139 : }
140 0 : }
141 :
142 0 : bool SvxNoSpaceEdit::set_property(const OString &rKey, const OString &rValue)
143 : {
144 0 : if (rKey == "only-numeric")
145 0 : bOnlyNumeric = toBool(rValue);
146 : else
147 0 : return Edit::set_property(rKey, rValue);
148 0 : return true;
149 : }
150 :
151 :
152 : /********************************************************************/
153 : /* */
154 : /* SvxProxyTabPage */
155 : /* */
156 : /********************************************************************/
157 :
158 0 : SvxProxyTabPage::SvxProxyTabPage(Window* pParent, const SfxItemSet& rSet)
159 : : SfxTabPage(pParent, "OptProxyPage","cui/ui/optproxypage.ui", rSet)
160 : , aProxyModePN("ooInetProxyType")
161 : , aHttpProxyPN("ooInetHTTPProxyName")
162 : , aHttpPortPN("ooInetHTTPProxyPort")
163 : , aHttpsProxyPN("ooInetHTTPSProxyName")
164 : , aHttpsPortPN("ooInetHTTPSProxyPort")
165 : , aFtpProxyPN("ooInetFTPProxyName")
166 : , aFtpPortPN("ooInetFTPProxyPort")
167 0 : , aNoProxyDescPN("ooInetNoProxy")
168 : {
169 0 : get(m_pProxyModeLB, "proxymode");
170 :
171 0 : get(m_pHttpProxyFT, "httpft");
172 0 : get(m_pHttpProxyED, "http");
173 0 : get(m_pHttpPortFT, "httpportft");
174 0 : get(m_pHttpPortED, "httpport");
175 :
176 0 : get(m_pHttpsProxyFT, "httpsft");
177 0 : get(m_pHttpsProxyED, "https");
178 0 : get(m_pHttpsPortFT, "httpsportft");
179 0 : get(m_pHttpsPortED, "httpsport");
180 :
181 0 : get(m_pFtpProxyFT, "ftpft");
182 0 : get(m_pFtpProxyED, "ftp");
183 0 : get(m_pFtpPortFT, "ftpportft");
184 0 : get(m_pFtpPortED, "ftpport");
185 :
186 0 : get(m_pNoProxyForFT, "noproxyft");
187 0 : get(m_pNoProxyForED, "noproxy");
188 0 : get(m_pNoProxyDescFT, "noproxydesc");
189 :
190 0 : Link aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
191 0 : m_pHttpPortED->SetLoseFocusHdl( aLink );
192 0 : m_pHttpsPortED->SetLoseFocusHdl( aLink );
193 0 : m_pFtpPortED->SetLoseFocusHdl( aLink );
194 :
195 0 : m_pProxyModeLB->SetSelectHdl(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
196 :
197 : Reference< com::sun::star::lang::XMultiServiceFactory >
198 : xConfigurationProvider(
199 : configuration::theDefaultProvider::get(
200 0 : comphelper::getProcessComponentContext() ) );
201 :
202 0 : OUString aConfigRoot( "org.openoffice.Inet/Settings" );
203 :
204 0 : beans::NamedValue aProperty;
205 0 : aProperty.Name = OUString( "nodepath" );
206 0 : aProperty.Value = makeAny( aConfigRoot );
207 :
208 0 : Sequence< Any > aArgumentList( 1 );
209 0 : aArgumentList[0] = makeAny( aProperty );
210 :
211 0 : m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments(
212 : OUString( "com.sun.star.configuration.ConfigurationUpdateAccess" ),
213 0 : aArgumentList );
214 0 : }
215 :
216 0 : SvxProxyTabPage::~SvxProxyTabPage()
217 : {
218 0 : }
219 :
220 0 : SfxTabPage* SvxProxyTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
221 : {
222 0 : return new SvxProxyTabPage(pParent, rAttrSet);
223 : }
224 :
225 0 : void SvxProxyTabPage::ReadConfigData_Impl()
226 : {
227 : try {
228 0 : Reference< container::XNameAccess > xNameAccess(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
229 :
230 0 : sal_Int32 nIntValue = 0;
231 0 : OUString aStringValue;
232 :
233 0 : if( xNameAccess->getByName(aProxyModePN) >>= nIntValue )
234 : {
235 0 : m_pProxyModeLB->SelectEntryPos( (sal_uInt16) nIntValue );
236 : }
237 :
238 0 : if( xNameAccess->getByName(aHttpProxyPN) >>= aStringValue )
239 : {
240 0 : m_pHttpProxyED->SetText( aStringValue );
241 : }
242 :
243 0 : if( xNameAccess->getByName(aHttpPortPN) >>= nIntValue )
244 : {
245 0 : m_pHttpPortED->SetText( OUString::number( nIntValue ));
246 : }
247 :
248 0 : if( xNameAccess->getByName(aHttpsProxyPN) >>= aStringValue )
249 : {
250 0 : m_pHttpsProxyED->SetText( aStringValue );
251 : }
252 :
253 0 : if( xNameAccess->getByName(aHttpsPortPN) >>= nIntValue )
254 : {
255 0 : m_pHttpsPortED->SetText( OUString::number( nIntValue ));
256 : }
257 :
258 0 : if( xNameAccess->getByName(aFtpProxyPN) >>= aStringValue )
259 : {
260 0 : m_pFtpProxyED->SetText( aStringValue );
261 : }
262 :
263 0 : if( xNameAccess->getByName(aFtpPortPN) >>= nIntValue )
264 : {
265 0 : m_pFtpPortED->SetText( OUString::number( nIntValue ));
266 : }
267 :
268 0 : if( xNameAccess->getByName(aNoProxyDescPN) >>= aStringValue )
269 : {
270 0 : m_pNoProxyForED->SetText( aStringValue );
271 0 : }
272 : }
273 :
274 0 : catch (const container::NoSuchElementException&) {
275 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: NoSuchElementException caught" );
276 : }
277 :
278 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
279 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: WrappedTargetException caught" );
280 : }
281 :
282 0 : catch (const RuntimeException &) {
283 : OSL_TRACE( "SvxProxyTabPage::ReadConfigData_Impl: RuntimeException caught" );
284 : }
285 :
286 0 : }
287 :
288 0 : void SvxProxyTabPage::ReadConfigDefaults_Impl()
289 : {
290 : try
291 : {
292 0 : Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
293 :
294 0 : sal_Int32 nIntValue = 0;
295 0 : OUString aStringValue;
296 :
297 0 : if( xPropertyState->getPropertyDefault(aHttpProxyPN) >>= aStringValue )
298 : {
299 0 : m_pHttpProxyED->SetText( aStringValue );
300 : }
301 :
302 0 : if( xPropertyState->getPropertyDefault(aHttpPortPN) >>= nIntValue )
303 : {
304 0 : m_pHttpPortED->SetText( OUString::number( nIntValue ));
305 : }
306 :
307 0 : if( xPropertyState->getPropertyDefault(aHttpsProxyPN) >>= aStringValue )
308 : {
309 0 : m_pHttpsProxyED->SetText( aStringValue );
310 : }
311 :
312 0 : if( xPropertyState->getPropertyDefault(aHttpsPortPN) >>= nIntValue )
313 : {
314 0 : m_pHttpsPortED->SetText( OUString::number( nIntValue ));
315 : }
316 :
317 0 : if( xPropertyState->getPropertyDefault(aFtpProxyPN) >>= aStringValue )
318 : {
319 0 : m_pFtpProxyED->SetText( aStringValue );
320 : }
321 :
322 0 : if( xPropertyState->getPropertyDefault(aFtpPortPN) >>= nIntValue )
323 : {
324 0 : m_pFtpPortED->SetText( OUString::number( nIntValue ));
325 : }
326 :
327 0 : if( xPropertyState->getPropertyDefault(aNoProxyDescPN) >>= aStringValue )
328 : {
329 0 : m_pNoProxyForED->SetText( aStringValue );
330 0 : }
331 : }
332 0 : catch (const beans::UnknownPropertyException &)
333 : {
334 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
335 : }
336 :
337 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
338 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
339 : }
340 :
341 0 : catch (const RuntimeException &)
342 : {
343 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
344 : }
345 0 : }
346 :
347 0 : void SvxProxyTabPage::RestoreConfigDefaults_Impl()
348 : {
349 : try
350 : {
351 0 : Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
352 :
353 0 : xPropertyState->setPropertyToDefault(aProxyModePN);
354 0 : xPropertyState->setPropertyToDefault(aHttpProxyPN);
355 0 : xPropertyState->setPropertyToDefault(aHttpPortPN);
356 0 : xPropertyState->setPropertyToDefault(aHttpsProxyPN);
357 0 : xPropertyState->setPropertyToDefault(aHttpsPortPN);
358 0 : xPropertyState->setPropertyToDefault(aFtpProxyPN);
359 0 : xPropertyState->setPropertyToDefault(aFtpPortPN);
360 0 : xPropertyState->setPropertyToDefault(aNoProxyDescPN);
361 :
362 0 : Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
363 0 : xChangesBatch->commitChanges();
364 : }
365 :
366 0 : catch (const beans::UnknownPropertyException &)
367 : {
368 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
369 : }
370 :
371 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
372 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
373 : }
374 :
375 0 : catch (const RuntimeException &)
376 : {
377 : OSL_TRACE( "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
378 : }
379 0 : }
380 :
381 0 : void SvxProxyTabPage::Reset(const SfxItemSet&)
382 : {
383 0 : ReadConfigData_Impl();
384 :
385 0 : m_pProxyModeLB->SaveValue();
386 0 : m_pHttpProxyED->SaveValue();
387 0 : m_pHttpPortED->SaveValue();
388 0 : m_pHttpsProxyED->SaveValue();
389 0 : m_pHttpsPortED->SaveValue();
390 0 : m_pFtpProxyED->SaveValue();
391 0 : m_pFtpPortED->SaveValue();
392 0 : m_pNoProxyForED->SaveValue();
393 :
394 0 : EnableControls_Impl( m_pProxyModeLB->GetSelectEntryPos() == 2 );
395 0 : }
396 :
397 0 : sal_Bool SvxProxyTabPage::FillItemSet(SfxItemSet& )
398 : {
399 0 : sal_Bool bModified=sal_False;
400 :
401 : try {
402 0 : Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
403 :
404 0 : sal_uInt16 nSelPos = m_pProxyModeLB->GetSelectEntryPos();
405 0 : if(m_pProxyModeLB->GetSavedValue() != nSelPos)
406 : {
407 0 : if( nSelPos == 1 )
408 : {
409 0 : RestoreConfigDefaults_Impl();
410 0 : return sal_True;
411 : }
412 :
413 0 : xPropertySet->setPropertyValue(aProxyModePN,
414 0 : makeAny((sal_Int32) nSelPos));
415 0 : bModified = sal_True;
416 : }
417 :
418 0 : if(m_pHttpProxyED->GetSavedValue() != m_pHttpProxyED->GetText())
419 : {
420 0 : xPropertySet->setPropertyValue( aHttpProxyPN, makeAny(m_pHttpProxyED->GetText()));
421 0 : bModified = sal_True;
422 : }
423 :
424 0 : if ( m_pHttpPortED->GetSavedValue() != m_pHttpPortED->GetText() )
425 : {
426 0 : xPropertySet->setPropertyValue( aHttpPortPN, makeAny(m_pHttpPortED->GetText().toInt32()));
427 0 : bModified = sal_True;
428 : }
429 :
430 0 : if( m_pHttpsProxyED->GetSavedValue() != m_pHttpsProxyED->GetText() )
431 : {
432 0 : xPropertySet->setPropertyValue( aHttpsProxyPN, makeAny(m_pHttpsProxyED->GetText()) );
433 0 : bModified = sal_True;
434 : }
435 :
436 0 : if ( m_pHttpsPortED->GetSavedValue() != m_pHttpsPortED->GetText() )
437 : {
438 0 : xPropertySet->setPropertyValue( aHttpsPortPN, makeAny(m_pHttpsPortED->GetText().toInt32()) );
439 0 : bModified = sal_True;
440 : }
441 :
442 0 : if( m_pFtpProxyED->GetSavedValue() != m_pFtpProxyED->GetText())
443 : {
444 0 : xPropertySet->setPropertyValue( aFtpProxyPN, makeAny(m_pFtpProxyED->GetText()) );
445 0 : bModified = sal_True;
446 : }
447 :
448 0 : if ( m_pFtpPortED->GetSavedValue() != m_pFtpPortED->GetText() )
449 : {
450 0 : xPropertySet->setPropertyValue( aFtpPortPN, makeAny(m_pFtpPortED->GetText().toInt32()));
451 0 : bModified = sal_True;
452 : }
453 :
454 0 : if ( m_pNoProxyForED->GetSavedValue() != m_pNoProxyForED->GetText() )
455 : {
456 0 : xPropertySet->setPropertyValue( aNoProxyDescPN, makeAny( m_pNoProxyForED->GetText()));
457 0 : bModified = sal_True;
458 : }
459 :
460 0 : Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
461 0 : xChangesBatch->commitChanges();
462 : }
463 :
464 0 : catch (const com::sun::star::lang::IllegalArgumentException &) {
465 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
466 : }
467 :
468 0 : catch (const beans::UnknownPropertyException &) {
469 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
470 : }
471 :
472 0 : catch (const beans::PropertyVetoException &) {
473 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
474 : }
475 :
476 0 : catch (const com::sun::star::lang::WrappedTargetException &) {
477 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
478 : }
479 :
480 0 : catch (const RuntimeException &) {
481 : OSL_TRACE( "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
482 : }
483 :
484 0 : return bModified;
485 : }
486 :
487 0 : void SvxProxyTabPage::EnableControls_Impl(sal_Bool bEnable)
488 : {
489 0 : m_pHttpProxyFT->Enable(bEnable);
490 0 : m_pHttpProxyED->Enable(bEnable);
491 0 : m_pHttpPortFT->Enable(bEnable);
492 0 : m_pHttpPortED->Enable(bEnable);
493 :
494 0 : m_pHttpsProxyFT->Enable(bEnable);
495 0 : m_pHttpsProxyED->Enable(bEnable);
496 0 : m_pHttpsPortFT->Enable(bEnable);
497 0 : m_pHttpsPortED->Enable(bEnable);
498 :
499 0 : m_pFtpProxyFT->Enable(bEnable);
500 0 : m_pFtpProxyED->Enable(bEnable);
501 0 : m_pFtpPortFT->Enable(bEnable);
502 0 : m_pFtpPortED->Enable(bEnable);
503 :
504 0 : m_pNoProxyForFT->Enable(bEnable);
505 0 : m_pNoProxyForED->Enable(bEnable);
506 0 : m_pNoProxyDescFT->Enable(bEnable);
507 0 : }
508 :
509 : // -----------------------------------------------------------------------
510 :
511 0 : IMPL_LINK( SvxProxyTabPage, ProxyHdl_Impl, ListBox *, pBox )
512 : {
513 0 : sal_uInt16 nPos = pBox->GetSelectEntryPos();
514 :
515 : // Restore original system values
516 0 : if( nPos == 1 )
517 : {
518 0 : ReadConfigDefaults_Impl();
519 : }
520 :
521 0 : EnableControls_Impl(nPos == 2);
522 0 : return 0;
523 : }
524 :
525 : // -----------------------------------------------------------------------
526 :
527 0 : IMPL_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Edit *, pEdit )
528 : {
529 0 : OUString aValue = pEdit->GetText();
530 :
531 0 : if ( !comphelper::string::isdigitAsciiString(aValue) || (long)aValue.toInt32() > USHRT_MAX )
532 0 : pEdit->SetText( OUString('0') );
533 0 : return 0;
534 : }
535 :
536 :
537 :
538 : //#98647#----------------------------------------------
539 0 : void SvxScriptExecListBox::RequestHelp( const HelpEvent& rHEvt )
540 : { // try to show tips just like as on toolbars
541 0 : sal_uInt16 nPos=LISTBOX_ENTRY_NOTFOUND;
542 0 : sal_uInt16 nTop = GetTopEntry();
543 0 : sal_uInt16 nCount = GetDisplayLineCount(); // Attention: Not GetLineCount()
544 0 : Point aPt = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
545 0 : Rectangle aItemRect;
546 0 : if( nCount > 0 ) // if there're some entries, find it.
547 0 : for( nPos = nTop ; nPos <= nTop+nCount-1 ; nPos++ ) {
548 0 : aItemRect = GetBoundingRectangle(nPos);
549 0 : if( aPt.Y() < aItemRect.Top() || aPt.Y() > aItemRect.Bottom() )
550 0 : continue;
551 : else
552 0 : break;
553 : }
554 : else // if not, nothing happens.
555 0 : return;
556 0 : OUString aHelpText;
557 0 : if( nPos <= nTop+nCount-1 ) // if find the matching entry, get its content.
558 0 : aHelpText = GetEntry(nPos);
559 0 : if( aHelpText.getLength() && GetTextWidth(aHelpText)<GetOutputSizePixel().Width() )
560 0 : aHelpText = OUString(); // if the entry is quite short, clear the helping tip content.
561 0 : aItemRect = Rectangle(Point(0,0),GetSizePixel());
562 0 : aPt = Point(OutputToScreenPixel( aItemRect.TopLeft() ));
563 0 : aItemRect.Left() = aPt.X();
564 0 : aItemRect.Top() = aPt.Y();
565 0 : aPt = OutputToScreenPixel( aItemRect.BottomRight() );
566 0 : aItemRect.Right() = aPt.X();
567 0 : aItemRect.Bottom() = aPt.Y();
568 0 : if( rHEvt.GetMode() == HELPMODE_BALLOON )
569 0 : Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aHelpText);
570 : else
571 0 : Help::ShowQuickHelp( this, aItemRect, aHelpText );
572 : }
573 :
574 : /********************************************************************/
575 : /* */
576 : /* SvxSecurityTabPage */
577 : /* */
578 : /********************************************************************/
579 :
580 0 : SvxSecurityTabPage::SvxSecurityTabPage(Window* pParent, const SfxItemSet& rSet)
581 : : SfxTabPage(pParent, "OptSecurityPage", "cui/ui/optsecuritypage.ui", rSet)
582 0 : , mpSecOptions(new SvtSecurityOptions)
583 : , mpSecOptDlg(NULL)
584 0 : , mpCertPathDlg(NULL)
585 : {
586 0 : get(m_pSecurityOptionsPB, "options");
587 0 : get(m_pSavePasswordsCB, "savepassword");
588 :
589 : //fdo#65595, we height-for-width support here, but for now we can
590 : //bodge it
591 0 : Size aSize(m_pSavePasswordsCB->CalcMinimumSize(56*approximate_char_width()));
592 0 : m_pSavePasswordsCB->set_width_request(aSize.Width());
593 0 : m_pSavePasswordsCB->set_height_request(aSize.Height());
594 :
595 0 : get(m_pShowConnectionsPB, "connections");
596 0 : get(m_pMasterPasswordCB, "usemasterpassword");
597 0 : get(m_pMasterPasswordFT, "masterpasswordtext");
598 0 : get(m_pMasterPasswordPB, "masterpassword");
599 0 : get(m_pMacroSecFrame, "macrosecurity");
600 0 : get(m_pMacroSecPB, "macro");
601 0 : get(m_pCertFrame, "certificatepath");
602 0 : get(m_pCertPathPB, "cert");
603 0 : m_sPasswordStoringDeactivateStr = get<FixedText>("nopasswordsave")->GetText();
604 :
605 0 : InitControls();
606 :
607 0 : m_pSecurityOptionsPB->SetClickHdl( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
608 0 : m_pSavePasswordsCB->SetClickHdl( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
609 0 : m_pMasterPasswordPB->SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
610 0 : m_pMasterPasswordCB->SetClickHdl( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
611 0 : m_pShowConnectionsPB->SetClickHdl( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
612 0 : m_pMacroSecPB->SetClickHdl( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
613 0 : m_pCertPathPB->SetClickHdl( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
614 :
615 0 : ActivatePage( rSet );
616 0 : }
617 :
618 0 : SvxSecurityTabPage::~SvxSecurityTabPage()
619 : {
620 0 : delete mpCertPathDlg;
621 :
622 0 : delete mpSecOptions;
623 0 : delete mpSecOptDlg;
624 0 : }
625 :
626 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl)
627 : {
628 0 : if ( !mpSecOptDlg )
629 0 : mpSecOptDlg = new svx::SecurityOptionsDialog( this, mpSecOptions );
630 0 : mpSecOptDlg->Execute();
631 0 : return 0;
632 : }
633 :
634 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, SavePasswordHdl)
635 : {
636 : try
637 : {
638 : Reference< task::XPasswordContainer2 > xMasterPasswd(
639 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
640 :
641 0 : if ( m_pSavePasswordsCB->IsChecked() )
642 : {
643 0 : sal_Bool bOldValue = xMasterPasswd->allowPersistentStoring( sal_True );
644 0 : xMasterPasswd->removeMasterPassword();
645 0 : if ( xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
646 : {
647 0 : m_pMasterPasswordPB->Enable( sal_True );
648 0 : m_pMasterPasswordCB->Check( sal_True );
649 0 : m_pMasterPasswordCB->Enable( sal_True );
650 0 : m_pMasterPasswordFT->Enable( sal_True );
651 0 : m_pShowConnectionsPB->Enable( sal_True );
652 : }
653 : else
654 : {
655 0 : xMasterPasswd->allowPersistentStoring( bOldValue );
656 0 : m_pSavePasswordsCB->Check( sal_False );
657 : }
658 : }
659 : else
660 : {
661 0 : QueryBox aQuery( this, WB_YES_NO|WB_DEF_NO, m_sPasswordStoringDeactivateStr );
662 0 : sal_uInt16 nRet = aQuery.Execute();
663 :
664 0 : if( RET_YES == nRet )
665 : {
666 0 : xMasterPasswd->allowPersistentStoring( sal_False );
667 0 : m_pMasterPasswordCB->Check( sal_True );
668 0 : m_pMasterPasswordPB->Enable( sal_False );
669 0 : m_pMasterPasswordCB->Enable( sal_False );
670 0 : m_pMasterPasswordFT->Enable( sal_False );
671 0 : m_pShowConnectionsPB->Enable( sal_False );
672 : }
673 : else
674 : {
675 0 : m_pSavePasswordsCB->Check( sal_True );
676 0 : m_pMasterPasswordPB->Enable( sal_True );
677 0 : m_pShowConnectionsPB->Enable( sal_True );
678 0 : }
679 0 : }
680 : }
681 0 : catch (const Exception&)
682 : {
683 0 : m_pSavePasswordsCB->Check( !m_pSavePasswordsCB->IsChecked() );
684 : }
685 :
686 0 : return 0;
687 : }
688 :
689 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordHdl)
690 : {
691 : try
692 : {
693 : Reference< task::XPasswordContainer2 > xMasterPasswd(
694 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
695 :
696 0 : if ( xMasterPasswd->isPersistentStoringAllowed() )
697 0 : xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() );
698 : }
699 0 : catch (const Exception&)
700 : {}
701 :
702 0 : return 0;
703 : }
704 :
705 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl)
706 : {
707 : try
708 : {
709 : Reference< task::XPasswordContainer2 > xMasterPasswd(
710 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
711 :
712 0 : if ( m_pMasterPasswordCB->IsChecked() )
713 : {
714 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword( Reference< task::XInteractionHandler >() ) )
715 : {
716 0 : m_pMasterPasswordPB->Enable( sal_True );
717 0 : m_pMasterPasswordFT->Enable( sal_True );
718 : }
719 : else
720 : {
721 0 : m_pMasterPasswordCB->Check( sal_False );
722 0 : m_pMasterPasswordPB->Enable( sal_True );
723 0 : m_pMasterPasswordFT->Enable( sal_True );
724 : }
725 : }
726 : else
727 : {
728 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword( Reference< task::XInteractionHandler >() ) )
729 : {
730 0 : m_pMasterPasswordPB->Enable( sal_False );
731 0 : m_pMasterPasswordFT->Enable( sal_False );
732 : }
733 : else
734 : {
735 0 : m_pMasterPasswordCB->Check( sal_True );
736 0 : m_pMasterPasswordPB->Enable( sal_True );
737 0 : m_pShowConnectionsPB->Enable( sal_True );
738 : }
739 0 : }
740 : }
741 0 : catch (const Exception&)
742 : {
743 0 : m_pSavePasswordsCB->Check( !m_pSavePasswordsCB->IsChecked() );
744 : }
745 :
746 0 : return 0;
747 : }
748 :
749 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, ShowPasswordsHdl)
750 : {
751 : try
752 : {
753 : Reference< task::XPasswordContainer2 > xMasterPasswd(
754 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
755 :
756 0 : if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword( Reference< task::XInteractionHandler>() ) )
757 : {
758 0 : svx::WebConnectionInfoDialog aDlg( this );
759 0 : aDlg.Execute();
760 0 : }
761 : }
762 0 : catch (const Exception&)
763 : {}
764 0 : return 0;
765 : }
766 :
767 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, CertPathPBHdl)
768 : {
769 0 : if (!mpCertPathDlg)
770 0 : mpCertPathDlg = new CertPathDialog(this);
771 :
772 0 : OUString sOrig = mpCertPathDlg->getDirectory();
773 0 : short nRet = mpCertPathDlg->Execute();
774 :
775 0 : if (nRet == RET_OK && sOrig != mpCertPathDlg->getDirectory())
776 : {
777 0 : WarningBox aWarnBox(this, CUI_RES(RID_SVX_MSGBOX_OPTIONS_RESTART));
778 0 : aWarnBox.Execute();
779 : }
780 :
781 0 : return 0;
782 : }
783 :
784 0 : IMPL_LINK_NOARG(SvxSecurityTabPage, MacroSecPBHdl)
785 : {
786 : try
787 : {
788 : Reference< security::XDocumentDigitalSignatures > xD(
789 0 : security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
790 0 : xD->manageTrustedSources();
791 : }
792 0 : catch (const Exception& e)
793 : {
794 : OSL_FAIL(OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
795 : (void)e;
796 : }
797 0 : return 0;
798 : }
799 :
800 :
801 0 : void SvxSecurityTabPage::InitControls()
802 : {
803 : // Hide all controls which belong to the macro security button in case the macro
804 : // security settings managed by the macro security dialog opened via the button
805 : // are all readonly or if the macros are disabled in general.
806 : // @@@ Better would be to query the dialog whether it is 'useful' or not. Exposing
807 : // macro security dialog implementations here, which is bad.
808 0 : if ( mpSecOptions->IsMacroDisabled()
809 0 : || ( mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL )
810 0 : && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS )
811 0 : && mpSecOptions->IsReadOnly( SvtSecurityOptions::E_SECUREURLS ) ) )
812 : {
813 : //Hide these
814 0 : m_pMacroSecFrame->Hide();
815 : }
816 :
817 : #ifndef UNX
818 : m_pCertFrame->Hide();
819 : #endif
820 :
821 0 : m_pMasterPasswordPB->Enable( sal_False );
822 0 : m_pMasterPasswordCB->Enable( sal_False );
823 0 : m_pMasterPasswordCB->Check( sal_True );
824 0 : m_pMasterPasswordFT->Enable( sal_False );
825 0 : m_pShowConnectionsPB->Enable( sal_False );
826 :
827 : // initialize the password saving checkbox
828 : try
829 : {
830 : Reference< task::XPasswordContainer2 > xMasterPasswd(
831 0 : task::PasswordContainer::create(comphelper::getProcessComponentContext()));
832 :
833 0 : if ( xMasterPasswd->isPersistentStoringAllowed() )
834 : {
835 0 : m_pMasterPasswordCB->Enable( sal_True );
836 0 : m_pShowConnectionsPB->Enable( sal_True );
837 0 : m_pSavePasswordsCB->Check( sal_True );
838 :
839 0 : if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
840 0 : m_pMasterPasswordCB->Check( sal_False );
841 : else
842 : {
843 0 : m_pMasterPasswordPB->Enable( sal_True );
844 0 : m_pMasterPasswordCB->Check( sal_True );
845 0 : m_pMasterPasswordFT->Enable( sal_True );
846 : }
847 0 : }
848 : }
849 0 : catch (const Exception&)
850 : {
851 0 : m_pSavePasswordsCB->Enable( sal_False );
852 : }
853 0 : }
854 :
855 0 : SfxTabPage* SvxSecurityTabPage::Create(Window* pParent, const SfxItemSet& rAttrSet )
856 : {
857 0 : return new SvxSecurityTabPage(pParent, rAttrSet);
858 : }
859 :
860 0 : void SvxSecurityTabPage::ActivatePage( const SfxItemSet& )
861 : {
862 0 : }
863 :
864 0 : int SvxSecurityTabPage::DeactivatePage( SfxItemSet* _pSet )
865 : {
866 0 : if( _pSet )
867 0 : FillItemSet( *_pSet );
868 0 : return LEAVE_PAGE;
869 : }
870 :
871 : namespace
872 : {
873 0 : bool CheckAndSave( SvtSecurityOptions& _rOpt, SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModfied )
874 : {
875 0 : bool bModified = false;
876 0 : if ( _rOpt.IsOptionEnabled( _eOpt ) )
877 : {
878 0 : bModified = _rOpt.IsOptionSet( _eOpt ) != _bIsChecked;
879 0 : if ( bModified )
880 : {
881 0 : _rOpt.SetOption( _eOpt, _bIsChecked );
882 0 : _rModfied = true;
883 : }
884 : }
885 :
886 0 : return bModified;
887 : }
888 : }
889 :
890 0 : sal_Bool SvxSecurityTabPage::FillItemSet( SfxItemSet& )
891 : {
892 0 : bool bModified = false;
893 :
894 0 : if ( mpSecOptDlg )
895 : {
896 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SAVEORSEND, mpSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
897 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_SIGNING, mpSecOptDlg->IsSignDocsChecked(), bModified );
898 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_PRINT, mpSecOptDlg->IsPrintDocsChecked(), bModified );
899 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_CREATEPDF, mpSecOptDlg->IsCreatePdfChecked(), bModified );
900 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO, mpSecOptDlg->IsRemovePersInfoChecked(), bModified );
901 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD, mpSecOptDlg->IsRecommPasswdChecked(), bModified );
902 0 : CheckAndSave( *mpSecOptions, SvtSecurityOptions::E_CTRLCLICK_HYPERLINK, mpSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
903 : }
904 :
905 0 : return bModified;
906 : }
907 :
908 : /*--------------------------------------------------------------------*/
909 :
910 0 : void SvxSecurityTabPage::Reset( const SfxItemSet& )
911 : {
912 0 : }
913 :
914 0 : MozPluginTabPage::MozPluginTabPage(Window* pParent, const SfxItemSet& rSet)
915 0 : : SfxTabPage(pParent, "OptBrowserPage", "cui/ui/optbrowserpage.ui", rSet)
916 : {
917 0 : get(m_pWBasicCodeCB, "display");
918 0 : }
919 :
920 0 : MozPluginTabPage::~MozPluginTabPage()
921 : {
922 0 : }
923 :
924 0 : SfxTabPage* MozPluginTabPage::Create( Window* pParent,
925 : const SfxItemSet& rAttrSet )
926 : {
927 0 : return new MozPluginTabPage( pParent, rAttrSet );
928 : }
929 0 : sal_Bool MozPluginTabPage::FillItemSet( SfxItemSet& )
930 : {
931 0 : sal_Bool hasInstall = isInstalled();
932 0 : sal_Bool hasChecked = m_pWBasicCodeCB->IsChecked();
933 0 : if(hasInstall && (!hasChecked)){
934 : //try to uninstall
935 0 : uninstallPlugin();
936 : }
937 0 : else if((!hasInstall) && hasChecked){
938 : //try to install
939 0 : installPlugin();
940 : }
941 : else{
942 : // do nothing
943 : }
944 0 : return sal_True;
945 : }
946 0 : void MozPluginTabPage::Reset( const SfxItemSet& )
947 : {
948 0 : m_pWBasicCodeCB->Check( isInstalled());
949 0 : m_pWBasicCodeCB->SaveValue();
950 0 : }
951 :
952 : #ifdef WNT
953 : extern "C" {
954 : int lc_isInstalled(const char* realFilePath);
955 : int lc_installPlugin(const char* realFilePath);
956 : int lc_uninstallPlugin(const char* realFilePath);
957 : }
958 : #endif
959 :
960 : #define NPP_PATH_MAX 2048
961 0 : inline bool getDllURL(OString * path)
962 : {
963 : OSL_ASSERT(path != NULL);
964 0 : OUString dirPath/*dllPath, */;
965 0 : if (osl_getExecutableFile(&dirPath.pData) != osl_Process_E_None) {
966 0 : return false;
967 : }
968 0 : dirPath = dirPath.copy(0, dirPath.lastIndexOf('/'));
969 0 : OUString sysDirPath;
970 0 : osl::FileBase::getSystemPathFromFileURL(dirPath, sysDirPath);
971 0 : *path = OUStringToOString(sysDirPath, RTL_TEXTENCODING_ASCII_US);
972 0 : return true;
973 : }
974 :
975 0 : sal_Bool MozPluginTabPage::isInstalled()
976 : {
977 : #ifdef UNIX
978 : // get the real file referred by .so lnk file
979 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
980 0 : char lnkReferFilePath[NPP_PATH_MAX] = {0};
981 0 : char* pHome = getpwuid(getuid())->pw_dir;
982 0 : strcat(lnkFilePath, pHome);
983 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
984 :
985 : struct stat sBuf;
986 0 : if (0 > lstat(lnkFilePath, &sBuf))
987 0 : return false;
988 0 : if (!S_ISLNK(sBuf.st_mode))
989 0 : return false;
990 0 : if (0 >= readlink(lnkFilePath, lnkReferFilePath, NPP_PATH_MAX))
991 0 : return false;
992 : // If the link is relative, then we regard it as non-standard
993 0 : if (lnkReferFilePath[0] != '/')
994 0 : return false;
995 :
996 : // get the real file path
997 0 : char realFilePath[NPP_PATH_MAX] = {0};
998 0 : OString tempString;
999 0 : if (!getDllURL(&tempString)) {
1000 0 : return false;
1001 : }
1002 0 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX - 1);
1003 0 : strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1004 :
1005 0 : if (0 != strcmp(lnkReferFilePath, realFilePath))
1006 0 : return false;
1007 0 : return true;
1008 : #endif
1009 : #ifdef WNT
1010 : // get the value from registry
1011 : sal_Bool ret = true;
1012 : OString tempString;
1013 : char realFilePath[NPP_PATH_MAX] = {0};
1014 : if (!getDllURL(&tempString)){
1015 : return false;
1016 : }
1017 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1018 : if(! lc_isInstalled(realFilePath))
1019 : ret =true;
1020 : else
1021 : ret = false;
1022 : return ret;
1023 : #endif
1024 : }
1025 :
1026 0 : sal_Bool MozPluginTabPage::installPlugin()
1027 : {
1028 : #ifdef UNIX
1029 : // get the real file referred by .so lnk file
1030 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
1031 0 : char* pHome = getpwuid(getuid())->pw_dir;
1032 0 : strcat(lnkFilePath, pHome);
1033 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1034 0 : remove(lnkFilePath);
1035 :
1036 : // create the dirs if necessary
1037 : struct stat buf;
1038 0 : char tmpDir[NPP_PATH_MAX] = {0};
1039 0 : sprintf(tmpDir, "%s/.mozilla", pHome);
1040 0 : if (0 > stat(lnkFilePath, &buf))
1041 : {
1042 0 : mkdir(tmpDir, 0755);
1043 0 : strcat(tmpDir, "/plugins");
1044 0 : mkdir(tmpDir, 0755);
1045 : }
1046 :
1047 : // get the real file path
1048 0 : char realFilePath[NPP_PATH_MAX] = {0};
1049 0 : OString tempString;
1050 0 : if (!getDllURL(&tempString)) {
1051 0 : return false;
1052 : }
1053 0 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX - 1);
1054 0 : strcat(realFilePath, "/libnpsoplugin" SAL_DLLEXTENSION);
1055 :
1056 : // create the link
1057 0 : if (0 != symlink(realFilePath, lnkFilePath))
1058 0 : return false;
1059 0 : return true;
1060 : #endif
1061 : #ifdef WNT
1062 : OString tempString;
1063 : char realFilePath[NPP_PATH_MAX] = {0};
1064 : if (!getDllURL(&tempString)) {
1065 : return false;
1066 : }
1067 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1068 : if( !lc_installPlugin(realFilePath))
1069 : return true;
1070 : else
1071 : return false;
1072 : #endif
1073 : }
1074 :
1075 0 : sal_Bool MozPluginTabPage::uninstallPlugin()
1076 : {
1077 : #ifdef UNIX
1078 : // get the real file referred by .so lnk file
1079 0 : char lnkFilePath[NPP_PATH_MAX] = {0};
1080 0 : char* pHome = getpwuid(getuid())->pw_dir;
1081 0 : strcat(lnkFilePath, pHome);
1082 0 : strcat(lnkFilePath, "/.mozilla/plugins/libnpsoplugin" SAL_DLLEXTENSION);
1083 :
1084 0 : if(0 > remove(lnkFilePath))
1085 0 : return false;
1086 0 : return true;
1087 : #endif
1088 : #ifdef WNT
1089 : OString tempString;
1090 : char realFilePath[NPP_PATH_MAX] = {0};
1091 : if (!getDllURL(&tempString)) {
1092 : return false;
1093 : }
1094 : strncpy(realFilePath, tempString.getStr(), NPP_PATH_MAX);
1095 : if(!lc_uninstallPlugin(realFilePath))
1096 : return true;
1097 : else
1098 : return false;
1099 : #endif
1100 : }
1101 :
1102 : /* -------------------------------------------------------------------------*/
1103 :
1104 : class MailerProgramCfg_Impl : public utl::ConfigItem
1105 : {
1106 : friend class SvxEMailTabPage;
1107 : // variables
1108 : OUString sProgram;
1109 : // readonly states
1110 : sal_Bool bROProgram;
1111 :
1112 : const Sequence<OUString> GetPropertyNames();
1113 : public:
1114 : MailerProgramCfg_Impl();
1115 : virtual ~MailerProgramCfg_Impl();
1116 :
1117 : virtual void Commit();
1118 : virtual void Notify( const com::sun::star::uno::Sequence< OUString >& _rPropertyNames);
1119 : };
1120 :
1121 : /* -------------------------------------------------------------------------*/
1122 :
1123 0 : MailerProgramCfg_Impl::MailerProgramCfg_Impl() :
1124 : utl::ConfigItem("Office.Common/ExternalMailer"),
1125 0 : bROProgram(sal_False)
1126 : {
1127 0 : const Sequence< OUString > aNames = GetPropertyNames();
1128 0 : const Sequence< Any > aValues = GetProperties(aNames);
1129 0 : const Sequence< sal_Bool > aROStates = GetReadOnlyStates(aNames);
1130 0 : const Any* pValues = aValues.getConstArray();
1131 0 : const sal_Bool* pROStates = aROStates.getConstArray();
1132 0 : for(sal_Int32 nProp = 0; nProp < aValues.getLength(); nProp++)
1133 : {
1134 0 : if(pValues[nProp].hasValue())
1135 : {
1136 0 : switch(nProp)
1137 : {
1138 : case 0 :
1139 : {
1140 0 : pValues[nProp] >>= sProgram;
1141 0 : bROProgram = pROStates[nProp];
1142 : }
1143 0 : break;
1144 : }
1145 : }
1146 0 : }
1147 0 : }
1148 :
1149 : /* -------------------------------------------------------------------------*/
1150 :
1151 0 : MailerProgramCfg_Impl::~MailerProgramCfg_Impl()
1152 : {
1153 0 : }
1154 :
1155 : /* -------------------------------------------------------------------------*/
1156 :
1157 0 : const Sequence<OUString> MailerProgramCfg_Impl::GetPropertyNames()
1158 : {
1159 0 : Sequence<OUString> aRet(1);
1160 0 : OUString* pRet = aRet.getArray();
1161 0 : pRet[0] = "Program";
1162 0 : return aRet;
1163 : }
1164 :
1165 : /* -------------------------------------------------------------------------*/
1166 :
1167 0 : void MailerProgramCfg_Impl::Commit()
1168 : {
1169 0 : const Sequence< OUString > aOrgNames = GetPropertyNames();
1170 0 : sal_Int32 nOrgCount = aOrgNames.getLength();
1171 :
1172 0 : Sequence< OUString > aNames(nOrgCount);
1173 0 : Sequence< Any > aValues(nOrgCount);
1174 0 : sal_Int32 nRealCount = 0;
1175 :
1176 0 : for(int nProp = 0; nProp < nOrgCount; nProp++)
1177 : {
1178 0 : switch(nProp)
1179 : {
1180 : case 0:
1181 : {
1182 0 : if (!bROProgram)
1183 : {
1184 0 : aNames[nRealCount] = aOrgNames[nProp];
1185 0 : aValues[nRealCount] <<= sProgram;
1186 0 : ++nRealCount;
1187 : }
1188 : }
1189 0 : break;
1190 : }
1191 : }
1192 :
1193 0 : aNames.realloc(nRealCount);
1194 0 : aValues.realloc(nRealCount);
1195 0 : PutProperties(aNames, aValues);
1196 0 : }
1197 :
1198 0 : void MailerProgramCfg_Impl::Notify( const com::sun::star::uno::Sequence< OUString >& )
1199 : {
1200 0 : }
1201 :
1202 : /* -------------------------------------------------------------------------*/
1203 :
1204 0 : struct SvxEMailTabPage_Impl
1205 : {
1206 : MailerProgramCfg_Impl aMailConfig;
1207 : };
1208 :
1209 0 : SvxEMailTabPage::SvxEMailTabPage(Window* pParent, const SfxItemSet& rSet)
1210 : : SfxTabPage( pParent, "OptEmailPage", "cui/ui/optemailpage.ui", rSet)
1211 0 : , pImpl(new SvxEMailTabPage_Impl)
1212 : {
1213 0 : get(m_pMailContainer, "OptEmailPage");
1214 0 : get(m_pMailerURLFI, "lockemail");
1215 0 : get(m_pMailerURLED, "url");
1216 0 : get(m_pMailerURLPB, "browse");
1217 0 : m_sDefaultFilterName = get<FixedText>("browsetitle")->GetText();
1218 0 : m_pMailerURLPB->SetClickHdl( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
1219 0 : }
1220 :
1221 : /* -------------------------------------------------------------------------*/
1222 :
1223 0 : SvxEMailTabPage::~SvxEMailTabPage()
1224 : {
1225 0 : delete pImpl;
1226 0 : }
1227 :
1228 : /* -------------------------------------------------------------------------*/
1229 :
1230 0 : SfxTabPage* SvxEMailTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
1231 : {
1232 0 : return new SvxEMailTabPage(pParent, rAttrSet);
1233 : }
1234 :
1235 : /* -------------------------------------------------------------------------*/
1236 :
1237 0 : sal_Bool SvxEMailTabPage::FillItemSet( SfxItemSet& )
1238 : {
1239 0 : sal_Bool bMailModified = sal_False;
1240 0 : if(!pImpl->aMailConfig.bROProgram && m_pMailerURLED->GetSavedValue() != m_pMailerURLED->GetText())
1241 : {
1242 0 : pImpl->aMailConfig.sProgram = m_pMailerURLED->GetText();
1243 0 : bMailModified = sal_True;
1244 : }
1245 0 : if ( bMailModified )
1246 0 : pImpl->aMailConfig.Commit();
1247 :
1248 0 : return sal_False;
1249 : }
1250 :
1251 : /* -------------------------------------------------------------------------*/
1252 :
1253 0 : void SvxEMailTabPage::Reset( const SfxItemSet& )
1254 : {
1255 0 : m_pMailerURLED->Enable(sal_True );
1256 0 : m_pMailerURLPB->Enable(sal_True );
1257 :
1258 0 : if (pImpl->aMailConfig.bROProgram)
1259 0 : m_pMailerURLFI->Show();
1260 :
1261 0 : m_pMailerURLED->SetText(pImpl->aMailConfig.sProgram);
1262 0 : m_pMailerURLED->SaveValue();
1263 :
1264 0 : m_pMailContainer->Enable(!pImpl->aMailConfig.bROProgram);
1265 0 : }
1266 :
1267 : /* -------------------------------------------------------------------------*/
1268 :
1269 0 : IMPL_LINK( SvxEMailTabPage, FileDialogHdl_Impl, PushButton*, pButton )
1270 : {
1271 0 : if (m_pMailerURLPB == pButton && !pImpl->aMailConfig.bROProgram)
1272 : {
1273 : FileDialogHelper aHelper(
1274 : com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
1275 0 : 0 );
1276 0 : OUString sPath = m_pMailerURLED->GetText();
1277 0 : if ( sPath.isEmpty() )
1278 0 : sPath = OUString("/usr/bin");
1279 :
1280 0 : OUString sUrl;
1281 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL(sPath, sUrl);
1282 0 : aHelper.SetDisplayDirectory(sUrl);
1283 0 : aHelper.AddFilter( m_sDefaultFilterName, OUString("*"));
1284 :
1285 0 : if ( ERRCODE_NONE == aHelper.Execute() )
1286 : {
1287 0 : sUrl = aHelper.GetPath();
1288 0 : ::utl::LocalFileHelper::ConvertURLToPhysicalName(sUrl, sPath);
1289 0 : m_pMailerURLED->SetText(sPath);
1290 0 : }
1291 : }
1292 0 : return 0;
1293 0 : }
1294 :
1295 : // -----------------------------------------------------------------------------
1296 :
1297 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|