1b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b557fc96SAndrew Rist * distributed with this work for additional information
6b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b557fc96SAndrew Rist * "License"); you may not use this file except in compliance
9b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at
10b557fc96SAndrew Rist *
11b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b557fc96SAndrew Rist *
13b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b557fc96SAndrew Rist * software distributed under the License is distributed on an
15b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b557fc96SAndrew Rist * KIND, either express or implied. See the License for the
17b557fc96SAndrew Rist * specific language governing permissions and limitations
18b557fc96SAndrew Rist * under the License.
19b557fc96SAndrew Rist *
20b557fc96SAndrew Rist *************************************************************/
21b557fc96SAndrew Rist
22b557fc96SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir //-----------------------------------------------------------
29cdf0e10cSrcweir // interface includes
30cdf0e10cSrcweir //-----------------------------------------------------------
31cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
32cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
33cdf0e10cSrcweir #include <osl/file.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir //--------------------------------------------------------------
36cdf0e10cSrcweir // other includes
37cdf0e10cSrcweir //--------------------------------------------------------------
38cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #ifndef _RTL_USTRING_
41cdf0e10cSrcweir #include <rtl/ustring.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <sal/types.h>
44cdf0e10cSrcweir #include <osl/diagnose.h>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XFOLDERPICKER_HPP_
47cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir
50cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_
51cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
54cdf0e10cSrcweir
55cdf0e10cSrcweir #include <stdio.h>
56cdf0e10cSrcweir
57cdf0e10cSrcweir #ifndef _FPSERVICEINFO_HXX_
58cdf0e10cSrcweir #include "..\FOPServiceInfo.hxx"
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir
61cdf0e10cSrcweir #include <osl/file.hxx>
62cdf0e10cSrcweir
63cdf0e10cSrcweir #define _WIN32_DCOM
64cdf0e10cSrcweir
65cdf0e10cSrcweir #include <windows.h>
66cdf0e10cSrcweir
67cdf0e10cSrcweir //--------------------------------------------------------------
68cdf0e10cSrcweir // namesapces
69cdf0e10cSrcweir //--------------------------------------------------------------
70cdf0e10cSrcweir
71cdf0e10cSrcweir using namespace ::rtl ;
72cdf0e10cSrcweir using namespace ::cppu ;
73cdf0e10cSrcweir using namespace ::com::sun::star::uno ;
74cdf0e10cSrcweir using namespace ::com::sun::star::lang ;
75cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
76cdf0e10cSrcweir using namespace std ;
77cdf0e10cSrcweir
78cdf0e10cSrcweir //--------------------------------------------------------------
79cdf0e10cSrcweir // defines
80cdf0e10cSrcweir //--------------------------------------------------------------
81cdf0e10cSrcweir
82cdf0e10cSrcweir #define RDB_SYSPATH "D:\\Projects\\gsl\\sysui\\wntmsci7\\bin\\applicat.rdb"
83cdf0e10cSrcweir
84cdf0e10cSrcweir //--------------------------------------------------------------
85cdf0e10cSrcweir // global variables
86cdf0e10cSrcweir //--------------------------------------------------------------
87cdf0e10cSrcweir
88cdf0e10cSrcweir Reference< XMultiServiceFactory > g_xFactory;
89cdf0e10cSrcweir
90cdf0e10cSrcweir /*
91cdf0e10cSrcweir void CreateDeepDirectory( )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // create a deep directory
94cdf0e10cSrcweir
95cdf0e10cSrcweir OUString aPathURL( L"file:///d|/Deep" );
96cdf0e10cSrcweir OUString normalizedPath;
97cdf0e10cSrcweir
98cdf0e10cSrcweir OSL_ASSERT( ::osl::FileBase::E_None == \
99cdf0e10cSrcweir ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
100cdf0e10cSrcweir
101cdf0e10cSrcweir while( ::osl::FileBase::E_None == osl::Directory::create( normalizedPath ) )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir aPathURL += L"/Deep";
104cdf0e10cSrcweir OSL_ASSERT( ::osl::FileBase::E_None == \
105cdf0e10cSrcweir ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir }
109cdf0e10cSrcweir */
110cdf0e10cSrcweir
111cdf0e10cSrcweir //--------------------------------------------------------------
112cdf0e10cSrcweir // main
113cdf0e10cSrcweir //--------------------------------------------------------------
114cdf0e10cSrcweir
115cdf0e10cSrcweir
main(int,char *,char *)116cdf0e10cSrcweir int SAL_CALL main(int /*nArgc*/, char* /*Argv[]*/, char* /*Env[]*/ )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir CoInitializeEx( NULL, COINIT_MULTITHREADED );
119cdf0e10cSrcweir
120cdf0e10cSrcweir printf("Starting test of FolderPicker Service\n");
121cdf0e10cSrcweir
122cdf0e10cSrcweir //CreateDeepDirectory( );
123cdf0e10cSrcweir
124cdf0e10cSrcweir //-------------------------------------------------
125cdf0e10cSrcweir // get the global service-manager
126cdf0e10cSrcweir //-------------------------------------------------
127cdf0e10cSrcweir
128cdf0e10cSrcweir // Get global factory for uno services.
129cdf0e10cSrcweir OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
130cdf0e10cSrcweir Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
131cdf0e10cSrcweir
132*07a3d7f1SPedro Giffuni // Print a message if an error occurred.
133cdf0e10cSrcweir if ( g_xFactory.is() == sal_False )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
136cdf0e10cSrcweir return(-1);
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir printf("Creating RegistryServiceFactory successful\n");
140cdf0e10cSrcweir
141cdf0e10cSrcweir //-------------------------------------------------
142cdf0e10cSrcweir // try to get an Interface to a XFilePicker Service
143cdf0e10cSrcweir //-------------------------------------------------
144cdf0e10cSrcweir
145cdf0e10cSrcweir Reference< XFolderPicker > xFolderPicker;
146cdf0e10cSrcweir
147cdf0e10cSrcweir xFolderPicker = Reference< XFolderPicker >(
148cdf0e10cSrcweir g_xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM ( FOLDER_PICKER_SERVICE_NAME ) ) ), UNO_QUERY );
149cdf0e10cSrcweir
150cdf0e10cSrcweir if ( xFolderPicker.is() == sal_False )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir OSL_ENSURE( sal_False, "Error creating FolderPicker Service" );
153cdf0e10cSrcweir return(-1);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir try
157cdf0e10cSrcweir {
158cdf0e10cSrcweir xFolderPicker->setDisplayDirectory( L"file:///C|" );
159cdf0e10cSrcweir xFolderPicker->setTitle( L"FolderBrowse Dialog" );
160cdf0e10cSrcweir xFolderPicker->execute( );
161cdf0e10cSrcweir
162cdf0e10cSrcweir OUString rootDir = xFolderPicker->getDisplayDirectory( );
163cdf0e10cSrcweir OUString selectedDir = xFolderPicker->getDirectory( );
164cdf0e10cSrcweir
165cdf0e10cSrcweir xFolderPicker->setDisplayDirectory( selectedDir );
166cdf0e10cSrcweir xFolderPicker->execute( );
167cdf0e10cSrcweir
168cdf0e10cSrcweir rootDir = xFolderPicker->getDisplayDirectory( );
169cdf0e10cSrcweir selectedDir = xFolderPicker->getDirectory( );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir MessageBox( NULL, "Exception caught!", "Error", MB_OK );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir //--------------------------------------------------
177cdf0e10cSrcweir // shutdown
178cdf0e10cSrcweir //--------------------------------------------------
179cdf0e10cSrcweir
180cdf0e10cSrcweir // Cast factory to XComponent
181cdf0e10cSrcweir Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
182cdf0e10cSrcweir
183*07a3d7f1SPedro Giffuni // Print a message if an error occurred.
184cdf0e10cSrcweir if ( xComponent.is() == sal_False )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir OSL_ENSURE(sal_False, "Error shuting down");
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir // Dispose and clear factory
190cdf0e10cSrcweir xComponent->dispose();
191cdf0e10cSrcweir g_xFactory.clear();
192cdf0e10cSrcweir g_xFactory = Reference< XMultiServiceFactory >();
193cdf0e10cSrcweir
194cdf0e10cSrcweir printf("Test successful\n");
195cdf0e10cSrcweir
196cdf0e10cSrcweir CoUninitialize( );
197cdf0e10cSrcweir
198cdf0e10cSrcweir return 0;
199cdf0e10cSrcweir }
200