summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2013-07-26 18:21:45 +0100
committerMichael Meeks <michael.meeks@suse.com>2013-07-26 18:22:19 +0100
commitd32b179c3f2b16bb96679816db485d62ce8fe87f (patch)
treecabdac33dbd07263bbce96ca27024bafce9b67f6 /desktop
parent04646443b3ee3baef0c3bdbaefad0eb66b71d33a (diff)
more liblibreoffice pieces.
Change-Id: I21d67de281847321d784cddc652d4a51a437fadf
Diffstat (limited to 'desktop')
-rw-r--r--desktop/inc/liblibreoffice.hxx17
-rw-r--r--desktop/inc/liblibreoffice_impl.hxx27
-rw-r--r--desktop/source/lib/init.cxx109
3 files changed, 110 insertions, 43 deletions
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx
index 48c0a24edbc0..eb7715b68c8f 100644
--- a/desktop/inc/liblibreoffice.hxx
+++ b/desktop/inc/liblibreoffice.hxx
@@ -10,17 +10,26 @@
#ifndef _LIBLIBREOFFICE_HXX
#define _LIBLIBREOFFICE_HXX
-typedef struct _LODocument LODocument;
+class LODocument
+{
+public:
+ virtual ~LODocument() {}
+
+ virtual bool saveAs (const char *url) = 0;
+};
class LibLibreOffice
{
public:
- virtual bool initialize (const char *installPath) = 0;
+ virtual ~LibLibreOffice () {};
+
+ virtual bool initialize (const char *installPath) = 0;
virtual LODocument *documentLoad (const char *url) = 0;
- virtual bool documentSave (const char *url) = 0;
- virtual ~LibLibreOffice () {};
+ // return the last error as a string, free me.
+ virtual char *getError() = 0;
+
};
LibLibreOffice *lo_init (const char *install_path);
diff --git a/desktop/inc/liblibreoffice_impl.hxx b/desktop/inc/liblibreoffice_impl.hxx
deleted file mode 100644
index 3f7783ec4d67..000000000000
--- a/desktop/inc/liblibreoffice_impl.hxx
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- 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/.
- */
-
-#ifndef _LIBLIBREOFFICE_IMPL_HXX
-#define _LIBLIBREOFFICE_IMPL_HXX
-
-#include "liblibreoffice.hxx"
-
-class LibLibreOffice_Impl : public LibLibreOffice
-{
-public:
- virtual bool initialize (const char *installPath);
-
- virtual LODocument *documentLoad (const char *url);
- virtual bool documentSave (const char *url);
-
- virtual ~LibLibreOffice_Impl ();
-};
-
-#endif
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index d564c8c8e2ae..d753f9a33ed6 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -7,9 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <liblibreoffice_impl.hxx>
-
#include <stdio.h>
+#include <string.h>
+
+#include "liblibreoffice.hxx"
#include <tools/errinf.hxx>
#include <osl/file.hxx>
@@ -20,7 +21,9 @@
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -34,34 +37,111 @@
using namespace ::com::sun::star;
+class LibLODocument_Impl;
+class LibLibreOffice_Impl;
+
+static LibLibreOffice_Impl *gImpl = NULL;
+
+class LibLODocument_Impl : public LODocument
+{
+ uno::Reference < css::lang::XComponent > mxComponent;
+public:
+ LibLODocument_Impl( const uno::Reference < css::lang::XComponent > &xComponent )
+ : mxComponent( xComponent )
+ { }
+ virtual bool saveAs (const char *url);
+};
+
+class LibLibreOffice_Impl : public LibLibreOffice
+{
+public:
+ rtl::OUString maLastExceptionMsg;
+
+ virtual bool initialize (const char *installPath);
+
+ virtual LODocument *documentLoad (const char *url);
+
+ virtual char *getError();
+
+ virtual ~LibLibreOffice_Impl ();
+};
+
// Wonder global state ...
static uno::Reference<css::uno::XComponentContext> xContext;
static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
+static OUString getUString( const char *str )
+{
+ if( !str )
+ return OUString( "" );
+ return OStringToOUString( OString( str, strlen (str) ),
+ RTL_TEXTENCODING_UTF8 );
+}
+
LODocument *
LibLibreOffice_Impl::documentLoad( const char *docUrl )
{
- OUString sUrl = OUString::createFromAscii (docUrl);
+ OUString sUrl = getUString( docUrl );
OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
uno::Reference < css::frame::XDesktop2 > xComponentLoader =
css::frame::Desktop::create(xContext);
osl_getProcessWorkingDir(&sWorkingDir.pData);
- osl::FileBase::getFileURLFromSystemPath(sUrl, sDocPathUrl);
+ osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl );
osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
- uno::Reference < css::lang::XComponent > xComponent = xComponentLoader->loadComponentFromURL(
- sAbsoluteDocUrl, OUString("_blank"), 0,
- uno::Sequence < css::beans::PropertyValue >());
+ maLastExceptionMsg = "";
+ try {
+ uno::Reference < css::lang::XComponent > xComponent =
+ xComponentLoader->loadComponentFromURL(
+ sAbsoluteDocUrl, OUString("_blank"), 0,
+ uno::Sequence < css::beans::PropertyValue >());
+ if( xComponentLoader.is() )
+ return new LibLODocument_Impl( xComponent );
+ else
+ maLastExceptionMsg = "unknown load failure";
+ } catch (const uno::Exception &ex) {
+ maLastExceptionMsg = ex.Message;
+ }
return NULL;
}
-bool
-LibLibreOffice_Impl::documentSave( const char * )
+bool LibLODocument_Impl::saveAs (const char *url)
{
- return 1;
+ OUString sURL = getUString( url );
+
+ try {
+ uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW );
+ uno::Sequence< beans::PropertyValue > aSeq = xDocument->getArgs();
+
+ OUString aFilterName;
+ for( sal_Int32 i = 0; i < aSeq.getLength(); ++i )
+ {
+ if( aSeq[i].Name == "FilterName" )
+ aSeq[i].Value >>= aFilterName;
+ }
+ aSeq.realloc(2);
+ aSeq[0].Name = "Overwrite";
+ aSeq[0].Value <<= sal_True;
+ aSeq[1].Name = "FilterName";
+ aSeq[1].Value <<= aFilterName;
+
+ uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW );
+ xStorable->storeAsURL( sURL, aSeq );
+
+ return true;
+ } catch (const uno::Exception &ex) {
+ gImpl->maLastExceptionMsg = "exception " + ex.Message;
+ return false;
+ }
+}
+
+char *LibLibreOffice_Impl::getError()
+{
+ OString aStr = rtl::OUStringToOString( maLastExceptionMsg, RTL_TEXTENCODING_UTF8 );
+ return strndup( aStr.getStr(), aStr.getLength() );
}
static void
@@ -154,12 +234,17 @@ extern "C" {
LibLibreOffice *liblibreoffice_hook(void)
{
- fprintf( stderr, "create libreoffice object\n" );
- return new LibLibreOffice_Impl();
+ if( !gImpl )
+ {
+ fprintf( stderr, "create libreoffice object\n" );
+ gImpl = new LibLibreOffice_Impl();
+ }
+ return gImpl;
}
LibLibreOffice_Impl::~LibLibreOffice_Impl ()
{
+ gImpl = NULL;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */