diff options
author | Michael Meeks <michael.meeks@suse.com> | 2013-07-29 18:09:37 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-07-29 18:10:46 +0100 |
commit | 7874295626be8a3cbbb8fafc02f0dbda06f6d761 (patch) | |
tree | 2f6415298d7062912f82fe6835174ba7dad0274a | |
parent | 136f3bb1795048adc3ca5ba28d44809e5b791701 (diff) |
liblo - add ability to select filter / format for saveas.
Change-Id: I866c6cb836407019973559051c854d24f9549d2a
-rw-r--r-- | desktop/inc/liblibreoffice.hxx | 3 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 93 | ||||
-rw-r--r-- | smoketest/libtest.cxx | 7 |
3 files changed, 96 insertions, 7 deletions
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx index eb7715b68c8f..1dc2ede120ba 100644 --- a/desktop/inc/liblibreoffice.hxx +++ b/desktop/inc/liblibreoffice.hxx @@ -15,7 +15,8 @@ class LODocument public: virtual ~LODocument() {} - virtual bool saveAs (const char *url) = 0; + // Save as the given format, if format is NULL sniff from ext'n + virtual bool saveAs (const char *url, const char *format = NULL) = 0; }; class LibLibreOffice diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 696e413b1866..db958cbe831f 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -43,6 +43,59 @@ class LibLibreOffice_Impl; static LibLibreOffice_Impl *gImpl = NULL; +typedef struct { + const char *extn; + const char *filterName; +} ExtensionMap; + +static const ExtensionMap +aWriterExtensionMap[] = { + { "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 } +}; + +static const ExtensionMap +aCalcExtensionMap[] = { + { "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 } +}; + +static const ExtensionMap +aImpressExtensionMap[] = { + { "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 } +}; + + class LibLODocument_Impl : public LODocument { uno::Reference < css::lang::XComponent > mxComponent; @@ -50,7 +103,7 @@ public: LibLODocument_Impl( const uno::Reference < css::lang::XComponent > &xComponent ) : mxComponent( xComponent ) { } - virtual bool saveAs (const char *url); + virtual bool saveAs (const char *url, const char *format); }; class LibLibreOffice_Impl : public LibLibreOffice @@ -109,20 +162,52 @@ LibLibreOffice_Impl::documentLoad( const char *docUrl ) return NULL; } -bool LibLODocument_Impl::saveAs (const char *url) +bool LibLODocument_Impl::saveAs (const char *url, const char *format) { OUString sURL = getUString( url ); + OUString sFormat = getUString( format ); try { uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > aSeq = xDocument->getArgs(); - OUString aFilterName; + OUString aFilterName, aDocumentService; for( sal_Int32 i = 0; i < aSeq.getLength(); ++i ) { if( aSeq[i].Name == "FilterName" ) aSeq[i].Value >>= aFilterName; + else if( aSeq[i].Name == "DocumentService" ) + aSeq[i].Value >>= aDocumentService; + OUString aValue; + aSeq[i].Value >>= aValue; } + + if( aDocumentService == "") + { + gImpl->maLastExceptionMsg = "Unknown document type"; + return false; + } + const ExtensionMap *pMap; + + 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; + + if( format ) + { + for( sal_Int32 i = 0; pMap[i].extn; i++ ) + { + if( sFormat.equalsIgnoreAsciiCaseAscii( pMap[i].extn ) ) + { + aFilterName = getUString( pMap[i].filterName ); + break; + } + } + } + aSeq.realloc(2); aSeq[0].Name = "Overwrite"; aSeq[0].Value <<= sal_True; @@ -130,7 +215,7 @@ bool LibLODocument_Impl::saveAs (const char *url) aSeq[1].Value <<= aFilterName; uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW ); - xStorable->storeAsURL( sURL, aSeq ); + xStorable->storeToURL( sURL, aSeq ); return true; } catch (const uno::Exception &ex) { diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx index 390774913f73..4b9d1b3c884d 100644 --- a/smoketest/libtest.cxx +++ b/smoketest/libtest.cxx @@ -38,8 +38,11 @@ int main (int argc, char **argv) if( argc > 3 ) { - fprintf( stderr, "save document as '%s'\n", argv[3] ); - if ( !pDocument->saveAs( argv[ 3 ] ) ) + const char *pFilter = NULL; + if( argc > 4 ) + pFilter = argv[4]; + fprintf( stderr, "save document as '%s' (%s)\n", argv[3], pFilter ? pFilter : "<null>" ); + if( !pDocument->saveAs( argv[3], pFilter ) ) { char *pError = pOffice->getError(); fprintf( stderr, "failed to save document '%s'\n", pError); |