xref: /trunk/main/fpicker/source/office/OfficeFolderPicker.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 //------------------------------------------------------------------------------------
55 SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory )
56     :OCommonPicker( _rxFactory )
57 {
58 }
59 
60 //------------------------------------------------------------------------------------
61 SvtFolderPicker::~SvtFolderPicker()
62 {
63 }
64 
65 //------------------------------------------------------------------------------------
66 // disambiguate XInterface
67 //------------------------------------------------------------------------------------
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 )
81 {
82     OCommonPicker::setTitle( _rTitle );
83 }
84 
85 //------------------------------------------------------------------------------------
86 sal_Int16 SAL_CALL SvtFolderPicker::execute(  )
87 {
88     return OCommonPicker::execute();
89 }
90 
91 //------------------------------------------------------------------------------------
92 // XAsynchronousExecutableDialog functions
93 //------------------------------------------------------------------------------------
94 
95 //------------------------------------------------------------------------------------
96 void SAL_CALL SvtFolderPicker::setDialogTitle( const ::rtl::OUString& _rTitle)
97 {
98     setTitle( _rTitle );
99 }
100 
101 //------------------------------------------------------------------------------------
102 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener )
103 {
104     m_xListener = xListener;
105     prepareDialog();
106     prepareExecute();
107     getDialog()->EnableAutocompletion( sal_True );
108     getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) );
109 }
110 
111 //------------------------------------------------------------------------------------
112 SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent )
113 {
114     return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG );
115 }
116 
117 //------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
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 
160 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString& aDirectory )
161 {
162     m_aDisplayDirectory = aDirectory;
163 }
164 
165 //------------------------------------------------------------------------------------
166 ::rtl::OUString SAL_CALL SvtFolderPicker::getDisplayDirectory()
167 {
168     ::rtl::OUString aResult;
169 
170     if ( ! getDialog() )
171         return m_aDisplayDirectory;
172 
173     SvStringsDtor* pPathList = getDialog()->GetPathList();
174 
175     if ( pPathList->Count() )
176         aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
177 
178     delete pPathList;
179 
180     return aResult;
181 }
182 
183 //------------------------------------------------------------------------------------
184 ::rtl::OUString SAL_CALL SvtFolderPicker::getDirectory()
185 {
186     ::rtl::OUString aResult;
187 
188     if ( ! getDialog() )
189         return m_aDisplayDirectory;
190 
191     SvStringsDtor* pPathList = getDialog()->GetPathList();
192 
193     if ( pPathList->Count() )
194         aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
195 
196     delete pPathList;
197 
198     return aResult;
199 }
200 
201 //------------------------------------------------------------------------------------
202 void SAL_CALL SvtFolderPicker::setDescription( const ::rtl::OUString& aDescription )
203 {
204     m_aDescription = aDescription;
205 }
206 
207 //------------------------------------------------------------------------------------
208 // XServiceInfo
209 //------------------------------------------------------------------------------------
210 
211 /* XServiceInfo */
212 ::rtl::OUString SAL_CALL SvtFolderPicker::getImplementationName()
213 {
214     return impl_getStaticImplementationName();
215 }
216 
217 /* XServiceInfo */
218 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const ::rtl::OUString& sServiceName )
219 {
220     Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames();
221     const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
222     for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ )
223     {
224         if ( sServiceName == pArray[i] )
225         {
226             return sal_True ;
227         }
228     }
229     return sal_False ;
230 }
231 
232 /* XServiceInfo */
233 Sequence< ::rtl::OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames()
234 {
235     return impl_getStaticSupportedServiceNames();
236 }
237 
238 /* Helper for XServiceInfo */
239 Sequence< ::rtl::OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames()
240 {
241     Sequence< ::rtl::OUString > seqServiceNames(1);
242     seqServiceNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
243     return seqServiceNames ;
244 }
245 
246 /* Helper for XServiceInfo */
247 ::rtl::OUString SvtFolderPicker::impl_getStaticImplementationName()
248 {
249     return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" );
250 }
251 
252 /* Helper for registry */
253 Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext )
254 {
255     Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW);
256     return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) );
257 }
258