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 <sfx2/filedlghelper.hxx>
21 : #include <sal/types.h>
22 : #include <com/sun/star/lang/XInitialization.hpp>
23 : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
24 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
25 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
26 : #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
27 : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
28 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 : #include <com/sun/star/ui/dialogs/XControlInformation.hpp>
30 : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
31 : #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
32 : #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
33 : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
34 : #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
35 : #include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
36 : #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
37 : #include <com/sun/star/lang/XServiceInfo.hpp>
38 : #include <com/sun/star/beans/XPropertySet.hpp>
39 : #include <com/sun/star/beans/NamedValue.hpp>
40 : #include <com/sun/star/embed/ElementModes.hpp>
41 : #include <com/sun/star/container/XEnumeration.hpp>
42 : #include <com/sun/star/container/XContainerQuery.hpp>
43 : #include <com/sun/star/task/XInteractionRequest.hpp>
44 : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
45 :
46 : #include <comphelper/processfactory.hxx>
47 : #include <comphelper/sequenceashashmap.hxx>
48 : #include <comphelper/stillreadwriteinteraction.hxx>
49 : #include <comphelper/string.hxx>
50 : #include <comphelper/types.hxx>
51 : #include <tools/urlobj.hxx>
52 : #include <vcl/help.hxx>
53 : #include <unotools/ucbstreamhelper.hxx>
54 : #include <unotools/ucbhelper.hxx>
55 : #include <unotools/localfilehelper.hxx>
56 : #include <osl/file.hxx>
57 : #include <osl/mutex.hxx>
58 : #include <osl/security.hxx>
59 : #include <osl/thread.hxx>
60 : #include <vcl/cvtgrf.hxx>
61 : #include <vcl/msgbox.hxx>
62 : #include <vcl/mnemonic.hxx>
63 : #include <unotools/pathoptions.hxx>
64 : #include <unotools/securityoptions.hxx>
65 : #include <svl/itemset.hxx>
66 : #include <svl/eitem.hxx>
67 : #include <svl/intitem.hxx>
68 : #include <svl/stritem.hxx>
69 : #include <svtools/filter.hxx>
70 : #include <unotools/viewoptions.hxx>
71 : #include <unotools/moduleoptions.hxx>
72 : #include <svtools/helpid.hrc>
73 : #include <comphelper/docpasswordrequest.hxx>
74 : #include <comphelper/docpasswordhelper.hxx>
75 : #include <ucbhelper/content.hxx>
76 : #include <ucbhelper/commandenvironment.hxx>
77 : #include <comphelper/storagehelper.hxx>
78 : #include <toolkit/helper/vclunohelper.hxx>
79 : #include <sfx2/app.hxx>
80 : #include <sfx2/frame.hxx>
81 : #include <sfx2/docfile.hxx>
82 : #include <sfx2/docfac.hxx>
83 : #include "openflag.hxx"
84 : #include <sfx2/passwd.hxx>
85 : #include "sfx2/sfxresid.hxx"
86 : #include <sfx2/sfxsids.hrc>
87 : #include "filedlghelper.hrc"
88 : #include "filtergrouping.hxx"
89 : #include <sfx2/request.hxx>
90 : #include "filedlgimpl.hxx"
91 : #include <helpid.hrc>
92 : #include <sfxlocal.hrc>
93 : #include <rtl/strbuf.hxx>
94 :
95 : #ifdef UNX
96 : #include <errno.h>
97 : #include <sys/stat.h>
98 : #endif
99 :
100 : //-----------------------------------------------------------------------------
101 :
102 : using namespace ::com::sun::star;
103 : using namespace ::com::sun::star::container;
104 : using namespace ::com::sun::star::lang;
105 : using namespace ::com::sun::star::ui::dialogs;
106 : using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
107 : using namespace ::com::sun::star::uno;
108 : using namespace ::com::sun::star::beans;
109 : using namespace ::rtl;
110 : using namespace ::cppu;
111 :
112 : //-----------------------------------------------------------------------------
113 :
114 : #define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
115 : #define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
116 : #define USERITEM_NAME ::rtl::OUString("UserItem" )
117 :
118 : //-----------------------------------------------------------------------------
119 :
120 : namespace sfx2
121 : {
122 :
123 0 : const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
124 : {
125 0 : static const OUString aSD_EXPORT_IDENTIFIER( "SdExportLastFilter" );
126 0 : static const OUString aSI_EXPORT_IDENTIFIER( "SiExportLastFilter" );
127 0 : static const OUString aSW_EXPORT_IDENTIFIER( "SwExportLastFilter" );
128 :
129 0 : const OUString* pRet = NULL;
130 :
131 0 : switch( _eContext )
132 : {
133 0 : case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
134 0 : case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
135 0 : case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
136 0 : default: break;
137 : }
138 :
139 0 : return pRet;
140 : }
141 :
142 : String EncodeSpaces_Impl( const String& rSource );
143 : String DecodeSpaces_Impl( const String& rSource );
144 :
145 : // ------------------------------------------------------------------------
146 : // ----------- FileDialogHelper_Impl ---------------------------
147 : // ------------------------------------------------------------------------
148 :
149 : // ------------------------------------------------------------------------
150 : // XFilePickerListener Methods
151 : // ------------------------------------------------------------------------
152 0 : void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
153 : {
154 0 : SolarMutexGuard aGuard;
155 0 : mpAntiImpl->FileSelectionChanged( aEvent );
156 0 : }
157 :
158 : // ------------------------------------------------------------------------
159 0 : void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
160 : {
161 0 : SolarMutexGuard aGuard;
162 0 : mpAntiImpl->DirectoryChanged( aEvent );
163 0 : }
164 :
165 : // ------------------------------------------------------------------------
166 0 : OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
167 : {
168 0 : SolarMutexGuard aGuard;
169 0 : return mpAntiImpl->HelpRequested( aEvent );
170 : }
171 :
172 : // ------------------------------------------------------------------------
173 0 : void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
174 : {
175 0 : SolarMutexGuard aGuard;
176 0 : mpAntiImpl->ControlStateChanged( aEvent );
177 0 : }
178 :
179 : // ------------------------------------------------------------------------
180 0 : void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
181 : {
182 0 : SolarMutexGuard aGuard;
183 0 : mpAntiImpl->DialogSizeChanged();
184 0 : }
185 :
186 : // ------------------------------------------------------------------------
187 : // XDialogClosedListener Methods
188 : // ------------------------------------------------------------------------
189 0 : void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
190 : {
191 0 : SolarMutexGuard aGuard;
192 0 : mpAntiImpl->DialogClosed( _rEvent );
193 0 : postExecute( _rEvent.DialogResult );
194 0 : }
195 :
196 : // ------------------------------------------------------------------------
197 : // handle XFilePickerListener events
198 : // ------------------------------------------------------------------------
199 0 : void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
200 : {
201 0 : if ( mbHasVersions )
202 0 : updateVersions();
203 :
204 0 : if ( mbShowPreview )
205 0 : maPreViewTimer.Start();
206 0 : }
207 :
208 : // ------------------------------------------------------------------------
209 0 : void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
210 : {
211 0 : if ( mbShowPreview )
212 0 : TimeOutHdl_Impl( NULL );
213 0 : }
214 :
215 : // ------------------------------------------------------------------------
216 0 : OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
217 : {
218 : //!!! todo: cache the help strings (here or TRA)
219 :
220 0 : rtl::OString sHelpId;
221 : // mapping from element id -> help id
222 0 : switch ( aEvent.ElementId )
223 : {
224 : case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
225 0 : sHelpId = HID_FILESAVE_AUTOEXTENSION;
226 0 : break;
227 :
228 : case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
229 0 : sHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
230 0 : break;
231 :
232 : case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
233 0 : sHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
234 0 : break;
235 :
236 : case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
237 0 : sHelpId = HID_FILEOPEN_READONLY;
238 0 : break;
239 :
240 : case ExtendedFilePickerElementIds::CHECKBOX_LINK :
241 0 : sHelpId = HID_FILEDLG_LINK_CB;
242 0 : break;
243 :
244 : case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
245 0 : sHelpId = HID_FILEDLG_PREVIEW_CB;
246 0 : break;
247 :
248 : case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
249 0 : sHelpId = HID_FILESAVE_DOPLAY;
250 0 : break;
251 :
252 : case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
253 : case ExtendedFilePickerElementIds::LISTBOX_VERSION :
254 0 : sHelpId = HID_FILEOPEN_VERSION;
255 0 : break;
256 :
257 : case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
258 : case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
259 0 : sHelpId = HID_FILESAVE_TEMPLATE;
260 0 : break;
261 :
262 : case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
263 : case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
264 0 : sHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
265 0 : break;
266 :
267 : case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
268 0 : sHelpId = HID_FILESAVE_SELECTION;
269 0 : break;
270 :
271 : default:
272 : SAL_WARN( "sfx2.dialog", "invalid element id" );
273 : }
274 :
275 0 : OUString aHelpText;
276 0 : Help* pHelp = Application::GetHelp();
277 0 : if ( pHelp )
278 0 : aHelpText = String( pHelp->GetHelpText( rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8), NULL ) );
279 0 : return aHelpText;
280 : }
281 :
282 : // ------------------------------------------------------------------------
283 0 : void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
284 : {
285 0 : switch ( aEvent.ElementId )
286 : {
287 : case CommonFilePickerElementIds::LISTBOX_FILTER:
288 0 : updateFilterOptionsBox();
289 0 : enablePasswordBox( sal_False );
290 0 : updateSelectionBox();
291 : // only use it for export and with our own dialog
292 0 : if ( mbExport && !mbSystemPicker )
293 0 : updateExportButton();
294 0 : break;
295 :
296 : case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
297 0 : updatePreviewState();
298 0 : break;
299 : }
300 0 : }
301 :
302 : // ------------------------------------------------------------------------
303 0 : void FileDialogHelper_Impl::handleDialogSizeChanged()
304 : {
305 0 : if ( mbShowPreview )
306 0 : TimeOutHdl_Impl( NULL );
307 0 : }
308 :
309 : // ------------------------------------------------------------------------
310 : // XEventListener Methods
311 : // ------------------------------------------------------------------------
312 0 : void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
313 : {
314 0 : SolarMutexGuard aGuard;
315 0 : dispose();
316 0 : }
317 :
318 : // ------------------------------------------------------------------------
319 :
320 0 : void FileDialogHelper_Impl::dispose()
321 : {
322 0 : if ( mxFileDlg.is() )
323 : {
324 : // remove the event listener
325 0 : uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
326 0 : if ( xNotifier.is() )
327 0 : xNotifier->removeFilePickerListener( this );
328 :
329 0 : ::comphelper::disposeComponent( mxFileDlg );
330 0 : mxFileDlg.clear();
331 : }
332 0 : }
333 :
334 : // ------------------------------------------------------------------------
335 0 : String FileDialogHelper_Impl::getCurrentFilterUIName() const
336 : {
337 0 : String aFilterName;
338 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
339 :
340 0 : if( xFltMgr.is() )
341 : {
342 0 : aFilterName = xFltMgr->getCurrentFilter();
343 :
344 0 : if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
345 0 : aFilterName = getFilterName( aFilterName );
346 : }
347 :
348 0 : return aFilterName;
349 : }
350 :
351 : // ------------------------------------------------------------------------
352 0 : void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
353 : {
354 0 : SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
355 :
356 0 : if( aDlgOpt.Exists() )
357 : {
358 0 : OUString aLastFilter;
359 0 : if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
360 0 : setFilter( aLastFilter );
361 0 : }
362 0 : }
363 :
364 : // ------------------------------------------------------------------------
365 0 : void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
366 : {
367 : SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
368 0 : makeAny( getFilterWithExtension( getFilter() ) ) );
369 0 : }
370 :
371 : // ------------------------------------------------------------------------
372 0 : void FileDialogHelper_Impl::SaveLastUsedFilter( void )
373 : {
374 0 : const OUString* pConfigId = GetLastFilterConfigId( meContext );
375 0 : if( pConfigId )
376 0 : SaveLastUsedFilter( *pConfigId );
377 0 : }
378 :
379 : // ------------------------------------------------------------------------
380 0 : const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
381 : {
382 0 : String aFilterName = getCurrentFilterUIName();
383 :
384 0 : const SfxFilter* pFilter = NULL;
385 0 : if ( mpMatcher && aFilterName.Len() )
386 0 : pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
387 :
388 0 : return pFilter;
389 : }
390 :
391 : // ------------------------------------------------------------------------
392 0 : sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
393 : {
394 0 : sal_Bool bIsEnabled = sal_False;
395 :
396 0 : uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
397 0 : if ( xCtrlAccess.is() )
398 : {
399 : try
400 : {
401 0 : xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
402 0 : bIsEnabled = _bEnable;
403 : }
404 0 : catch( const IllegalArgumentException& )
405 : {
406 : OSL_FAIL( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
407 : }
408 : }
409 0 : return bIsEnabled;
410 : }
411 :
412 : // ------------------------------------------------------------------------
413 0 : sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
414 : {
415 0 : sal_Bool bResult = sal_False;
416 :
417 0 : if( mxFilterCFG.is() && _pFilter )
418 : {
419 : try {
420 0 : Sequence < PropertyValue > aProps;
421 0 : Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
422 0 : if ( aAny >>= aProps )
423 : {
424 0 : ::rtl::OUString aServiceName;
425 0 : sal_Int32 nPropertyCount = aProps.getLength();
426 0 : for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
427 : {
428 0 : if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
429 : {
430 0 : aProps[nProperty].Value >>= aServiceName;
431 0 : if( !aServiceName.isEmpty() )
432 0 : bResult = sal_True;
433 : }
434 0 : }
435 0 : }
436 : }
437 0 : catch( const Exception& )
438 : {
439 : }
440 : }
441 :
442 0 : return bResult;
443 : }
444 :
445 : // ------------------------------------------------------------------------
446 0 : sal_Bool FileDialogHelper_Impl::isInOpenMode() const
447 : {
448 0 : sal_Bool bRet = sal_False;
449 :
450 0 : switch ( m_nDialogType )
451 : {
452 : case FILEOPEN_SIMPLE:
453 : case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
454 : case FILEOPEN_PLAY:
455 : case FILEOPEN_READONLY_VERSION:
456 : case FILEOPEN_LINK_PREVIEW:
457 0 : bRet = sal_True;
458 : }
459 :
460 0 : return bRet;
461 : }
462 :
463 : // ------------------------------------------------------------------------
464 :
465 0 : void FileDialogHelper_Impl::updateFilterOptionsBox()
466 : {
467 0 : if ( !m_bHaveFilterOptions )
468 0 : return;
469 :
470 : updateExtendedControl(
471 : ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
472 0 : CheckFilterOptionsCapability( getCurentSfxFilter() )
473 0 : );
474 : }
475 :
476 : // ------------------------------------------------------------------------
477 :
478 0 : void FileDialogHelper_Impl::updateExportButton()
479 : {
480 0 : uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
481 0 : if ( xCtrlAccess.is() )
482 : {
483 0 : OUString sEllipses( "..." );
484 0 : OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
485 :
486 : // initialize button label; we need the label with the mnemonic char
487 0 : if ( maButtonLabel.isEmpty() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
488 : {
489 : // cut the ellipses, if necessary
490 0 : sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
491 0 : if ( -1 == nIndex )
492 0 : nIndex = sOldLabel.getLength();
493 0 : maButtonLabel = sOldLabel.copy( 0, nIndex );
494 : }
495 :
496 0 : OUString sLabel = maButtonLabel;
497 : // filter with options -> append ellipses on export button label
498 0 : if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
499 0 : sLabel += OUString( "..." );
500 :
501 0 : if ( sOldLabel != sLabel )
502 : {
503 : try
504 : {
505 0 : xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
506 : }
507 0 : catch( const IllegalArgumentException& )
508 : {
509 : SAL_WARN( "sfx2.dialog", "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
510 : }
511 0 : }
512 0 : }
513 0 : }
514 :
515 : // ------------------------------------------------------------------------
516 0 : void FileDialogHelper_Impl::updateSelectionBox()
517 : {
518 0 : if ( !mbHasSelectionBox )
519 0 : return;
520 :
521 : // Does the selection box exist?
522 0 : sal_Bool bSelectionBoxFound = sal_False;
523 0 : uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
524 0 : if ( xCtrlInfo.is() )
525 : {
526 0 : Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
527 0 : sal_uInt32 nCount = aCtrlList.getLength();
528 0 : for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
529 0 : if ( aCtrlList[ nCtrl ] == "SelectionBox" )
530 : {
531 0 : bSelectionBoxFound = sal_False;
532 0 : break;
533 0 : }
534 : }
535 :
536 0 : if ( bSelectionBoxFound )
537 : {
538 0 : const SfxFilter* pFilter = getCurentSfxFilter();
539 : mbSelectionFltrEnabled = updateExtendedControl(
540 : ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
541 0 : ( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
542 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
543 0 : xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
544 0 : }
545 : }
546 :
547 : // ------------------------------------------------------------------------
548 0 : void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
549 : {
550 0 : if ( ! mbHasPassword )
551 0 : return;
552 :
553 0 : sal_Bool bWasEnabled = mbIsPwdEnabled;
554 :
555 0 : const SfxFilter* pCurrentFilter = getCurentSfxFilter();
556 : mbIsPwdEnabled = updateExtendedControl(
557 : ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
558 0 : pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION )
559 0 : );
560 :
561 0 : if( bInit )
562 : {
563 : // in case of inintialization previous state is not interesting
564 0 : if( mbIsPwdEnabled )
565 : {
566 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
567 0 : if( mbPwdCheckBoxState )
568 0 : xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
569 : }
570 : }
571 0 : else if( !bWasEnabled && mbIsPwdEnabled )
572 : {
573 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
574 0 : if( mbPwdCheckBoxState )
575 0 : xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
576 : }
577 0 : else if( bWasEnabled && !mbIsPwdEnabled )
578 : {
579 : // remember user settings until checkbox is enabled
580 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
581 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
582 0 : sal_Bool bPassWord = sal_False;
583 0 : mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
584 0 : xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
585 : }
586 : }
587 :
588 : // ------------------------------------------------------------------------
589 0 : void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
590 : {
591 0 : if ( mbHasPreview )
592 : {
593 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
594 :
595 : // check, whether or not we have to display a preview
596 0 : if ( xCtrlAccess.is() )
597 : {
598 : try
599 : {
600 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
601 0 : sal_Bool bShowPreview = sal_False;
602 :
603 0 : if ( aValue >>= bShowPreview )
604 : {
605 0 : mbShowPreview = bShowPreview;
606 :
607 : // setShowState has currently no effect for the
608 : // OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
609 0 : uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
610 0 : if ( xFilePreview.is() )
611 0 : xFilePreview->setShowState( mbShowPreview );
612 :
613 0 : if ( _bUpdatePreviewWindow )
614 0 : TimeOutHdl_Impl( NULL );
615 0 : }
616 : }
617 0 : catch( const Exception& )
618 : {
619 : SAL_WARN( "sfx2.dialog", "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
620 : }
621 0 : }
622 : }
623 0 : }
624 :
625 : // ------------------------------------------------------------------------
626 0 : void FileDialogHelper_Impl::updateVersions()
627 : {
628 0 : Sequence < OUString > aEntries;
629 0 : Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
630 :
631 0 : if ( aPathSeq.getLength() == 1 )
632 : {
633 0 : INetURLObject aObj( aPathSeq[0] );
634 :
635 0 : if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
636 0 : ( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
637 : {
638 : try
639 : {
640 : uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
641 : aObj.GetMainURL( INetURLObject::NO_DECODE ),
642 0 : embed::ElementModes::READ );
643 :
644 : DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
645 0 : if ( !xStorage.is() )
646 0 : throw uno::RuntimeException();
647 :
648 0 : uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
649 :
650 0 : aEntries.realloc( xVersions.getLength() + 1 );
651 0 : aEntries[0] = SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ).toString();
652 :
653 0 : for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
654 0 : aEntries[ i + 1 ] = xVersions[i].Identifier;
655 : }
656 0 : catch( const uno::Exception& )
657 : {
658 : }
659 0 : }
660 : }
661 :
662 0 : uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
663 0 : Any aValue;
664 :
665 : try
666 : {
667 0 : xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
668 0 : ControlActions::DELETE_ITEMS, aValue );
669 : }
670 0 : catch( const IllegalArgumentException& ){}
671 :
672 0 : sal_Int32 nCount = aEntries.getLength();
673 :
674 0 : if ( nCount )
675 : {
676 : try
677 : {
678 0 : aValue <<= aEntries;
679 0 : xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
680 0 : ControlActions::ADD_ITEMS, aValue );
681 :
682 0 : Any aPos;
683 0 : aPos <<= (sal_Int32) 0;
684 0 : xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
685 0 : ControlActions::SET_SELECT_ITEM, aPos );
686 : }
687 0 : catch( const IllegalArgumentException& ){}
688 0 : }
689 0 : }
690 :
691 : // -----------------------------------------------------------------------
692 0 : IMPL_LINK_NOARG(FileDialogHelper_Impl, TimeOutHdl_Impl)
693 : {
694 0 : if ( !mbHasPreview )
695 0 : return 0;
696 :
697 0 : maGraphic.Clear();
698 :
699 0 : Any aAny;
700 0 : uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
701 :
702 0 : if ( ! xFilePicker.is() )
703 0 : return 0;
704 :
705 0 : Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
706 :
707 0 : if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
708 : {
709 0 : OUString aURL = aPathSeq[0];
710 :
711 0 : if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
712 : {
713 : // changed the code slightly;
714 : // before: the bitmap was scaled and
715 : // surrounded a white frame
716 : // now: the bitmap will only be scaled
717 : // and the filepicker implementation
718 : // is responsible for placing it at its
719 : // proper position and painting a frame
720 :
721 0 : Bitmap aBmp = maGraphic.GetBitmap();
722 0 : if ( !aBmp.IsEmpty() )
723 : {
724 : // scale the bitmap to the correct size
725 0 : sal_Int32 nOutWidth = xFilePicker->getAvailableWidth();
726 0 : sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
727 0 : sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
728 0 : sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
729 :
730 0 : double nXRatio = (double) nOutWidth / nBmpWidth;
731 0 : double nYRatio = (double) nOutHeight / nBmpHeight;
732 :
733 0 : if ( nXRatio < nYRatio )
734 0 : aBmp.Scale( nXRatio, nXRatio );
735 : else
736 0 : aBmp.Scale( nYRatio, nYRatio );
737 :
738 : // Convert to true color, to allow CopyPixel
739 0 : aBmp.Convert( BMP_CONVERSION_24BIT );
740 :
741 : // and copy it into the Any
742 0 : SvMemoryStream aData;
743 :
744 0 : aData << aBmp;
745 :
746 : const Sequence < sal_Int8 > aBuffer(
747 0 : static_cast< const sal_Int8* >(aData.GetData()),
748 0 : aData.GetEndOfData() );
749 :
750 0 : aAny <<= aBuffer;
751 0 : }
752 0 : }
753 : }
754 :
755 : try
756 : {
757 0 : SolarMutexReleaser aReleaseForCallback;
758 : // clear the preview window
759 0 : xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
760 : }
761 0 : catch( const IllegalArgumentException& )
762 : {
763 : }
764 :
765 0 : return 0;
766 : }
767 :
768 : // ------------------------------------------------------------------------
769 0 : ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
770 : Graphic& rGraphic ) const
771 : {
772 0 : if ( utl::UCBContentHelper::IsFolder( rURL ) )
773 0 : return ERRCODE_IO_NOTAFILE;
774 :
775 0 : if ( !mpGraphicFilter )
776 0 : return ERRCODE_IO_NOTSUPPORTED;
777 :
778 : // select graphic filter from dialog filter selection
779 0 : OUString aCurFilter( getFilter() );
780 :
781 0 : sal_uInt16 nFilter = !aCurFilter.isEmpty() && mpGraphicFilter->GetImportFormatCount()
782 0 : ? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
783 0 : : GRFILTER_FORMAT_DONTKNOW;
784 :
785 0 : INetURLObject aURLObj( rURL );
786 :
787 0 : if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
788 : {
789 0 : aURLObj.SetSmartProtocol( INET_PROT_FILE );
790 0 : aURLObj.SetSmartURL( rURL );
791 : }
792 :
793 0 : ErrCode nRet = ERRCODE_NONE;
794 :
795 0 : sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
796 : // non-local?
797 0 : if ( INET_PROT_FILE != aURLObj.GetProtocol() )
798 : {
799 0 : SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
800 :
801 0 : if( pStream )
802 0 : nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
803 : else
804 0 : nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
805 0 : delete pStream;
806 : }
807 : else
808 : {
809 0 : nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
810 : }
811 :
812 0 : return nRet;
813 : }
814 :
815 : // ------------------------------------------------------------------------
816 0 : ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
817 : {
818 0 : ErrCode nRet = ERRCODE_NONE;
819 :
820 0 : if ( ! maGraphic )
821 : {
822 0 : OUString aPath;;
823 0 : Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
824 :
825 0 : if ( aPathSeq.getLength() == 1 )
826 : {
827 0 : aPath = aPathSeq[0];
828 : }
829 :
830 0 : if ( !aPath.isEmpty() )
831 0 : nRet = getGraphic( aPath, rGraphic );
832 : else
833 0 : nRet = ERRCODE_IO_GENERAL;
834 : }
835 : else
836 0 : rGraphic = maGraphic;
837 :
838 0 : return nRet;
839 : }
840 :
841 : // ------------------------------------------------------------------------
842 0 : static bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
843 : {
844 : try
845 : {
846 0 : uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
847 0 : if ( !xSI.is() )
848 0 : return true;
849 0 : return xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) );
850 : }
851 0 : catch( const Exception& )
852 : {
853 : }
854 0 : return false;
855 : }
856 :
857 : enum open_or_save_t {OPEN, SAVE, UNDEFINED};
858 0 : static open_or_save_t lcl_OpenOrSave(sal_Int16 const nDialogType)
859 : {
860 0 : switch (nDialogType)
861 : {
862 : case FILEOPEN_SIMPLE:
863 : case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
864 : case FILEOPEN_PLAY:
865 : case FILEOPEN_READONLY_VERSION:
866 : case FILEOPEN_LINK_PREVIEW:
867 0 : return OPEN;
868 : case FILESAVE_SIMPLE:
869 : case FILESAVE_AUTOEXTENSION_PASSWORD:
870 : case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
871 : case FILESAVE_AUTOEXTENSION_SELECTION:
872 : case FILESAVE_AUTOEXTENSION_TEMPLATE:
873 : case FILESAVE_AUTOEXTENSION:
874 0 : return SAVE;
875 : default:
876 : assert(false); // invalid dialog type
877 : }
878 0 : return UNDEFINED;
879 : }
880 :
881 : // ------------------------------------------------------------------------
882 : // ----------- FileDialogHelper_Impl ---------------------------
883 : // ------------------------------------------------------------------------
884 :
885 0 : FileDialogHelper_Impl::FileDialogHelper_Impl(
886 : FileDialogHelper* _pAntiImpl,
887 : sal_Int16 nDialogType,
888 : sal_Int64 nFlags,
889 : sal_Int16 nDialog,
890 : Window* _pPreferredParentWindow,
891 : const String& sStandardDir,
892 : const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
893 : )
894 : :m_nDialogType ( nDialogType )
895 0 : ,meContext ( FileDialogHelper::UNKNOWN_CONTEXT )
896 : {
897 0 : const char* pServiceName=0;
898 0 : if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
899 0 : pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
900 0 : else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
901 0 : pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
902 : else
903 0 : pServiceName = FILE_OPEN_SERVICE_NAME;
904 0 : OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
905 :
906 0 : uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
907 :
908 : // create the file open dialog
909 : // the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
910 :
911 0 : mpPreferredParentWindow = _pPreferredParentWindow;
912 0 : mpAntiImpl = _pAntiImpl;
913 0 : mnError = ERRCODE_NONE;
914 0 : mbHasAutoExt = sal_False;
915 0 : mbHasPassword = sal_False;
916 0 : m_bHaveFilterOptions = sal_False;
917 0 : mbIsPwdEnabled = sal_True;
918 0 : mbHasVersions = sal_False;
919 0 : mbHasPreview = sal_False;
920 0 : mbShowPreview = sal_False;
921 0 : mbAddGraphicFilter = SFXWB_GRAPHIC == (nFlags & SFXWB_GRAPHIC);
922 0 : mbDeleteMatcher = sal_False;
923 0 : mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
924 0 : mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
925 0 : mbIsSaveDlg = sal_False;
926 0 : mbPwdCheckBoxState = sal_False;
927 0 : mbSelection = sal_False;
928 0 : mbSelectionEnabled = sal_True;
929 0 : mbHasSelectionBox = sal_False;
930 0 : mbSelectionFltrEnabled = sal_False;
931 :
932 : // default settings
933 0 : m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
934 0 : if (OPEN == lcl_OpenOrSave(m_nDialogType))
935 0 : m_nMustFlags = SFX_FILTER_IMPORT;
936 : else
937 0 : m_nMustFlags = SFX_FILTER_EXPORT;
938 :
939 :
940 0 : mpMatcher = NULL;
941 0 : mpGraphicFilter = NULL;
942 0 : mnPostUserEventId = 0;
943 :
944 : // create the picker component
945 0 : mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
946 0 : mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
947 :
948 0 : uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
949 0 : uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
950 :
951 0 : if ( ! mxFileDlg.is() || ! xNotifier.is() )
952 : {
953 0 : mnError = ERRCODE_ABORT;
954 0 : return;
955 : }
956 :
957 :
958 0 : if ( xInit.is() )
959 : {
960 0 : sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
961 :
962 0 : switch ( m_nDialogType )
963 : {
964 : case FILEOPEN_SIMPLE:
965 0 : nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
966 0 : break;
967 :
968 : case FILESAVE_SIMPLE:
969 0 : nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
970 0 : mbIsSaveDlg = sal_True;
971 0 : break;
972 :
973 : case FILESAVE_AUTOEXTENSION_PASSWORD:
974 0 : nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
975 0 : mbHasPassword = sal_True;
976 0 : mbHasAutoExt = sal_True;
977 0 : mbIsSaveDlg = sal_True;
978 0 : break;
979 :
980 : case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
981 0 : nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
982 0 : mbHasPassword = sal_True;
983 :
984 0 : m_bHaveFilterOptions = sal_True;
985 0 : if( xFactory.is() )
986 : {
987 : mxFilterCFG = uno::Reference< XNameAccess >(
988 0 : xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
989 0 : UNO_QUERY );
990 : }
991 :
992 0 : mbHasAutoExt = sal_True;
993 0 : mbIsSaveDlg = sal_True;
994 0 : break;
995 :
996 : case FILESAVE_AUTOEXTENSION_SELECTION:
997 0 : nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
998 0 : mbHasAutoExt = sal_True;
999 0 : mbIsSaveDlg = sal_True;
1000 0 : mbHasSelectionBox = sal_True;
1001 0 : if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
1002 : {
1003 : mxFilterCFG = uno::Reference< XNameAccess >(
1004 0 : xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
1005 0 : UNO_QUERY );
1006 : }
1007 0 : break;
1008 :
1009 : case FILESAVE_AUTOEXTENSION_TEMPLATE:
1010 0 : nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
1011 0 : mbHasAutoExt = sal_True;
1012 0 : mbIsSaveDlg = sal_True;
1013 0 : break;
1014 :
1015 : case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
1016 0 : nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
1017 0 : mbHasPreview = sal_True;
1018 :
1019 : // aPreviewTimer
1020 0 : maPreViewTimer.SetTimeout( 500 );
1021 0 : maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1022 0 : break;
1023 :
1024 : case FILEOPEN_PLAY:
1025 0 : nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
1026 0 : break;
1027 :
1028 : case FILEOPEN_READONLY_VERSION:
1029 0 : nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
1030 0 : mbHasVersions = sal_True;
1031 0 : break;
1032 :
1033 : case FILEOPEN_LINK_PREVIEW:
1034 0 : nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
1035 0 : mbHasPreview = sal_True;
1036 : // aPreviewTimer
1037 0 : maPreViewTimer.SetTimeout( 500 );
1038 0 : maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
1039 0 : break;
1040 :
1041 : case FILESAVE_AUTOEXTENSION:
1042 0 : nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
1043 0 : mbHasAutoExt = sal_True;
1044 0 : mbIsSaveDlg = sal_True;
1045 0 : break;
1046 :
1047 : default:
1048 : SAL_WARN( "sfx2.dialog", "FileDialogHelper::ctor with unknown type" );
1049 0 : break;
1050 : }
1051 :
1052 0 : Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
1053 :
1054 : // This is a hack. We currently know that the internal file picker implementation
1055 : // supports the extended arguments as specified below.
1056 : // TODO:
1057 : // a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
1058 : // b) adjust the implementation of the system file picker to that it recognizes it
1059 0 : if ( mbSystemPicker )
1060 : {
1061 0 : aInitArguments[0] <<= nTemplateDescription;
1062 : }
1063 : else
1064 : {
1065 0 : aInitArguments[0] <<= NamedValue(
1066 : ::rtl::OUString( "TemplateDescription" ),
1067 : makeAny( nTemplateDescription )
1068 0 : );
1069 :
1070 0 : ::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
1071 :
1072 0 : aInitArguments[1] <<= NamedValue(
1073 : ::rtl::OUString( "StandardDir" ),
1074 : makeAny( sStandardDirTemp )
1075 0 : );
1076 :
1077 0 : aInitArguments[2] <<= NamedValue(
1078 : ::rtl::OUString( "BlackList" ),
1079 : makeAny( rBlackList )
1080 0 : );
1081 :
1082 :
1083 0 : if ( mpPreferredParentWindow )
1084 0 : aInitArguments[3] <<= NamedValue(
1085 : ::rtl::OUString( "ParentWindow" ),
1086 : makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
1087 0 : );
1088 : }
1089 :
1090 : try
1091 : {
1092 0 : xInit->initialize( aInitArguments );
1093 : }
1094 0 : catch( const Exception& )
1095 : {
1096 : OSL_FAIL( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
1097 0 : }
1098 : }
1099 :
1100 :
1101 : // set multiselection mode
1102 0 : if ( nFlags & SFXWB_MULTISELECTION )
1103 0 : mxFileDlg->setMultiSelectionMode( sal_True );
1104 :
1105 0 : if (mbAddGraphicFilter) // generate graphic filter only on demand
1106 : {
1107 0 : addGraphicFilter();
1108 : }
1109 :
1110 : // Export dialog
1111 0 : if ( mbExport )
1112 : {
1113 0 : mxFileDlg->setTitle( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ).toString() );
1114 : try {
1115 0 : com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
1116 0 : xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
1117 : }
1118 0 : catch( const Exception & ) { }
1119 : }
1120 :
1121 : // the "insert file" dialog needs another title
1122 0 : if ( mbInsert )
1123 : {
1124 0 : mxFileDlg->setTitle( SfxResId( STR_SFX_EXPLORERFILE_INSERT ).toString() );
1125 0 : uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
1126 0 : if ( xExtDlg.is() )
1127 : {
1128 : try
1129 : {
1130 0 : xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
1131 0 : SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ).toString() );
1132 : }
1133 0 : catch( const IllegalArgumentException& ){}
1134 0 : }
1135 : }
1136 :
1137 : // add the event listener
1138 0 : xNotifier->addFilePickerListener( this );
1139 : }
1140 :
1141 : // ------------------------------------------------------------------------
1142 0 : FileDialogHelper_Impl::~FileDialogHelper_Impl()
1143 : {
1144 : // Remove user event if we haven't received it yet
1145 0 : if ( mnPostUserEventId )
1146 0 : Application::RemoveUserEvent( mnPostUserEventId );
1147 0 : mnPostUserEventId = 0;
1148 :
1149 0 : delete mpGraphicFilter;
1150 :
1151 0 : if ( mbDeleteMatcher )
1152 0 : delete mpMatcher;
1153 :
1154 0 : maPreViewTimer.SetTimeoutHdl( Link() );
1155 :
1156 0 : ::comphelper::disposeComponent( mxFileDlg );
1157 0 : }
1158 :
1159 : #define nMagic -1
1160 :
1161 0 : class PickerThread_Impl : public ::osl::Thread
1162 : {
1163 : uno::Reference < XFilePicker > mxPicker;
1164 : ::osl::Mutex maMutex;
1165 : virtual void SAL_CALL run();
1166 : sal_Int16 mnRet;
1167 : public:
1168 : PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
1169 : : mxPicker( rPicker ), mnRet(nMagic) {}
1170 :
1171 : sal_Int16 GetReturnValue()
1172 : { ::osl::MutexGuard aGuard( maMutex ); return mnRet; }
1173 :
1174 0 : void SetReturnValue( sal_Int16 aRetValue )
1175 0 : { ::osl::MutexGuard aGuard( maMutex ); mnRet = aRetValue; }
1176 : };
1177 :
1178 0 : void SAL_CALL PickerThread_Impl::run()
1179 : {
1180 : try
1181 : {
1182 0 : sal_Int16 n = mxPicker->execute();
1183 0 : SetReturnValue( n );
1184 : }
1185 0 : catch( const RuntimeException& )
1186 : {
1187 0 : SetReturnValue( ExecutableDialogResults::CANCEL );
1188 : SAL_WARN( "sfx2.dialog", "RuntimeException caught" );
1189 : }
1190 0 : }
1191 :
1192 : // ------------------------------------------------------------------------
1193 0 : void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
1194 : {
1195 : DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
1196 0 : if ( !_pControlId || !_pHelpId )
1197 0 : return;
1198 :
1199 : // forward these ids to the file picker
1200 : try
1201 : {
1202 0 : const ::rtl::OUString sHelpIdPrefix( INET_HID_SCHEME );
1203 : // the ids for the single controls
1204 0 : uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1205 0 : if ( xControlAccess.is() )
1206 : {
1207 0 : while ( *_pControlId )
1208 : {
1209 : DBG_ASSERT( INetURLObject( rtl::OStringToOUString( *_pHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
1210 0 : ::rtl::OUString sId( sHelpIdPrefix );
1211 0 : sId += ::rtl::OUString( *_pHelpId, strlen( *_pHelpId ), RTL_TEXTENCODING_UTF8 );
1212 0 : xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
1213 :
1214 0 : ++_pControlId; ++_pHelpId;
1215 0 : }
1216 0 : }
1217 : }
1218 0 : catch( const Exception& )
1219 : {
1220 : OSL_FAIL( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
1221 : }
1222 : }
1223 :
1224 : // ------------------------------------------------------------------------
1225 0 : IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
1226 : {
1227 : (void)NOTINTERESTEDIN;
1228 0 : mnPostUserEventId = 0;
1229 0 : enablePasswordBox( sal_True );
1230 0 : updateFilterOptionsBox( );
1231 0 : updateSelectionBox( );
1232 :
1233 0 : return 0L;
1234 : }
1235 :
1236 : // ------------------------------------------------------------------------
1237 0 : void FileDialogHelper_Impl::preExecute()
1238 : {
1239 0 : loadConfig( );
1240 0 : setDefaultValues( );
1241 0 : updatePreviewState( sal_False );
1242 :
1243 0 : implInitializeFileName( );
1244 :
1245 : #if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
1246 : // allow for dialog implementations which need to be executed before they return valid values for
1247 : // current filter and such
1248 :
1249 : // On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
1250 : // through before it returns from execution
1251 0 : mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
1252 : #else
1253 : // However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
1254 : // get through in time... so we call the methods directly
1255 : enablePasswordBox( sal_True );
1256 : updateFilterOptionsBox( );
1257 : updateSelectionBox( );
1258 : #endif
1259 0 : }
1260 :
1261 : // ------------------------------------------------------------------------
1262 0 : void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
1263 : {
1264 0 : if ( ExecutableDialogResults::CANCEL != _nResult )
1265 0 : saveConfig();
1266 0 : }
1267 :
1268 : // ------------------------------------------------------------------------
1269 0 : void FileDialogHelper_Impl::implInitializeFileName( )
1270 : {
1271 0 : if ( !maFileName.isEmpty() )
1272 : {
1273 0 : INetURLObject aObj( maPath );
1274 0 : aObj.Append( maFileName );
1275 :
1276 : // in case we're operating as save dialog, and "auto extension" is checked,
1277 : // cut the extension from the name
1278 0 : if ( mbIsSaveDlg && mbHasAutoExt )
1279 : {
1280 : try
1281 : {
1282 0 : sal_Bool bAutoExtChecked = sal_False;
1283 :
1284 0 : uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
1285 0 : if ( xControlAccess.is()
1286 0 : && ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
1287 0 : >>= bAutoExtChecked
1288 : )
1289 : )
1290 : {
1291 0 : if ( bAutoExtChecked )
1292 : { // cut the extension
1293 0 : aObj.removeExtension( );
1294 0 : mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
1295 : }
1296 0 : }
1297 : }
1298 0 : catch( const Exception& )
1299 : {
1300 : OSL_FAIL( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
1301 : }
1302 0 : }
1303 : }
1304 0 : }
1305 :
1306 : // ------------------------------------------------------------------------
1307 0 : sal_Int16 FileDialogHelper_Impl::implDoExecute()
1308 : {
1309 0 : preExecute();
1310 :
1311 0 : sal_Int16 nRet = ExecutableDialogResults::CANCEL;
1312 :
1313 : //On MacOSX the native file picker has to run in the primordial thread because of drawing issues
1314 : //On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
1315 : //primordial thread as the ucb gnome-vfs2 provider was initialized in.
1316 :
1317 : {
1318 : try
1319 : {
1320 : #ifdef WNT
1321 : if ( mbSystemPicker )
1322 : {
1323 : SolarMutexReleaser aSolarMutex;
1324 : nRet = mxFileDlg->execute();
1325 : }
1326 : else
1327 : #endif
1328 0 : nRet = mxFileDlg->execute();
1329 : }
1330 0 : catch( const Exception& )
1331 : {
1332 : SAL_WARN( "sfx2.dialog", "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1333 : }
1334 : }
1335 :
1336 0 : postExecute( nRet );
1337 :
1338 0 : return nRet;
1339 : }
1340 :
1341 : // ------------------------------------------------------------------------
1342 0 : void FileDialogHelper_Impl::implStartExecute()
1343 : {
1344 : DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
1345 :
1346 0 : preExecute();
1347 :
1348 0 : if ( mbSystemPicker )
1349 : {
1350 : }
1351 : else
1352 : {
1353 : try
1354 : {
1355 0 : uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
1356 0 : if ( xAsyncDlg.is() )
1357 0 : xAsyncDlg->startExecuteModal( this );
1358 : }
1359 0 : catch( const Exception& )
1360 : {
1361 : SAL_WARN( "sfx2.dialog", "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
1362 : }
1363 : }
1364 0 : }
1365 :
1366 : // ------------------------------------------------------------------------
1367 0 : void lcl_saveLastURLs(std::vector<rtl::OUString>& rpURLList,
1368 : ::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
1369 : {
1370 0 : lLastURLs.clear();
1371 0 : for(std::vector<rtl::OUString>::iterator i = rpURLList.begin(); i != rpURLList.end(); ++i)
1372 0 : lLastURLs.push_back(*i);
1373 0 : }
1374 :
1375 : // ------------------------------------------------------------------------
1376 0 : void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker, std::vector<rtl::OUString>& rpURLList, const SfxFilter* pFilter)
1377 : {
1378 0 : rpURLList.clear();
1379 :
1380 0 : rtl::OUString sExtension;
1381 0 : if (pFilter)
1382 : {
1383 0 : sExtension = pFilter->GetDefaultExtension ();
1384 0 : sExtension = comphelper::string::remove(sExtension, '*');
1385 0 : sExtension = comphelper::string::remove(sExtension, '.');
1386 : }
1387 :
1388 : // a) the new way (optional!)
1389 0 : uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
1390 0 : if (xPickNew.is())
1391 : {
1392 0 : Sequence< OUString > lFiles = xPickNew->getSelectedFiles();
1393 0 : ::sal_Int32 nFiles = lFiles.getLength();
1394 0 : for(sal_Int32 i = 0; i < nFiles; ++i)
1395 0 : rpURLList.push_back(lFiles[i]);
1396 : }
1397 :
1398 : // b) the olde way ... non optional.
1399 : else
1400 : {
1401 0 : uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
1402 0 : Sequence< OUString > lFiles = xPickOld->getFiles();
1403 0 : ::sal_Int32 nFiles = lFiles.getLength();
1404 0 : if ( nFiles == 1 )
1405 : {
1406 0 : rpURLList.push_back(lFiles[0]);
1407 : }
1408 0 : else if ( nFiles > 1 )
1409 : {
1410 0 : INetURLObject aPath( lFiles[0] );
1411 0 : aPath.setFinalSlash();
1412 :
1413 0 : for (::sal_Int32 i = 1; i < nFiles; i++)
1414 : {
1415 0 : if (i == 1)
1416 0 : aPath.Append( lFiles[i] );
1417 : else
1418 0 : aPath.setName( lFiles[i] );
1419 :
1420 0 : rpURLList.push_back(aPath.GetMainURL(INetURLObject::NO_DECODE));
1421 0 : }
1422 0 : }
1423 : }
1424 :
1425 0 : lcl_saveLastURLs(rpURLList, mlLastURLs);
1426 0 : }
1427 :
1428 : // ------------------------------------------------------------------------
1429 0 : ErrCode FileDialogHelper_Impl::execute( std::vector<rtl::OUString>& rpURLList,
1430 : SfxItemSet *& rpSet,
1431 : String& rFilter )
1432 : {
1433 : // rFilter is a pure output parameter, it shouldn't be used for anything else
1434 : // changing this would surely break code
1435 : // rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
1436 :
1437 0 : uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
1438 :
1439 : // retrieves parameters from rpSet
1440 : // for now only Password is used
1441 0 : if ( rpSet )
1442 : {
1443 : // check password checkbox if the document had password before
1444 0 : if( mbHasPassword )
1445 : {
1446 0 : SFX_ITEMSET_ARG( rpSet, pPassItem, SfxBoolItem, SID_PASSWORDINTERACTION, sal_False );
1447 0 : mbPwdCheckBoxState = ( pPassItem != NULL && pPassItem->GetValue() );
1448 :
1449 : // in case the document has password to modify, the dialog should be shown
1450 0 : SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
1451 0 : mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() );
1452 : }
1453 :
1454 0 : SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False );
1455 0 : if ( pSelectItem )
1456 0 : mbSelection = pSelectItem->GetValue();
1457 : else
1458 0 : mbSelectionEnabled = sal_False;
1459 :
1460 : // the password will be set in case user decide so
1461 0 : rpSet->ClearItem( SID_PASSWORDINTERACTION );
1462 0 : rpSet->ClearItem( SID_PASSWORD );
1463 0 : rpSet->ClearItem( SID_ENCRYPTIONDATA );
1464 0 : rpSet->ClearItem( SID_RECOMMENDREADONLY );
1465 0 : rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
1466 :
1467 : }
1468 :
1469 0 : if ( mbHasPassword && !mbPwdCheckBoxState )
1470 : {
1471 0 : SvtSecurityOptions aSecOpt;
1472 : mbPwdCheckBoxState = (
1473 0 : aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
1474 : }
1475 :
1476 0 : rpURLList.clear();
1477 :
1478 0 : if ( ! mxFileDlg.is() )
1479 0 : return ERRCODE_ABORT;
1480 :
1481 0 : if ( ExecutableDialogResults::CANCEL != implDoExecute() )
1482 : {
1483 : // create an itemset if there is no
1484 0 : if( !rpSet )
1485 0 : rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
1486 :
1487 : // the item should remain only if it was set by the dialog
1488 0 : rpSet->ClearItem( SID_SELECTION );
1489 :
1490 0 : if( mbExport && mbHasSelectionBox )
1491 : {
1492 : try
1493 : {
1494 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
1495 0 : sal_Bool bSelection = sal_False;
1496 0 : if ( aValue >>= bSelection )
1497 0 : rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
1498 : }
1499 0 : catch( const IllegalArgumentException& )
1500 : {
1501 : OSL_FAIL( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1502 : }
1503 : }
1504 :
1505 :
1506 : // set the read-only flag. When inserting a file, this flag is always set
1507 0 : if ( mbInsert )
1508 0 : rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
1509 : else
1510 : {
1511 0 : if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
1512 : {
1513 : try
1514 : {
1515 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
1516 0 : sal_Bool bReadOnly = sal_False;
1517 0 : if ( ( aValue >>= bReadOnly ) && bReadOnly )
1518 0 : rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
1519 : }
1520 0 : catch( const IllegalArgumentException& )
1521 : {
1522 : OSL_FAIL( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
1523 : }
1524 : }
1525 : }
1526 0 : if ( mbHasVersions && xCtrlAccess.is() )
1527 : {
1528 : try
1529 : {
1530 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
1531 0 : ControlActions::GET_SELECTED_ITEM_INDEX );
1532 0 : sal_Int32 nVersion = 0;
1533 0 : if ( ( aValue >>= nVersion ) && nVersion > 0 )
1534 : // open a special version; 0 == current version
1535 0 : rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
1536 : }
1537 0 : catch( const IllegalArgumentException& ){}
1538 : }
1539 :
1540 : // set the filter
1541 0 : getRealFilter( rFilter );
1542 :
1543 0 : const SfxFilter* pCurrentFilter = getCurentSfxFilter();
1544 :
1545 : // fill the rpURLList
1546 0 : implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
1547 0 : if ( rpURLList.empty() )
1548 0 : return ERRCODE_ABORT;
1549 :
1550 : // check, whether or not we have to display a password box
1551 0 : if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
1552 : {
1553 : try
1554 : {
1555 0 : Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
1556 0 : sal_Bool bPassWord = sal_False;
1557 0 : if ( ( aValue >>= bPassWord ) && bPassWord )
1558 : {
1559 : // ask for a password
1560 0 : rtl::OUString aDocName(rpURLList[0]);
1561 0 : ErrCode errCode = RequestPassword(pCurrentFilter, aDocName, rpSet);
1562 0 : if (errCode != ERRCODE_NONE)
1563 0 : return errCode;
1564 0 : }
1565 : }
1566 0 : catch( const IllegalArgumentException& ){}
1567 : }
1568 :
1569 0 : SaveLastUsedFilter();
1570 0 : return ERRCODE_NONE;
1571 : }
1572 : else
1573 0 : return ERRCODE_ABORT;
1574 : }
1575 :
1576 : // ------------------------------------------------------------------------
1577 0 : ErrCode FileDialogHelper_Impl::execute()
1578 : {
1579 0 : if ( ! mxFileDlg.is() )
1580 0 : return ERRCODE_ABORT;
1581 :
1582 0 : sal_Int16 nRet = implDoExecute();
1583 :
1584 0 : maPath = mxFileDlg->getDisplayDirectory();
1585 :
1586 0 : if ( ExecutableDialogResults::CANCEL == nRet )
1587 0 : return ERRCODE_ABORT;
1588 : else
1589 : {
1590 0 : return ERRCODE_NONE;
1591 : }
1592 : }
1593 :
1594 : // ------------------------------------------------------------------------
1595 0 : OUString FileDialogHelper_Impl::getPath() const
1596 : {
1597 0 : OUString aPath;
1598 :
1599 0 : if ( mxFileDlg.is() )
1600 0 : aPath = mxFileDlg->getDisplayDirectory();
1601 :
1602 0 : if ( aPath.isEmpty() )
1603 0 : aPath = maPath;
1604 :
1605 0 : return aPath;
1606 : }
1607 :
1608 : // ------------------------------------------------------------------------
1609 0 : OUString FileDialogHelper_Impl::getFilter() const
1610 : {
1611 0 : String aFilter = getCurrentFilterUIName();
1612 :
1613 0 : if( !aFilter.Len() )
1614 0 : aFilter = maCurFilter;
1615 :
1616 0 : return aFilter;
1617 : }
1618 :
1619 : // ------------------------------------------------------------------------
1620 0 : void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
1621 : {
1622 0 : _rFilter = getCurrentFilterUIName();
1623 :
1624 0 : if ( !_rFilter.Len() )
1625 0 : _rFilter = maCurFilter;
1626 :
1627 0 : if ( _rFilter.Len() && mpMatcher )
1628 : {
1629 : const SfxFilter* pFilter =
1630 0 : mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
1631 0 : _rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
1632 : }
1633 0 : }
1634 :
1635 0 : void FileDialogHelper_Impl::verifyPath()
1636 : {
1637 : #ifdef UNX
1638 : // lp#905355, fdo#43895
1639 : // Check that the file has read only permission and is in /tmp -- this is
1640 : // the case if we have opened the file from the web with firefox only.
1641 0 : if (maFileName.isEmpty()) {
1642 : return;
1643 : }
1644 0 : INetURLObject url(maPath);
1645 0 : if (url.GetProtocol() != INET_PROT_FILE
1646 0 : || url.getName(0, true, INetURLObject::DECODE_WITH_CHARSET) != "tmp")
1647 : {
1648 : return;
1649 : }
1650 0 : if (maFileName.indexOf('/') != -1) {
1651 : SAL_WARN("sfx2", maFileName << " contains /");
1652 : return;
1653 : }
1654 : url.insertName(
1655 : maFileName, false, INetURLObject::LAST_SEGMENT, true,
1656 0 : INetURLObject::ENCODE_ALL);
1657 0 : rtl::OUString sysPathU;
1658 : osl::FileBase::RC e = osl::FileBase::getSystemPathFromFileURL(
1659 0 : url.GetMainURL(INetURLObject::NO_DECODE), sysPathU);
1660 0 : if (e != osl::FileBase::E_None) {
1661 : SAL_WARN(
1662 : "sfx2",
1663 : "getSystemPathFromFileURL("
1664 : << url.GetMainURL(INetURLObject::NO_DECODE) << ") failed with "
1665 : << +e);
1666 : return;
1667 : }
1668 0 : rtl::OString sysPathC;
1669 0 : if (!sysPathU.convertToString(
1670 0 : &sysPathC, osl_getThreadTextEncoding(),
1671 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
1672 0 : | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
1673 : {
1674 : SAL_WARN(
1675 : "sfx2",
1676 : "convertToString(" << sysPathU << ") failed for encoding "
1677 : << +osl_getThreadTextEncoding());
1678 : return;
1679 : }
1680 : struct stat aFileStat;
1681 0 : if (stat(sysPathC.getStr(), &aFileStat) == -1) {
1682 : SAL_WARN(
1683 : "sfx2",
1684 : "stat(" << sysPathC.getStr() << ") failed with errno " << errno);
1685 : return;
1686 : }
1687 0 : if ((aFileStat.st_mode & (S_IRWXO | S_IRWXG | S_IRWXU)) == S_IRUSR) {
1688 0 : maPath = SvtPathOptions().GetWorkPath();
1689 0 : mxFileDlg->setDisplayDirectory( maPath );
1690 0 : }
1691 : #endif
1692 : }
1693 :
1694 : // ------------------------------------------------------------------------
1695 0 : void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
1696 : {
1697 0 : if ( _rPath.isEmpty() )
1698 : // nothing to do
1699 0 : return;
1700 :
1701 0 : maPath = _rPath;
1702 0 : if ( mxFileDlg.is() )
1703 : {
1704 : try
1705 : {
1706 0 : mxFileDlg->setDisplayDirectory( maPath );
1707 0 : verifyPath();
1708 : }
1709 0 : catch( const IllegalArgumentException& )
1710 : {
1711 : OSL_FAIL( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
1712 : }
1713 : }
1714 : }
1715 :
1716 : // ------------------------------------------------------------------------
1717 0 : void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
1718 : {
1719 0 : maFileName = _rFile;
1720 0 : if ( mxFileDlg.is() )
1721 : {
1722 : try
1723 : {
1724 0 : mxFileDlg->setDefaultName( maFileName );
1725 0 : verifyPath();
1726 : }
1727 0 : catch( const IllegalArgumentException& )
1728 : {
1729 : OSL_FAIL( "FileDialogHelper_Impl::setFileName: caught an exception!" );
1730 : }
1731 : }
1732 0 : }
1733 :
1734 : // ------------------------------------------------------------------------
1735 0 : void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
1736 : {
1737 : DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
1738 :
1739 0 : maCurFilter = rFilter;
1740 :
1741 0 : if ( !rFilter.isEmpty() && mpMatcher )
1742 : {
1743 : const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
1744 0 : rFilter, m_nMustFlags, m_nDontFlags );
1745 0 : if ( pFilter )
1746 0 : maCurFilter = pFilter->GetUIName();
1747 : }
1748 :
1749 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1750 :
1751 0 : if ( !maCurFilter.isEmpty() && xFltMgr.is() )
1752 : {
1753 : try
1754 : {
1755 0 : xFltMgr->setCurrentFilter( maCurFilter );
1756 : }
1757 0 : catch( const IllegalArgumentException& ){}
1758 0 : }
1759 0 : }
1760 :
1761 : // ------------------------------------------------------------------------
1762 0 : void FileDialogHelper_Impl::createMatcher( const String& rFactory )
1763 : {
1764 0 : mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
1765 0 : mbDeleteMatcher = sal_True;
1766 0 : }
1767 :
1768 : // ------------------------------------------------------------------------
1769 0 : void FileDialogHelper_Impl::addFilters( const String& rFactory,
1770 : SfxFilterFlags nMust,
1771 : SfxFilterFlags nDont )
1772 : {
1773 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1774 :
1775 0 : if ( ! xFltMgr.is() )
1776 : return;
1777 :
1778 : // we still need a matcher to convert UI names to filter names
1779 0 : if ( !rFactory.Len() )
1780 : {
1781 0 : SfxApplication *pSfxApp = SFX_APP();
1782 0 : mpMatcher = &pSfxApp->GetFilterMatcher();
1783 0 : mbDeleteMatcher = sal_False;
1784 : }
1785 : else
1786 : {
1787 0 : mpMatcher = new SfxFilterMatcher( rFactory );
1788 0 : mbDeleteMatcher = sal_True;
1789 : }
1790 :
1791 0 : uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
1792 : uno::Reference< XContainerQuery > xFilterCont(
1793 0 : xSMGR->createInstance(::rtl::OUString("com.sun.star.document.FilterFactory")),
1794 0 : UNO_QUERY);
1795 0 : if ( ! xFilterCont.is() )
1796 : return;
1797 :
1798 0 : m_nMustFlags |= nMust;
1799 0 : m_nDontFlags |= nDont;
1800 :
1801 : // create the list of filters
1802 0 : ::rtl::OUStringBuffer sQuery(256);
1803 0 : sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM("getSortedFilterList()"));
1804 0 : sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":module="));
1805 0 : sQuery.append(rFactory); // use long name here !
1806 0 : sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":iflags="));
1807 0 : sQuery.append(::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
1808 0 : sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":eflags="));
1809 0 : sQuery.append(::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
1810 :
1811 0 : uno::Reference< XEnumeration > xResult;
1812 : try
1813 : {
1814 0 : xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
1815 : }
1816 0 : catch( const uno::Exception& )
1817 : {
1818 : SAL_WARN( "sfx2.dialog", "Could not get filters from the configuration!" );
1819 : }
1820 :
1821 0 : TSortedFilterList aIter (xResult);
1822 :
1823 : // no matcher any longer used ...
1824 0 : mbDeleteMatcher = sal_False;
1825 :
1826 : // append the filters
1827 0 : ::rtl::OUString sFirstFilter;
1828 0 : if (OPEN == lcl_OpenOrSave(m_nDialogType))
1829 0 : ::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
1830 0 : else if ( mbExport )
1831 0 : ::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
1832 : else
1833 0 : ::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
1834 :
1835 : // set our initial selected filter (if we do not already have one)
1836 0 : if ( maSelectFilter.isEmpty() )
1837 0 : maSelectFilter = sFirstFilter;
1838 : }
1839 :
1840 : // ------------------------------------------------------------------------
1841 0 : void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
1842 : const OUString& rExtension )
1843 : {
1844 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1845 :
1846 0 : if ( ! xFltMgr.is() )
1847 0 : return;
1848 :
1849 : try
1850 : {
1851 0 : xFltMgr->appendFilter( rFilterName, rExtension );
1852 :
1853 0 : if ( maSelectFilter.isEmpty() )
1854 0 : maSelectFilter = rFilterName;
1855 : }
1856 0 : catch( const IllegalArgumentException& )
1857 : {
1858 : SAL_WARN( "sfx2.dialog", "Could not append Filter" << rFilterName );
1859 0 : }
1860 : }
1861 :
1862 : // ------------------------------------------------------------------------
1863 0 : void FileDialogHelper_Impl::addGraphicFilter()
1864 : {
1865 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
1866 :
1867 0 : if ( ! xFltMgr.is() )
1868 0 : return;
1869 :
1870 : // create the list of filters
1871 0 : mpGraphicFilter = new GraphicFilter;
1872 0 : sal_uInt16 i, j, nCount = mpGraphicFilter->GetImportFormatCount();
1873 :
1874 : // compute the extension string for all known import filters
1875 0 : String aExtensions;
1876 :
1877 0 : for ( i = 0; i < nCount; i++ )
1878 : {
1879 0 : j = 0;
1880 0 : String sWildcard;
1881 0 : while( sal_True )
1882 : {
1883 0 : sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
1884 0 : if ( !sWildcard.Len() )
1885 0 : break;
1886 0 : if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
1887 : {
1888 0 : if ( aExtensions.Len() )
1889 0 : aExtensions += sal_Unicode(';');
1890 0 : aExtensions += sWildcard;
1891 : }
1892 : }
1893 0 : }
1894 :
1895 : #if defined(WNT)
1896 : if ( aExtensions.Len() > 240 )
1897 : aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
1898 : #endif
1899 0 : sal_Bool bIsInOpenMode = isInOpenMode();
1900 :
1901 : try
1902 : {
1903 0 : OUString aAllFilterName = SfxResId( STR_SFX_IMPORT_ALL ).toString();
1904 0 : aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
1905 :
1906 0 : xFltMgr->appendFilter( aAllFilterName, aExtensions );
1907 0 : maSelectFilter = aAllFilterName;
1908 : }
1909 0 : catch( const IllegalArgumentException& )
1910 : {
1911 : SAL_WARN( "sfx2.dialog", "Could not append Filter" );
1912 : }
1913 :
1914 : // Now add the filter
1915 0 : for ( i = 0; i < nCount; i++ )
1916 : {
1917 0 : String aName = mpGraphicFilter->GetImportFormatName( i );
1918 0 : String aExt;
1919 0 : j = 0;
1920 0 : String sWildcard;
1921 0 : while( sal_True )
1922 : {
1923 0 : sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
1924 0 : if ( !sWildcard.Len() )
1925 0 : break;
1926 0 : if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
1927 : {
1928 0 : if ( aExt.Len() )
1929 0 : aExt += sal_Unicode(';');
1930 0 : aExt += sWildcard;
1931 : }
1932 : }
1933 0 : aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
1934 : try
1935 : {
1936 0 : xFltMgr->appendFilter( aName, aExt );
1937 : }
1938 0 : catch( const IllegalArgumentException& )
1939 : {
1940 : SAL_WARN( "sfx2.dialog", "Could not append Filter" );
1941 : }
1942 0 : }
1943 : }
1944 :
1945 : // ------------------------------------------------------------------------
1946 : #define GRF_CONFIG_STR " "
1947 : #define STD_CONFIG_STR "1 "
1948 :
1949 0 : void FileDialogHelper_Impl::saveConfig()
1950 : {
1951 0 : uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
1952 0 : Any aValue;
1953 :
1954 0 : if ( ! xDlg.is() )
1955 0 : return;
1956 :
1957 0 : if ( mbHasPreview )
1958 : {
1959 0 : SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
1960 0 : String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
1961 :
1962 : try
1963 : {
1964 0 : sal_Bool bValue = sal_False;
1965 0 : aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
1966 0 : bValue = sal_False;
1967 0 : aValue >>= bValue;
1968 0 : aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
1969 :
1970 0 : INetURLObject aObj( getPath() );
1971 :
1972 0 : if ( aObj.GetProtocol() == INET_PROT_FILE )
1973 0 : aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1974 :
1975 0 : String aFilter = getFilter();
1976 0 : aFilter = EncodeSpaces_Impl( aFilter );
1977 0 : aUserData.SetToken( 3, ' ', aFilter );
1978 :
1979 0 : aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
1980 : }
1981 0 : catch( const IllegalArgumentException& ){}
1982 : }
1983 : else
1984 : {
1985 0 : sal_Bool bWriteConfig = sal_False;
1986 0 : SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
1987 0 : String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
1988 :
1989 0 : if ( aDlgOpt.Exists() )
1990 : {
1991 0 : Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
1992 0 : OUString aTemp;
1993 0 : if ( aUserItem >>= aTemp )
1994 0 : aUserData = String( aTemp );
1995 : }
1996 :
1997 0 : if ( mbHasAutoExt )
1998 : {
1999 : try
2000 : {
2001 0 : aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
2002 0 : sal_Bool bAutoExt = sal_True;
2003 0 : aValue >>= bAutoExt;
2004 0 : aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
2005 0 : bWriteConfig = sal_True;
2006 : }
2007 0 : catch( const IllegalArgumentException& ){}
2008 : }
2009 :
2010 0 : if ( ! mbIsSaveDlg )
2011 : {
2012 0 : OUString aPath = getPath();
2013 0 : if ( !aPath.isEmpty() &&
2014 0 : utl::LocalFileHelper::IsLocalFile( aPath ) )
2015 : {
2016 0 : aUserData.SetToken( 1, ' ', aPath );
2017 0 : bWriteConfig = sal_True;
2018 0 : }
2019 : }
2020 :
2021 0 : if( mbHasSelectionBox && mbSelectionFltrEnabled )
2022 : {
2023 : try
2024 : {
2025 0 : aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
2026 0 : sal_Bool bSelection = sal_True;
2027 0 : aValue >>= bSelection;
2028 0 : if ( comphelper::string::getTokenCount(aUserData, ' ') < 3 )
2029 0 : aUserData.Append(' ');
2030 0 : aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) );
2031 0 : bWriteConfig = sal_True;
2032 : }
2033 0 : catch( const IllegalArgumentException& ){}
2034 : }
2035 :
2036 0 : if ( bWriteConfig )
2037 0 : aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
2038 : }
2039 :
2040 0 : SfxApplication *pSfxApp = SFX_APP();
2041 0 : pSfxApp->SetLastDir_Impl( getPath() );
2042 : }
2043 :
2044 : // ------------------------------------------------------------------------
2045 : namespace
2046 : {
2047 0 : static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
2048 : {
2049 0 : SfxApplication *pSfxApp = SFX_APP();
2050 0 : String sPath = pSfxApp->GetLastDir_Impl();
2051 :
2052 0 : if ( !sPath.Len() )
2053 0 : sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
2054 :
2055 : // check if the path points to a valid (accessible) directory
2056 0 : sal_Bool bValid = sal_False;
2057 0 : if ( sPath.Len() )
2058 : {
2059 0 : String sPathCheck( sPath );
2060 0 : if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
2061 0 : sPathCheck += '/';
2062 0 : sPathCheck += '.';
2063 : try
2064 : {
2065 0 : ::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
2066 0 : bValid = aContent.isFolder();
2067 : }
2068 0 : catch( const Exception& ) {}
2069 : }
2070 :
2071 0 : if ( !bValid )
2072 0 : sPath.Erase();
2073 :
2074 0 : return sPath;
2075 : }
2076 : }
2077 :
2078 : // ------------------------------------------------------------------------
2079 0 : void FileDialogHelper_Impl::loadConfig()
2080 : {
2081 0 : uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
2082 0 : Any aValue;
2083 :
2084 0 : if ( ! xDlg.is() )
2085 0 : return;
2086 :
2087 0 : if ( mbHasPreview )
2088 : {
2089 0 : SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
2090 0 : String aUserData;
2091 :
2092 0 : if ( aViewOpt.Exists() )
2093 : {
2094 0 : Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2095 0 : OUString aTemp;
2096 0 : if ( aUserItem >>= aTemp )
2097 0 : aUserData = String( aTemp );
2098 : }
2099 :
2100 0 : if ( aUserData.Len() > 0 )
2101 : {
2102 : try
2103 : {
2104 : // respect the last "insert as link" state
2105 0 : sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32();
2106 0 : aValue <<= bLink;
2107 0 : xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
2108 :
2109 : // respect the last "show preview" state
2110 0 : sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
2111 0 : aValue <<= bShowPreview;
2112 0 : xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
2113 :
2114 0 : if ( maPath.isEmpty() )
2115 0 : displayFolder( getInitPath( aUserData, 2 ) );
2116 :
2117 0 : if ( maCurFilter.isEmpty() )
2118 : {
2119 0 : String aFilter = aUserData.GetToken( 3, ' ' );
2120 0 : aFilter = DecodeSpaces_Impl( aFilter );
2121 0 : setFilter( aFilter );
2122 : }
2123 :
2124 : // set the member so we know that we have to show the preview
2125 0 : mbShowPreview = bShowPreview;
2126 : }
2127 0 : catch( const IllegalArgumentException& ){}
2128 : }
2129 :
2130 0 : if ( maPath.isEmpty() )
2131 0 : displayFolder( SvtPathOptions().GetGraphicPath() );
2132 : }
2133 : else
2134 : {
2135 0 : SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
2136 0 : String aUserData;
2137 :
2138 0 : if ( aViewOpt.Exists() )
2139 : {
2140 0 : Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2141 0 : OUString aTemp;
2142 0 : if ( aUserItem >>= aTemp )
2143 0 : aUserData = String( aTemp );
2144 : }
2145 :
2146 0 : if ( ! aUserData.Len() )
2147 0 : aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
2148 :
2149 0 : if ( maPath.isEmpty() )
2150 0 : displayFolder( getInitPath( aUserData, 1 ) );
2151 :
2152 0 : if ( mbHasAutoExt )
2153 : {
2154 0 : sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
2155 0 : aValue <<= (sal_Bool) nFlag;
2156 : try
2157 : {
2158 0 : xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
2159 : }
2160 0 : catch( const IllegalArgumentException& ){}
2161 : }
2162 :
2163 0 : if( mbHasSelectionBox )
2164 : {
2165 0 : sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32();
2166 0 : aValue <<= (sal_Bool) nFlag;
2167 : try
2168 : {
2169 0 : xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue );
2170 : }
2171 0 : catch( const IllegalArgumentException& ){}
2172 : }
2173 :
2174 0 : if ( maPath.isEmpty() )
2175 0 : displayFolder( SvtPathOptions().GetWorkPath() );
2176 0 : }
2177 : }
2178 :
2179 : // ------------------------------------------------------------------------
2180 0 : void FileDialogHelper_Impl::setDefaultValues()
2181 : {
2182 : // when no filter is set, we set the curentFilter to <all>
2183 0 : if ( maCurFilter.isEmpty() && !maSelectFilter.isEmpty() )
2184 : {
2185 0 : uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
2186 : try
2187 : {
2188 0 : xFltMgr->setCurrentFilter( maSelectFilter );
2189 : }
2190 0 : catch( const IllegalArgumentException& )
2191 0 : {}
2192 : }
2193 :
2194 : // when no path is set, we use the standard 'work' folder
2195 0 : if ( maPath.isEmpty() )
2196 : {
2197 0 : OUString aWorkFolder = SvtPathOptions().GetWorkPath();
2198 : try
2199 : {
2200 0 : mxFileDlg->setDisplayDirectory( aWorkFolder );
2201 : }
2202 0 : catch( const Exception& )
2203 : {
2204 : OSL_FAIL( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
2205 0 : }
2206 : }
2207 0 : }
2208 :
2209 0 : sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
2210 : {
2211 0 : return !maFilters.empty();
2212 : }
2213 :
2214 0 : void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
2215 : const OUString& rFilterWithExtension )
2216 : {
2217 0 : maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
2218 :
2219 0 : }
2220 :
2221 0 : OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
2222 : {
2223 0 : OUString sRet;
2224 0 : for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2225 : {
2226 0 : if ( (*pIter).Second == rFilterWithExtension )
2227 : {
2228 0 : sRet = (*pIter).First;
2229 0 : break;
2230 : }
2231 : }
2232 0 : return sRet;
2233 : }
2234 :
2235 0 : OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
2236 : {
2237 0 : OUString sRet;
2238 0 : for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
2239 : {
2240 0 : if ( (*pIter).First == rFilter )
2241 : {
2242 0 : sRet = (*pIter).Second;
2243 0 : break;
2244 : }
2245 : }
2246 0 : return sRet;
2247 : }
2248 :
2249 0 : void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
2250 : {
2251 0 : meContext = _eNewContext;
2252 :
2253 0 : const OUString* pConfigId = GetLastFilterConfigId( _eNewContext );
2254 0 : if( pConfigId )
2255 0 : LoadLastUsedFilter( *pConfigId );
2256 0 : }
2257 :
2258 : // ------------------------------------------------------------------------
2259 : // ----------- FileDialogHelper ---------------------------
2260 : // ------------------------------------------------------------------------
2261 :
2262 0 : FileDialogHelper::FileDialogHelper(
2263 : sal_Int16 nDialogType,
2264 : sal_Int64 nFlags,
2265 : const String& rFact,
2266 : SfxFilterFlags nMust,
2267 0 : SfxFilterFlags nDont )
2268 : {
2269 0 : mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
2270 0 : mxImp = mpImp;
2271 :
2272 : // create the list of filters
2273 : mpImp->addFilters(
2274 0 : SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2275 0 : }
2276 :
2277 : // ------------------------------------------------------------------------
2278 0 : FileDialogHelper::FileDialogHelper(
2279 : sal_Int16 nDialogType,
2280 : sal_Int64 nFlags,
2281 : const String& rFact,
2282 : sal_Int16 nDialog,
2283 : SfxFilterFlags nMust,
2284 : SfxFilterFlags nDont,
2285 : const String& rStandardDir,
2286 0 : const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
2287 : {
2288 0 : mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
2289 0 : mxImp = mpImp;
2290 :
2291 : // create the list of filters
2292 : mpImp->addFilters(
2293 0 : SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
2294 0 : }
2295 :
2296 : // ------------------------------------------------------------------------
2297 0 : FileDialogHelper::FileDialogHelper(
2298 : sal_Int16 nDialogType,
2299 : sal_Int64 nFlags,
2300 0 : Window* _pPreferredParent )
2301 : {
2302 0 : mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
2303 0 : mxImp = mpImp;
2304 0 : }
2305 :
2306 : // ------------------------------------------------------------------------
2307 0 : FileDialogHelper::FileDialogHelper(
2308 : sal_Int16 nDialogType,
2309 : sal_Int64 nFlags,
2310 : const ::rtl::OUString& aFilterUIName,
2311 : const ::rtl::OUString& aExtName,
2312 : const ::rtl::OUString& rStandardDir,
2313 : const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
2314 0 : Window* _pPreferredParent )
2315 : {
2316 0 : mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
2317 0 : mxImp = mpImp;
2318 :
2319 : // the wildcard here is expected in form "*.extension"
2320 0 : ::rtl::OUString aWildcard;
2321 0 : if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
2322 : {
2323 0 : if ( !aExtName.isEmpty() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
2324 0 : aWildcard = ::rtl::OUString( "*." );
2325 : else
2326 0 : aWildcard = ::rtl::OUString( "*" );
2327 : }
2328 :
2329 0 : aWildcard += aExtName;
2330 :
2331 : ::rtl::OUString const aUIString = ::sfx2::addExtension( aFilterUIName,
2332 0 : aWildcard, (OPEN == lcl_OpenOrSave(mpImp->m_nDialogType)), *mpImp);
2333 0 : AddFilter( aUIString, aWildcard );
2334 0 : }
2335 :
2336 : // ------------------------------------------------------------------------
2337 0 : FileDialogHelper::~FileDialogHelper()
2338 : {
2339 0 : mpImp->dispose();
2340 0 : mxImp.clear();
2341 0 : }
2342 :
2343 : // ------------------------------------------------------------------------
2344 0 : void FileDialogHelper::CreateMatcher( const String& rFactory )
2345 : {
2346 0 : mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
2347 0 : }
2348 :
2349 : // ------------------------------------------------------------------------
2350 0 : void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
2351 : {
2352 0 : mpImp->setControlHelpIds( _pControlId, _pHelpId );
2353 0 : }
2354 :
2355 0 : void FileDialogHelper::SetContext( Context _eNewContext )
2356 : {
2357 0 : mpImp->SetContext( _eNewContext );
2358 0 : }
2359 :
2360 : // ------------------------------------------------------------------------
2361 0 : IMPL_LINK_NOARG(FileDialogHelper, ExecuteSystemFilePicker)
2362 : {
2363 0 : m_nError = mpImp->execute();
2364 0 : if ( m_aDialogClosedLink.IsSet() )
2365 0 : m_aDialogClosedLink.Call( this );
2366 :
2367 0 : return 0L;
2368 : }
2369 :
2370 : // ------------------------------------------------------------------------
2371 : // rDirPath has to be a directory
2372 0 : ErrCode FileDialogHelper::Execute( std::vector<rtl::OUString>& rpURLList,
2373 : SfxItemSet *& rpSet,
2374 : String& rFilter,
2375 : const String& rDirPath )
2376 : {
2377 0 : SetDisplayFolder( rDirPath );
2378 0 : return mpImp->execute( rpURLList, rpSet, rFilter );
2379 : }
2380 :
2381 :
2382 : // ------------------------------------------------------------------------
2383 0 : ErrCode FileDialogHelper::Execute()
2384 : {
2385 0 : return mpImp->execute();
2386 : }
2387 :
2388 : // ------------------------------------------------------------------------
2389 0 : ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet,
2390 : String& rFilter )
2391 : {
2392 : ErrCode nRet;
2393 0 : std::vector<rtl::OUString> rURLList;
2394 0 : nRet = mpImp->execute(rURLList, rpSet, rFilter);
2395 0 : return nRet;
2396 : }
2397 :
2398 0 : void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
2399 : {
2400 0 : m_aDialogClosedLink = rEndDialogHdl;
2401 0 : m_nError = ERRCODE_NONE;
2402 0 : if ( mpImp->isSystemFilePicker() )
2403 0 : Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
2404 : else
2405 0 : mpImp->implStartExecute();
2406 0 : }
2407 :
2408 : // ------------------------------------------------------------------------
2409 :
2410 0 : short FileDialogHelper::GetDialogType() const
2411 : {
2412 0 : return mpImp ? mpImp->m_nDialogType : 0;
2413 : }
2414 :
2415 : // ------------------------------------------------------------------------
2416 :
2417 0 : sal_Bool FileDialogHelper::IsPasswordEnabled() const
2418 : {
2419 0 : return mpImp ? mpImp->isPasswordEnabled() : sal_False;
2420 : }
2421 :
2422 : // ------------------------------------------------------------------------
2423 :
2424 0 : String FileDialogHelper::GetRealFilter() const
2425 : {
2426 0 : String sFilter;
2427 0 : if ( mpImp )
2428 0 : mpImp->getRealFilter( sFilter );
2429 0 : return sFilter;
2430 : }
2431 :
2432 : // ------------------------------------------------------------------------
2433 0 : void FileDialogHelper::SetTitle( const String& rNewTitle )
2434 : {
2435 0 : if ( mpImp->mxFileDlg.is() )
2436 0 : mpImp->mxFileDlg->setTitle( rNewTitle );
2437 0 : }
2438 :
2439 : // ------------------------------------------------------------------------
2440 0 : String FileDialogHelper::GetPath() const
2441 : {
2442 0 : OUString aPath;
2443 :
2444 0 : if ( mpImp->mlLastURLs.size() > 0)
2445 0 : return mpImp->mlLastURLs[0];
2446 :
2447 0 : if ( mpImp->mxFileDlg.is() )
2448 : {
2449 0 : Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
2450 :
2451 0 : if ( aPathSeq.getLength() == 1 )
2452 : {
2453 0 : aPath = aPathSeq[0];
2454 0 : }
2455 : }
2456 :
2457 0 : return aPath;
2458 : }
2459 :
2460 : // ------------------------------------------------------------------------
2461 0 : Sequence < OUString > FileDialogHelper::GetMPath() const
2462 : {
2463 0 : if ( mpImp->mlLastURLs.size() > 0)
2464 0 : return mpImp->mlLastURLs.getAsConstList();
2465 :
2466 0 : if ( mpImp->mxFileDlg.is() )
2467 0 : return mpImp->mxFileDlg->getFiles();
2468 : else
2469 : {
2470 0 : Sequence < OUString > aEmpty;
2471 0 : return aEmpty;
2472 : }
2473 : }
2474 :
2475 : // ------------------------------------------------------------------------
2476 0 : Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
2477 : {
2478 : // a) the new way (optional!)
2479 0 : uno::Sequence< ::rtl::OUString > aResultSeq;
2480 0 : uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
2481 0 : if (xPickNew.is())
2482 : {
2483 0 : aResultSeq = xPickNew->getSelectedFiles();
2484 : }
2485 : // b) the olde way ... non optional.
2486 : else
2487 : {
2488 0 : uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
2489 0 : Sequence< OUString > lFiles = xPickOld->getFiles();
2490 0 : ::sal_Int32 nFiles = lFiles.getLength();
2491 0 : if ( nFiles > 1 )
2492 : {
2493 0 : aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
2494 :
2495 0 : INetURLObject aPath( lFiles[0] );
2496 0 : aPath.setFinalSlash();
2497 :
2498 0 : for (::sal_Int32 i = 1; i < nFiles; i++)
2499 : {
2500 0 : if (i == 1)
2501 0 : aPath.Append( lFiles[i] );
2502 : else
2503 0 : aPath.setName( lFiles[i] );
2504 :
2505 0 : aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
2506 0 : }
2507 : }
2508 : else
2509 0 : aResultSeq = lFiles;
2510 : }
2511 :
2512 0 : return aResultSeq;
2513 : }
2514 :
2515 : // ------------------------------------------------------------------------
2516 0 : String FileDialogHelper::GetDisplayDirectory() const
2517 : {
2518 0 : return mpImp->getPath();
2519 : }
2520 :
2521 : // ------------------------------------------------------------------------
2522 0 : String FileDialogHelper::GetCurrentFilter() const
2523 : {
2524 0 : return mpImp->getFilter();
2525 : }
2526 :
2527 : // ------------------------------------------------------------------------
2528 0 : ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
2529 : {
2530 0 : return mpImp->getGraphic( rGraphic );
2531 : }
2532 :
2533 : // ------------------------------------------------------------------------
2534 0 : static int impl_isFolder( const OUString& rPath )
2535 : {
2536 : try
2537 : {
2538 : ::ucbhelper::Content aContent(
2539 : rPath, uno::Reference< ucb::XCommandEnvironment > (),
2540 0 : comphelper::getProcessComponentContext() );
2541 0 : if ( aContent.isFolder() )
2542 0 : return 1;
2543 :
2544 0 : return 0;
2545 : }
2546 0 : catch ( const Exception & )
2547 : {
2548 : }
2549 :
2550 0 : return -1;
2551 : }
2552 :
2553 0 : void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
2554 : {
2555 0 : if ( !_rPath.Len() )
2556 0 : return;
2557 :
2558 : // if the given path isn't a folder, we cut off the last part
2559 : // and take it as filename and the rest of the path should be
2560 : // the folder
2561 :
2562 0 : INetURLObject aObj( _rPath );
2563 :
2564 0 : ::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
2565 0 : aObj.removeSegment();
2566 0 : ::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
2567 :
2568 0 : int nIsFolder = impl_isFolder( _rPath );
2569 0 : if ( nIsFolder == 0 ||
2570 0 : ( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
2571 : {
2572 0 : mpImp->setFileName( sFileName );
2573 0 : mpImp->displayFolder( sPath );
2574 : }
2575 : else
2576 : {
2577 0 : INetURLObject aObjPathName( _rPath );
2578 0 : ::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
2579 0 : if ( sFolder.isEmpty() )
2580 : {
2581 : // _rPath is not a valid path -> fallback to home directory
2582 0 : osl::Security aSecurity;
2583 0 : aSecurity.getHomeDir( sFolder );
2584 : }
2585 0 : mpImp->displayFolder( sFolder );
2586 0 : }
2587 : }
2588 :
2589 : // ------------------------------------------------------------------------
2590 0 : void FileDialogHelper::SetDisplayFolder( const String& _rURL )
2591 : {
2592 0 : mpImp->displayFolder( _rURL );
2593 0 : }
2594 :
2595 : // ------------------------------------------------------------------------
2596 0 : void FileDialogHelper::SetFileName( const String& _rFileName )
2597 : {
2598 0 : mpImp->setFileName( _rFileName );
2599 0 : }
2600 :
2601 : // ------------------------------------------------------------------------
2602 0 : void FileDialogHelper::AddFilter( const String& rFilterName,
2603 : const String& rExtension )
2604 : {
2605 0 : mpImp->addFilter( rFilterName, rExtension );
2606 0 : }
2607 :
2608 : // ------------------------------------------------------------------------
2609 0 : void FileDialogHelper::SetCurrentFilter( const String& rFilter )
2610 : {
2611 0 : String sFilter( rFilter );
2612 0 : if ( mpImp->isShowFilterExtensionEnabled() )
2613 0 : sFilter = mpImp->getFilterWithExtension( rFilter );
2614 0 : mpImp->setFilter( sFilter );
2615 0 : }
2616 :
2617 : // ------------------------------------------------------------------------
2618 0 : uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
2619 : {
2620 0 : return mpImp->mxFileDlg;
2621 : }
2622 :
2623 : // ------------------------------------------------------------------------
2624 : // XFilePickerListener Methods
2625 : // ------------------------------------------------------------------------
2626 0 : void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
2627 : {
2628 0 : mpImp->handleFileSelectionChanged( aEvent );
2629 0 : }
2630 :
2631 : // ------------------------------------------------------------------------
2632 0 : void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
2633 : {
2634 0 : mpImp->handleDirectoryChanged( aEvent );
2635 0 : }
2636 :
2637 : // ------------------------------------------------------------------------
2638 0 : OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
2639 : {
2640 0 : return mpImp->handleHelpRequested( aEvent );
2641 : }
2642 :
2643 : // ------------------------------------------------------------------------
2644 0 : void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
2645 : {
2646 0 : mpImp->handleControlStateChanged( aEvent );
2647 0 : }
2648 :
2649 : // ------------------------------------------------------------------------
2650 0 : void SAL_CALL FileDialogHelper::DialogSizeChanged()
2651 : {
2652 0 : mpImp->handleDialogSizeChanged();
2653 0 : }
2654 :
2655 : // ------------------------------------------------------------------------
2656 0 : void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
2657 : {
2658 0 : m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
2659 0 : if ( m_aDialogClosedLink.IsSet() )
2660 0 : m_aDialogClosedLink.Call( this );
2661 0 : }
2662 :
2663 : // ------------------------------------------------------------------------
2664 :
2665 0 : ErrCode FileOpenDialog_Impl( sal_Int16 nDialogType,
2666 : sal_Int64 nFlags,
2667 : const String& rFact,
2668 : std::vector<rtl::OUString>& rpURLList,
2669 : String& rFilter,
2670 : SfxItemSet *& rpSet,
2671 : const String* pPath,
2672 : sal_Int16 nDialog,
2673 : const String& rStandardDir,
2674 : const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
2675 : {
2676 : ErrCode nRet;
2677 : FileDialogHelper aDialog( nDialogType, nFlags,
2678 0 : rFact, nDialog, 0, 0, rStandardDir, rBlackList );
2679 :
2680 0 : String aPath;
2681 0 : if ( pPath )
2682 0 : aPath = *pPath;
2683 :
2684 0 : nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
2685 : DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
2686 :
2687 0 : return nRet;
2688 : }
2689 :
2690 0 : ErrCode RequestPassword(const SfxFilter* pCurrentFilter, rtl::OUString& aURL, SfxItemSet* pSet)
2691 : {
2692 0 : uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
2693 0 : if( xInteractionHandler.is() )
2694 : {
2695 : // TODO: need a save way to distinguish MS filters from other filters
2696 : // for now MS-filters are the only alien filters that support encryption
2697 0 : sal_Bool bMSType = !pCurrentFilter->IsOwnFormat();
2698 : ::comphelper::DocPasswordRequestType eType = bMSType ?
2699 : ::comphelper::DocPasswordRequestType_MS :
2700 0 : ::comphelper::DocPasswordRequestType_STANDARD;
2701 :
2702 0 : ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, aURL, ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
2703 :
2704 0 : uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
2705 0 : xInteractionHandler->handle( rRequest );
2706 0 : if ( pPasswordRequest->isPassword() )
2707 : {
2708 0 : if ( pPasswordRequest->getPassword().getLength() )
2709 : {
2710 : // TODO/LATER: The filters should show the password dialog themself in future
2711 0 : if ( bMSType )
2712 : {
2713 : // all the current MS-filters use MSCodec_Std97 implementation
2714 0 : uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
2715 0 : uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
2716 :
2717 0 : if ( aEncryptionKey.getLength() )
2718 : {
2719 0 : ::comphelper::SequenceAsHashMap aHashData;
2720 0 : aHashData[ ::rtl::OUString( "STD97EncryptionKey" ) ] <<= aEncryptionKey;
2721 0 : aHashData[ ::rtl::OUString( "STD97UniqueID" ) ] <<= aUniqueID;
2722 :
2723 0 : pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
2724 : }
2725 : else
2726 0 : return ERRCODE_IO_NOTSUPPORTED;
2727 : }
2728 : else
2729 : {
2730 0 : pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
2731 : }
2732 : }
2733 :
2734 0 : if ( pPasswordRequest->getRecommendReadOnly() )
2735 0 : pSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
2736 :
2737 0 : if ( bMSType )
2738 : {
2739 : // the empty password has 0 as Hash
2740 0 : sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( "com.sun.star.text.TextDocument" ).equals( pCurrentFilter->GetServiceName() ) );
2741 0 : if ( nHash )
2742 0 : pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
2743 : }
2744 : else
2745 : {
2746 0 : uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
2747 0 : if ( aModifyPasswordInfo.getLength() )
2748 0 : pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
2749 : }
2750 : }
2751 : else
2752 0 : return ERRCODE_ABORT;
2753 : }
2754 0 : return ERRCODE_NONE;
2755 : }
2756 :
2757 : // ------------------------------------------------------------------------
2758 0 : String EncodeSpaces_Impl( const String& rSource )
2759 : {
2760 0 : String sRet( rSource );
2761 0 : sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
2762 0 : return sRet;
2763 : }
2764 :
2765 : // ------------------------------------------------------------------------
2766 0 : String DecodeSpaces_Impl( const String& rSource )
2767 : {
2768 0 : String sRet( rSource );
2769 0 : sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
2770 0 : return sRet;
2771 : }
2772 :
2773 : // ------------------------------------------------------------------------
2774 :
2775 66 : } // end of namespace sfx2
2776 :
2777 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|