1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 #include "OfficeFolderPicker.hxx"
28 
29 #include "iodlg.hxx"
30 
31 #include <list>
32 #include <tools/urlobj.hxx>
33 
34 #define _SVSTDARR_STRINGSDTOR
35 #include "svl/svstdarr.hxx"
36 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
37 #include <com/sun/star/container/XSet.hpp>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <cppuhelper/factory.hxx>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <unotools/pathoptions.hxx>
42 
43 // using ----------------------------------------------------------------
44 
45 using namespace     ::com::sun::star::container;
46 using namespace     ::com::sun::star::lang;
47 using namespace     ::com::sun::star::uno;
48 using namespace     ::com::sun::star::beans;
49 
50 //------------------------------------------------------------------------------------
51 // class SvtFolderPicker
52 //------------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------------
SvtFolderPicker(const Reference<XMultiServiceFactory> & _rxFactory)55 SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory )
56 	:OCommonPicker( _rxFactory )
57 {
58 }
59 
60 //------------------------------------------------------------------------------------
~SvtFolderPicker()61 SvtFolderPicker::~SvtFolderPicker()
62 {
63 }
64 
65 //------------------------------------------------------------------------------------
66 // disambiguate XInterface
67 //------------------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(SvtFolderPicker,OCommonPicker,SvtFolderPicker_Base)68 IMPLEMENT_FORWARD_XINTERFACE2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base )
69 
70 //------------------------------------------------------------------------------------
71 // disambiguate XTypeProvider
72 //------------------------------------------------------------------------------------
73 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base )
74 
75 //------------------------------------------------------------------------------------
76 // XExecutableDialog functions
77 //------------------------------------------------------------------------------------
78 
79 //------------------------------------------------------------------------------------
80 void SAL_CALL SvtFolderPicker::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException)
81 {
82 	OCommonPicker::setTitle( _rTitle );
83 }
84 
85 //------------------------------------------------------------------------------------
execute()86 sal_Int16 SAL_CALL SvtFolderPicker::execute(  ) throw (RuntimeException)
87 {
88 	return OCommonPicker::execute();
89 }
90 
91 //------------------------------------------------------------------------------------
92 // XAsynchronousExecutableDialog functions
93 //------------------------------------------------------------------------------------
94 
95 //------------------------------------------------------------------------------------
setDialogTitle(const::rtl::OUString & _rTitle)96 void SAL_CALL SvtFolderPicker::setDialogTitle( const ::rtl::OUString& _rTitle) throw (RuntimeException)
97 {
98     setTitle( _rTitle );
99 }
100 
101 //------------------------------------------------------------------------------------
startExecuteModal(const Reference<::com::sun::star::ui::dialogs::XDialogClosedListener> & xListener)102 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException)
103 {
104     m_xListener = xListener;
105     prepareDialog();
106     prepareExecute();
107     getDialog()->EnableAutocompletion( sal_True );
108     getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) );
109 }
110 
111 //------------------------------------------------------------------------------------
implCreateDialog(Window * _pParent)112 SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent )
113 {
114 	return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG );
115 }
116 
117 //------------------------------------------------------------------------------------
implExecutePicker()118 sal_Int16 SvtFolderPicker::implExecutePicker( )
119 {
120     prepareExecute();
121 
122     // now we are ready to execute the dialog
123     getDialog()->EnableAutocompletion( sal_False );
124 	sal_Int16 nRet = getDialog()->Execute();
125 
126 	return nRet;
127 }
128 
129 //------------------------------------------------------------------------------------
prepareExecute()130 void SvtFolderPicker::prepareExecute()
131 {
132     // set the default directory
133     if ( m_aDisplayDirectory.getLength() > 0 )
134         getDialog()->SetPath( m_aDisplayDirectory );
135     else
136     {
137         // Default-Standard-Dir setzen
138         INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
139         getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE) );
140     }
141 }
142 
143 //-----------------------------------------------------------------------------
IMPL_LINK(SvtFolderPicker,DialogClosedHdl,Dialog *,pDlg)144 IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog*, pDlg )
145 {
146     if ( m_xListener.is() )
147     {
148         sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() );
149         ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
150         m_xListener->dialogClosed( aEvent );
151         m_xListener.clear();
152     }
153     return 0;
154   }
155 
156 //------------------------------------------------------------------------------------
157 // XFolderPicker functions
158 //------------------------------------------------------------------------------------
159 
setDisplayDirectory(const::rtl::OUString & aDirectory)160 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString& aDirectory )
161     throw( IllegalArgumentException, RuntimeException )
162 {
163 	m_aDisplayDirectory = aDirectory;
164 }
165 
166 //------------------------------------------------------------------------------------
getDisplayDirectory()167 ::rtl::OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException )
168 {
169 	::rtl::OUString aResult;
170 
171     if ( ! getDialog() )
172 		return m_aDisplayDirectory;
173 
174 	SvStringsDtor* pPathList = getDialog()->GetPathList();
175 
176 	if ( pPathList->Count() )
177 		aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
178 
179 	delete pPathList;
180 
181     return aResult;
182 }
183 
184 //------------------------------------------------------------------------------------
getDirectory()185 ::rtl::OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException )
186 {
187 	::rtl::OUString aResult;
188 
189     if ( ! getDialog() )
190 		return m_aDisplayDirectory;
191 
192 	SvStringsDtor* pPathList = getDialog()->GetPathList();
193 
194 	if ( pPathList->Count() )
195 		aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
196 
197 	delete pPathList;
198 
199     return aResult;
200 }
201 
202 //------------------------------------------------------------------------------------
setDescription(const::rtl::OUString & aDescription)203 void SAL_CALL SvtFolderPicker::setDescription( const ::rtl::OUString& aDescription )
204     throw( RuntimeException )
205 {
206 	m_aDescription = aDescription;
207 }
208 
209 //------------------------------------------------------------------------------------
210 // XServiceInfo
211 //------------------------------------------------------------------------------------
212 
213 /* XServiceInfo */
getImplementationName()214 ::rtl::OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException )
215 {
216 	return impl_getStaticImplementationName();
217 }
218 
219 /* XServiceInfo */
supportsService(const::rtl::OUString & sServiceName)220 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const ::rtl::OUString& sServiceName ) throw( RuntimeException )
221 {
222     Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames();
223     const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
224     for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ )
225 	{
226         if ( sServiceName == pArray[i] )
227 		{
228             return sal_True ;
229 		}
230 	}
231     return sal_False ;
232 }
233 
234 /* XServiceInfo */
getSupportedServiceNames()235 Sequence< ::rtl::OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException )
236 {
237 	return impl_getStaticSupportedServiceNames();
238 }
239 
240 /* Helper for XServiceInfo */
impl_getStaticSupportedServiceNames()241 Sequence< ::rtl::OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames()
242 {
243     Sequence< ::rtl::OUString > seqServiceNames(1);
244     seqServiceNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
245     return seqServiceNames ;
246 }
247 
248 /* Helper for XServiceInfo */
impl_getStaticImplementationName()249 ::rtl::OUString SvtFolderPicker::impl_getStaticImplementationName()
250 {
251     return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" );
252 }
253 
254 /* Helper for registry */
impl_createInstance(const Reference<XComponentContext> & rxContext)255 Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext )
256     throw( Exception )
257 {
258 	Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW);
259 	return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) );
260 }
261 
262