bump product version to 4.1.6.2
[LibreOffice.git] / desktop / source / lib / init.cxx
blobd564c8c8e2aeaec768d22248883608ed1d021c7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <liblibreoffice_impl.hxx>
12 #include <stdio.h>
14 #include <tools/errinf.hxx>
15 #include <osl/file.hxx>
16 #include <osl/process.h>
17 #include <rtl/strbuf.hxx>
18 #include <rtl/bootstrap.hxx>
19 #include <cppuhelper/bootstrap.hxx>
20 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/lang/Locale.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/ucb/XContentProvider.hpp>
28 #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
30 #include <vcl/svapp.hxx>
31 #include <tools/resmgr.hxx>
32 #include <vcl/graphicfilter.hxx>
33 #include <unotools/syslocaleoptions.hxx>
35 using namespace ::com::sun::star;
37 // Wonder global state ...
38 static uno::Reference<css::uno::XComponentContext> xContext;
39 static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
40 static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
42 LODocument *
43 LibLibreOffice_Impl::documentLoad( const char *docUrl )
45 OUString sUrl = OUString::createFromAscii (docUrl);
46 OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
48 uno::Reference < css::frame::XDesktop2 > xComponentLoader =
49 css::frame::Desktop::create(xContext);
51 osl_getProcessWorkingDir(&sWorkingDir.pData);
52 osl::FileBase::getFileURLFromSystemPath(sUrl, sDocPathUrl);
53 osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
55 uno::Reference < css::lang::XComponent > xComponent = xComponentLoader->loadComponentFromURL(
56 sAbsoluteDocUrl, OUString("_blank"), 0,
57 uno::Sequence < css::beans::PropertyValue >());
58 return NULL;
61 bool
62 LibLibreOffice_Impl::documentSave( const char * )
64 return 1;
67 static void
68 force_c_locale( void )
70 // force locale (and resource files loaded) to en-US
71 OUString aLangISO( "en-US" );
72 LanguageTag aLocale( aLangISO );
73 ResMgr::SetDefaultLocale( aLocale );
74 SvtSysLocaleOptions aLocalOptions;
75 aLocalOptions.SetLocaleConfigString( aLangISO );
76 aLocalOptions.SetUILocaleConfigString( aLangISO );
79 static void
80 aBasicErrorFunc( const OUString &rErr, const OUString &rAction )
82 OStringBuffer aErr( "Unexpected dialog: " );
83 aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
84 aErr.append( " Error: " );
85 aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
86 fprintf( stderr, "Unexpected basic error dialog '%s'\n", aErr.getStr() );
89 static void
90 initialize_uno( const OUString &aAppURL )
92 rtl::Bootstrap::setIniFilename( aAppURL + "/fundamentalrc" );
94 rtl::Bootstrap::set( "CONFIGURATION_LAYERS",
95 "xcsxcu:${BRAND_BASE_DIR}/share/registry "
96 "res:${BRAND_BASE_DIR}/share/registry "
97 // "bundledext:${${BRAND_BASE_DIR}/program/unorc:BUNDLED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini " );
98 // "sharedext:${${BRAND_BASE_DIR}/program/unorc:SHARED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini "
99 // "userext:${${BRAND_BASE_DIR}/program/unorc:UNO_USER_PACKAGES_CACHE}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini "
100 // "user:${$BRAND_BASE_DIR/program/bootstraprc:UserInstallation}/user/registrymodifications.xcu"
103 xContext = cppu::defaultBootstrap_InitialComponentContext();
104 fprintf( stderr, "Uno initialized %d\n", xContext.is() );
105 xFactory = xContext->getServiceManager();
106 xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
107 comphelper::setProcessServiceFactory(xSFactory);
109 // set UserInstallation to user profile dir in test/user-template
110 // rtl::Bootstrap aDefaultVars;
111 // aDefaultVars.set(OUString("UserInstallation"), aAppURL + "../registry" );
112 // configmgr setup ?
115 bool
116 LibLibreOffice_Impl::initialize( const char *app_path )
118 static bool bInitialized = false;
119 if( bInitialized )
120 return true;
122 if( !app_path )
123 return false;
125 OUString aAppPath( app_path, strlen( app_path ), RTL_TEXTENCODING_UTF8 );
126 OUString aAppURL;
127 if( osl::FileBase::getFileURLFromSystemPath( aAppPath, aAppURL ) !=
128 osl::FileBase::E_None )
129 return false;
131 try {
132 initialize_uno( aAppURL );
133 force_c_locale();
135 // Force headless
136 rtl::Bootstrap::set( "SAL_USE_VCLPLUGIN", "svp" );
137 InitVCL();
138 Application::EnableHeadlessMode(true);
140 ErrorHandler::RegisterDisplay( aBasicErrorFunc );
142 fprintf( stderr, "initialized\n" );
143 bInitialized = true;
144 } catch (css::uno::Exception & e) {
145 fprintf( stderr, "bootstrapping exception '%s'\n",
146 OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
148 return bInitialized;
151 extern "C" {
152 SAL_DLLPUBLIC_EXPORT LibLibreOffice *liblibreoffice_hook(void);
155 LibLibreOffice *liblibreoffice_hook(void)
157 fprintf( stderr, "create libreoffice object\n" );
158 return new LibLibreOffice_Impl();
161 LibLibreOffice_Impl::~LibLibreOffice_Impl ()
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */