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