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