Bump version to 24.04.3.4
[LibreOffice.git] / fpicker / source / office / OfficeFilePicker.cxx
blob723a8a279918057089cc2d92f48fe5f3a3bd4244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "iodlg.hxx"
24 #include "RemoteFilesDialog.hxx"
26 #include <utility>
27 #include <vector>
28 #include <algorithm>
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;
51 struct FilterEntry
53 protected:
54 OUString m_sTitle;
55 OUString m_sFilter;
57 UnoFilterList m_aSubFilters;
59 public:
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;
106 Any m_aValue;
107 OUString m_aLabel;
108 bool m_bEnabled : 1;
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() )
142 INetURLObject aPath;
143 INetURLObject givenPath( m_aDisplayDirectory );
144 if (!givenPath.HasError())
145 aPath = givenPath;
146 else
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 ) );
156 isFileSet = true;
158 if ( !isFileSet && !m_aDefaultName.isEmpty() )
160 m_xDlg->SetPath( m_aDefaultName );
161 m_xDlg->SetHasFilename( true );
164 else
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 );
188 if ( m_pFilterList )
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 );
199 else
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();
224 // SvtFilePicker
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;
291 return nBits;
295 void SvtFilePicker::notify( sal_Int16 _nEventId, sal_Int16 _nControlId )
297 if ( !m_xListener.is() )
298 return;
300 FilePickerEvent aEvent( *this, _nControlId );
302 switch ( _nEventId )
304 case FILE_SELECTION_CHANGED:
305 m_xListener->fileSelectionChanged( aEvent );
306 break;
307 case DIRECTORY_CHANGED:
308 m_xListener->directoryChanged( aEvent );
309 break;
310 case CTRL_STATE_CHANGED:
311 m_xListener->controlStateChanged( aEvent );
312 break;
313 case DIALOG_SIZE_CHANGED:
314 m_xListener->dialogSizeChanged();
315 break;
316 default:
317 SAL_WARN( "fpicker.office", "SvtFilePicker::notify(): Unknown event id!" );
318 break;
323 namespace {
325 struct FilterTitleMatch
327 protected:
328 const OUString& rTitle;
330 public:
331 explicit FilterTitleMatch( const OUString& _rTitle ) : rTitle( _rTitle ) { }
334 bool operator () ( const FilterEntry& _rEntry )
336 bool bMatch;
337 if ( !_rEntry.hasSubFilters() )
338 // a real filter
339 bMatch = ( _rEntry.getTitle() == rTitle );
340 else
341 // a filter group -> search the sub filters
342 bMatch =
343 ::std::any_of(
344 _rEntry.beginSubFilters(),
345 _rEntry.endSubFilters(),
346 *this
349 return bMatch;
351 bool operator () ( const UnoFilterEntry& _rEntry )
353 return _rEntry.First == rTitle;
359 bool SvtFilePicker::FilterNameExists( const OUString& rTitle )
361 bool bRet = false;
363 if ( m_pFilterList )
364 bRet =
365 ::std::any_of(
366 m_pFilterList->begin(),
367 m_pFilterList->end(),
368 FilterTitleMatch( rTitle )
371 return bRet;
375 bool SvtFilePicker::FilterNameExists( const UnoFilterList& _rGroupedFilters )
377 bool bRet = false;
379 if ( m_pFilterList )
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 ) ) )
385 break;
387 bRet = pStart != pEnd;
390 return bRet;
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 );
422 prepareExecute();
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
429 if (m_xDlg)
430 m_xDlg->SetFileCallback( nullptr );
432 return nRet;
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 );
449 return dialog;
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 )
494 setTitle( _rTitle );
497 void SAL_CALL SvtFilePicker::startExecuteModal( const Reference< css::ui::dialogs::XDialogClosedListener >& xListener )
499 m_xDlgClosedListener = xListener;
500 prepareDialog();
501 prepareExecute();
502 m_xDlg->EnableAutocompletion();
503 if (!m_xDlg->PrepareExecute())
504 return;
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 )
513 checkAlive();
515 SolarMutexGuard aGuard;
516 m_bMultiSelection = bMode;
519 void SAL_CALL SvtFilePicker::setDefaultName( const OUString& aName )
521 checkAlive();
523 SolarMutexGuard aGuard;
524 m_aDefaultName = aName;
527 void SAL_CALL SvtFilePicker::setDisplayDirectory( const OUString& aDirectory )
529 checkAlive();
531 SolarMutexGuard aGuard;
532 m_aDisplayDirectory = aDirectory;
535 OUString SAL_CALL SvtFilePicker::getDisplayDirectory()
537 checkAlive();
539 SolarMutexGuard aGuard;
540 if (m_xDlg)
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;
555 return aPath;
557 else
558 return m_aDisplayDirectory;
561 Sequence< OUString > SAL_CALL SvtFilePicker::getSelectedFiles()
563 checkAlive();
565 SolarMutexGuard aGuard;
566 if (!m_xDlg)
568 Sequence< OUString > aEmpty;
569 return 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)
579 aFiles.realloc(1);
580 return aFiles;
584 // XFilePickerControlAccess functions
587 void SAL_CALL SvtFilePicker::setValue( sal_Int16 nElementID,
588 sal_Int16 nControlAction,
589 const Any& rValue )
591 checkAlive();
593 SolarMutexGuard aGuard;
594 if (m_xDlg)
596 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
597 aAccess.setValue( nElementID, nControlAction, rValue );
599 else
601 if ( !m_pElemList )
602 m_pElemList.reset( new ElementList );
604 bool bFound = false;
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 );
613 bFound = true;
617 if ( !bFound )
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 )
630 checkAlive();
632 SolarMutexGuard aGuard;
633 Any aAny;
635 // execute() called?
636 if (m_xDlg)
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;
650 break;
655 return aAny;
659 void SAL_CALL SvtFilePicker::setLabel( sal_Int16 nLabelID, const OUString& rValue )
661 checkAlive();
663 SolarMutexGuard aGuard;
664 if (m_xDlg)
666 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
667 aAccess.setLabel( nLabelID, rValue );
669 else
671 if ( !m_pElemList )
672 m_pElemList.reset( new ElementList );
674 bool bFound = false;
676 for (auto & elem : *m_pElemList)
678 if ( elem.m_nElementID == nLabelID )
680 elem.setLabel( rValue );
681 bFound = true;
685 if ( !bFound )
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 )
697 checkAlive();
699 SolarMutexGuard aGuard;
700 OUString aLabel;
702 if (m_xDlg)
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;
715 break;
720 return aLabel;
724 void SAL_CALL SvtFilePicker::enableControl( sal_Int16 nElementID, sal_Bool bEnable )
726 checkAlive();
728 SolarMutexGuard aGuard;
729 if (m_xDlg)
731 ::svt::OControlAccess aAccess(m_xDlg.get(), m_xDlg->GetView());
732 aAccess.enableControl( nElementID, bEnable );
734 else
736 if ( !m_pElemList )
737 m_pElemList.reset( new ElementList );
739 bool bFound = false;
741 for (auto & elem : *m_pElemList)
743 if ( elem.m_nElementID == nElementID )
745 elem.setEnabled( bEnable );
746 bFound = true;
750 if ( !bFound )
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 )
765 checkAlive();
767 SolarMutexGuard aGuard;
768 m_xListener = xListener;
772 void SAL_CALL SvtFilePicker::removeFilePickerListener( const Reference< XFilePickerListener >& )
774 checkAlive();
776 SolarMutexGuard aGuard;
777 m_xListener.clear();
780 // XFilePreview functions
781 Sequence< sal_Int16 > SAL_CALL SvtFilePicker::getSupportedImageFormats()
783 checkAlive();
785 return { FilePreviewImageFormats::BITMAP };
788 sal_Int32 SAL_CALL SvtFilePicker::getTargetColorDepth()
790 return 0;
793 sal_Int32 SAL_CALL SvtFilePicker::getAvailableWidth()
795 checkAlive();
797 SolarMutexGuard aGuard;
798 sal_Int32 nWidth = 0;
800 if (m_xDlg)
801 nWidth = m_xDlg->getAvailableWidth();
803 return nWidth;
806 sal_Int32 SAL_CALL SvtFilePicker::getAvailableHeight()
808 checkAlive();
810 SolarMutexGuard aGuard;
811 sal_Int32 nHeight = 0;
813 if (m_xDlg)
814 nHeight = m_xDlg->getAvailableHeight();
816 return nHeight;
819 void SAL_CALL SvtFilePicker::setImage(sal_Int16 /*aImageFormat*/, const Any& rImage)
821 checkAlive();
823 SolarMutexGuard aGuard;
824 if (m_xDlg)
825 m_xDlg->setImage(rImage);
828 sal_Bool SAL_CALL SvtFilePicker::setShowState( sal_Bool )
830 checkAlive();
832 SolarMutexGuard aGuard;
833 bool bRet = false;
835 if (m_xDlg)
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
849 bRet = false;
852 return bRet;
856 sal_Bool SAL_CALL SvtFilePicker::getShowState()
858 checkAlive();
860 SolarMutexGuard aGuard;
861 bool bRet = false;
863 if (m_xDlg)
864 bRet = m_xDlg->getShowState();
866 return bRet;
870 // XFilterGroupManager functions
873 void SAL_CALL SvtFilePicker::appendFilterGroup( const OUString& sGroupTitle,
874 const Sequence< StringPair >& aFilters )
876 checkAlive();
878 SolarMutexGuard aGuard;
880 // check the names
881 if ( FilterNameExists( aFilters ) )
882 throw IllegalArgumentException(
883 "filter name exists",
884 getXWeak(), 1);
886 // ensure that we have a filter list
887 OUString sInitialCurrentFilter;
888 if ( aFilters.hasElements() )
889 sInitialCurrentFilter = aFilters[0].First;
890 ensureFilterList( sInitialCurrentFilter );
892 // append the filter
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 )
903 checkAlive();
905 SolarMutexGuard aGuard;
906 // check the name
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 );
914 // append the filter
915 m_pFilterList->insert( m_pFilterList->end(), FilterEntry( aTitle, aFilter ) );
919 void SAL_CALL SvtFilePicker::setCurrentFilter( const OUString& aTitle )
921 checkAlive();
923 SolarMutexGuard aGuard;
924 if ( ! FilterNameExists( aTitle ) )
925 throw IllegalArgumentException();
927 m_aCurrentFilter = aTitle;
929 if (m_xDlg)
930 m_xDlg->SetCurFilter( aTitle );
934 OUString SAL_CALL SvtFilePicker::getCurrentFilter()
936 checkAlive();
938 SolarMutexGuard aGuard;
939 OUString aFilter = m_xDlg ? m_xDlg->GetCurFilter() :
940 m_aCurrentFilter;
941 return aFilter;
945 // XInitialization functions
948 void SAL_CALL SvtFilePicker::initialize( const Sequence< Any >& _rArguments )
950 checkAlive();
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
959 int index = 0;
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;
966 index = 1;
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 );
1008 return true;
1010 if ( _rName == "StandardDir" )
1012 OSL_VERIFY( _rValue >>= m_aStandardDir );
1013 return true;
1016 if ( _rName == "DenyList" )
1018 OSL_VERIFY( _rValue >>= m_aDenyList );
1019 return true;
1023 return OCommonPicker::implHandleInitializationArgument( _rName, _rValue );
1027 // XServiceInfo
1030 /* XServiceInfo */
1031 OUString SAL_CALL SvtFilePicker::getImplementationName()
1033 return "com.sun.star.svtools.OfficeFilePicker";
1036 /* XServiceInfo */
1037 sal_Bool SAL_CALL SvtFilePicker::supportsService( const OUString& sServiceName )
1039 return cppu::supportsService(this, sServiceName);
1042 /* XServiceInfo */
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 );
1076 return dialog;
1079 // XServiceInfo
1082 /* XServiceInfo */
1083 OUString SAL_CALL SvtRemoteFilePicker::getImplementationName()
1085 return "com.sun.star.svtools.RemoteFilePicker";
1088 /* XServiceInfo */
1089 sal_Bool SAL_CALL SvtRemoteFilePicker::supportsService( const OUString& sServiceName )
1091 return cppu::supportsService(this, sServiceName);
1094 /* XServiceInfo */
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: */