LCOV - code coverage report
Current view: top level - sd/source/ui/remotecontrol - ImagePreparer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 123 0.0 %
Date: 2014-11-03 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "ImagePreparer.hxx"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <osl/file.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <sax/tools/converter.hxx>
      26             : #include <rtl/strbuf.hxx>
      27             : #include <unotools/streamwrap.hxx>
      28             : 
      29             : #include <svl/itemset.hxx>
      30             : #include <sfx2/docfile.hxx>
      31             : 
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <com/sun/star/document/XFilter.hpp>
      35             : #include <com/sun/star/document/XImporter.hpp>
      36             : #include <com/sun/star/document/XExporter.hpp>
      37             : #include <com/sun/star/drawing/GraphicExportFilter.hpp>
      38             : #include <com/sun/star/lang/XServiceName.hpp>
      39             : #include <com/sun/star/presentation/XPresentationPage.hpp>
      40             : #include <com/sun/star/text/XTextRange.hpp>
      41             : 
      42             : using namespace ::sd;
      43             : using namespace ::osl;
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::uno;
      46             : 
      47           0 : ImagePreparer::ImagePreparer(
      48             :     const uno::Reference<presentation::XSlideShowController>& rxController,
      49             :     Transmitter *aTransmitter )
      50             :  :  xController( rxController ),
      51           0 :     pTransmitter( aTransmitter )
      52             : {
      53             :     SAL_INFO( "sdremote", "ImagePreparer - start" );
      54           0 :     SetTimeout( 50 );
      55           0 :     mnSendingSlide = 0;
      56           0 :     Start();
      57           0 : }
      58             : 
      59           0 : ImagePreparer::~ImagePreparer()
      60             : {
      61             :     SAL_INFO( "sdremote", "ImagePreparer - stop" );
      62           0 :     Stop();
      63           0 : }
      64             : 
      65           0 : void ImagePreparer::Timeout()
      66             : {
      67           0 :     sal_uInt32 aSlides = xController->getSlideCount();
      68             :     SAL_INFO( "sdremote", "ImagePreparer " << xController->isRunning() <<
      69             :               " sending slide " << mnSendingSlide << " of " << aSlides );
      70           0 :     if ( xController->isRunning() && // not stopped/disposed of.
      71           0 :          mnSendingSlide < aSlides )
      72             :     {
      73           0 :         sendPreview( mnSendingSlide );
      74           0 :         sendNotes( mnSendingSlide );
      75           0 :         mnSendingSlide++;
      76           0 :         Start();
      77             :     }
      78             :     else
      79           0 :         Stop();
      80           0 : }
      81             : 
      82           0 : void ImagePreparer::sendPreview( sal_uInt32 aSlideNumber )
      83             : {
      84             :     sal_uInt64 aSize;
      85             :     uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, 320, 240,
      86           0 :         aSize );
      87           0 :     if ( !xController->isRunning() )
      88           0 :         return;
      89             : 
      90           0 :     OUStringBuffer aStrBuffer;
      91           0 :     ::sax::Converter::encodeBase64( aStrBuffer, aImageData );
      92             : 
      93             :     OString aEncodedShortString = OUStringToOString(
      94           0 :         aStrBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
      95             : 
      96             :     // Start the writing
      97           0 :     OStringBuffer aBuffer;
      98             : 
      99           0 :     aBuffer.append( "slide_preview\n" );
     100             : 
     101           0 :     aBuffer.append( OString::number( aSlideNumber ).getStr() );
     102           0 :     aBuffer.append( "\n" );
     103             : 
     104           0 :     aBuffer.append( aEncodedShortString.getStr() );
     105           0 :     aBuffer.append( "\n\n" );
     106             :     pTransmitter->addMessage( aBuffer.makeStringAndClear(),
     107           0 :         Transmitter::PRIORITY_LOW );
     108             : 
     109             : }
     110             : 
     111           0 : uno::Sequence<sal_Int8> ImagePreparer::preparePreview(
     112             :     sal_uInt32 aSlideNumber, sal_uInt32 aWidth, sal_uInt32 aHeight,
     113             :     sal_uInt64 &rSize )
     114             : {
     115           0 :     OUString aFileURL;
     116           0 :     FileBase::createTempFile( 0, 0, &aFileURL );
     117             : 
     118             :     uno::Reference< drawing::XGraphicExportFilter > xFilter =
     119           0 :         drawing::GraphicExportFilter::create( ::comphelper::getProcessComponentContext() );
     120             : 
     121           0 :     if ( !xController->isRunning() )
     122           0 :         return uno::Sequence<sal_Int8>();
     123             : 
     124             :     uno::Reference< lang::XComponent > xSourceDoc(
     125           0 :         xController->getSlideByIndex( aSlideNumber ),
     126           0 :         uno::UNO_QUERY_THROW );
     127             : 
     128           0 :     xFilter->setSourceDocument( xSourceDoc );
     129             : 
     130           0 :     uno::Sequence< beans::PropertyValue > aFilterData(3);
     131             : 
     132           0 :     aFilterData[0].Name = "PixelWidth";
     133           0 :     aFilterData[0].Value <<= aWidth;
     134             : 
     135           0 :     aFilterData[1].Name = "PixelHeight";
     136           0 :     aFilterData[1].Value <<= aHeight;
     137             : 
     138           0 :     aFilterData[2].Name = "ColorMode";
     139           0 :     aFilterData[2].Value <<= sal_Int32(0); // 0: Color, 1: B&W
     140             : 
     141           0 :     uno::Sequence< beans::PropertyValue > aProps(3);
     142             : 
     143           0 :     aProps[0].Name = "MediaType";
     144           0 :     aProps[0].Value <<= OUString( "image/png" );
     145             : 
     146           0 :     aProps[1].Name = "URL";
     147           0 :     aProps[1].Value <<= aFileURL;
     148             : 
     149           0 :     aProps[2].Name = "FilterData";
     150           0 :     aProps[2].Value <<= aFilterData;
     151             : 
     152           0 :     xFilter->filter( aProps );
     153             : 
     154             :     // FIXME: error handling.
     155             : 
     156           0 :     File aFile( aFileURL );
     157           0 :     aFile.open(0);
     158             :     sal_uInt64 aRead;
     159           0 :     rSize = 0;
     160           0 :     aFile.getSize( rSize );
     161           0 :     uno::Sequence<sal_Int8> aContents( rSize );
     162             : 
     163           0 :     aFile.read( aContents.getArray(), rSize, aRead );
     164           0 :     aFile.close();
     165           0 :     File::remove( aFileURL );
     166           0 :     return aContents;
     167             : 
     168             : }
     169             : 
     170           0 : void ImagePreparer::sendNotes( sal_uInt32 aSlideNumber )
     171             : {
     172             : 
     173           0 :     OString aNotes = prepareNotes( aSlideNumber );
     174             : 
     175           0 :     if ( aNotes.isEmpty() )
     176           0 :         return;
     177             : 
     178             : //     OUStringBuffer aStrBuffer;
     179             : //     ::sax::Converter::encodeBase64( aStrBuffer, aTemp );
     180             : 
     181             : //     OString aNotes = OUStringToOString(
     182             : //         aStrBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
     183             : 
     184           0 :     if ( !xController->isRunning() )
     185           0 :         return;
     186             : 
     187             :     // Start the writing
     188           0 :     OStringBuffer aBuffer;
     189             : 
     190           0 :     aBuffer.append( "slide_notes\n" );
     191             : 
     192           0 :     aBuffer.append( OString::number( aSlideNumber ).getStr() );
     193           0 :     aBuffer.append( "\n" );
     194             : 
     195           0 :     aBuffer.append( "<html><body>" );
     196           0 :     aBuffer.append( aNotes );
     197           0 :     aBuffer.append( "</body></html>" );
     198           0 :     aBuffer.append( "\n\n" );
     199             :     pTransmitter->addMessage( aBuffer.makeStringAndClear(),
     200           0 :         Transmitter::PRIORITY_LOW );
     201             : }
     202             : 
     203             : // Code copied from sdremote/source/presenter/PresenterNotesView.cxx
     204           0 : OString ImagePreparer::prepareNotes( sal_uInt32 aSlideNumber )
     205             : {
     206           0 :     OUStringBuffer aRet;
     207             : 
     208           0 :     if ( !xController->isRunning() )
     209           0 :         return "";
     210             : 
     211           0 :     uno::Reference<css::drawing::XDrawPage> aNotesPage;
     212             :     uno::Reference< drawing::XDrawPage > xSourceDoc(
     213           0 :         xController->getSlideByIndex( aSlideNumber ),
     214           0 :         uno::UNO_QUERY_THROW );
     215             :     uno::Reference<presentation::XPresentationPage> xPresentationPage(
     216           0 :         xSourceDoc, UNO_QUERY);
     217           0 :     if (xPresentationPage.is())
     218           0 :         aNotesPage = xPresentationPage->getNotesPage();
     219             :     else
     220           0 :         return "";
     221             : 
     222             :     static const OUString sNotesShapeName (
     223           0 :         "com.sun.star.presentation.NotesShape" );
     224             :     static const OUString sTextShapeName (
     225           0 :         "com.sun.star.drawing.TextShape" );
     226             : 
     227           0 :     uno::Reference<container::XIndexAccess> xIndexAccess ( aNotesPage, UNO_QUERY);
     228           0 :     if (xIndexAccess.is())
     229             :     {
     230             : 
     231             :         // Iterate over all shapes and find the one that holds the text.
     232           0 :         sal_Int32 nCount (xIndexAccess->getCount());
     233           0 :         for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     234             :         {
     235             : 
     236             :             uno::Reference<lang::XServiceName> xServiceName (
     237           0 :                 xIndexAccess->getByIndex(nIndex), UNO_QUERY);
     238           0 :             if (xServiceName.is()
     239           0 :                 && xServiceName->getServiceName().equals(sNotesShapeName))
     240             :             {
     241           0 :                 uno::Reference<text::XTextRange> xText (xServiceName, UNO_QUERY);
     242           0 :                 if (xText.is())
     243             :                 {
     244           0 :                     aRet.append(xText->getString());
     245           0 :                     aRet.append("<br/>");
     246           0 :                 }
     247             :             }
     248             :             else
     249             :             {
     250             :                 uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor (
     251           0 :                     xIndexAccess->getByIndex(nIndex), UNO_QUERY);
     252           0 :                 if (xShapeDescriptor.is())
     253             :                 {
     254           0 :                     OUString sType (xShapeDescriptor->getShapeType());
     255           0 :                     if (sType.equals(sNotesShapeName) || sType.equals(sTextShapeName))
     256             :                     {
     257             :                         uno::Reference<text::XTextRange> xText (
     258           0 :                             xIndexAccess->getByIndex(nIndex), UNO_QUERY);
     259           0 :                         if (xText.is())
     260             :                         {
     261           0 :                             aRet.append(xText->getString());
     262           0 :                             aRet.append("<br/>");
     263           0 :                         }
     264           0 :                     }
     265           0 :                 }
     266             :             }
     267           0 :         }
     268             :     }
     269             :     // Replace all newlines with <br\> tags
     270           0 :     for ( sal_Int32 i = 0; i < aRet.getLength(); i++ )
     271             :     {
     272           0 :         if ( aRet[i] == '\n' )
     273             :         {
     274           0 :             aRet[i]=  '<';
     275           0 :             aRet.insert( i+1, "br/>" );
     276             :         }
     277             :     }
     278             :     return OUStringToOString(
     279           0 :         aRet.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
     280             : }
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10