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 
28 //-----------------------------------------------------------
29 //	interface includes
30 //-----------------------------------------------------------
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 #include <osl/file.hxx>
34 
35 //--------------------------------------------------------------
36 //	other includes
37 //--------------------------------------------------------------
38 #include <cppuhelper/servicefactory.hxx>
39 
40 #ifndef _RTL_USTRING_
41 #include <rtl/ustring.hxx>
42 #endif
43 #include <sal/types.h>
44 #include <osl/diagnose.h>
45 
46 #ifndef _COM_SUN_STAR_UI_XFOLDERPICKER_HPP_
47 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
48 #endif
49 
50 #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_
51 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
52 #endif
53 #include <cppuhelper/implbase1.hxx>
54 
55 #include <stdio.h>
56 
57 #ifndef _FPSERVICEINFO_HXX_
58 #include "..\FOPServiceInfo.hxx"
59 #endif
60 
61 #include <osl/file.hxx>
62 
63 #define _WIN32_DCOM
64 
65 #include <windows.h>
66 
67 //--------------------------------------------------------------
68 //	namesapces
69 //--------------------------------------------------------------
70 
71 using namespace	::rtl					;
72 using namespace	::cppu					;
73 using namespace	::com::sun::star::uno	;
74 using namespace	::com::sun::star::lang	;
75 using namespace ::com::sun::star::ui::dialogs;
76 using namespace std						;
77 
78 //--------------------------------------------------------------
79 //	defines
80 //--------------------------------------------------------------
81 
82 #define RDB_SYSPATH "D:\\Projects\\gsl\\sysui\\wntmsci7\\bin\\applicat.rdb"
83 
84 //--------------------------------------------------------------
85 //	global variables
86 //--------------------------------------------------------------
87 
88 Reference< XMultiServiceFactory >	g_xFactory;
89 
90 /*
91 void CreateDeepDirectory( )
92 {
93 	// create a deep directory
94 
95 	OUString aPathURL( L"file:///d|/Deep" );
96 	OUString normalizedPath;
97 
98 	OSL_ASSERT( ::osl::FileBase::E_None == \
99 		::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
100 
101 	while( ::osl::FileBase::E_None == osl::Directory::create( normalizedPath ) )
102 	{
103 		aPathURL += L"/Deep";
104 		OSL_ASSERT( ::osl::FileBase::E_None == \
105 			::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
106 	}
107 
108 }
109 */
110 
111 //--------------------------------------------------------------
112 //	main
113 //--------------------------------------------------------------
114 
115 
main(int,char *,char *)116 int SAL_CALL main(int /*nArgc*/, char* /*Argv[]*/, char* /*Env[]*/	)
117 {
118 	CoInitializeEx( NULL, COINIT_MULTITHREADED );
119 
120 	printf("Starting test of FolderPicker Service\n");
121 
122 	//CreateDeepDirectory( );
123 
124 	//-------------------------------------------------
125 	// get the global service-manager
126 	//-------------------------------------------------
127 
128 	// Get global factory for uno services.
129 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
130 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
131 
132 	// Print a message if an error occured.
133 	if ( g_xFactory.is() == sal_False )
134 	{
135 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
136 		return(-1);
137 	}
138 
139 	printf("Creating RegistryServiceFactory successful\n");
140 
141 	//-------------------------------------------------
142 	// try to get an Interface to a XFilePicker Service
143 	//-------------------------------------------------
144 
145 	Reference< XFolderPicker > xFolderPicker;
146 
147 	xFolderPicker = Reference< XFolderPicker >(
148 		g_xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM ( FOLDER_PICKER_SERVICE_NAME ) ) ), UNO_QUERY );
149 
150 	if ( xFolderPicker.is() == sal_False )
151 	{
152 		OSL_ENSURE( sal_False, "Error creating FolderPicker Service" );
153 		return(-1);
154 	}
155 
156 	try
157 	{
158 		xFolderPicker->setDisplayDirectory( L"file:///C|" );
159 		xFolderPicker->setTitle( L"FolderBrowse Dialog" );
160 		xFolderPicker->execute( );
161 
162 		OUString rootDir = xFolderPicker->getDisplayDirectory( );
163 	    OUString selectedDir = xFolderPicker->getDirectory( );
164 
165         xFolderPicker->setDisplayDirectory( selectedDir );
166 		xFolderPicker->execute( );
167 
168         rootDir = xFolderPicker->getDisplayDirectory( );
169 	    selectedDir = xFolderPicker->getDirectory( );
170 	}
171     catch( ::com::sun::star::uno::Exception& )
172 	{
173 		MessageBox( NULL, "Exception caught!", "Error", MB_OK );
174 	}
175 
176 	//--------------------------------------------------
177 	// shutdown
178 	//--------------------------------------------------
179 
180 	// Cast factory to XComponent
181 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
182 
183 	// Print a message if an error occured.
184 	if ( xComponent.is() == sal_False )
185 	{
186 		OSL_ENSURE(sal_False, "Error shuting down");
187 	}
188 
189 	// Dispose and clear factory
190 	xComponent->dispose();
191 	g_xFactory.clear();
192 	g_xFactory = Reference< XMultiServiceFactory >();
193 
194 	printf("Test successful\n");
195 
196 	CoUninitialize( );
197 
198 	return 0;
199 }
200