2013-03-05 16:40:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-03-05 13:16:36 +00:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2013-08-16 11:08:32 +03:00
|
|
|
#include <config_folders.h>
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <stdio.h>
|
2013-07-26 18:21:45 +01:00
|
|
|
#include <string.h>
|
2013-07-26 19:15:41 +01:00
|
|
|
#include <stdlib.h>
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
#include "liblibreoffice.h"
|
2013-03-05 13:16:36 +00:00
|
|
|
|
|
|
|
#include <tools/errinf.hxx>
|
|
|
|
#include <osl/file.hxx>
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <osl/process.h>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <rtl/strbuf.hxx>
|
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2013-07-26 18:21:45 +01:00
|
|
|
#include <com/sun/star/frame/XModel.hpp>
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
2013-07-26 18:21:45 +01:00
|
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
2013-03-05 13:16:36 +00:00
|
|
|
#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>
|
2014-04-05 21:48:47 +02:00
|
|
|
#include <unotools/mediadescriptor.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
using namespace css;
|
|
|
|
using namespace utl;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2013-11-15 14:05:16 +01:00
|
|
|
struct LibLODocument_Impl;
|
|
|
|
struct LibLibreOffice_Impl;
|
2013-07-26 18:21:45 +01:00
|
|
|
|
|
|
|
static LibLibreOffice_Impl *gImpl = NULL;
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
const char *extn;
|
|
|
|
const char *filterName;
|
|
|
|
} ExtensionMap;
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aWriterExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "doc", "MS Word 97" },
|
|
|
|
{ "docx", "MS Word 2007 XML" },
|
|
|
|
{ "fodt", "OpenDocument Text Flat XML" },
|
|
|
|
{ "html", "HTML (StarWriter)" },
|
|
|
|
{ "odt", "writer8" },
|
|
|
|
{ "ott", "writer8_template" },
|
|
|
|
{ "pdf", "writer_pdf_Export" },
|
|
|
|
{ "txt", "Text" },
|
|
|
|
{ "xhtml", "XHTML Writer File" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aCalcExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "csv", "Text - txt - csv (StarCalc)" },
|
|
|
|
{ "fods", "OpenDocument Spreadsheet Flat XML" },
|
|
|
|
{ "html", "HTML (StarCalc)" },
|
|
|
|
{ "ods", "calc8" },
|
|
|
|
{ "ots", "calc8_template" },
|
|
|
|
{ "pdf", "calc_pdf_Export" },
|
|
|
|
{ "xhtml", "XHTML Calc File" },
|
|
|
|
{ "xls", "MS Excel 97" },
|
|
|
|
{ "xlsx", "Calc MS Excel 2007 XML" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aImpressExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "fodp", "OpenDocument Presentation Flat XML" },
|
|
|
|
{ "html", "impress_html_Export" },
|
|
|
|
{ "odg", "impress8_draw" },
|
|
|
|
{ "odp", "impress8" },
|
|
|
|
{ "otp", "impress8_template" },
|
|
|
|
{ "pdf", "impress_pdf_Export" },
|
|
|
|
{ "potm", "Impress MS PowerPoint 2007 XML Template" },
|
|
|
|
{ "pot", "MS PowerPoint 97 Vorlage" },
|
|
|
|
{ "pptx", "Impress MS PowerPoint 2007 XML" },
|
|
|
|
{ "pps", "MS PowerPoint 97 Autoplay" },
|
|
|
|
{ "ppt", "MS PowerPoint 97" },
|
|
|
|
{ "svg", "impress_svg_Export" },
|
|
|
|
{ "swf", "impress_flash_Export" },
|
|
|
|
{ "xhtml", "XHTML Impress File" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static OUString getUString(const char* pString)
|
2013-11-15 18:00:05 +02:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (pString == NULL)
|
|
|
|
return OUString();
|
|
|
|
|
|
|
|
OString sString(pString, strlen(pString));
|
|
|
|
return OStringToOUString(sString, RTL_TEXTENCODING_UTF8);
|
2013-11-15 18:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to convert a relative URL to an absolute one
|
2014-04-05 21:48:47 +02:00
|
|
|
static OUString getAbsoluteURL(const char* pURL)
|
2013-11-15 18:00:05 +02:00
|
|
|
{
|
|
|
|
OUString aURL( getUString( pURL ) );
|
|
|
|
OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
|
|
|
|
|
|
|
|
// FIXME: this would appear to kill non-file URLs.
|
|
|
|
osl_getProcessWorkingDir(&sWorkingDir.pData);
|
|
|
|
osl::FileBase::getFileURLFromSystemPath( aURL, sDocPathUrl );
|
|
|
|
osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
|
|
|
|
|
|
|
|
return sAbsoluteDocUrl;
|
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2013-11-15 12:09:10 +00:00
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT LibreOffice *liblibreoffice_hook(void);
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void doc_destroy(LibreOfficeDocument* pThis);
|
|
|
|
static int doc_saveAs(LibreOfficeDocument* pThis, const char* pUrl, const char* pFormat);
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
struct LibLODocument_Impl : public _LibreOfficeDocument
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<css::lang::XComponent> mxComponent;
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
|
|
|
|
mxComponent( xComponent )
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
nSize = sizeof(LibreOffice);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
|
|
|
destroy = doc_destroy;
|
|
|
|
saveAs = doc_saveAs;
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void doc_destroy(LibreOfficeDocument *pThis)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLODocument_Impl *pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
delete pDocument;
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void lo_destroy (LibreOffice* pThis);
|
|
|
|
static int lo_initialize (LibreOffice* pThis, const char* pInstallPath);
|
|
|
|
static LibreOfficeDocument* lo_documentLoad (LibreOffice* pThis, const char* pURL);
|
|
|
|
static char * lo_getError (LibreOffice* pThis);
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
struct LibLibreOffice_Impl : public _LibreOffice
|
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString maLastExceptionMsg;
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
LibLibreOffice_Impl()
|
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
nSize = sizeof(LibreOfficeDocument);
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
destroy = lo_destroy;
|
|
|
|
initialize = lo_initialize;
|
|
|
|
documentLoad = lo_documentLoad;
|
|
|
|
getError = lo_getError;
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
};
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
// Wonder global state ...
|
|
|
|
static uno::Reference<css::uno::XComponentContext> xContext;
|
|
|
|
static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
|
|
|
|
static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static LibreOfficeDocument* lo_documentLoad(LibreOffice* pThis, const char* pURL)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString aURL = getAbsoluteURL(pURL);
|
2013-03-05 14:29:26 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<frame::XDesktop2> xComponentLoader = frame::Desktop::create(xContext);
|
2013-03-05 14:29:26 +00:00
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
pLib->maLastExceptionMsg = "";
|
2014-04-05 21:48:47 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XComponent> xComponent;
|
|
|
|
xComponent = xComponentLoader->loadComponentFromURL(
|
|
|
|
aURL, OUString("_blank"), 0,
|
|
|
|
uno::Sequence<css::beans::PropertyValue>());
|
|
|
|
|
|
|
|
if (xComponentLoader.is())
|
|
|
|
return new LibLODocument_Impl(xComponent);
|
2013-07-26 18:21:45 +01:00
|
|
|
else
|
2013-11-15 12:09:10 +00:00
|
|
|
pLib->maLastExceptionMsg = "unknown load failure";
|
2014-04-05 21:48:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
catch (const uno::Exception& exception)
|
|
|
|
{
|
|
|
|
pLib->maLastExceptionMsg = exception.Message;
|
2013-07-26 18:21:45 +01:00
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static int doc_saveAs(LibreOfficeDocument* pThis, const char* sUrl, const char* pFormat)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString sFormat = getUString(pFormat);
|
|
|
|
OUString aURL = getAbsoluteURL(sUrl);
|
2013-11-05 23:34:37 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference<frame::XModel> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW);
|
|
|
|
uno::Sequence<beans::PropertyValue> aSequence = xDocument->getArgs();
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
MediaDescriptor aMediaDescriptor(aSequence);
|
|
|
|
OUString sPropertyName = MediaDescriptor::PROP_DOCUMENTSERVICE();
|
|
|
|
OUString aDocumentService = aMediaDescriptor.getUnpackedValueOrDefault(sPropertyName, OUString());
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
if (aDocumentService.isEmpty())
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Unknown document type";
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
|
|
|
|
const ExtensionMap* pMap;
|
2013-07-29 18:09:37 +01:00
|
|
|
|
|
|
|
if( aDocumentService == "com.sun.star.sheet.SpreadsheetDocument" )
|
|
|
|
pMap = (const ExtensionMap *)aCalcExtensionMap;
|
|
|
|
else if( aDocumentService == "com.sun.star.presentation.PresentationDocument" )
|
|
|
|
pMap = (const ExtensionMap *)aImpressExtensionMap;
|
|
|
|
else // for the sake of argument only writer documents ...
|
|
|
|
pMap = (const ExtensionMap *)aWriterExtensionMap;
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
if (pFormat == NULL)
|
2013-11-05 23:34:37 +01:00
|
|
|
{
|
|
|
|
// sniff from the extension
|
2014-04-05 21:48:47 +02:00
|
|
|
sal_Int32 idx = aURL.lastIndexOf(".");
|
2013-11-05 23:34:37 +01:00
|
|
|
if( idx > 0 )
|
|
|
|
{
|
2013-11-07 11:37:19 +00:00
|
|
|
sFormat = aURL.copy( idx + 1 );
|
2013-11-05 23:34:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "input filename without a suffix";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString aFilterName;
|
2014-04-05 21:48:47 +02:00
|
|
|
for (sal_Int32 i = 0; pMap[i].extn; ++i)
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (sFormat.equalsIgnoreAsciiCaseAscii(pMap[i].extn))
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
aFilterName = getUString(pMap[i].filterName);
|
2013-11-05 23:34:37 +01:00
|
|
|
break;
|
2013-07-29 18:09:37 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
if (aFilterName.isEmpty())
|
2013-11-05 23:34:37 +01:00
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "no output filter found for provided suffix";
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
MediaDescriptor aSaveMediaDescriptor;
|
|
|
|
aSaveMediaDescriptor["Overwrite"] <<= sal_True;
|
|
|
|
aSaveMediaDescriptor["FilterName"] <<= aFilterName;
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
|
|
|
|
xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
|
2013-07-26 18:21:45 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
catch (const uno::Exception& exception)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "exception: " + exception.Message;
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-26 18:21:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static char* lo_getError (LibreOffice *pThis)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
|
|
|
OString aString = OUStringToOString(pLib->maLastExceptionMsg, RTL_TEXTENCODING_UTF8);
|
|
|
|
char* pMemory = (char*) malloc(aString.getLength() + 1);
|
|
|
|
strcpy(pMemory, aString.getStr());
|
|
|
|
return pMemory;
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void force_c_locale(void)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
|
|
|
// force locale (and resource files loaded) to en-US
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString aLangISO("en-US");
|
|
|
|
LanguageTag aLocale(aLangISO);
|
|
|
|
ResMgr::SetDefaultLocale(aLocale);
|
2013-03-05 13:16:36 +00:00
|
|
|
SvtSysLocaleOptions aLocalOptions;
|
2014-04-05 21:48:47 +02:00
|
|
|
aLocalOptions.SetLocaleConfigString(aLangISO);
|
|
|
|
aLocalOptions.SetUILocaleConfigString(aLangISO);
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
OStringBuffer aBuffer("Unexpected dialog: ");
|
|
|
|
aBuffer.append(OUStringToOString(rAction, RTL_TEXTENCODING_ASCII_US));
|
|
|
|
aBuffer.append(" Error: ");
|
|
|
|
aBuffer.append(OUStringToOString(rError, RTL_TEXTENCODING_ASCII_US));
|
|
|
|
|
|
|
|
fprintf(stderr, "Unexpected basic error dialog '%s'\n", aBuffer.getStr());
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void initialize_uno(const OUString &aAppURL)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2013-03-05 22:21:57 +00:00
|
|
|
rtl::Bootstrap::setIniFilename( aAppURL + "/fundamentalrc" );
|
|
|
|
|
|
|
|
rtl::Bootstrap::set( "CONFIGURATION_LAYERS",
|
2013-08-16 11:08:32 +03:00
|
|
|
"xcsxcu:${BRAND_BASE_DIR}/" LIBO_SHARE_FOLDER "/registry "
|
|
|
|
"res:${BRAND_BASE_DIR}/" LIBO_SHARE_FOLDER "/registry "
|
|
|
|
// "bundledext:${${BRAND_BASE_DIR}/" LIBO_ETC_FOLDER "/unorc:BUNDLED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini " );
|
|
|
|
// "sharedext:${${BRAND_BASE_DIR}/" LIBO_ETC_FOLDER "/unorc:SHARED_EXTENSIONS_USER}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini "
|
|
|
|
// "userext:${${BRAND_BASE_DIR}/" LIBO_ETC_FOLDER "/unorc:UNO_USER_PACKAGES_CACHE}/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/configmgr.ini "
|
|
|
|
// "user:${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/bootstraprc:UserInstallation}/user/registrymodifications.xcu"
|
2013-03-05 22:21:57 +00:00
|
|
|
);
|
|
|
|
|
2013-03-05 16:40:01 +00:00
|
|
|
xContext = cppu::defaultBootstrap_InitialComponentContext();
|
2014-04-05 21:48:47 +02:00
|
|
|
fprintf(stderr, "Uno initialized %d\n", xContext.is());
|
2013-03-05 16:40:01 +00:00
|
|
|
xFactory = xContext->getServiceManager();
|
|
|
|
xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
|
|
|
|
comphelper::setProcessServiceFactory(xSFactory);
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
// set UserInstallation to user profile dir in test/user-template
|
2013-03-05 22:21:57 +00:00
|
|
|
// rtl::Bootstrap aDefaultVars;
|
2013-04-07 12:06:47 +02:00
|
|
|
// aDefaultVars.set(OUString("UserInstallation"), aAppURL + "../registry" );
|
2013-03-05 22:21:57 +00:00
|
|
|
// configmgr setup ?
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static int lo_initialize(LibreOffice* pThis, const char* pAppPath)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2013-11-15 12:09:10 +00:00
|
|
|
(void) pThis;
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
static bool bInitialized = false;
|
2014-04-05 21:48:47 +02:00
|
|
|
if (bInitialized)
|
2013-11-15 12:09:10 +00:00
|
|
|
return 1;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
if (!pAppPath)
|
2013-11-15 12:09:10 +00:00
|
|
|
return 0;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString aAppPath(pAppPath, strlen(pAppPath), RTL_TEXTENCODING_UTF8);
|
2013-03-05 13:16:36 +00:00
|
|
|
OUString aAppURL;
|
2014-04-05 21:48:47 +02:00
|
|
|
if (osl::FileBase::getFileURLFromSystemPath(aAppPath, aAppURL) != osl::FileBase::E_None)
|
2013-11-15 12:09:10 +00:00
|
|
|
return 0;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
initialize_uno(aAppURL);
|
2013-03-05 13:16:36 +00:00
|
|
|
force_c_locale();
|
2013-03-05 22:21:57 +00:00
|
|
|
|
|
|
|
// Force headless
|
2014-04-05 21:48:47 +02:00
|
|
|
rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
|
2013-03-05 13:16:36 +00:00
|
|
|
InitVCL();
|
2013-03-05 22:21:57 +00:00
|
|
|
Application::EnableHeadlessMode(true);
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
ErrorHandler::RegisterDisplay(aBasicErrorFunc);
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
fprintf(stderr, "initialized\n");
|
2013-03-05 13:16:36 +00:00
|
|
|
bInitialized = true;
|
2014-04-05 21:48:47 +02:00
|
|
|
}
|
|
|
|
catch (css::uno::Exception& exception)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "bootstrapping exception '%s'\n",
|
|
|
|
OUStringToOString(exception.Message, RTL_TEXTENCODING_UTF8).getStr());
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
return bInitialized;
|
|
|
|
}
|
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
LibreOffice *liblibreoffice_hook(void)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (!gImpl)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
fprintf(stderr, "create libreoffice object\n");
|
2013-07-26 18:21:45 +01:00
|
|
|
gImpl = new LibLibreOffice_Impl();
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
return static_cast<LibreOffice*>(gImpl);
|
2013-03-05 16:19:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void lo_destroy(LibreOffice *pThis)
|
2013-03-05 16:19:58 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
delete pLib;
|
2013-07-26 18:21:45 +01:00
|
|
|
gImpl = NULL;
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|