1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "OfficeControlAccess.hxx"
22 #include "OfficeFilePicker.hxx"
24 #include "RemoteFilesDialog.hxx"
29 #include <sal/log.hxx>
30 #include <tools/urlobj.hxx>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
33 #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
34 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <com/sun/star/beans/NamedValue.hpp>
37 #include <unotools/pathoptions.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <o3tl/make_shared.hxx>
40 #include <vcl/svapp.hxx>
42 using namespace ::com::sun::star::container
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::ui::dialogs
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::beans
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::utl
;
57 UnoFilterList m_aSubFilters
;
60 FilterEntry( OUString _aTitle
, OUString _aFilter
)
61 :m_sTitle(std::move( _aTitle
))
62 ,m_sFilter(std::move( _aFilter
))
66 FilterEntry( OUString _aTitle
, const UnoFilterList
& _rSubFilters
);
68 const OUString
& getTitle() const { return m_sTitle
; }
69 const OUString
& getFilter() const { return m_sFilter
; }
71 /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
72 bool hasSubFilters( ) const;
74 /** retrieves the filters belonging to the entry
76 void getSubFilters( UnoFilterList
& _rSubFilterList
);
78 // helpers for iterating the sub filters
79 const UnoFilterEntry
* beginSubFilters() const { return m_aSubFilters
.getConstArray(); }
80 const UnoFilterEntry
* endSubFilters() const { return m_aSubFilters
.getConstArray() + m_aSubFilters
.getLength(); }
84 FilterEntry::FilterEntry( OUString _aTitle
, const UnoFilterList
& _rSubFilters
)
85 :m_sTitle(std::move( _aTitle
))
86 ,m_aSubFilters( _rSubFilters
)
91 bool FilterEntry::hasSubFilters( ) const
93 return m_aSubFilters
.hasElements();
97 void FilterEntry::getSubFilters( UnoFilterList
& _rSubFilterList
)
99 _rSubFilterList
= m_aSubFilters
;
102 struct ElementEntry_Impl
104 sal_Int16 m_nElementID
;
105 sal_Int16 m_nControlAction
;
110 bool m_bHasValue
: 1;
111 bool m_bHasLabel
: 1;
112 bool m_bHasEnabled
: 1;
114 explicit ElementEntry_Impl( sal_Int16 nId
);
116 void setValue( const Any
& rVal
) { m_aValue
= rVal
; m_bHasValue
= true; }
117 void setAction( sal_Int16 nAction
) { m_nControlAction
= nAction
; }
118 void setLabel( const OUString
& rVal
) { m_aLabel
= rVal
; m_bHasLabel
= true; }
119 void setEnabled( bool bEnabled
) { m_bEnabled
= bEnabled
; m_bHasEnabled
= true; }
122 ElementEntry_Impl::ElementEntry_Impl( sal_Int16 nId
)
123 : m_nElementID( nId
)
124 , m_nControlAction( 0 )
125 , m_bEnabled( false )
126 , m_bHasValue( false )
127 , m_bHasLabel( false )
128 , m_bHasEnabled( false )
132 void SvtFilePicker::prepareExecute()
134 // set the default directory
135 // --**-- doesn't match the spec yet
136 if ( !m_aDisplayDirectory
.isEmpty() || !m_aDefaultName
.isEmpty() )
138 bool isFileSet
= false;
139 if ( !m_aDisplayDirectory
.isEmpty() )
143 INetURLObject
givenPath( m_aDisplayDirectory
);
144 if (!givenPath
.HasError())
148 aPath
= INetURLObject( SvtPathOptions().GetWorkPath() );
150 if ( !m_aDefaultName
.isEmpty() )
152 aPath
.insertName( m_aDefaultName
);
153 m_xDlg
->SetHasFilename( true );
155 m_xDlg
->SetPath( aPath
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
158 if ( !isFileSet
&& !m_aDefaultName
.isEmpty() )
160 m_xDlg
->SetPath( m_aDefaultName
);
161 m_xDlg
->SetHasFilename( true );
166 // set the default standard dir
167 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
168 m_xDlg
->SetPath( aStdDirObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
171 // set the control values and set the control labels, too
172 if ( m_pElemList
&& !m_pElemList
->empty() )
174 ::svt::OControlAccess
aAccess( m_xDlg
.get(), m_xDlg
->GetView() );
176 for (auto const& elem
: *m_pElemList
)
178 if ( elem
.m_bHasValue
)
179 aAccess
.setValue( elem
.m_nElementID
, elem
.m_nControlAction
, elem
.m_aValue
);
180 if ( elem
.m_bHasLabel
)
181 aAccess
.setLabel( elem
.m_nElementID
, elem
.m_aLabel
);
182 if ( elem
.m_bHasEnabled
)
183 aAccess
.enableControl( elem
.m_nElementID
, elem
.m_bEnabled
);
190 for (auto & elem
: *m_pFilterList
)
192 if ( elem
.hasSubFilters() )
193 { // it's a filter group
194 UnoFilterList aSubFilters
;
195 elem
.getSubFilters( aSubFilters
);
197 m_xDlg
->AddFilterGroup( elem
.getTitle(), aSubFilters
);
201 // it's a single filter
202 m_xDlg
->AddFilter( elem
.getTitle(), elem
.getFilter() );
207 // set the default filter
208 if ( !m_aCurrentFilter
.isEmpty() )
209 m_xDlg
->SetCurFilter( m_aCurrentFilter
);
213 void SvtFilePicker::DialogClosedHdl(sal_Int32 nResult
)
215 if ( m_xDlgClosedListener
.is() )
217 sal_Int16 nRet
= static_cast< sal_Int16
>(nResult
);
218 css::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
219 m_xDlgClosedListener
->dialogClosed( aEvent
);
220 m_xDlgClosedListener
.clear();
225 PickerFlags
SvtFilePicker::getPickerFlags() const
227 // set the winbits for creating the filedialog
228 PickerFlags nBits
= PickerFlags::NONE
;
230 // set the standard bits according to the service name
231 if ( m_nServiceType
== TemplateDescription::FILEOPEN_SIMPLE
)
233 nBits
= PickerFlags::Open
;
235 else if ( m_nServiceType
== TemplateDescription::FILESAVE_SIMPLE
)
237 nBits
= PickerFlags::SaveAs
;
239 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION
)
241 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
;
243 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD
)
245 nBits
= PickerFlags::SaveAs
| PickerFlags::Password
| PickerFlags::AutoExtension
;
247 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
)
249 nBits
= PickerFlags::SaveAs
| PickerFlags::Password
| PickerFlags::AutoExtension
| PickerFlags::FilterOptions
;
251 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE
)
253 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
| PickerFlags::Templates
;
255 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION
)
257 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
| PickerFlags::Selection
;
260 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
)
262 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::ShowPreview
| PickerFlags::ImageTemplate
;
264 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_PLAY
)
266 nBits
= PickerFlags::Open
| PickerFlags::PlayButton
;
268 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PLAY
)
270 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::PlayButton
;
272 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_READONLY_VERSION
)
274 nBits
= PickerFlags::Open
| PickerFlags::ReadOnly
| PickerFlags::ShowVersions
;
276 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW
)
278 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::ShowPreview
;
280 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR
)
282 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::ShowPreview
| PickerFlags::ImageAnchor
;
284 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_PREVIEW
)
286 nBits
= PickerFlags::Open
| PickerFlags::ShowPreview
;
288 if ( m_bMultiSelection
&& ( nBits
& PickerFlags::Open
) )
289 nBits
|= PickerFlags::MultiSelection
;
295 void SvtFilePicker::notify( sal_Int16 _nEventId
, sal_Int16 _nControlId
)
297 if ( !m_xListener
.is() )
300 FilePickerEvent
aEvent( *this, _nControlId
);
304 case FILE_SELECTION_CHANGED
:
305 m_xListener
->fileSelectionChanged( aEvent
);
307 case DIRECTORY_CHANGED
:
308 m_xListener
->directoryChanged( aEvent
);
310 case CTRL_STATE_CHANGED
:
311 m_xListener
->controlStateChanged( aEvent
);
313 case DIALOG_SIZE_CHANGED
:
314 m_xListener
->dialogSizeChanged();
317 SAL_WARN( "fpicker.office", "SvtFilePicker::notify(): Unknown event id!" );
325 struct FilterTitleMatch
328 const OUString
& rTitle
;
331 explicit FilterTitleMatch( const OUString
& _rTitle
) : rTitle( _rTitle
) { }
334 bool operator () ( const FilterEntry
& _rEntry
)
337 if ( !_rEntry
.hasSubFilters() )
339 bMatch
= ( _rEntry
.getTitle() == rTitle
);
341 // a filter group -> search the sub filters
344 _rEntry
.beginSubFilters(),
345 _rEntry
.endSubFilters(),
351 bool operator () ( const UnoFilterEntry
& _rEntry
)
353 return _rEntry
.First
== rTitle
;
359 bool SvtFilePicker::FilterNameExists( const OUString
& rTitle
)
366 m_pFilterList
->begin(),
367 m_pFilterList
->end(),
368 FilterTitleMatch( rTitle
)
375 bool SvtFilePicker::FilterNameExists( const UnoFilterList
& _rGroupedFilters
)
381 const UnoFilterEntry
* pStart
= _rGroupedFilters
.getConstArray();
382 const UnoFilterEntry
* pEnd
= pStart
+ _rGroupedFilters
.getLength();
383 for ( ; pStart
!= pEnd
; ++pStart
)
384 if ( ::std::any_of( m_pFilterList
->begin(), m_pFilterList
->end(), FilterTitleMatch( pStart
->First
) ) )
387 bRet
= pStart
!= pEnd
;
394 void SvtFilePicker::ensureFilterList( const OUString
& _rInitialCurrentFilter
)
396 if ( !m_pFilterList
)
398 m_pFilterList
.reset( new FilterList
);
400 // set the first filter to the current filter
401 if ( m_aCurrentFilter
.isEmpty() )
402 m_aCurrentFilter
= _rInitialCurrentFilter
;
408 SvtFilePicker::SvtFilePicker()
409 :m_bMultiSelection ( false )
410 ,m_nServiceType ( TemplateDescription::FILEOPEN_SIMPLE
)
414 SvtFilePicker::~SvtFilePicker()
418 sal_Int16
SvtFilePicker::implExecutePicker( )
420 m_xDlg
->SetFileCallback( this );
424 m_xDlg
->EnableAutocompletion();
425 // now we are ready to execute the dialog
426 sal_Int16 nRet
= m_xDlg
->run();
428 // coverity[check_after_deref] - the execution of the dialog yields, so it is possible the at this point the window or the dialog is closed
430 m_xDlg
->SetFileCallback( nullptr );
435 std::shared_ptr
<SvtFileDialog_Base
> SvtFilePicker::implCreateDialog( weld::Window
* pParent
)
437 PickerFlags nBits
= getPickerFlags();
439 auto dialog
= o3tl::make_shared
<SvtFileDialog
>(pParent
, nBits
);
441 // Set StandardDir if present
442 if ( !m_aStandardDir
.isEmpty())
444 OUString sStandardDir
= m_aStandardDir
;
445 dialog
->SetStandardDir( sStandardDir
);
446 dialog
->SetDenyList( m_aDenyList
);
453 // disambiguate XInterface
455 IMPLEMENT_FORWARD_XINTERFACE2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
458 // disambiguate XTypeProvider
460 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
462 IMPLEMENT_FORWARD_XINTERFACE3( SvtRemoteFilePicker
, SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
465 // disambiguate XTypeProvider
467 css::uno::Sequence
< css::uno::Type
> SAL_CALL
SvtRemoteFilePicker::getTypes( )
469 return ::comphelper::concatSequences(
470 SvtFilePicker::getTypes(),
471 OCommonPicker::getTypes(),
472 SvtFilePicker_Base::getTypes()
475 IMPLEMENT_GET_IMPLEMENTATION_ID( SvtRemoteFilePicker
)
478 // XExecutableDialog functions
481 void SAL_CALL
SvtFilePicker::setTitle( const OUString
& _rTitle
)
483 OCommonPicker::setTitle( _rTitle
);
486 sal_Int16 SAL_CALL
SvtFilePicker::execute( )
488 return OCommonPicker::execute();
491 // XAsynchronousExecutableDialog functions
492 void SAL_CALL
SvtFilePicker::setDialogTitle( const OUString
& _rTitle
)
497 void SAL_CALL
SvtFilePicker::startExecuteModal( const Reference
< css::ui::dialogs::XDialogClosedListener
>& xListener
)
499 m_xDlgClosedListener
= xListener
;
502 m_xDlg
->EnableAutocompletion();
503 if (!m_xDlg
->PrepareExecute())
505 weld::DialogController::runAsync(m_xDlg
, [this](sal_Int32 nResult
){
506 DialogClosedHdl(nResult
);
510 // XFilePicker functions
511 void SAL_CALL
SvtFilePicker::setMultiSelectionMode( sal_Bool bMode
)
515 SolarMutexGuard aGuard
;
516 m_bMultiSelection
= bMode
;
519 void SAL_CALL
SvtFilePicker::setDefaultName( const OUString
& aName
)
523 SolarMutexGuard aGuard
;
524 m_aDefaultName
= aName
;
527 void SAL_CALL
SvtFilePicker::setDisplayDirectory( const OUString
& aDirectory
)
531 SolarMutexGuard aGuard
;
532 m_aDisplayDirectory
= aDirectory
;
535 OUString SAL_CALL
SvtFilePicker::getDisplayDirectory()
539 SolarMutexGuard aGuard
;
542 OUString aPath
= m_xDlg
->GetPath();
544 if( m_aOldHideDirectory
== aPath
)
545 return m_aOldDisplayDirectory
;
546 m_aOldHideDirectory
= aPath
;
548 if( !m_xDlg
->ContentIsFolder( aPath
) )
550 INetURLObject
aFolder( aPath
);
551 aFolder
.CutLastName();
552 aPath
= aFolder
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
554 m_aOldDisplayDirectory
= aPath
;
558 return m_aDisplayDirectory
;
561 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getSelectedFiles()
565 SolarMutexGuard aGuard
;
568 Sequence
< OUString
> aEmpty
;
572 return comphelper::containerToSequence(m_xDlg
->GetPathList());
575 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getFiles()
577 Sequence
< OUString
> aFiles
= getSelectedFiles();
578 if (aFiles
.getLength() > 1)
584 // XFilePickerControlAccess functions
587 void SAL_CALL
SvtFilePicker::setValue( sal_Int16 nElementID
,
588 sal_Int16 nControlAction
,
593 SolarMutexGuard aGuard
;
596 ::svt::OControlAccess
aAccess( m_xDlg
.get(), m_xDlg
->GetView() );
597 aAccess
.setValue( nElementID
, nControlAction
, rValue
);
602 m_pElemList
.reset( new ElementList
);
606 for (auto & elem
: *m_pElemList
)
608 if ( ( elem
.m_nElementID
== nElementID
) &&
609 ( !elem
.m_bHasValue
|| ( elem
.m_nControlAction
== nControlAction
) ) )
611 elem
.setAction( nControlAction
);
612 elem
.setValue( rValue
);
619 ElementEntry_Impl
aNew( nElementID
);
620 aNew
.setAction( nControlAction
);
621 aNew
.setValue( rValue
);
622 m_pElemList
->insert( m_pElemList
->end(), aNew
);
628 Any SAL_CALL
SvtFilePicker::getValue( sal_Int16 nElementID
, sal_Int16 nControlAction
)
632 SolarMutexGuard aGuard
;
638 ::svt::OControlAccess
aAccess( m_xDlg
.get(), m_xDlg
->GetView() );
639 aAny
= aAccess
.getValue( nElementID
, nControlAction
);
641 else if ( m_pElemList
)
643 for (auto const& elem
: *m_pElemList
)
645 if ( ( elem
.m_nElementID
== nElementID
) &&
646 ( elem
.m_bHasValue
) &&
647 ( elem
.m_nControlAction
== nControlAction
) )
649 aAny
= elem
.m_aValue
;
659 void SAL_CALL
SvtFilePicker::setLabel( sal_Int16 nLabelID
, const OUString
& rValue
)
663 SolarMutexGuard aGuard
;
666 ::svt::OControlAccess
aAccess( m_xDlg
.get(), m_xDlg
->GetView() );
667 aAccess
.setLabel( nLabelID
, rValue
);
672 m_pElemList
.reset( new ElementList
);
676 for (auto & elem
: *m_pElemList
)
678 if ( elem
.m_nElementID
== nLabelID
)
680 elem
.setLabel( rValue
);
687 ElementEntry_Impl
aNew( nLabelID
);
688 aNew
.setLabel( rValue
);
689 m_pElemList
->insert( m_pElemList
->end(), aNew
);
695 OUString SAL_CALL
SvtFilePicker::getLabel( sal_Int16 nLabelID
)
699 SolarMutexGuard aGuard
;
704 ::svt::OControlAccess
aAccess(m_xDlg
.get(), m_xDlg
->GetView());
705 aLabel
= aAccess
.getLabel( nLabelID
);
707 else if ( m_pElemList
)
709 for (auto const& elem
: *m_pElemList
)
711 if ( elem
.m_nElementID
== nLabelID
)
713 if ( elem
.m_bHasLabel
)
714 aLabel
= elem
.m_aLabel
;
724 void SAL_CALL
SvtFilePicker::enableControl( sal_Int16 nElementID
, sal_Bool bEnable
)
728 SolarMutexGuard aGuard
;
731 ::svt::OControlAccess
aAccess(m_xDlg
.get(), m_xDlg
->GetView());
732 aAccess
.enableControl( nElementID
, bEnable
);
737 m_pElemList
.reset( new ElementList
);
741 for (auto & elem
: *m_pElemList
)
743 if ( elem
.m_nElementID
== nElementID
)
745 elem
.setEnabled( bEnable
);
752 ElementEntry_Impl
aNew( nElementID
);
753 aNew
.setEnabled( bEnable
);
754 m_pElemList
->insert( m_pElemList
->end(), aNew
);
760 // XFilePickerNotifier functions
763 void SAL_CALL
SvtFilePicker::addFilePickerListener( const Reference
< XFilePickerListener
>& xListener
)
767 SolarMutexGuard aGuard
;
768 m_xListener
= xListener
;
772 void SAL_CALL
SvtFilePicker::removeFilePickerListener( const Reference
< XFilePickerListener
>& )
776 SolarMutexGuard aGuard
;
780 // XFilePreview functions
781 Sequence
< sal_Int16
> SAL_CALL
SvtFilePicker::getSupportedImageFormats()
785 return { FilePreviewImageFormats::BITMAP
};
788 sal_Int32 SAL_CALL
SvtFilePicker::getTargetColorDepth()
793 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableWidth()
797 SolarMutexGuard aGuard
;
798 sal_Int32 nWidth
= 0;
801 nWidth
= m_xDlg
->getAvailableWidth();
806 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableHeight()
810 SolarMutexGuard aGuard
;
811 sal_Int32 nHeight
= 0;
814 nHeight
= m_xDlg
->getAvailableHeight();
819 void SAL_CALL
SvtFilePicker::setImage(sal_Int16
/*aImageFormat*/, const Any
& rImage
)
823 SolarMutexGuard aGuard
;
825 m_xDlg
->setImage(rImage
);
828 sal_Bool SAL_CALL
SvtFilePicker::setShowState( sal_Bool
)
832 SolarMutexGuard aGuard
;
837 // #97633 for the system filedialog it's
838 // useful to make the preview switchable
839 // because the preview occupies
840 // half of the size of the file listbox
841 // which is not the case here,
842 // so we (TRA/FS) decided not to make
843 // the preview window switchable because
844 // else we would have to change the layout
845 // of the file dialog dynamically
846 // support for set/getShowState is optionally
847 // see css::ui::dialogs::XFilePreview
856 sal_Bool SAL_CALL
SvtFilePicker::getShowState()
860 SolarMutexGuard aGuard
;
864 bRet
= m_xDlg
->getShowState();
870 // XFilterGroupManager functions
873 void SAL_CALL
SvtFilePicker::appendFilterGroup( const OUString
& sGroupTitle
,
874 const Sequence
< StringPair
>& aFilters
)
878 SolarMutexGuard aGuard
;
881 if ( FilterNameExists( aFilters
) )
882 throw IllegalArgumentException(
883 "filter name exists",
886 // ensure that we have a filter list
887 OUString sInitialCurrentFilter
;
888 if ( aFilters
.hasElements() )
889 sInitialCurrentFilter
= aFilters
[0].First
;
890 ensureFilterList( sInitialCurrentFilter
);
893 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( sGroupTitle
, aFilters
) );
897 // XFilterManager functions
900 void SAL_CALL
SvtFilePicker::appendFilter( const OUString
& aTitle
,
901 const OUString
& aFilter
)
905 SolarMutexGuard aGuard
;
907 if ( FilterNameExists( aTitle
) )
908 // TODO: a more precise exception message
909 throw IllegalArgumentException();
911 // ensure that we have a filter list
912 ensureFilterList( aTitle
);
915 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( aTitle
, aFilter
) );
919 void SAL_CALL
SvtFilePicker::setCurrentFilter( const OUString
& aTitle
)
923 SolarMutexGuard aGuard
;
924 if ( ! FilterNameExists( aTitle
) )
925 throw IllegalArgumentException();
927 m_aCurrentFilter
= aTitle
;
930 m_xDlg
->SetCurFilter( aTitle
);
934 OUString SAL_CALL
SvtFilePicker::getCurrentFilter()
938 SolarMutexGuard aGuard
;
939 OUString aFilter
= m_xDlg
? m_xDlg
->GetCurFilter() :
945 // XInitialization functions
948 void SAL_CALL
SvtFilePicker::initialize( const Sequence
< Any
>& _rArguments
)
952 Sequence
< Any
> aArguments( _rArguments
.getLength());
954 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
956 if ( _rArguments
.hasElements() )
958 // compatibility: one argument, type sal_Int16 , specifies the service type
960 auto pArguments
= aArguments
.getArray();
961 if (_rArguments
[0] >>= m_nServiceType
)
963 // skip the first entry if it was the ServiceType, because it's not needed in OCommonPicker::initialize and it's not a NamedValue
964 NamedValue emptyNamedValue
;
965 pArguments
[0] <<= emptyNamedValue
;
969 for ( int i
= index
; i
< _rArguments
.getLength(); i
++)
971 NamedValue namedValue
;
972 pArguments
[i
] = _rArguments
[i
];
974 if (aArguments
[i
] >>= namedValue
)
977 if ( namedValue
.Name
== "StandardDir" )
979 OUString sStandardDir
;
981 namedValue
.Value
>>= sStandardDir
;
983 // Set the directory for the "back to the default dir" button
984 if ( !sStandardDir
.isEmpty() )
986 m_aStandardDir
= sStandardDir
;
989 else if ( namedValue
.Name
== "DenyList" )
991 namedValue
.Value
>>= m_aDenyList
;
997 // let the base class analyze the sequence (will call into implHandleInitializationArgument)
998 OCommonPicker::initialize( aArguments
);
1002 bool SvtFilePicker::implHandleInitializationArgument( const OUString
& _rName
, const Any
& _rValue
)
1004 if ( _rName
== "TemplateDescription" )
1006 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
1007 OSL_VERIFY( _rValue
>>= m_nServiceType
);
1010 if ( _rName
== "StandardDir" )
1012 OSL_VERIFY( _rValue
>>= m_aStandardDir
);
1016 if ( _rName
== "DenyList" )
1018 OSL_VERIFY( _rValue
>>= m_aDenyList
);
1023 return OCommonPicker::implHandleInitializationArgument( _rName
, _rValue
);
1031 OUString SAL_CALL
SvtFilePicker::getImplementationName()
1033 return "com.sun.star.svtools.OfficeFilePicker";
1037 sal_Bool SAL_CALL
SvtFilePicker::supportsService( const OUString
& sServiceName
)
1039 return cppu::supportsService(this, sServiceName
);
1043 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getSupportedServiceNames()
1045 return { "com.sun.star.ui.dialogs.OfficeFilePicker" };
1048 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1049 fpicker_SvtFilePicker_get_implementation(
1050 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
1052 return cppu::acquire(new SvtFilePicker());
1056 // SvtRemoteFilePicker
1058 SvtRemoteFilePicker::SvtRemoteFilePicker()
1062 std::shared_ptr
<SvtFileDialog_Base
> SvtRemoteFilePicker::implCreateDialog(weld::Window
* pParent
)
1064 PickerFlags nBits
= getPickerFlags();
1066 auto dialog
= std::make_shared
<RemoteFilesDialog
>(pParent
, nBits
);
1068 // Set StandardDir if present
1069 if ( !m_aStandardDir
.isEmpty())
1071 OUString sStandardDir
= m_aStandardDir
;
1072 dialog
->SetStandardDir( sStandardDir
);
1073 dialog
->SetDenyList( m_aDenyList
);
1083 OUString SAL_CALL
SvtRemoteFilePicker::getImplementationName()
1085 return "com.sun.star.svtools.RemoteFilePicker";
1089 sal_Bool SAL_CALL
SvtRemoteFilePicker::supportsService( const OUString
& sServiceName
)
1091 return cppu::supportsService(this, sServiceName
);
1095 Sequence
< OUString
> SAL_CALL
SvtRemoteFilePicker::getSupportedServiceNames()
1097 return { "com.sun.star.ui.dialogs.RemoteFilePicker" };
1101 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1102 fpicker_SvtRemoteFilePicker_get_implementation(
1103 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
1105 return cppu::acquire(new SvtRemoteFilePicker());
1108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */