diff options
author | Andrzej J. R. Hunt <andrzej@ahunt.org> | 2012-07-11 17:44:41 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:22:54 +0100 |
commit | 9d7d8eb7a8a7a26e85f5fa8fde9580947bf005ab (patch) | |
tree | a88e3dec6e2e5cad9913b8670c595d54f4e088bd /sd/source/ui/remotecontrol/Receiver.cxx | |
parent | a4e7636536da9548998ae7e8c6ff1bc21b5b8765 (diff) |
Image export, encoding and decoding. Protocol improvements.
Change-Id: Ibbc7ac02c5946a49c1cd777abc2853fe7e158009
Diffstat (limited to 'sd/source/ui/remotecontrol/Receiver.cxx')
-rw-r--r-- | sd/source/ui/remotecontrol/Receiver.cxx | 185 |
1 files changed, 146 insertions, 39 deletions
diff --git a/sd/source/ui/remotecontrol/Receiver.cxx b/sd/source/ui/remotecontrol/Receiver.cxx index a2120b1a7d64..9015d799ec0e 100644 --- a/sd/source/ui/remotecontrol/Receiver.cxx +++ b/sd/source/ui/remotecontrol/Receiver.cxx @@ -1,38 +1,34 @@ -/************************************************************************* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2012 Andrzej J.R. Hunt - * - * LibreOffice - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * LibreOffice is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * Libreoffice is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with LibreOffice. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 "Receiver.hxx" -#include <cstring> +#include <string.h> #include <com/sun/star/frame/XFramesSupplier.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XExporter.hpp> #include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> + #include <comphelper/processfactory.hxx> +#include <osl/file.hxx> +#include <xmlsec/base64.h> +#include <rtl/ustrbuf.hxx> +#include <sax/tools/converter.hxx> using namespace sd; using namespace ::com::sun::star::presentation; using namespace ::com::sun::star; using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using rtl::OUString; +using rtl::OString; +using namespace ::osl; + Receiver::Receiver() { g_type_init (); @@ -65,7 +61,7 @@ void Receiver::executeCommand( JsonObject *aObject, Reference<XSlideShowControll } -void Receiver::parseCommand( const char* aCommand, sal_Int32 size, XSlideShowController *aController ) +void Receiver::parseCommand( const char* aCommand, sal_Int32 size, osl::StreamSocket &aStreamSocket ) { Reference<XSlideShowController> xSlideShowController; try { @@ -78,6 +74,7 @@ void Receiver::parseCommand( const char* aCommand, sal_Int32 size, XSlideShowCon Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW); // Throws an exception if now slideshow running xSlideShowController = Reference<XSlideShowController>( xPresentation->getController(), UNO_QUERY_THROW ); + sendPreview( 1, xSlideShowController, aStreamSocket ); } catch ( com::sun::star::uno::RuntimeException &e ) { @@ -107,18 +104,128 @@ void Receiver::parseCommand( const char* aCommand, sal_Int32 size, XSlideShowCon } -// void preparePreview(sal_Int32 aSlideNumber, Reference<SlideShowController> aController) -// { -// uno::Reference< XDrawPage > aSlide( aController->getSlideByIndex( aSlideNumber ) ); -// -// uno::Reference< lang::XMultiServiceFactory > xServiceManager( -// ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); -// -// uno::Reference< XGraphicExportFilter > xGraphicExportFilter( xServiceManager->createInstance( -// "com.sun.star.drawing.GraphicExportFilter" ) , UNO_QUERY_THROW ); -// -// xGraphicExportFilter->setSource( aSlide ); +void sendPreview(sal_uInt32 aSlideNumber, Reference<XSlideShowController> xSlideShowController, osl::StreamSocket &mStreamSocket ) +{ + + sal_uInt64 aSize; + + uno::Sequence<sal_Int8> aData = preparePreview( aSlideNumber, xSlideShowController, 320, 240, aSize ); + + rtl::OUStringBuffer aStrBuffer; +// char* aDataEncoded = (char*) xmlSecBase64Encode( (xmlSecByte *) aData, aSize, 0 ); + ::sax::Converter::encodeBase64( aStrBuffer, aData ); + + OUString aEncodedString = aStrBuffer.makeStringAndClear(); + OString aEncodedShortString = rtl::OUStringToOString( aEncodedString, RTL_TEXTENCODING_UTF8 ); +// aEncodedString.convertToString( &aEncodedShortString, RTL_TEXTENCODING_UTF8 , 0); + + JsonBuilder *aBuilder = json_builder_new(); + + + json_builder_begin_object( aBuilder ); + + json_builder_set_member_name( aBuilder, "command" ); + json_builder_add_string_value( aBuilder, "slide_preview" ); + + json_builder_set_member_name( aBuilder, "slide_number" ); + json_builder_add_int_value( aBuilder, 2 ); + + json_builder_set_member_name( aBuilder, "image_preview" ); + json_builder_add_string_value( aBuilder, aEncodedShortString.getStr() ); + + // FIXME: get the slide number + json_builder_end_object( aBuilder ); + + JsonGenerator *aGen = json_generator_new(); + JsonNode *aRoot = json_builder_get_root( aBuilder ); + json_generator_set_root( aGen, aRoot ); + char *aCommand = json_generator_to_data( aGen, NULL); + + json_node_free( aRoot ); + g_object_unref ( aGen ); + g_object_unref ( aBuilder ); + + sal_Int32 aLen = strlen( aCommand ); + + OString aLengthString = OString::valueOf( aLen ); + const char *aLengthChar = aLengthString.getStr(); + + sal_Int32 aLengthLength = aLengthString.getLength(); + + fprintf( stderr, "%s\n", aCommand ); + + mStreamSocket.write( aLengthChar, aLengthLength ); + mStreamSocket.write( "\n", 1 ); + mStreamSocket.write( aCommand, aLen ); + // Transmit here. + + g_free( aCommand ); + +} + +Sequence<sal_Int8> preparePreview(sal_uInt32 aSlideNumber, Reference<XSlideShowController> xSlideShowController, sal_uInt32 aWidth, sal_uInt32 aHeight, sal_uInt64 &rSize ) +{ + + // Create temp file + OUString aFileURL; + FileBase::createTempFile( 0, 0, &aFileURL ); + + + uno::Reference< lang::XMultiServiceFactory > xServiceManager( + ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + + uno::Reference< XFilter > xFilter( xServiceManager->createInstance( + "com.sun.star.drawing.GraphicExportFilter" ) , UNO_QUERY_THROW ); + + uno::Reference< XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW ); + + + uno::Reference< lang::XComponent > xSourceDoc( + xSlideShowController->getSlideByIndex( aSlideNumber ) , uno::UNO_QUERY_THROW ); + + xExporter->setSourceDocument( xSourceDoc ); + + Sequence< beans::PropertyValue > aFilterData(3); + aFilterData[0].Name = "PixelWidth"; + aFilterData[0].Value <<= 2000; + aFilterData[1].Name = "PixelHeight"; + aFilterData[1].Value <<= 2000; + + // Add quality if jpg "Quality" [1-100] + // FIXME: is setting color mode needed. + aFilterData[2].Name = "ColorMode"; + aFilterData[2].Value <<= 0; // Color + + uno::Sequence< beans::PropertyValue > aProps(3); + aProps[0].Name = "MediaType"; + aProps[0].Value <<= OUString( "image/png" ); + + aProps[1].Name = "URL"; + aProps[1].Value <<= aFileURL; + + aProps[2].Name = "FilterData"; + aProps[2].Value <<= aFilterData; + + xFilter->filter( aProps ); + + fprintf( stderr, "%s\n", rtl::OUStringToOString( aFileURL , RTL_TEXTENCODING_UTF8 ).getStr() ); + + // FIXME: error handling. + + File aFile( aFileURL ); + aFile.open(0); + sal_uInt64 aRead; + rSize = 0; + aFile.getSize( rSize ); + uno::Sequence<sal_Int8> aContents( rSize ); + + aFile.read( aContents.getArray(), rSize, aRead ); + aFile.close(); + File::remove( aFileURL ); + return aContents; + +} -// } +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file |