1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Test_fops.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
35 //-----------------------------------------------------------
37 //-----------------------------------------------------------
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/registry/XSimpleRegistry.hpp>
40 #include <osl/file.hxx>
42 //--------------------------------------------------------------
44 //--------------------------------------------------------------
45 #include <cppuhelper/servicefactory.hxx>
48 #include <rtl/ustring.hxx>
50 #include <sal/types.h>
51 #include <osl/diagnose.h>
53 #ifndef _COM_SUN_STAR_UI_XFOLDERPICKER_HPP_
54 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
57 #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_
58 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
60 #include <cppuhelper/implbase1.hxx>
64 #ifndef _FPSERVICEINFO_HXX_
65 #include "..\FOPServiceInfo.hxx"
68 #include <osl/file.hxx>
74 //--------------------------------------------------------------
76 //--------------------------------------------------------------
78 using namespace ::rtl
;
79 using namespace ::cppu
;
80 using namespace ::com::sun::star::uno
;
81 using namespace ::com::sun::star::lang
;
82 using namespace ::com::sun::star::ui::dialogs
;
85 //--------------------------------------------------------------
87 //--------------------------------------------------------------
89 #define RDB_SYSPATH "D:\\Projects\\gsl\\sysui\\wntmsci7\\bin\\applicat.rdb"
91 //--------------------------------------------------------------
93 //--------------------------------------------------------------
95 Reference
< XMultiServiceFactory
> g_xFactory
;
98 void CreateDeepDirectory( )
100 // create a deep directory
102 OUString aPathURL( L"file:///d|/Deep" );
103 OUString normalizedPath;
105 OSL_ASSERT( ::osl::FileBase::E_None == \
106 ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
108 while( ::osl::FileBase::E_None == osl::Directory::create( normalizedPath ) )
110 aPathURL += L"/Deep";
111 OSL_ASSERT( ::osl::FileBase::E_None == \
112 ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) );
118 //--------------------------------------------------------------
120 //--------------------------------------------------------------
123 int SAL_CALL
main(int /*nArgc*/, char* /*Argv[]*/, char* /*Env[]*/ )
125 CoInitializeEx( NULL
, COINIT_MULTITHREADED
);
127 printf("Starting test of FolderPicker Service\n");
129 //CreateDeepDirectory( );
131 //-------------------------------------------------
132 // get the global service-manager
133 //-------------------------------------------------
135 // Get global factory for uno services.
136 OUString rdbName
= OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH
) );
137 Reference
< XMultiServiceFactory
> g_xFactory( createRegistryServiceFactory( rdbName
) );
139 // Print a message if an error occured.
140 if ( g_xFactory
.is() == sal_False
)
142 OSL_ENSURE(sal_False
, "Can't create RegistryServiceFactory");
146 printf("Creating RegistryServiceFactory successful\n");
148 //-------------------------------------------------
149 // try to get an Interface to a XFilePicker Service
150 //-------------------------------------------------
152 Reference
< XFolderPicker
> xFolderPicker
;
154 xFolderPicker
= Reference
< XFolderPicker
>(
155 g_xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM ( FOLDER_PICKER_SERVICE_NAME
) ) ), UNO_QUERY
);
157 if ( xFolderPicker
.is() == sal_False
)
159 OSL_ENSURE( sal_False
, "Error creating FolderPicker Service" );
165 xFolderPicker
->setDisplayDirectory( L
"file:///C|" );
166 xFolderPicker
->setTitle( L
"FolderBrowse Dialog" );
167 xFolderPicker
->execute( );
169 OUString rootDir
= xFolderPicker
->getDisplayDirectory( );
170 OUString selectedDir
= xFolderPicker
->getDirectory( );
172 xFolderPicker
->setDisplayDirectory( selectedDir
);
173 xFolderPicker
->execute( );
175 rootDir
= xFolderPicker
->getDisplayDirectory( );
176 selectedDir
= xFolderPicker
->getDirectory( );
178 catch( ::com::sun::star::uno::Exception
& )
180 MessageBox( NULL
, "Exception caught!", "Error", MB_OK
);
183 //--------------------------------------------------
185 //--------------------------------------------------
187 // Cast factory to XComponent
188 Reference
< XComponent
> xComponent( g_xFactory
, UNO_QUERY
);
190 // Print a message if an error occured.
191 if ( xComponent
.is() == sal_False
)
193 OSL_ENSURE(sal_False
, "Error shuting down");
196 // Dispose and clear factory
197 xComponent
->dispose();
199 g_xFactory
= Reference
< XMultiServiceFactory
>();
201 printf("Test successful\n");