summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2013-03-05 13:16:36 +0000
committerMichael Meeks <michael.meeks@suse.com>2013-03-12 15:35:33 +0000
commit8887de72c184bec6225a952ec90433ae1b7a5b26 (patch)
treef3d90d221b5eba49aa14ff713c7d11216935b233 /desktop
parent6ea685090806a2a2f39b8d5ec6a749eaf9b1856e (diff)
liblibo: create initial liblibreoffice.
bootstrap libreoffice, start a dummy test-harness: can't use CppUnit or link to any URE / LibreOffice libraries. Change-Id: I855b640557f93959749e966a2d8e5e577fd84574
Diffstat (limited to 'desktop')
-rw-r--r--desktop/Library_libreoffice.mk25
-rw-r--r--desktop/Library_sofficeapp.mk5
-rw-r--r--desktop/Module_desktop.mk1
-rw-r--r--desktop/inc/liblibreoffice.h38
-rw-r--r--desktop/source/lib/init.cxx139
-rw-r--r--desktop/source/lib/shim.cxx52
6 files changed, 260 insertions, 0 deletions
diff --git a/desktop/Library_libreoffice.mk b/desktop/Library_libreoffice.mk
new file mode 100644
index 000000000000..a40bbd74f987
--- /dev/null
+++ b/desktop/Library_libreoffice.mk
@@ -0,0 +1,25 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Library_Library,libreoffice))
+
+$(eval $(call gb_Library_set_include,libreoffice,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/desktop/inc \
+))
+
+$(eval $(call gb_Library_use_libraries,libreoffice,\
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_Library_add_exception_objects,libreoffice,\
+ desktop/source/lib/shim \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 2a635b5953c9..5ae66d259d30 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -90,6 +90,11 @@ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
desktop/source/migration/migration \
))
+# liblibreoffice bits
+$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
+ desktop/source/lib/init \
+))
+
ifeq ($(ENABLE_TELEPATHY),TRUE)
$(eval $(call gb_Library_use_libraries,sofficeapp,tubes))
endif
diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk
index 538553ac7dd1..d97bff3f1b1c 100644
--- a/desktop/Module_desktop.mk
+++ b/desktop/Module_desktop.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_Module_add_targets,desktop,\
AllLangResTarget_dkt \
Library_deployment \
Library_deploymentmisc \
+ Library_libreoffice \
Library_offacc \
Library_sofficeapp \
Library_spl \
diff --git a/desktop/inc/liblibreoffice.h b/desktop/inc/liblibreoffice.h
new file mode 100644
index 000000000000..dde50cec88e1
--- /dev/null
+++ b/desktop/inc/liblibreoffice.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+/*
+ * A simple C API to setup and use libreoffice
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ int errno;
+ char *message;
+} LOError;
+
+typedef int loboolean;
+typedef struct _LODocument LODocument;
+
+loboolean lo_initialize (const char *install_path);
+
+void lo_error_free (LOError *error);
+LOError *lo_error_new (int errno, const char *message);
+
+LODocument *lo_document_load (const char *url, LOError **opt_error);
+loboolean lo_document_save (const char *url, LOError **opt_error);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
new file mode 100644
index 000000000000..5aab66bd42d2
--- /dev/null
+++ b/desktop/source/lib/init.cxx
@@ -0,0 +1,139 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <stdio.h>
+
+#include <liblibreoffice.h>
+#include <tools/errinf.hxx>
+#include <osl/file.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/bootstrap.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <comphelper/processfactory.hxx>
+
+#include <com/sun/star/lang/Locale.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/ucb/XContentProvider.hpp>
+#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
+
+#include <vcl/svapp.hxx>
+#include <tools/resmgr.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <unotools/syslocaleoptions.hxx>
+
+using namespace ::com::sun::star;
+
+// Wonder global state ...
+static uno::Reference<css::uno::XComponentContext> xContext;
+static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
+static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
+
+SAL_DLLPUBLIC_EXPORT void
+lo_error_free( LOError * )
+{
+}
+
+SAL_DLLPUBLIC_EXPORT LOError *
+lo_error_new( int, const char * )
+{
+ return NULL;
+}
+
+SAL_DLLPUBLIC_EXPORT LODocument *
+lo_document_load( const char *, LOError ** )
+{
+ return NULL;
+}
+
+SAL_DLLPUBLIC_EXPORT loboolean
+lo_document_save( const char *, LOError ** )
+{
+ return 1;
+}
+
+static void
+force_c_locale( void )
+{
+ // force locale (and resource files loaded) to en-US
+ css::lang::Locale aLocale( "en", "US", "");
+ ResMgr::SetDefaultLocale( aLocale );
+ SvtSysLocaleOptions aLocalOptions;
+ OUString aLangISO( "en-US" );
+ aLocalOptions.SetLocaleConfigString( aLangISO );
+ aLocalOptions.SetUILocaleConfigString( aLangISO );
+}
+
+static void
+aBasicErrorFunc( const OUString &rErr, const OUString &rAction )
+{
+ OStringBuffer aErr( "Unexpected dialog: " );
+ aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
+ aErr.append( " Error: " );
+ aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
+ fprintf( stderr, "Unexpected basic error dialog '%s'\n", aErr.getStr() );
+}
+
+static void
+initialize_uno( const rtl::OUString &aUserProfileURL )
+{
+ // set UserInstallation to user profile dir in test/user-template
+ rtl::Bootstrap aDefaultVars;
+ aDefaultVars.set(rtl::OUString("UserInstallation"), aUserProfileURL );
+
+ xContext = comphelper::getProcessComponentContext();
+ xFactory = xContext->getServiceManager();
+ xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
+}
+
+SAL_DLLPUBLIC_EXPORT loboolean
+lo_initialize( const char *app_path )
+{
+ static bool bInitialized = false;
+ if( bInitialized )
+ return true;
+
+ if( !app_path )
+ return false;
+
+ OUString aAppPath( app_path, strlen( app_path ), RTL_TEXTENCODING_UTF8 );
+ OUString aAppURL;
+ if( osl::FileBase::getFileURLFromSystemPath( aAppPath, aAppURL ) !=
+ osl::FileBase::E_None )
+ return false;
+
+ try {
+ initialize_uno( aAppURL + "../registry" );
+ force_c_locale();
+ InitVCL();
+ if (Application::IsHeadlessModeRequested())
+ Application::EnableHeadlessMode(true);
+
+ ErrorHandler::RegisterDisplay( aBasicErrorFunc );
+
+ fprintf (stderr, "do nothing yet");
+ bInitialized = true;
+ } catch (css::uno::Exception & e) {
+ fprintf( stderr, "bootstrapping exception '%s'\n",
+ OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+ return bInitialized;
+}
+
+extern "C" {
+ SAL_DLLPUBLIC_EXPORT LibLibreOffice *liblibreoffice_hook(void);
+}
+
+LibLibreOffice *liblibreoffice_hook(void)
+{
+ return new LibLibreOffice();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
diff --git a/desktop/source/lib/shim.cxx b/desktop/source/lib/shim.cxx
new file mode 100644
index 000000000000..c57803e588fa
--- /dev/null
+++ b/desktop/source/lib/shim.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifdef LINUX
+
+#include <sal/types.h>
+#include <liblibreoffice.h>
+
+#include <dlfcn.h>
+#ifdef AIX
+# include <sys/ldr.h>
+#endif
+
+#define TARGET_LIB SAL_MODULENAME( "sofficeapp" )
+
+extern "C" {
+ typedef LibLibreOffice *(HookFunction)(void);
+};
+
+extern LibLibreOffice *lo_init( const char *install_path )
+{
+ if( !install_path )
+ return NULL;
+ char *impl_lib = malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 );
+ strcpy( imp_lib, install_path );
+ strcat( imp_lib, "/" );
+ strcat( imp_lib, TARGET_LIB );
+ void *dlhandle = dlopen( imp_lib, RTLD_LAZY );
+ if( !dlhandle )
+ {
+ fprintf( stderr, "failed to open library '%s'\n", imp_lib );
+ return NULL;
+ }
+ free( imp_lib );
+
+ HookFunction *pSym = dlsym( dlhandle, "liblibreoffice_hook" );
+ if( !pSym ) {
+ fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
+ return NULL;
+ }
+ return pSym();
+}
+
+#endif // LINUX - port me !
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */