update dev300-m58
[ooovba.git] / padmin / source / pamain.cxx
blobb82e009658aea62446accfed1294b57c28046ce8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pamain.cxx,v $
10 * $Revision: 1.17 $
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 #include <stdio.h>
32 #include <unistd.h>
34 #include "tools/testtoolloader.hxx"
36 #include "vcl/svapp.hxx"
37 #include "vcl/wrkwin.hxx"
38 #include "vcl/unowrap.hxx"
40 #include "padialog.hxx"
41 #include "helper.hxx"
42 #include "desktopcontext.hxx"
44 #include "cppuhelper/bootstrap.hxx"
45 #include "comphelper/processfactory.hxx"
46 #include "ucbhelper/contentbroker.hxx"
47 #include "ucbhelper/configurationkeys.hxx"
48 #include "unotools/configmgr.hxx"
50 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
52 using namespace padmin;
53 using namespace rtl;
54 using namespace cppu;
55 using namespace com::sun::star::uno;
56 using namespace com::sun::star::lang;
57 using namespace comphelper;
59 // -----------------------------------------------------------------------
61 class MyApp : public Application
63 public:
64 void Main();
65 virtual USHORT Exception( USHORT nError );
67 static void ReadStringHook( String& );
70 MyApp aMyApp;
72 void MyApp::ReadStringHook( String& rStr )
74 static String maProduct;
75 if( ! maProduct.Len() )
77 Any aRet = utl::ConfigManager::GetDirectConfigProperty( utl::ConfigManager::PRODUCTNAME );
78 OUString aProd;
79 aRet >>= aProd;
80 maProduct = String( aProd );
82 rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", maProduct );
86 // -----------------------------------------------------------------------
88 USHORT MyApp::Exception( USHORT nError )
90 switch( nError & EXC_MAJORTYPE )
92 case EXC_RSCNOTLOADED:
93 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
94 break;
96 return 0;
99 void MyApp::Main()
101 PADialog* pPADialog;
103 EnableAutoHelpId();
105 //-------------------------------------------------
106 // create the global service-manager
107 //-------------------------------------------------
108 Reference< XMultiServiceFactory > xFactory;
111 Reference< XComponentContext > xCtx = defaultBootstrap_InitialComponentContext();
112 xFactory = Reference< XMultiServiceFactory >( xCtx->getServiceManager(), UNO_QUERY );
113 if( xFactory.is() )
114 setProcessServiceFactory( xFactory );
116 catch( com::sun::star::uno::Exception& rExc)
120 if( ! xFactory.is() )
122 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
123 exit( 1 );
126 // Detect desktop environment - need to do this as early as possible
127 com::sun::star::uno::setCurrentContext(
128 new DesktopContext( com::sun::star::uno::getCurrentContext() ) );
131 * Create UCB.
133 Sequence< Any > aArgs( 2 );
134 aArgs[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
135 aArgs[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
136 #if OSL_DEBUG_LEVEL > 1
137 sal_Bool bSuccess =
138 #endif
139 ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
141 #if OSL_DEBUG_LEVEL > 1
142 if ( !bSuccess )
144 fprintf( stderr, "Error creating UCB, installation must be in disorder. Exiting.\n" );
145 exit( 1 );
147 #endif
150 * Initialize the Java UNO AccessBridge if accessibility is turned on
153 if( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() )
155 BOOL bQuitApp;
156 if( !InitAccessBridge( true, bQuitApp ) )
157 if( bQuitApp )
158 return;
161 // initialize test-tool library (if available)
162 tools::InitTestToolLib();
164 ResMgr::SetReadStringHook( MyApp::ReadStringHook );
166 pPADialog = PADialog::Create( NULL , FALSE );
167 Application::SetDisplayName( pPADialog->GetText() );
168 pPADialog->SetIcon(501);
169 pPADialog->Execute();
170 delete pPADialog;
172 tools::DeInitTestToolLib();
175 * clean up UCB
177 ::ucbhelper::ContentBroker::deinitialize();