[PATCH] pptx import:supporting FilterData properties:PageRange and I...

Sven Jacobi (via Code Review) gerrit at gerrit.libreoffice.org
Mon Mar 11 05:36:12 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2665

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/65/2665/1

pptx import:supporting FilterData properties:PageRange and ImportNotesPages

Change-Id: I9da8455bb10e93f1ae6c4894d4f15ff7fbcdfa07
---
M oox/inc/oox/core/filterbase.hxx
M oox/inc/oox/ppt/presentationfragmenthandler.hxx
M oox/source/core/filterbase.cxx
M oox/source/ppt/presentationfragmenthandler.cxx
4 files changed, 173 insertions(+), 110 deletions(-)



diff --git a/oox/inc/oox/core/filterbase.hxx b/oox/inc/oox/core/filterbase.hxx
index 171ae5f..5f47ea9 100644
--- a/oox/inc/oox/core/filterbase.hxx
+++ b/oox/inc/oox/core/filterbase.hxx
@@ -32,6 +32,7 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/basemutex.hxx>
 #include <cppuhelper/implbase5.hxx>
+#include <comphelper/sequenceashashmap.hxx>
 #include "oox/helper/binarystreambase.hxx"
 #include "oox/helper/storagebase.hxx"
 #include "oox/dllapi.h"
@@ -140,6 +141,9 @@
     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator >&
                         getStatusIndicator() const;
 
+    /** Returns the FilterData */
+    ::comphelper::SequenceAsHashMap& getFilterData() const;
+
     /** Returns the media descriptor. */
     ::comphelper::MediaDescriptor& getMediaDescriptor() const;
 
diff --git a/oox/inc/oox/ppt/presentationfragmenthandler.hxx b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
index 6943368..bb94884 100644
--- a/oox/inc/oox/ppt/presentationfragmenthandler.hxx
+++ b/oox/inc/oox/ppt/presentationfragmenthandler.hxx
@@ -48,6 +48,9 @@
                         const oox::ppt::SlidePersistPtr pPersist );
 
 private:
+
+    void importSlide(sal_uInt32 nSlide, sal_Bool bFirstSlide, sal_Bool bImportNotes);
+
     std::vector< rtl::OUString > maSlideMasterVector;
     std::vector< rtl::OUString > maSlidesVector;
     std::vector< rtl::OUString > maNotesMasterVector;
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index 3c3e8c3..8643d2c 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -132,6 +132,7 @@
 
     FilterDirection     meDirection;
     SequenceAsHashMap   maArguments;
+    SequenceAsHashMap   maFilterData;
     MediaDescriptor     maMediaDesc;
     OUString            maFileUrl;
     StorageRef          mxStorage;
@@ -202,6 +203,8 @@
 {
     try
     {
+        // writing back the FilterData to the MediaDescriptor
+        maMediaDesc["FilterData"] = makeAny(maFilterData.getAsConstPropertyValueList());
         // write the descriptor back to the document model (adds the passwords)
         mxModel->attachResource( maFileUrl, maMediaDesc.getAsConstPropertyValueList() );
         // unlock the model controllers
@@ -276,6 +279,11 @@
 MediaDescriptor& FilterBase::getMediaDescriptor() const
 {
     return mxImpl->maMediaDesc;
+}
+
+SequenceAsHashMap& FilterBase::getFilterData() const
+{
+    return mxImpl->maFilterData;
 }
 
 const OUString& FilterBase::getFileUrl() const
@@ -548,6 +556,7 @@
     mxImpl->mxStatusIndicator = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_STATUSINDICATOR(), Reference< XStatusIndicator >() );
     mxImpl->mxInteractionHandler = mxImpl->maMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INTERACTIONHANDLER(), Reference< XInteractionHandler >() );
     mxImpl->mxParentShape = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "ParentShape", mxImpl->mxParentShape );
+    mxImpl->maFilterData = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "FilterData", Sequence< PropertyValue >() );
 
     // Check for ISO OOXML
     OUString sFilterName = mxImpl->maMediaDesc.getUnpackedValueOrDefault( "FilterName", OUString() );
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx
index 6d077e7..c2fdf53 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -19,6 +19,7 @@
 
 #include "comphelper/anytostring.hxx"
 #include "cppuhelper/exc_hlp.hxx"
+#include <tools/multisel.hxx>
 
 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPages.hpp>
@@ -130,133 +131,123 @@
     }
 }
 
-void PresentationFragmentHandler::finalizeImport()
+void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, sal_Bool bFirstPage, sal_Bool bImportNotesPage)
 {
-    // todo: localized progress bar text
-    const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
-    if ( rxStatusIndicator.is() )
-        rxStatusIndicator->start( OUString(), 10000 );
+    PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
 
-    try
-    {
-        PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
+    Reference< frame::XModel > xModel( rFilter.getModel() );
+    Reference< drawing::XDrawPage > xSlide;
 
-        Reference< frame::XModel > xModel( rFilter.getModel() );
-        Reference< drawing::XDrawPage > xSlide;
-        sal_uInt32 nSlide;
+    // importing slide pages and its corresponding notes page
+    Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
+    Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY_THROW );
 
-        // importing slide pages and its corresponding notes page
-        Reference< drawing::XDrawPagesSupplier > xDPS( xModel, uno::UNO_QUERY_THROW );
-        Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_QUERY_THROW );
+    try {
 
-        for( nSlide = 0; nSlide < maSlidesVector.size(); nSlide++ )
+        if( bFirstPage )
+            xDrawPages->getByIndex( 0 ) >>= xSlide;
+        else
+            xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
+
+        OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
+        if( !aSlideFragmentPath.isEmpty() )
         {
-            if ( rxStatusIndicator.is() )
-                rxStatusIndicator->setValue( ( nSlide * 10000 ) / maSlidesVector.size() );
+            SlidePersistPtr pMasterPersistPtr;
+            SlidePersistPtr pSlidePersistPtr( new SlidePersist( rFilter, sal_False, sal_False, xSlide,
+                                ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
 
-            if( nSlide == 0 )
-                xDrawPages->getByIndex( 0 ) >>= xSlide;
-            else
-                xSlide = xDrawPages->insertNewByIndex( nSlide );
+            FragmentHandlerRef xSlideFragmentHandler( new SlideFragmentHandler( rFilter, aSlideFragmentPath, pSlidePersistPtr, Slide ) );
 
-            OUString aSlideFragmentPath = getFragmentPathFromRelId( maSlidesVector[ nSlide ] );
-            if( !aSlideFragmentPath.isEmpty() )
+            // importing the corresponding masterpage/layout
+            OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideLayout" ) );
+            if ( !aLayoutFragmentPath.isEmpty() )
             {
-                OUString aMasterFragmentPath;
-                SlidePersistPtr pMasterPersistPtr;
-                SlidePersistPtr pSlidePersistPtr( new SlidePersist( rFilter, sal_False, sal_False, xSlide,
-                                    ShapePtr( new PPTShape( Slide, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
-
-                FragmentHandlerRef xSlideFragmentHandler( new SlideFragmentHandler( rFilter, aSlideFragmentPath, pSlidePersistPtr, Slide ) );
-
-                // importing the corresponding masterpage/layout
-                OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideLayout" ) );
-                if ( !aLayoutFragmentPath.isEmpty() )
+                // importing layout
+                RelationsRef xLayoutRelations = rFilter.importRelations( aLayoutFragmentPath );
+                OUString aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideMaster" ) );
+                if( !aMasterFragmentPath.isEmpty() )
                 {
-                    // importing layout
-                    RelationsRef xLayoutRelations = rFilter.importRelations( aLayoutFragmentPath );
-                    aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "slideMaster" ) );
-                    if( !aMasterFragmentPath.isEmpty() )
+                    // check if the corresponding masterpage+layout has already been imported
+                    std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
+                    std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
+                    while( aIter != rMasterPages.end() )
                     {
-                        // check if the corresponding masterpage+layout has already been imported
-                        std::vector< SlidePersistPtr >& rMasterPages( rFilter.getMasterPages() );
-                        std::vector< SlidePersistPtr >::iterator aIter( rMasterPages.begin() );
-                        while( aIter != rMasterPages.end() )
+                        if ( ( (*aIter)->getPath() == aMasterFragmentPath ) && ( (*aIter)->getLayoutPath() == aLayoutFragmentPath ) )
                         {
-                            if ( ( (*aIter)->getPath() == aMasterFragmentPath ) && ( (*aIter)->getLayoutPath() == aLayoutFragmentPath ) )
-                            {
-                                pMasterPersistPtr = *aIter;
-                                break;
-                            }
-                            ++aIter;
+                            pMasterPersistPtr = *aIter;
+                            break;
                         }
+                        ++aIter;
+                    }
 
-                        if ( !pMasterPersistPtr.get() )
-                        {   // masterpersist not found, we have to load it
-                            Reference< drawing::XDrawPage > xMasterPage;
-                            Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW );
-                            Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_QUERY_THROW );
+                    if ( !pMasterPersistPtr.get() )
+                    {   // masterpersist not found, we have to load it
+                        Reference< drawing::XDrawPage > xMasterPage;
+                        Reference< drawing::XMasterPagesSupplier > xMPS( xModel, uno::UNO_QUERY_THROW );
+                        Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_QUERY_THROW );
 
-                            if( !(rFilter.getMasterPages().size() ))
-                                xMasterPages->getByIndex( 0 ) >>= xMasterPage;
+                        if( !(rFilter.getMasterPages().size() ))
+                            xMasterPages->getByIndex( 0 ) >>= xMasterPage;
+                        else
+                            xMasterPage = xMasterPages->insertNewByIndex( xMasterPages->getCount() );
+
+                        pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_False, xMasterPage,
+                            ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
+                        pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
+                        rFilter.getMasterPages().push_back( pMasterPersistPtr );
+                        rFilter.setActualSlidePersist( pMasterPersistPtr );
+                        FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) );
+
+                        // set the correct theme
+                        OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "theme" ) );
+                        if( !aThemeFragmentPath.isEmpty() )
+                        {
+                            std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() );
+                            std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
+                            if( aIter2 == rThemes.end() )
+                            {
+                                oox::drawingml::ThemePtr pThemePtr( new oox::drawingml::Theme() );
+                                pMasterPersistPtr->setTheme( pThemePtr );
+                                Reference<xml::dom::XDocument> xDoc=
+                                    rFilter.importFragment(aThemeFragmentPath);
+
+                                rFilter.importFragment(
+                                    new ThemeFragmentHandler(
+                                        rFilter, aThemeFragmentPath, *pThemePtr ),
+                                    Reference<xml::sax::XFastSAXSerializable>(
+                                        xDoc,
+                                        UNO_QUERY_THROW));
+                                rThemes[ aThemeFragmentPath ] = pThemePtr;
+                                pThemePtr->setFragment(xDoc);
+                            }
                             else
-                                xMasterPage = xMasterPages->insertNewByIndex( xMasterPages->getCount() );
-
-                            pMasterPersistPtr = SlidePersistPtr( new SlidePersist( rFilter, sal_True, sal_False, xMasterPage,
-                                ShapePtr( new PPTShape( Master, "com.sun.star.drawing.GroupShape" ) ), mpTextListStyle ) );
-                            pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
-                            rFilter.getMasterPages().push_back( pMasterPersistPtr );
-                            rFilter.setActualSlidePersist( pMasterPersistPtr );
-                            FragmentHandlerRef xMasterFragmentHandler( new SlideFragmentHandler( rFilter, aMasterFragmentPath, pMasterPersistPtr, Master ) );
-
-                            // set the correct theme
-                            OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "theme" ) );
-                            if( !aThemeFragmentPath.isEmpty() )
                             {
-                                std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.getThemes() );
-                                std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
-                                if( aIter2 == rThemes.end() )
-                                {
-                                    oox::drawingml::ThemePtr pThemePtr( new oox::drawingml::Theme() );
-                                    pMasterPersistPtr->setTheme( pThemePtr );
-                                    Reference<xml::dom::XDocument> xDoc=
-                                        rFilter.importFragment(aThemeFragmentPath);
-
-                                    rFilter.importFragment(
-                                        new ThemeFragmentHandler(
-                                            rFilter, aThemeFragmentPath, *pThemePtr ),
-                                        Reference<xml::sax::XFastSAXSerializable>(
-                                            xDoc,
-                                            UNO_QUERY_THROW));
-                                    rThemes[ aThemeFragmentPath ] = pThemePtr;
-                                    pThemePtr->setFragment(xDoc);
-                                }
-                                else
-                                {
-                                    pMasterPersistPtr->setTheme( (*aIter2).second );
-                                }
+                                pMasterPersistPtr->setTheme( (*aIter2).second );
                             }
-                            importSlide( xMasterFragmentHandler, pMasterPersistPtr );
-                            rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
-                            pMasterPersistPtr->createBackground( rFilter );
-                            pMasterPersistPtr->createXShapes( rFilter );
                         }
+                        importSlide( xMasterFragmentHandler, pMasterPersistPtr );
+                        rFilter.importFragment( new LayoutFragmentHandler( rFilter, aLayoutFragmentPath, pMasterPersistPtr ) );
+                        pMasterPersistPtr->createBackground( rFilter );
+                        pMasterPersistPtr->createXShapes( rFilter );
                     }
                 }
+            }
 
-                // importing slide page
-                if (pMasterPersistPtr.get()) {
-                    pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
-                    pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
-                    Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
-                    if( xMasterPageTarget.is() )
-                        xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
-                }
-                rFilter.getDrawPages().push_back( pSlidePersistPtr );
-                rFilter.setActualSlidePersist( pSlidePersistPtr );
-                importSlide( xSlideFragmentHandler, pSlidePersistPtr );
-                pSlidePersistPtr->createBackground( rFilter );
-                pSlidePersistPtr->createXShapes( rFilter );
+            // importing slide page
+            if (pMasterPersistPtr.get()) {
+                pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
+                pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
+                Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
+                if( xMasterPageTarget.is() )
+                    xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
+            }
+            rFilter.getDrawPages().push_back( pSlidePersistPtr );
+            rFilter.setActualSlidePersist( pSlidePersistPtr );
+            importSlide( xSlideFragmentHandler, pSlidePersistPtr );
+            pSlidePersistPtr->createBackground( rFilter );
+            pSlidePersistPtr->createXShapes( rFilter );
+
+            if(bImportNotesPage) {
 
                 // now importing the notes page
                 OUString aNotesFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "notesSlide" ) );
@@ -281,7 +272,6 @@
                 }
             }
         }
-        ResolveTextFields( rFilter );
     }
     catch( uno::Exception& )
     {
@@ -292,10 +282,67 @@
                 RTL_TEXTENCODING_UTF8 )).getStr() );
 
     }
+}
 
-    // todo error handling;
-    if ( rxStatusIndicator.is() )
-        rxStatusIndicator->end();
+void PresentationFragmentHandler::finalizeImport()
+{
+    PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() );
+
+    sal_Int32 nPageCount = maSlidesVector.size();
+
+    // we will take the FilterData property "PageRange" if available, otherwise full range is used
+    comphelper::SequenceAsHashMap& rFilterData = rFilter.getFilterData();
+
+    // writing back the original PageCount of this document, it can be accessed from the XModel
+    // via getArgs after the import.
+    rFilterData["OriginalPageCount"] = makeAny(nPageCount);
+    sal_Bool bImportNotesPages = rFilterData.getUnpackedValueOrDefault("ImportNotesPages", sal_True);
+    OUString aPageRange = rFilterData.getUnpackedValueOrDefault("PageRange", OUString());
+
+    if( !aPageRange.getLength() )
+    {
+        aPageRange = OUStringBuffer()
+            .append( static_cast< sal_Int32 >( 1 ) )
+            .append( static_cast< sal_Unicode >( '-' ) )
+            .append( nPageCount ).makeStringAndClear();
+    }
+
+    StringRangeEnumerator aRangeEnumerator( aPageRange, 0, nPageCount - 1 );
+    StringRangeEnumerator::Iterator aIter = aRangeEnumerator.begin();
+    StringRangeEnumerator::Iterator aEnd  = aRangeEnumerator.end();
+    if(aIter!=aEnd) {
+
+        // todo: localized progress bar text
+        const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
+        if ( rxStatusIndicator.is() )
+            rxStatusIndicator->start( OUString(), 10000 );
+
+        try
+        {
+            int nPagesImported = 0;
+            while (aIter!=aEnd)
+            {
+                if ( rxStatusIndicator.is() )
+                    rxStatusIndicator->setValue((nPagesImported * 10000) / aRangeEnumerator.size());
+
+                importSlide(*aIter, !nPagesImported, bImportNotesPages);
+                nPagesImported++;
+                ++aIter;
+            }
+            ResolveTextFields( rFilter );
+        }
+        catch( uno::Exception& )
+        {
+            OSL_FAIL( OString("oox::ppt::PresentationFragmentHandler::finalizeImport(), "
+                        "exception caught: " +
+                OUStringToOString(
+                    comphelper::anyToString( cppu::getCaughtException() ),
+                    RTL_TEXTENCODING_UTF8 )).getStr() );
+        }
+        // todo error handling;
+        if ( rxStatusIndicator.is() )
+            rxStatusIndicator->end();
+    }
 }
 
 // CT_Presentation
@@ -362,7 +409,7 @@
         try
         {
             if ( pSlidePersistPtr->isNotesPage() )
-                xPropertySet->setPropertyValue( "sIsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
+                xPropertySet->setPropertyValue( "IsHeaderVisible", Any( aHeaderFooter.mbHeader ) );
             xPropertySet->setPropertyValue( "IsFooterVisible", Any( aHeaderFooter.mbFooter ) );
             xPropertySet->setPropertyValue( "IsDateTimeVisible", Any( aHeaderFooter.mbDateTime ) );
             xPropertySet->setPropertyValue( "IsPageNumberVisible", Any( aHeaderFooter.mbSlideNumber ) );

-- 
To view, visit https://gerrit.libreoffice.org/2665
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9da8455bb10e93f1ae6c4894d4f15ff7fbcdfa07
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Sven Jacobi <Sven-Jacobi at gmx.de>



More information about the LibreOffice mailing list