xref: /aoo42x/main/padmin/source/pamain.cxx (revision 9625a7c7)
1466d5a0bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3466d5a0bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4466d5a0bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5466d5a0bSAndrew Rist  * distributed with this work for additional information
6466d5a0bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7466d5a0bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8466d5a0bSAndrew Rist  * "License"); you may not use this file except in compliance
9466d5a0bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10466d5a0bSAndrew Rist  *
11466d5a0bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12466d5a0bSAndrew Rist  *
13466d5a0bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14466d5a0bSAndrew Rist  * software distributed under the License is distributed on an
15466d5a0bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16466d5a0bSAndrew Rist  * KIND, either express or implied.  See the License for the
17466d5a0bSAndrew Rist  * specific language governing permissions and limitations
18466d5a0bSAndrew Rist  * under the License.
19466d5a0bSAndrew Rist  *
20466d5a0bSAndrew Rist  *************************************************************/
21466d5a0bSAndrew Rist 
22466d5a0bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir #include <unistd.h>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "tools/testtoolloader.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "vcl/svapp.hxx"
30cdf0e10cSrcweir #include "vcl/wrkwin.hxx"
31cdf0e10cSrcweir #include "vcl/unowrap.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "padialog.hxx"
34cdf0e10cSrcweir #include "helper.hxx"
35cdf0e10cSrcweir #include "desktopcontext.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
38cdf0e10cSrcweir #include "comphelper/processfactory.hxx"
39cdf0e10cSrcweir #include "ucbhelper/contentbroker.hxx"
40cdf0e10cSrcweir #include "ucbhelper/configurationkeys.hxx"
41cdf0e10cSrcweir #include "unotools/configmgr.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace padmin;
46cdf0e10cSrcweir using namespace rtl;
47cdf0e10cSrcweir using namespace cppu;
48cdf0e10cSrcweir using namespace com::sun::star::uno;
49cdf0e10cSrcweir using namespace com::sun::star::lang;
50cdf0e10cSrcweir using namespace comphelper;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // -----------------------------------------------------------------------
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class MyApp : public Application
55cdf0e10cSrcweir {
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir     void			Main();
58cdf0e10cSrcweir 	virtual sal_uInt16	Exception( sal_uInt16 nError );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     static void ReadStringHook( String& );
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir MyApp aMyApp;
64cdf0e10cSrcweir 
ReadStringHook(String & rStr)65cdf0e10cSrcweir void MyApp::ReadStringHook( String& rStr )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     static String maProduct;
68cdf0e10cSrcweir     if( ! maProduct.Len() )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         Any aRet = utl::ConfigManager::GetDirectConfigProperty( utl::ConfigManager::PRODUCTNAME );
71cdf0e10cSrcweir         OUString aProd;
72cdf0e10cSrcweir         aRet >>= aProd;
73cdf0e10cSrcweir         maProduct = String( aProd );
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir     rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", maProduct );
76cdf0e10cSrcweir };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // -----------------------------------------------------------------------
80cdf0e10cSrcweir 
Exception(sal_uInt16 nError)81cdf0e10cSrcweir sal_uInt16 MyApp::Exception( sal_uInt16 nError )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	switch( nError & EXC_MAJORTYPE )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		case EXC_RSCNOTLOADED:
86cdf0e10cSrcweir 			Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
87cdf0e10cSrcweir 			break;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 	return 0;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
Main()92cdf0e10cSrcweir void MyApp::Main()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	PADialog* pPADialog;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     EnableAutoHelpId();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	//-------------------------------------------------
99cdf0e10cSrcweir 	// create the global service-manager
100cdf0e10cSrcweir 	//-------------------------------------------------
101cdf0e10cSrcweir     Reference< XMultiServiceFactory > xFactory;
102cdf0e10cSrcweir     try
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         Reference< XComponentContext > xCtx = defaultBootstrap_InitialComponentContext();
105cdf0e10cSrcweir         xFactory = Reference< XMultiServiceFactory >(  xCtx->getServiceManager(), UNO_QUERY );
106cdf0e10cSrcweir         if( xFactory.is() )
107cdf0e10cSrcweir             setProcessServiceFactory( xFactory );
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     catch( com::sun::star::uno::Exception& rExc)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     if( ! xFactory.is() )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
116cdf0e10cSrcweir         exit( 1 );
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	// Detect desktop environment - need to do this as early as possible
120cdf0e10cSrcweir     com::sun::star::uno::setCurrentContext(
121cdf0e10cSrcweir         new DesktopContext( com::sun::star::uno::getCurrentContext() ) );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     /*
124cdf0e10cSrcweir      *	Create UCB.
125cdf0e10cSrcweir      */
126cdf0e10cSrcweir 	Sequence< Any > aArgs( 2 );
127cdf0e10cSrcweir 	aArgs[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
128cdf0e10cSrcweir 	aArgs[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
129cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
130cdf0e10cSrcweir 	sal_Bool bSuccess =
131cdf0e10cSrcweir #endif
132cdf0e10cSrcweir         ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
135cdf0e10cSrcweir 	if ( !bSuccess )
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir 		fprintf( stderr, "Error creating UCB, installation must be in disorder. Exiting.\n" );
138cdf0e10cSrcweir         exit( 1 );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir #endif
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     /*
143cdf0e10cSrcweir      * Initialize the Java UNO AccessBridge if accessibility is turned on
144cdf0e10cSrcweir      */
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() )
147cdf0e10cSrcweir     {
148*9625a7c7SAndre Fischer         sal_Bool bQuitApp (sal_False);
149cdf0e10cSrcweir         if( !InitAccessBridge( true, bQuitApp ) )
150cdf0e10cSrcweir             if( bQuitApp )
151cdf0e10cSrcweir                 return;
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // initialize test-tool library (if available)
155cdf0e10cSrcweir     tools::InitTestToolLib();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     ResMgr::SetReadStringHook( MyApp::ReadStringHook );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	pPADialog = PADialog::Create( NULL , sal_False );
160cdf0e10cSrcweir 	Application::SetDisplayName( pPADialog->GetText() );
161cdf0e10cSrcweir 	pPADialog->SetIcon(501);
162cdf0e10cSrcweir 	pPADialog->Execute();
163cdf0e10cSrcweir 	delete pPADialog;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     tools::DeInitTestToolLib();
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     /*
168cdf0e10cSrcweir      *  clean up UCB
169cdf0e10cSrcweir      */
170cdf0e10cSrcweir 	::ucbhelper::ContentBroker::deinitialize();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir }
173