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 #include <stdio.h> 29 #include <unistd.h> 30 31 #include "tools/testtoolloader.hxx" 32 33 #include "vcl/svapp.hxx" 34 #include "vcl/wrkwin.hxx" 35 #include "vcl/unowrap.hxx" 36 37 #include "padialog.hxx" 38 #include "helper.hxx" 39 #include "desktopcontext.hxx" 40 41 #include "cppuhelper/bootstrap.hxx" 42 #include "comphelper/processfactory.hxx" 43 #include "ucbhelper/contentbroker.hxx" 44 #include "ucbhelper/configurationkeys.hxx" 45 #include "unotools/configmgr.hxx" 46 47 #include "com/sun/star/lang/XMultiServiceFactory.hpp" 48 49 using namespace padmin; 50 using namespace rtl; 51 using namespace cppu; 52 using namespace com::sun::star::uno; 53 using namespace com::sun::star::lang; 54 using namespace comphelper; 55 56 // ----------------------------------------------------------------------- 57 58 class MyApp : public Application 59 { 60 public: 61 void Main(); 62 virtual sal_uInt16 Exception( sal_uInt16 nError ); 63 64 static void ReadStringHook( String& ); 65 }; 66 67 MyApp aMyApp; 68 69 void MyApp::ReadStringHook( String& rStr ) 70 { 71 static String maProduct; 72 if( ! maProduct.Len() ) 73 { 74 Any aRet = utl::ConfigManager::GetDirectConfigProperty( utl::ConfigManager::PRODUCTNAME ); 75 OUString aProd; 76 aRet >>= aProd; 77 maProduct = String( aProd ); 78 } 79 rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", maProduct ); 80 }; 81 82 83 // ----------------------------------------------------------------------- 84 85 sal_uInt16 MyApp::Exception( sal_uInt16 nError ) 86 { 87 switch( nError & EXC_MAJORTYPE ) 88 { 89 case EXC_RSCNOTLOADED: 90 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) ); 91 break; 92 } 93 return 0; 94 } 95 96 void MyApp::Main() 97 { 98 PADialog* pPADialog; 99 100 EnableAutoHelpId(); 101 102 //------------------------------------------------- 103 // create the global service-manager 104 //------------------------------------------------- 105 Reference< XMultiServiceFactory > xFactory; 106 try 107 { 108 Reference< XComponentContext > xCtx = defaultBootstrap_InitialComponentContext(); 109 xFactory = Reference< XMultiServiceFactory >( xCtx->getServiceManager(), UNO_QUERY ); 110 if( xFactory.is() ) 111 setProcessServiceFactory( xFactory ); 112 } 113 catch( com::sun::star::uno::Exception& rExc) 114 { 115 } 116 117 if( ! xFactory.is() ) 118 { 119 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" ); 120 exit( 1 ); 121 } 122 123 // Detect desktop environment - need to do this as early as possible 124 com::sun::star::uno::setCurrentContext( 125 new DesktopContext( com::sun::star::uno::getCurrentContext() ) ); 126 127 /* 128 * Create UCB. 129 */ 130 Sequence< Any > aArgs( 2 ); 131 aArgs[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL ); 132 aArgs[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE ); 133 #if OSL_DEBUG_LEVEL > 1 134 sal_Bool bSuccess = 135 #endif 136 ::ucbhelper::ContentBroker::initialize( xFactory, aArgs ); 137 138 #if OSL_DEBUG_LEVEL > 1 139 if ( !bSuccess ) 140 { 141 fprintf( stderr, "Error creating UCB, installation must be in disorder. Exiting.\n" ); 142 exit( 1 ); 143 } 144 #endif 145 146 /* 147 * Initialize the Java UNO AccessBridge if accessibility is turned on 148 */ 149 150 if( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() ) 151 { 152 sal_Bool bQuitApp; 153 if( !InitAccessBridge( true, bQuitApp ) ) 154 if( bQuitApp ) 155 return; 156 } 157 158 // initialize test-tool library (if available) 159 tools::InitTestToolLib(); 160 161 ResMgr::SetReadStringHook( MyApp::ReadStringHook ); 162 163 pPADialog = PADialog::Create( NULL , sal_False ); 164 Application::SetDisplayName( pPADialog->GetText() ); 165 pPADialog->SetIcon(501); 166 pPADialog->Execute(); 167 delete pPADialog; 168 169 tools::DeInitTestToolLib(); 170 171 /* 172 * clean up UCB 173 */ 174 ::ucbhelper::ContentBroker::deinitialize(); 175 176 } 177