LibreOffice Module fpicker (master) 1
OfficeFilePicker.cxx
Go to the documentation of this file.
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
22#include "OfficeFilePicker.hxx"
23#include "iodlg.hxx"
24#include "RemoteFilesDialog.hxx"
25
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>
39#include <o3tl/make_shared.hxx>
40#include <vcl/svapp.hxx>
41
42using namespace ::com::sun::star::container;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::ui::dialogs;
45using namespace ::com::sun::star::uno;
46using namespace ::com::sun::star::beans;
47using namespace ::com::sun::star::awt;
48using namespace ::utl;
49
50
51struct FilterEntry
52{
53protected:
54 OUString m_sTitle;
55 OUString m_sFilter;
56
57 UnoFilterList m_aSubFilters;
58
59public:
60 FilterEntry( OUString _aTitle, OUString _aFilter )
61 :m_sTitle(std::move( _aTitle ))
62 ,m_sFilter(std::move( _aFilter ))
63 {
64 }
65
66 FilterEntry( OUString _aTitle, const UnoFilterList& _rSubFilters );
67
68 const OUString& getTitle() const { return m_sTitle; }
69 const OUString& getFilter() const { return m_sFilter; }
70
72 bool hasSubFilters( ) const;
73
76 void getSubFilters( UnoFilterList& _rSubFilterList );
77
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(); }
81};
82
83
84FilterEntry::FilterEntry( OUString _aTitle, const UnoFilterList& _rSubFilters )
85 :m_sTitle(std::move( _aTitle ))
86 ,m_aSubFilters( _rSubFilters )
87{
88}
89
90
91bool FilterEntry::hasSubFilters( ) const
92{
93 return m_aSubFilters.hasElements();
94}
95
96
97void FilterEntry::getSubFilters( UnoFilterList& _rSubFilterList )
98{
99 _rSubFilterList = m_aSubFilters;
100}
101
103{
104 sal_Int16 m_nElementID;
107 OUString m_aLabel;
108 bool m_bEnabled : 1;
109
110 bool m_bHasValue : 1;
111 bool m_bHasLabel : 1;
113
114 explicit ElementEntry_Impl( sal_Int16 nId );
115
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; }
120};
121
123 : m_nElementID( nId )
124 , m_nControlAction( 0 )
125 , m_bEnabled( false )
126 , m_bHasValue( false )
127 , m_bHasLabel( false )
128 , m_bHasEnabled( false )
129{}
130
131
133{
134 // set the default directory
135 // --**-- doesn't match the spec yet
136 if ( !m_aDisplayDirectory.isEmpty() || !m_aDefaultName.isEmpty() )
137 {
138 bool isFileSet = false;
139 if ( !m_aDisplayDirectory.isEmpty() )
140 {
141
142 INetURLObject aPath;
144 if (!givenPath.HasError())
145 aPath = givenPath;
146 else
147 {
148 aPath = INetURLObject( SvtPathOptions().GetWorkPath() );
149 }
150 if ( !m_aDefaultName.isEmpty() )
151 {
152 aPath.insertName( m_aDefaultName );
153 m_xDlg->SetHasFilename( true );
154 }
156 isFileSet = true;
157 }
158 if ( !isFileSet && !m_aDefaultName.isEmpty() )
159 {
160 m_xDlg->SetPath( m_aDefaultName );
161 m_xDlg->SetHasFilename( true );
162 }
163 }
164 else
165 {
166 // set the default standard dir
167 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
169 }
170
171 // set the control values and set the control labels, too
172 if ( m_pElemList && !m_pElemList->empty() )
173 {
174 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
175
176 for (auto const& elem : *m_pElemList)
177 {
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 );
184 }
185
186 }
187
188 if ( m_pFilterList )
189 {
190 for (auto & elem : *m_pFilterList)
191 {
192 if ( elem.hasSubFilters() )
193 { // it's a filter group
195 elem.getSubFilters( aSubFilters );
196
197 m_xDlg->AddFilterGroup( elem.getTitle(), aSubFilters );
198 }
199 else
200 {
201 // it's a single filter
202 m_xDlg->AddFilter( elem.getTitle(), elem.getFilter() );
203 }
204 }
205 }
206
207 // set the default filter
208 if ( !m_aCurrentFilter.isEmpty() )
209 m_xDlg->SetCurFilter( m_aCurrentFilter );
210
211}
212
213void SvtFilePicker::DialogClosedHdl(sal_Int32 nResult)
214{
215 if ( m_xDlgClosedListener.is() )
216 {
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();
221 }
222}
223
224// SvtFilePicker
226{
227 // set the winbits for creating the filedialog
229
230 // set the standard bits according to the service name
231 if ( m_nServiceType == TemplateDescription::FILEOPEN_SIMPLE )
232 {
233 nBits = PickerFlags::Open;
234 }
235 else if ( m_nServiceType == TemplateDescription::FILESAVE_SIMPLE )
236 {
237 nBits = PickerFlags::SaveAs;
238 }
239 else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION )
240 {
242 }
243 else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD )
244 {
246 }
247 else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS )
248 {
250 }
251 else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE )
252 {
254 }
255 else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION )
256 {
258 }
259
260 else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE )
261 {
263 }
264 else if ( m_nServiceType == TemplateDescription::FILEOPEN_PLAY )
265 {
267 }
268 else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PLAY )
269 {
271 }
272 else if ( m_nServiceType == TemplateDescription::FILEOPEN_READONLY_VERSION )
273 {
275 }
276 else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PREVIEW )
277 {
279 }
280 else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR )
281 {
283 }
284 else if ( m_nServiceType == TemplateDescription::FILEOPEN_PREVIEW )
285 {
287 }
288 if ( m_bMultiSelection && ( nBits & PickerFlags::Open ) )
290
291 return nBits;
292}
293
294
295void SvtFilePicker::notify( sal_Int16 _nEventId, sal_Int16 _nControlId )
296{
297 if ( !m_xListener.is() )
298 return;
299
300 FilePickerEvent aEvent( *this, _nControlId );
301
302 switch ( _nEventId )
303 {
305 m_xListener->fileSelectionChanged( aEvent );
306 break;
308 m_xListener->directoryChanged( aEvent );
309 break;
311 m_xListener->controlStateChanged( aEvent );
312 break;
314 m_xListener->dialogSizeChanged();
315 break;
316 default:
317 SAL_WARN( "fpicker.office", "SvtFilePicker::notify(): Unknown event id!" );
318 break;
319 }
320}
321
322
323namespace {
324
325 struct FilterTitleMatch
326 {
327 protected:
328 const OUString& rTitle;
329
330 public:
331 explicit FilterTitleMatch( const OUString& _rTitle ) : rTitle( _rTitle ) { }
332
333
334 bool operator () ( const FilterEntry& _rEntry )
335 {
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
347 );
348
349 return bMatch;
350 }
351 bool operator () ( const UnoFilterEntry& _rEntry )
352 {
353 return _rEntry.First == rTitle;
354 }
355 };
356}
357
358
359bool SvtFilePicker::FilterNameExists( const OUString& rTitle )
360{
361 bool bRet = false;
362
363 if ( m_pFilterList )
364 bRet =
365 ::std::any_of(
366 m_pFilterList->begin(),
367 m_pFilterList->end(),
368 FilterTitleMatch( rTitle )
369 );
370
371 return bRet;
372}
373
374
375bool SvtFilePicker::FilterNameExists( const UnoFilterList& _rGroupedFilters )
376{
377 bool bRet = false;
378
379 if ( m_pFilterList )
380 {
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;
386
387 bRet = pStart != pEnd;
388 }
389
390 return bRet;
391}
392
393
394void SvtFilePicker::ensureFilterList( const OUString& _rInitialCurrentFilter )
395{
396 if ( !m_pFilterList )
397 {
398 m_pFilterList.reset( new FilterList );
399
400 // set the first filter to the current filter
401 if ( m_aCurrentFilter.isEmpty() )
402 m_aCurrentFilter = _rInitialCurrentFilter;
403 }
404}
405
406
407
409 :m_bMultiSelection ( false )
410 ,m_nServiceType ( TemplateDescription::FILEOPEN_SIMPLE )
411{
412}
413
415{
416}
417
419{
420 m_xDlg->SetFileCallback( this );
421
423
424 m_xDlg->EnableAutocompletion();
425 // now we are ready to execute the dialog
426 sal_Int16 nRet = m_xDlg->run();
427
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 );
431
432 return nRet;
433}
434
435std::shared_ptr<SvtFileDialog_Base> SvtFilePicker::implCreateDialog( weld::Window* pParent )
436{
437 PickerFlags nBits = getPickerFlags();
438
439 auto dialog = o3tl::make_shared<SvtFileDialog>(pParent, nBits);
440
441 // Set StandardDir if present
442 if ( !m_aStandardDir.isEmpty())
443 {
444 OUString sStandardDir = m_aStandardDir;
445 dialog->SetStandardDir( sStandardDir );
446 dialog->SetDenyList( m_aDenyList );
447 }
448
449 return dialog;
450}
451
452
453// disambiguate XInterface
454
456
457
458// disambiguate XTypeProvider
459
461
463
464
465// disambiguate XTypeProvider
466
467css::uno::Sequence< css::uno::Type > SAL_CALL SvtRemoteFilePicker::getTypes( )
468{
469 return ::comphelper::concatSequences(
471 OCommonPicker::getTypes(),
473 );
474}
476
477
478// XExecutableDialog functions
479
480
481void SAL_CALL SvtFilePicker::setTitle( const OUString& _rTitle )
482{
483 OCommonPicker::setTitle( _rTitle );
484}
485
486sal_Int16 SAL_CALL SvtFilePicker::execute( )
487{
488 return OCommonPicker::execute();
489}
490
491// XAsynchronousExecutableDialog functions
492void SAL_CALL SvtFilePicker::setDialogTitle( const OUString& _rTitle )
493{
494 setTitle( _rTitle );
495}
496
497void SAL_CALL SvtFilePicker::startExecuteModal( const Reference< css::ui::dialogs::XDialogClosedListener >& xListener )
498{
499 m_xDlgClosedListener = xListener;
502 m_xDlg->EnableAutocompletion();
503 if (!m_xDlg->PrepareExecute())
504 return;
505 weld::DialogController::runAsync(m_xDlg, [this](sal_Int32 nResult){
506 DialogClosedHdl(nResult);
507 });
508}
509
510// XFilePicker functions
512{
513 checkAlive();
514
515 SolarMutexGuard aGuard;
516 m_bMultiSelection = bMode;
517}
518
519void SAL_CALL SvtFilePicker::setDefaultName( const OUString& aName )
520{
521 checkAlive();
522
523 SolarMutexGuard aGuard;
525}
526
527void SAL_CALL SvtFilePicker::setDisplayDirectory( const OUString& aDirectory )
528{
529 checkAlive();
530
531 SolarMutexGuard aGuard;
532 m_aDisplayDirectory = aDirectory;
533}
534
536{
537 checkAlive();
538
539 SolarMutexGuard aGuard;
540 if (m_xDlg)
541 {
542 OUString aPath = m_xDlg->GetPath();
543
544 if( m_aOldHideDirectory == aPath )
546 m_aOldHideDirectory = aPath;
547
548 if( !m_xDlg->ContentIsFolder( aPath ) )
549 {
550 INetURLObject aFolder( aPath );
551 aFolder.CutLastName();
553 }
555 return aPath;
556 }
557 else
558 return m_aDisplayDirectory;
559}
560
561Sequence< OUString > SAL_CALL SvtFilePicker::getSelectedFiles()
562{
563 checkAlive();
564
565 SolarMutexGuard aGuard;
566 if (!m_xDlg)
567 {
568 Sequence< OUString > aEmpty;
569 return aEmpty;
570 }
571
572 return comphelper::containerToSequence(m_xDlg->GetPathList());
573}
574
575Sequence< OUString > SAL_CALL SvtFilePicker::getFiles()
576{
577 Sequence< OUString > aFiles = getSelectedFiles();
578 if (aFiles.getLength() > 1)
579 aFiles.realloc(1);
580 return aFiles;
581}
582
583
584// XFilePickerControlAccess functions
585
586
587void SAL_CALL SvtFilePicker::setValue( sal_Int16 nElementID,
588 sal_Int16 nControlAction,
589 const Any& rValue )
590{
591 checkAlive();
592
593 SolarMutexGuard aGuard;
594 if (m_xDlg)
595 {
596 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
597 aAccess.setValue( nElementID, nControlAction, rValue );
598 }
599 else
600 {
601 if ( !m_pElemList )
602 m_pElemList.reset( new ElementList );
603
604 bool bFound = false;
605
606 for (auto & elem : *m_pElemList)
607 {
608 if ( ( elem.m_nElementID == nElementID ) &&
609 ( !elem.m_bHasValue || ( elem.m_nControlAction == nControlAction ) ) )
610 {
611 elem.setAction( nControlAction );
612 elem.setValue( rValue );
613 bFound = true;
614 }
615 }
616
617 if ( !bFound )
618 {
619 ElementEntry_Impl aNew( nElementID );
620 aNew.setAction( nControlAction );
621 aNew.setValue( rValue );
622 m_pElemList->insert( m_pElemList->end(), aNew );
623 }
624 }
625}
626
627
628Any SAL_CALL SvtFilePicker::getValue( sal_Int16 nElementID, sal_Int16 nControlAction )
629{
630 checkAlive();
631
632 SolarMutexGuard aGuard;
633 Any aAny;
634
635 // execute() called?
636 if (m_xDlg)
637 {
638 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
639 aAny = aAccess.getValue( nElementID, nControlAction );
640 }
641 else if ( m_pElemList )
642 {
643 for (auto const& elem : *m_pElemList)
644 {
645 if ( ( elem.m_nElementID == nElementID ) &&
646 ( elem.m_bHasValue ) &&
647 ( elem.m_nControlAction == nControlAction ) )
648 {
649 aAny = elem.m_aValue;
650 break;
651 }
652 }
653 }
654
655 return aAny;
656}
657
658
659void SAL_CALL SvtFilePicker::setLabel( sal_Int16 nLabelID, const OUString& rValue )
660{
661 checkAlive();
662
663 SolarMutexGuard aGuard;
664 if (m_xDlg)
665 {
666 ::svt::OControlAccess aAccess( m_xDlg.get(), m_xDlg->GetView() );
667 aAccess.setLabel( nLabelID, rValue );
668 }
669 else
670 {
671 if ( !m_pElemList )
672 m_pElemList.reset( new ElementList );
673
674 bool bFound = false;
675
676 for (auto & elem : *m_pElemList)
677 {
678 if ( elem.m_nElementID == nLabelID )
679 {
680 elem.setLabel( rValue );
681 bFound = true;
682 }
683 }
684
685 if ( !bFound )
686 {
687 ElementEntry_Impl aNew( nLabelID );
688 aNew.setLabel( rValue );
689 m_pElemList->insert( m_pElemList->end(), aNew );
690 }
691 }
692}
693
694
695OUString SAL_CALL SvtFilePicker::getLabel( sal_Int16 nLabelID )
696{
697 checkAlive();
698
699 SolarMutexGuard aGuard;
700 OUString aLabel;
701
702 if (m_xDlg)
703 {
704 ::svt::OControlAccess aAccess(m_xDlg.get(), m_xDlg->GetView());
705 aLabel = aAccess.getLabel( nLabelID );
706 }
707 else if ( m_pElemList )
708 {
709 for (auto const& elem : *m_pElemList)
710 {
711 if ( elem.m_nElementID == nLabelID )
712 {
713 if ( elem.m_bHasLabel )
714 aLabel = elem.m_aLabel;
715 break;
716 }
717 }
718 }
719
720 return aLabel;
721}
722
723
724void SAL_CALL SvtFilePicker::enableControl( sal_Int16 nElementID, sal_Bool bEnable )
725{
726 checkAlive();
727
728 SolarMutexGuard aGuard;
729 if (m_xDlg)
730 {
731 ::svt::OControlAccess aAccess(m_xDlg.get(), m_xDlg->GetView());
732 aAccess.enableControl( nElementID, bEnable );
733 }
734 else
735 {
736 if ( !m_pElemList )
737 m_pElemList.reset( new ElementList );
738
739 bool bFound = false;
740
741 for (auto & elem : *m_pElemList)
742 {
743 if ( elem.m_nElementID == nElementID )
744 {
745 elem.setEnabled( bEnable );
746 bFound = true;
747 }
748 }
749
750 if ( !bFound )
751 {
752 ElementEntry_Impl aNew( nElementID );
753 aNew.setEnabled( bEnable );
754 m_pElemList->insert( m_pElemList->end(), aNew );
755 }
756 }
757}
758
759
760// XFilePickerNotifier functions
761
762
763void SAL_CALL SvtFilePicker::addFilePickerListener( const Reference< XFilePickerListener >& xListener )
764{
765 checkAlive();
766
767 SolarMutexGuard aGuard;
768 m_xListener = xListener;
769}
770
771
772void SAL_CALL SvtFilePicker::removeFilePickerListener( const Reference< XFilePickerListener >& )
773{
774 checkAlive();
775
776 SolarMutexGuard aGuard;
777 m_xListener.clear();
778}
779
780// XFilePreview functions
781Sequence< sal_Int16 > SAL_CALL SvtFilePicker::getSupportedImageFormats()
782{
783 checkAlive();
784
785 return { FilePreviewImageFormats::BITMAP };
786}
787
789{
790 return 0;
791}
792
794{
795 checkAlive();
796
797 SolarMutexGuard aGuard;
798 sal_Int32 nWidth = 0;
799
800 if (m_xDlg)
801 nWidth = m_xDlg->getAvailableWidth();
802
803 return nWidth;
804}
805
807{
808 checkAlive();
809
810 SolarMutexGuard aGuard;
811 sal_Int32 nHeight = 0;
812
813 if (m_xDlg)
814 nHeight = m_xDlg->getAvailableHeight();
815
816 return nHeight;
817}
818
819void SAL_CALL SvtFilePicker::setImage(sal_Int16 /*aImageFormat*/, const Any& rImage)
820{
821 checkAlive();
822
823 SolarMutexGuard aGuard;
824 if (m_xDlg)
825 m_xDlg->setImage(rImage);
826}
827
829{
830 checkAlive();
831
832 SolarMutexGuard aGuard;
833 bool bRet = false;
834
835 if (m_xDlg)
836 {
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
848
849 bRet = false;
850 }
851
852 return bRet;
853}
854
855
857{
858 checkAlive();
859
860 SolarMutexGuard aGuard;
861 bool bRet = false;
862
863 if (m_xDlg)
864 bRet = m_xDlg->getShowState();
865
866 return bRet;
867}
868
869
870// XFilterGroupManager functions
871
872
873void SAL_CALL SvtFilePicker::appendFilterGroup( const OUString& sGroupTitle,
874 const Sequence< StringPair >& aFilters )
875{
876 checkAlive();
877
878 SolarMutexGuard aGuard;
879
880 // check the names
881 if ( FilterNameExists( aFilters ) )
882 throw IllegalArgumentException(
883 "filter name exists",
884 getXWeak(), 1);
885
886 // ensure that we have a filter list
887 OUString sInitialCurrentFilter;
888 if ( aFilters.hasElements() )
889 sInitialCurrentFilter = aFilters[0].First;
890 ensureFilterList( sInitialCurrentFilter );
891
892 // append the filter
893 m_pFilterList->insert( m_pFilterList->end(), FilterEntry( sGroupTitle, aFilters ) );
894}
895
896
897// XFilterManager functions
898
899
900void SAL_CALL SvtFilePicker::appendFilter( const OUString& aTitle,
901 const OUString& aFilter )
902{
903 checkAlive();
904
905 SolarMutexGuard aGuard;
906 // check the name
907 if ( FilterNameExists( aTitle ) )
908 // TODO: a more precise exception message
909 throw IllegalArgumentException();
910
911 // ensure that we have a filter list
912 ensureFilterList( aTitle );
913
914 // append the filter
915 m_pFilterList->insert( m_pFilterList->end(), FilterEntry( aTitle, aFilter ) );
916}
917
918
919void SAL_CALL SvtFilePicker::setCurrentFilter( const OUString& aTitle )
920{
921 checkAlive();
922
923 SolarMutexGuard aGuard;
924 if ( ! FilterNameExists( aTitle ) )
925 throw IllegalArgumentException();
926
927 m_aCurrentFilter = aTitle;
928
929 if (m_xDlg)
930 m_xDlg->SetCurFilter( aTitle );
931}
932
933
935{
936 checkAlive();
937
938 SolarMutexGuard aGuard;
939 OUString aFilter = m_xDlg ? m_xDlg->GetCurFilter() :
941 return aFilter;
942}
943
944
945// XInitialization functions
946
947
948void SAL_CALL SvtFilePicker::initialize( const Sequence< Any >& _rArguments )
949{
950 checkAlive();
951
952 Sequence< Any > aArguments( _rArguments.getLength());
953
954 m_nServiceType = TemplateDescription::FILEOPEN_SIMPLE;
955
956 if ( _rArguments.hasElements() )
957 {
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)
962 {
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;
967
968 }
969 for ( int i = index; i < _rArguments.getLength(); i++)
970 {
971 NamedValue namedValue;
972 pArguments[i] = _rArguments[i];
973
974 if (aArguments[i] >>= namedValue )
975 {
976
977 if ( namedValue.Name == "StandardDir" )
978 {
979 OUString sStandardDir;
980
981 namedValue.Value >>= sStandardDir;
982
983 // Set the directory for the "back to the default dir" button
984 if ( !sStandardDir.isEmpty() )
985 {
987 }
988 }
989 else if ( namedValue.Name == "DenyList" )
990 {
991 namedValue.Value >>= m_aDenyList;
992 }
993 }
994 }
995 }
996
997 // let the base class analyze the sequence (will call into implHandleInitializationArgument)
998 OCommonPicker::initialize( aArguments );
999}
1000
1001
1002bool SvtFilePicker::implHandleInitializationArgument( const OUString& _rName, const Any& _rValue )
1003{
1004 if ( _rName == "TemplateDescription" )
1005 {
1006 m_nServiceType = TemplateDescription::FILEOPEN_SIMPLE;
1007 OSL_VERIFY( _rValue >>= m_nServiceType );
1008 return true;
1009 }
1010 if ( _rName == "StandardDir" )
1011 {
1012 OSL_VERIFY( _rValue >>= m_aStandardDir );
1013 return true;
1014 }
1015
1016 if ( _rName == "DenyList" )
1017 {
1018 OSL_VERIFY( _rValue >>= m_aDenyList );
1019 return true;
1020 }
1021
1022
1023 return OCommonPicker::implHandleInitializationArgument( _rName, _rValue );
1024}
1025
1026
1027// XServiceInfo
1028
1029
1030/* XServiceInfo */
1032{
1033 return "com.sun.star.svtools.OfficeFilePicker";
1034}
1035
1036/* XServiceInfo */
1037sal_Bool SAL_CALL SvtFilePicker::supportsService( const OUString& sServiceName )
1038{
1039 return cppu::supportsService(this, sServiceName);
1040}
1041
1042/* XServiceInfo */
1043Sequence< OUString > SAL_CALL SvtFilePicker::getSupportedServiceNames()
1044{
1045 return { "com.sun.star.ui.dialogs.OfficeFilePicker" };
1046}
1047
1048extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1050 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
1051{
1052 return cppu::acquire(new SvtFilePicker());
1053}
1054
1055
1056// SvtRemoteFilePicker
1057
1059{
1060}
1061
1062std::shared_ptr<SvtFileDialog_Base> SvtRemoteFilePicker::implCreateDialog(weld::Window* pParent)
1063{
1064 PickerFlags nBits = getPickerFlags();
1065
1066 auto dialog = std::make_shared<RemoteFilesDialog>(pParent, nBits);
1067
1068 // Set StandardDir if present
1069 if ( !m_aStandardDir.isEmpty())
1070 {
1071 OUString sStandardDir = m_aStandardDir;
1072 dialog->SetStandardDir( sStandardDir );
1073 dialog->SetDenyList( m_aDenyList );
1074 }
1075
1076 return dialog;
1077}
1078
1079// XServiceInfo
1080
1081
1082/* XServiceInfo */
1084{
1085 return "com.sun.star.svtools.RemoteFilePicker";
1086}
1087
1088/* XServiceInfo */
1089sal_Bool SAL_CALL SvtRemoteFilePicker::supportsService( const OUString& sServiceName )
1090{
1091 return cppu::supportsService(this, sServiceName);
1092}
1093
1094/* XServiceInfo */
1096{
1097 return { "com.sun.star.ui.dialogs.RemoteFilePicker" };
1098}
1099
1100
1101extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1103 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
1104{
1105 return cppu::acquire(new SvtRemoteFilePicker());
1106}
1107
1108/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< FilterEntry > FilterList
css::uno::Sequence< UnoFilterEntry > UnoFilterList
css::beans::StringPair UnoFilterEntry
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * fpicker_SvtRemoteFilePicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * fpicker_SvtFilePicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
::std::vector< ElementEntry_Impl > ElementList
constexpr OUStringLiteral sServiceName
constexpr OUStringLiteral sStandardDir
AnyEventRef aEvent
void CutLastName()
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool HasError() const
bool insertName(std::u16string_view rTheName, bool bAppendFinalSlash=false, sal_Int32 nIndex=LAST_SEGMENT, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString m_aStandardDir
virtual sal_Bool SAL_CALL getShowState() override
OUString m_aCurrentFilter
virtual css::uno::Any SAL_CALL getValue(sal_Int16 ElementID, sal_Int16 ControlAction) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL appendFilter(const OUString &aTitle, const OUString &aFilter) override
virtual void SAL_CALL startExecuteModal(const css::uno::Reference< css::ui::dialogs::XDialogClosedListener > &xListener) override
virtual sal_Int32 SAL_CALL getTargetColorDepth() override
virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState) override
virtual void notify(sal_Int16 _nEventId, sal_Int16 _nControlId) override
virtual void SAL_CALL setCurrentFilter(const OUString &aTitle) override
virtual OUString SAL_CALL getDisplayDirectory() override
virtual void SAL_CALL enableControl(sal_Int16 ElementID, sal_Bool bEnable) override
virtual void SAL_CALL removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual OUString SAL_CALL getLabel(sal_Int16 ElementID) override
virtual sal_Int16 implExecutePicker() override
virtual sal_Int16 SAL_CALL execute() override
virtual std::shared_ptr< SvtFileDialog_Base > implCreateDialog(weld::Window *pParent) override
virtual void SAL_CALL setDialogTitle(const OUString &_rTitle) override
virtual sal_Int32 SAL_CALL getAvailableWidth() override
void ensureFilterList(const OUString &_rInitialCurrentFilter)
virtual void SAL_CALL setTitle(const OUString &_rTitle) override
virtual void SAL_CALL setDefaultName(const OUString &aName) override
bool FilterNameExists(const OUString &rTitle)
virtual OUString SAL_CALL getCurrentFilter() override
virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< OUString > SAL_CALL getSelectedFiles() override
std::unique_ptr< ElementList > m_pElemList
virtual sal_Int32 SAL_CALL getAvailableHeight() override
OUString m_aOldHideDirectory
virtual bool implHandleInitializationArgument(const OUString &_rName, const css::uno::Any &_rValue) override
handle a single argument from the XInitialization::initialize method
void DialogClosedHdl(sal_Int32 nResult)
virtual ~SvtFilePicker() override
css::uno::Reference< css::ui::dialogs::XFilePickerListener > m_xListener
virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const css::uno::Any &aImage) override
css::uno::Reference< css::ui::dialogs::XDialogClosedListener > m_xDlgClosedListener
OUString m_aDefaultName
std::unique_ptr< FilterList > m_pFilterList
css::uno::Sequence< OUString > m_aDenyList
OUString m_aOldDisplayDirectory
PickerFlags getPickerFlags() const
virtual css::uno::Sequence< OUString > SAL_CALL getFiles() override
virtual void SAL_CALL setLabel(sal_Int16 ElementID, const OUString &aValue) override
virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats() override
virtual void SAL_CALL setValue(sal_Int16 ElementID, sal_Int16 ControlAction, const css::uno::Any &value) override
virtual void SAL_CALL addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener) override
sal_Int16 m_nServiceType
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void SAL_CALL setDisplayDirectory(const OUString &aDirectory) override
virtual void SAL_CALL appendFilterGroup(const OUString &sGroupTitle, const css::uno::Sequence< css::beans::StringPair > &aFilters) override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual std::shared_ptr< SvtFileDialog_Base > implCreateDialog(weld::Window *pParent) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
std::shared_ptr< SvtFileDialog_Base > m_xDlg
void checkAlive() const
OUString m_aDisplayDirectory
implements the XControlAccess, XControlInformation and XFilePickerControlAccess for the file picker
void setValue(sal_Int16 nId, sal_Int16 nCtrlAction, const css::uno::Any &rValue)
void enableControl(sal_Int16 nId, bool bEnable)
css::uno::Any getValue(sal_Int16 nId, sal_Int16 nCtrlAction) const
void setLabel(sal_Int16 nId, const OUString &rValue)
OUString getLabel(sal_Int16 nId) const
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
OUString m_sTitle
Sequence< FilterName > aSubFilters
#define FILE_SELECTION_CHANGED
#define CTRL_STATE_CHANGED
#define DIALOG_SIZE_CHANGED
#define DIRECTORY_CHANGED
PickerFlags
OUString m_sFilter
Sequence< PropertyValue > aArguments
OUString aName
#define SAL_WARN(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
index
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_GET_IMPLEMENTATION_ID(DrawController)
sal_Int16 nId
ElementEntry_Impl(sal_Int16 nId)
void setAction(sal_Int16 nAction)
void setLabel(const OUString &rVal)
void setEnabled(bool bEnabled)
void setValue(const Any &rVal)
unsigned char sal_Bool
OUString aLabel
#define IMPLEMENT_FORWARD_XINTERFACE3(classname, refcountbase, baseclass2, baseclass3)