1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
31 #include "OfficeFolderPicker.hxx"
36 #include <tools/urlobj.hxx>
38 #define _SVSTDARR_STRINGSDTOR
39 #include "svl/svstdarr.hxx"
40 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
41 #include <com/sun/star/container/XSet.hpp>
42 #include <com/sun/star/uno/Any.hxx>
43 #include <cppuhelper/factory.hxx>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <unotools/pathoptions.hxx>
47 // using ----------------------------------------------------------------
49 using namespace ::com::sun::star::container
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::beans
;
54 //------------------------------------------------------------------------------------
55 // class SvtFolderPicker
56 //------------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------------
59 SvtFolderPicker::SvtFolderPicker( const Reference
< XMultiServiceFactory
>& _rxFactory
)
60 :OCommonPicker( _rxFactory
)
64 //------------------------------------------------------------------------------------
65 SvtFolderPicker::~SvtFolderPicker()
69 //------------------------------------------------------------------------------------
70 // disambiguate XInterface
71 //------------------------------------------------------------------------------------
72 IMPLEMENT_FORWARD_XINTERFACE2( SvtFolderPicker
, OCommonPicker
, SvtFolderPicker_Base
)
74 //------------------------------------------------------------------------------------
75 // disambiguate XTypeProvider
76 //------------------------------------------------------------------------------------
77 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFolderPicker
, OCommonPicker
, SvtFolderPicker_Base
)
79 //------------------------------------------------------------------------------------
80 // XExecutableDialog functions
81 //------------------------------------------------------------------------------------
83 //------------------------------------------------------------------------------------
84 void SAL_CALL
SvtFolderPicker::setTitle( const ::rtl::OUString
& _rTitle
) throw (RuntimeException
)
86 OCommonPicker::setTitle( _rTitle
);
89 //------------------------------------------------------------------------------------
90 sal_Int16 SAL_CALL
SvtFolderPicker::execute( ) throw (RuntimeException
)
92 return OCommonPicker::execute();
95 //------------------------------------------------------------------------------------
96 // XAsynchronousExecutableDialog functions
97 //------------------------------------------------------------------------------------
99 //------------------------------------------------------------------------------------
100 void SAL_CALL
SvtFolderPicker::setDialogTitle( const ::rtl::OUString
& _rTitle
) throw (RuntimeException
)
105 //------------------------------------------------------------------------------------
106 void SAL_CALL
SvtFolderPicker::startExecuteModal( const Reference
< ::com::sun::star::ui::dialogs::XDialogClosedListener
>& xListener
) throw (RuntimeException
)
108 m_xListener
= xListener
;
111 getDialog()->EnableAutocompletion( sal_True
);
112 getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker
, DialogClosedHdl
) );
115 //------------------------------------------------------------------------------------
116 SvtFileDialog
* SvtFolderPicker::implCreateDialog( Window
* _pParent
)
118 return new SvtFileDialog( _pParent
, SFXWB_PATHDIALOG
);
121 //------------------------------------------------------------------------------------
122 sal_Int16
SvtFolderPicker::implExecutePicker( )
126 // now we are ready to execute the dialog
127 getDialog()->EnableAutocompletion( sal_False
);
128 sal_Int16 nRet
= getDialog()->Execute();
133 //------------------------------------------------------------------------------------
134 void SvtFolderPicker::prepareExecute()
136 // set the default directory
137 if ( m_aDisplayDirectory
.getLength() > 0 )
138 getDialog()->SetPath( m_aDisplayDirectory
);
141 // Default-Standard-Dir setzen
142 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
143 getDialog()->SetPath( aStdDirObj
.GetMainURL( INetURLObject::NO_DECODE
) );
147 //-----------------------------------------------------------------------------
148 IMPL_LINK( SvtFolderPicker
, DialogClosedHdl
, Dialog
*, pDlg
)
150 if ( m_xListener
.is() )
152 sal_Int16 nRet
= static_cast< sal_Int16
>( pDlg
->GetResult() );
153 ::com::sun::star::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
154 m_xListener
->dialogClosed( aEvent
);
160 //------------------------------------------------------------------------------------
161 // XFolderPicker functions
162 //------------------------------------------------------------------------------------
164 void SAL_CALL
SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString
& aDirectory
)
165 throw( IllegalArgumentException
, RuntimeException
)
167 m_aDisplayDirectory
= aDirectory
;
170 //------------------------------------------------------------------------------------
171 ::rtl::OUString SAL_CALL
SvtFolderPicker::getDisplayDirectory() throw( RuntimeException
)
173 ::rtl::OUString aResult
;
176 return m_aDisplayDirectory
;
178 SvStringsDtor
* pPathList
= getDialog()->GetPathList();
180 if ( pPathList
->Count() )
181 aResult
= ::rtl::OUString( *pPathList
->GetObject( 0 ) );
188 //------------------------------------------------------------------------------------
189 ::rtl::OUString SAL_CALL
SvtFolderPicker::getDirectory() throw( RuntimeException
)
191 ::rtl::OUString aResult
;
194 return m_aDisplayDirectory
;
196 SvStringsDtor
* pPathList
= getDialog()->GetPathList();
198 if ( pPathList
->Count() )
199 aResult
= ::rtl::OUString( *pPathList
->GetObject( 0 ) );
206 //------------------------------------------------------------------------------------
207 void SAL_CALL
SvtFolderPicker::setDescription( const ::rtl::OUString
& aDescription
)
208 throw( RuntimeException
)
210 m_aDescription
= aDescription
;
213 //------------------------------------------------------------------------------------
215 //------------------------------------------------------------------------------------
218 ::rtl::OUString SAL_CALL
SvtFolderPicker::getImplementationName() throw( RuntimeException
)
220 return impl_getStaticImplementationName();
224 sal_Bool SAL_CALL
SvtFolderPicker::supportsService( const ::rtl::OUString
& sServiceName
) throw( RuntimeException
)
226 Sequence
< ::rtl::OUString
> seqServiceNames
= getSupportedServiceNames();
227 const ::rtl::OUString
* pArray
= seqServiceNames
.getConstArray();
228 for ( sal_Int32 i
= 0; i
< seqServiceNames
.getLength(); i
++ )
230 if ( sServiceName
== pArray
[i
] )
239 Sequence
< ::rtl::OUString
> SAL_CALL
SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException
)
241 return impl_getStaticSupportedServiceNames();
244 /* Helper for XServiceInfo */
245 Sequence
< ::rtl::OUString
> SvtFolderPicker::impl_getStaticSupportedServiceNames()
247 Sequence
< ::rtl::OUString
> seqServiceNames(1);
248 seqServiceNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
249 return seqServiceNames
;
252 /* Helper for XServiceInfo */
253 ::rtl::OUString
SvtFolderPicker::impl_getStaticImplementationName()
255 return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" );
258 /* Helper for registry */
259 Reference
< XInterface
> SAL_CALL
SvtFolderPicker::impl_createInstance( const Reference
< XComponentContext
>& rxContext
)
262 Reference
< XMultiServiceFactory
> xServiceManager (rxContext
->getServiceManager(), UNO_QUERY_THROW
);
263 return Reference
< XInterface
>( *new SvtFolderPicker( xServiceManager
) );