1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_fpicker.hxx" 30 31 32 //----------------------------------------------------------- 33 // interface includes 34 //----------------------------------------------------------- 35 #include <com/sun/star/lang/XComponent.hpp> 36 #include <com/sun/star/registry/XSimpleRegistry.hpp> 37 #include <osl/file.hxx> 38 39 //-------------------------------------------------------------- 40 // other includes 41 //-------------------------------------------------------------- 42 #include <cppuhelper/servicefactory.hxx> 43 44 #ifndef _RTL_USTRING_ 45 #include <rtl/ustring.hxx> 46 #endif 47 #include <sal/types.h> 48 #include <osl/diagnose.h> 49 50 #ifndef _COM_SUN_STAR_UI_XFOLDERPICKER_HPP_ 51 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 52 #endif 53 54 #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_ 55 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 56 #endif 57 #include <cppuhelper/implbase1.hxx> 58 59 #include <stdio.h> 60 61 #ifndef _FPSERVICEINFO_HXX_ 62 #include "..\FOPServiceInfo.hxx" 63 #endif 64 65 #include <osl/file.hxx> 66 67 #define _WIN32_DCOM 68 69 #include <windows.h> 70 71 //-------------------------------------------------------------- 72 // namesapces 73 //-------------------------------------------------------------- 74 75 using namespace ::rtl ; 76 using namespace ::cppu ; 77 using namespace ::com::sun::star::uno ; 78 using namespace ::com::sun::star::lang ; 79 using namespace ::com::sun::star::ui::dialogs; 80 using namespace std ; 81 82 //-------------------------------------------------------------- 83 // defines 84 //-------------------------------------------------------------- 85 86 #define RDB_SYSPATH "D:\\Projects\\gsl\\sysui\\wntmsci7\\bin\\applicat.rdb" 87 88 //-------------------------------------------------------------- 89 // global variables 90 //-------------------------------------------------------------- 91 92 Reference< XMultiServiceFactory > g_xFactory; 93 94 /* 95 void CreateDeepDirectory( ) 96 { 97 // create a deep directory 98 99 OUString aPathURL( L"file:///d|/Deep" ); 100 OUString normalizedPath; 101 102 OSL_ASSERT( ::osl::FileBase::E_None == \ 103 ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) ); 104 105 while( ::osl::FileBase::E_None == osl::Directory::create( normalizedPath ) ) 106 { 107 aPathURL += L"/Deep"; 108 OSL_ASSERT( ::osl::FileBase::E_None == \ 109 ::osl::FileBase::getNormalizedPathFromFileURL( aPathURL, normalizedPath ) ); 110 } 111 112 } 113 */ 114 115 //-------------------------------------------------------------- 116 // main 117 //-------------------------------------------------------------- 118 119 120 int SAL_CALL main(int /*nArgc*/, char* /*Argv[]*/, char* /*Env[]*/ ) 121 { 122 CoInitializeEx( NULL, COINIT_MULTITHREADED ); 123 124 printf("Starting test of FolderPicker Service\n"); 125 126 //CreateDeepDirectory( ); 127 128 //------------------------------------------------- 129 // get the global service-manager 130 //------------------------------------------------- 131 132 // Get global factory for uno services. 133 OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) ); 134 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) ); 135 136 // Print a message if an error occured. 137 if ( g_xFactory.is() == sal_False ) 138 { 139 OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory"); 140 return(-1); 141 } 142 143 printf("Creating RegistryServiceFactory successful\n"); 144 145 //------------------------------------------------- 146 // try to get an Interface to a XFilePicker Service 147 //------------------------------------------------- 148 149 Reference< XFolderPicker > xFolderPicker; 150 151 xFolderPicker = Reference< XFolderPicker >( 152 g_xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM ( FOLDER_PICKER_SERVICE_NAME ) ) ), UNO_QUERY ); 153 154 if ( xFolderPicker.is() == sal_False ) 155 { 156 OSL_ENSURE( sal_False, "Error creating FolderPicker Service" ); 157 return(-1); 158 } 159 160 try 161 { 162 xFolderPicker->setDisplayDirectory( L"file:///C|" ); 163 xFolderPicker->setTitle( L"FolderBrowse Dialog" ); 164 xFolderPicker->execute( ); 165 166 OUString rootDir = xFolderPicker->getDisplayDirectory( ); 167 OUString selectedDir = xFolderPicker->getDirectory( ); 168 169 xFolderPicker->setDisplayDirectory( selectedDir ); 170 xFolderPicker->execute( ); 171 172 rootDir = xFolderPicker->getDisplayDirectory( ); 173 selectedDir = xFolderPicker->getDirectory( ); 174 } 175 catch( ::com::sun::star::uno::Exception& ) 176 { 177 MessageBox( NULL, "Exception caught!", "Error", MB_OK ); 178 } 179 180 //-------------------------------------------------- 181 // shutdown 182 //-------------------------------------------------- 183 184 // Cast factory to XComponent 185 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY ); 186 187 // Print a message if an error occured. 188 if ( xComponent.is() == sal_False ) 189 { 190 OSL_ENSURE(sal_False, "Error shuting down"); 191 } 192 193 // Dispose and clear factory 194 xComponent->dispose(); 195 g_xFactory.clear(); 196 g_xFactory = Reference< XMultiServiceFactory >(); 197 198 printf("Test successful\n"); 199 200 CoUninitialize( ); 201 202 return 0; 203 } 204