LCOV - code coverage report
Current view: top level - sd/source/core - TransitionPreset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 72 84 85.7 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 87 176 49.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/animations/XTimeContainer.hpp>
      30                 :            : #include <com/sun/star/animations/XTransitionFilter.hpp>
      31                 :            : #include <com/sun/star/container/XEnumerationAccess.hpp>
      32                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      33                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      34                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      35                 :            : #include <com/sun/star/util/XMacroExpander.hpp>
      36                 :            : #include <com/sun/star/animations/AnimationNodeType.hpp>
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : #include <osl/mutex.hxx>
      39                 :            : #include <unotools/streamwrap.hxx>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <unotools/pathoptions.hxx>
      42                 :            : #include <tools/stream.hxx>
      43                 :            : 
      44                 :            : #include <rtl/uri.hxx>
      45                 :            : #include <rtl/instance.hxx>
      46                 :            : #include <tools/debug.hxx>
      47                 :            : 
      48                 :            : #include <TransitionPreset.hxx>
      49                 :            : #include <unotools/ucbstreamhelper.hxx>
      50                 :            : 
      51                 :            : #include <algorithm>
      52                 :            : 
      53                 :            : #include "sdpage.hxx"
      54                 :            : 
      55                 :            : using namespace ::com::sun::star;
      56                 :            : using namespace ::com::sun::star::animations;
      57                 :            : 
      58                 :            : using ::rtl::OUString;
      59                 :            : using ::com::sun::star::uno::UNO_QUERY;
      60                 :            : using ::com::sun::star::uno::UNO_QUERY_THROW;
      61                 :            : using ::com::sun::star::uno::Any;
      62                 :            : using ::com::sun::star::uno::Sequence;
      63                 :            : using ::com::sun::star::uno::Reference;
      64                 :            : using ::com::sun::star::uno::Exception;
      65                 :            : using ::com::sun::star::lang::XMultiServiceFactory;
      66                 :            : using ::com::sun::star::container::XEnumerationAccess;
      67                 :            : using ::com::sun::star::container::XEnumeration;
      68                 :            : using ::com::sun::star::beans::NamedValue;
      69                 :            : 
      70                 :            : namespace sd {
      71                 :            : 
      72                 :            : extern Reference< XAnimationNode > implImportEffects( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rPath );
      73                 :            : extern void implImportLabels( const Reference< XMultiServiceFactory >& xConfigProvider, const OUString& rNodePath, UStringMap& rStringMap );
      74                 :            : 
      75                 :        162 : TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
      76                 :            : {
      77                 :            :     // first locate preset id
      78 [ +  - ][ +  - ]:        162 :     Sequence< NamedValue > aUserData( xNode->getUserData() );
      79                 :        162 :     sal_Int32 nLength = aUserData.getLength();
      80                 :        162 :     const NamedValue* p = aUserData.getConstArray();
      81         [ +  - ]:        162 :     while( nLength-- )
      82                 :            :     {
      83         [ +  - ]:        162 :         if ( p->Name == "preset-id" )
      84                 :            :         {
      85                 :        162 :             p->Value >>= maPresetId;
      86                 :        162 :             break;
      87                 :            :         }
      88                 :            :     }
      89                 :            : 
      90                 :            :     // second, locate transition filter element
      91         [ +  - ]:        162 :     Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
      92 [ +  - ][ +  - ]:        162 :     Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
                 [ +  - ]
      93 [ +  - ][ +  - ]:        162 :     Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW );
                 [ +  - ]
      94                 :            : 
      95 [ +  - ][ +  - ]:        162 :     mnTransition = xTransition->getTransition();
      96 [ +  - ][ +  - ]:        162 :     mnSubtype = xTransition->getSubtype();
      97 [ +  - ][ +  - ]:        162 :     mbDirection = xTransition->getDirection();
      98 [ +  - ][ +  - ]:        162 :     mnFadeColor = xTransition->getFadeColor();
                 [ +  - ]
      99                 :        162 : }
     100                 :            : 
     101                 :          4 : bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList,
     102                 :            :                                               Reference< XMultiServiceFactory >& xServiceFactory,
     103                 :            :                                               UStringMap& rTransitionNameMape,
     104                 :            :                                               String aURL )
     105                 :            : {
     106                 :            :     // import transition presets
     107                 :          4 :     Reference< XAnimationNode > xAnimationNode;
     108                 :            : 
     109                 :            :     try {
     110 [ +  - ][ +  - ]:          4 :         xAnimationNode = implImportEffects( xServiceFactory, aURL );
                 [ +  - ]
     111         [ +  - ]:          4 :         Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW );
     112 [ +  - ][ +  - ]:          4 :         Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
                 [ +  - ]
     113                 :            : 
     114 [ +  - ][ +  - ]:        166 :         while( xEnumeration->hasMoreElements() )
                 [ +  + ]
     115                 :            :         {
     116 [ +  - ][ +  - ]:        162 :             Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
                 [ +  - ]
     117 [ +  - ][ +  - ]:        162 :             if( xChildNode->getType() == AnimationNodeType::PAR )
                 [ +  - ]
     118                 :            :             {
     119                 :            :                 // create it
     120 [ +  - ][ +  - ]:        162 :                 TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) );
                 [ +  - ]
     121                 :            : 
     122                 :            :                 // name it
     123                 :        162 :                 OUString aPresetId( pPreset->getPresetId() );
     124         [ +  - ]:        162 :                 if( !aPresetId.isEmpty() )
     125                 :            :                 {
     126         [ +  - ]:        162 :                     UStringMap::const_iterator aIter( rTransitionNameMape.find( aPresetId ) );
     127 [ +  + ][ +  - ]:        162 :                     if( aIter != rTransitionNameMape.end() )
     128         [ +  - ]:        142 :                         pPreset->maUIName = (*aIter).second;
     129                 :            : 
     130                 :            :                                 // add it
     131         [ +  - ]:        162 :                     rList.push_back( pPreset );
     132         [ +  - ]:        162 :                 }
     133                 :            :             }
     134                 :            :             else
     135                 :            :                 {
     136                 :            :                     OSL_FAIL( "sd::TransitionPreset::importTransitionPresetList(), misformed xml configuration file, giving up!" );
     137                 :            :                     break;
     138                 :            :                 }
     139 [ +  - ][ #  # ]:        166 :         }
     140         [ #  # ]:          0 :     } catch( Exception& ) {
     141                 :          0 :         return false;
     142                 :            :     }
     143                 :            : 
     144                 :          4 :     return true;
     145                 :            : }
     146                 :            : 
     147                 :            : #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
     148                 :            : 
     149                 :          2 : bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
     150                 :            : {
     151                 :          2 :     bool bRet = false;
     152                 :            : 
     153                 :            :     try
     154                 :            :     {
     155                 :            :         // Get service factory
     156         [ +  - ]:          2 :         Reference< XMultiServiceFactory > xServiceFactory( comphelper::getProcessServiceFactory() );
     157                 :            :         DBG_ASSERT( xServiceFactory.is(), "sd::CustomAnimationPresets::import(), got no service manager" );
     158         [ -  + ]:          2 :         if( !xServiceFactory.is() )
     159                 :          0 :             return false;
     160                 :            : 
     161         [ +  - ]:          2 :         uno::Reference< beans::XPropertySet > xProps( xServiceFactory, UNO_QUERY );
     162                 :          2 :         uno::Reference< uno::XComponentContext > xContext;
     163 [ +  - ][ +  - ]:          2 :         xProps->getPropertyValue( "DefaultContext" ) >>= xContext;
                 [ +  - ]
     164                 :            : 
     165                 :          2 :         uno::Reference< util::XMacroExpander > xMacroExpander;
     166         [ +  - ]:          2 :         if( xContext.is() )
     167 [ +  - ][ +  - ]:          2 :             xMacroExpander.set( xContext->getValueByName("/singletons/com.sun.star.util.theMacroExpander"), UNO_QUERY );
                 [ +  - ]
     168                 :            : 
     169                 :            :         // import ui strings
     170                 :            :         Reference< XMultiServiceFactory > xConfigProvider(
     171 [ +  - ][ +  - ]:          2 :             xServiceFactory->createInstance("com.sun.star.configuration.ConfigurationProvider" ), UNO_QUERY_THROW );
                 [ +  - ]
     172                 :            : 
     173         [ +  - ]:          2 :         UStringMap aTransitionNameMape;
     174                 :          2 :         const OUString aTransitionPath("/org.openoffice.Office.UI.Effects/UserInterface/Transitions" );
     175         [ +  - ]:          2 :         implImportLabels( xConfigProvider, aTransitionPath, aTransitionNameMape );
     176                 :            : 
     177                 :            :         // read path to transition effects files from config
     178                 :            :         Any propValue = uno::makeAny(
     179                 :            :             beans::PropertyValue("nodepath", -1,
     180                 :            :                 uno::makeAny( OUString("/org.openoffice.Office.Impress/Misc")),
     181 [ +  - ][ +  - ]:          2 :                 beans::PropertyState_DIRECT_VALUE ) );
     182                 :            : 
     183                 :            :         Reference<container::XNameAccess> xNameAccess(
     184         [ +  - ]:          2 :             xConfigProvider->createInstanceWithArguments(
     185                 :            :                 "com.sun.star.configuration.ConfigurationAccess",
     186                 :          2 :                 Sequence<Any>( &propValue, 1 ) ),
     187 [ +  - ][ +  - ]:          2 :                 UNO_QUERY_THROW );
         [ +  - ][ +  - ]
     188         [ +  - ]:          2 :         uno::Sequence< rtl::OUString > aFiles;
     189 [ +  - ][ +  - ]:          2 :         xNameAccess->getByName("TransitionFiles") >>= aFiles;
                 [ +  - ]
     190                 :            : 
     191         [ +  + ]:          6 :         for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
     192                 :            :         {
     193         [ +  - ]:          4 :             rtl::OUString aURL = aFiles[i];
     194         [ +  - ]:          4 :             if( aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL )) == 0 )
     195                 :            :             {
     196                 :            :                 // cut protocol
     197                 :          4 :                 rtl::OUString aMacro( aURL.copy( sizeof ( EXPAND_PROTOCOL ) -1 ) );
     198                 :            :                 // decode uric class chars
     199                 :          4 :                 aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
     200                 :            :                 // expand macro string
     201 [ +  - ][ +  - ]:          4 :                 aURL = xMacroExpander->expandMacros( aMacro );
     202                 :            :             }
     203                 :            : 
     204                 :            :             bRet |= importTransitionsFile( rList,
     205                 :            :                                            xServiceFactory,
     206                 :            :                                            aTransitionNameMape,
     207 [ +  - ][ +  - ]:          4 :                                            aURL );
                 [ +  - ]
     208                 :          4 :         }
     209                 :            : 
     210 [ +  - ][ +  - ]:          2 :         return bRet;
                 [ #  # ]
     211                 :            :     }
     212                 :          0 :     catch( Exception& )
     213                 :            :     {
     214                 :            :         OSL_FAIL( "sd::TransitionPreset::importResources(), Exception cought!" );
     215                 :            :     }
     216                 :            : 
     217                 :          0 :     return bRet;
     218                 :            : }
     219                 :            : 
     220                 :            : namespace
     221                 :            : {
     222                 :          2 :     class ImportedTransitionPresetList
     223                 :            :     {
     224                 :            :     private:
     225                 :            :         sd::TransitionPresetList m_aTransitionPresetList;
     226                 :            :     public:
     227                 :          2 :         ImportedTransitionPresetList()
     228                 :          2 :         {
     229                 :            :             sd::TransitionPreset::importTransitionPresetList(
     230         [ +  - ]:          2 :                 m_aTransitionPresetList);
     231                 :          2 :         }
     232                 :          4 :         const sd::TransitionPresetList& getList() const
     233                 :            :         {
     234                 :          4 :             return m_aTransitionPresetList;
     235                 :            :         }
     236                 :            :     };
     237                 :            : 
     238                 :            :     class theTransitionPresetList :
     239                 :            :         public rtl::Static<ImportedTransitionPresetList,
     240                 :            :                            theTransitionPresetList>
     241                 :            :     {
     242                 :            :     };
     243                 :            : }
     244                 :            : 
     245                 :          4 : const TransitionPresetList& TransitionPreset::getTransitionPresetList()
     246                 :            : {
     247                 :          4 :     return theTransitionPresetList::get().getList();
     248                 :            : }
     249                 :            : 
     250                 :          0 : void TransitionPreset::apply( SdPage* pSlide ) const
     251                 :            : {
     252         [ #  # ]:          0 :     if( pSlide )
     253                 :            :     {
     254                 :          0 :         pSlide->setTransitionType( mnTransition );
     255                 :          0 :         pSlide->setTransitionSubtype( mnSubtype );
     256                 :          0 :         pSlide->setTransitionDirection( mbDirection );
     257                 :          0 :         pSlide->setTransitionFadeColor( mnFadeColor );
     258                 :            :     }
     259                 :          0 : }
     260                 :            : 
     261                 :            : }
     262                 :            : 
     263                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10