LCOV - code coverage report
Current view: top level - sd/source/core - TransitionPreset.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 75 84.0 %
Date: 2015-06-13 12:38:46 Functions: 7 8 87.5 %
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 <com/sun/star/animations/XTimeContainer.hpp>
      21             : #include <com/sun/star/animations/XTransitionFilter.hpp>
      22             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      23             : #include <com/sun/star/container/XNameAccess.hpp>
      24             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      25             : #include <com/sun/star/beans/NamedValue.hpp>
      26             : #include <com/sun/star/util/theMacroExpander.hpp>
      27             : #include <com/sun/star/animations/AnimationNodeType.hpp>
      28             : #include <vcl/svapp.hxx>
      29             : #include <osl/mutex.hxx>
      30             : #include <unotools/streamwrap.hxx>
      31             : #include <comphelper/getexpandeduri.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <unotools/pathoptions.hxx>
      34             : #include <tools/stream.hxx>
      35             : 
      36             : #include <rtl/uri.hxx>
      37             : #include <rtl/instance.hxx>
      38             : 
      39             : #include <CustomAnimationPreset.hxx>
      40             : #include <TransitionPreset.hxx>
      41             : #include <unotools/ucbstreamhelper.hxx>
      42             : 
      43             : #include <algorithm>
      44             : 
      45             : #include "sdpage.hxx"
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::animations;
      49             : 
      50             : using ::com::sun::star::uno::UNO_QUERY;
      51             : using ::com::sun::star::uno::UNO_QUERY_THROW;
      52             : using ::com::sun::star::uno::Any;
      53             : using ::com::sun::star::uno::Sequence;
      54             : using ::com::sun::star::uno::Reference;
      55             : using ::com::sun::star::uno::Exception;
      56             : using ::com::sun::star::lang::XMultiServiceFactory;
      57             : using ::com::sun::star::container::XEnumerationAccess;
      58             : using ::com::sun::star::container::XEnumeration;
      59             : using ::com::sun::star::beans::NamedValue;
      60             : 
      61             : namespace sd {
      62             : 
      63         243 : TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
      64             : {
      65             :     // first locate preset id
      66         243 :     Sequence< NamedValue > aUserData( xNode->getUserData() );
      67         243 :     sal_Int32 nLength = aUserData.getLength();
      68         243 :     const NamedValue* p = aUserData.getConstArray();
      69         243 :     while( nLength-- )
      70             :     {
      71         243 :         if ( p->Name == "preset-id" )
      72             :         {
      73         243 :             p->Value >>= maPresetId;
      74         243 :             break;
      75             :         }
      76             :     }
      77             : 
      78             :     // second, locate transition filter element
      79         486 :     Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
      80         486 :     Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
      81         486 :     Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW );
      82             : 
      83         243 :     mnTransition = xTransition->getTransition();
      84         243 :     mnSubtype = xTransition->getSubtype();
      85         243 :     mbDirection = xTransition->getDirection();
      86         486 :     mnFadeColor = xTransition->getFadeColor();
      87         243 : }
      88             : 
      89           6 : bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList,
      90             :                                               Reference< XMultiServiceFactory >& xServiceFactory,
      91             :                                               UStringMap& rTransitionNameMape,
      92             :                                               const OUString& aURL )
      93             : {
      94             :     // import transition presets
      95           6 :     Reference< XAnimationNode > xAnimationNode;
      96             : 
      97             :     try {
      98           6 :         xAnimationNode = implImportEffects( xServiceFactory, aURL );
      99           6 :         Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW );
     100          12 :         Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
     101             : 
     102         255 :         while( xEnumeration->hasMoreElements() )
     103             :         {
     104         243 :             Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
     105         243 :             if( xChildNode->getType() == AnimationNodeType::PAR )
     106             :             {
     107             :                 // create it
     108         243 :                 TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) );
     109             : 
     110             :                 // name it
     111         486 :                 OUString aPresetId( pPreset->getPresetId() );
     112         243 :                 if( !aPresetId.isEmpty() )
     113             :                 {
     114         243 :                     UStringMap::const_iterator aIter( rTransitionNameMape.find( aPresetId ) );
     115         243 :                     if( aIter != rTransitionNameMape.end() )
     116         213 :                         pPreset->maUIName = (*aIter).second;
     117             : 
     118             :                                 // add it
     119         243 :                     rList.push_back( pPreset );
     120         243 :                 }
     121             :             }
     122             :             else
     123             :                 {
     124             :                     OSL_FAIL( "sd::TransitionPreset::importTransitionPresetList(), malformed xml configuration file, giving up!" );
     125           0 :                     break;
     126             :                 }
     127         249 :         }
     128           0 :     } catch( Exception& ) {
     129           0 :         return false;
     130             :     }
     131             : 
     132           6 :     return true;
     133             : }
     134             : 
     135           3 : bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
     136             : {
     137           3 :     bool bRet = false;
     138             : 
     139             :     try
     140             :     {
     141             :         uno::Reference< uno::XComponentContext > xContext(
     142           3 :             comphelper::getProcessComponentContext() );
     143             :         Reference< XMultiServiceFactory > xServiceFactory(
     144           6 :             xContext->getServiceManager(), UNO_QUERY_THROW );
     145             : 
     146             :         uno::Reference< util::XMacroExpander > xMacroExpander =
     147           6 :             util::theMacroExpander::get(xContext);
     148             : 
     149             :         // import ui strings
     150             :         Reference< XMultiServiceFactory > xConfigProvider =
     151           6 :             configuration::theDefaultProvider::get( xContext );
     152             : 
     153           6 :         UStringMap aTransitionNameMape;
     154           6 :         const OUString aTransitionPath("/org.openoffice.Office.UI.Effects/UserInterface/Transitions" );
     155           3 :         implImportLabels( xConfigProvider, aTransitionPath, aTransitionNameMape );
     156             : 
     157             :         // read path to transition effects files from config
     158             :         Any propValue = uno::makeAny(
     159             :             beans::PropertyValue("nodepath", -1,
     160             :                 uno::makeAny( OUString("/org.openoffice.Office.Impress/Misc")),
     161           6 :                 beans::PropertyState_DIRECT_VALUE ) );
     162             : 
     163             :         Reference<container::XNameAccess> xNameAccess(
     164           3 :             xConfigProvider->createInstanceWithArguments(
     165             :                 "com.sun.star.configuration.ConfigurationAccess",
     166           3 :                 Sequence<Any>( &propValue, 1 ) ),
     167           6 :                 UNO_QUERY_THROW );
     168           6 :         uno::Sequence< OUString > aFiles;
     169           3 :         xNameAccess->getByName("TransitionFiles") >>= aFiles;
     170             : 
     171           9 :         for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
     172             :         {
     173           6 :             OUString aURL = comphelper::getExpandedUri(xContext, aFiles[i]);
     174             : 
     175             :             bRet |= importTransitionsFile( rList,
     176             :                                            xServiceFactory,
     177             :                                            aTransitionNameMape,
     178           6 :                                            aURL );
     179           6 :         }
     180             : 
     181           6 :         return bRet;
     182             :     }
     183           0 :     catch( Exception& )
     184             :     {
     185             :         OSL_FAIL( "sd::TransitionPreset::importResources(), exception caught!" );
     186             :     }
     187             : 
     188           0 :     return bRet;
     189             : }
     190             : 
     191             : namespace
     192             : {
     193           3 :     class ImportedTransitionPresetList
     194             :     {
     195             :     private:
     196             :         sd::TransitionPresetList m_aTransitionPresetList;
     197             :     public:
     198           3 :         ImportedTransitionPresetList()
     199           3 :         {
     200             :             sd::TransitionPreset::importTransitionPresetList(
     201           3 :                 m_aTransitionPresetList);
     202           3 :         }
     203          42 :         const sd::TransitionPresetList& getList() const
     204             :         {
     205          42 :             return m_aTransitionPresetList;
     206             :         }
     207             :     };
     208             : 
     209             :     class theTransitionPresetList :
     210             :         public rtl::Static<ImportedTransitionPresetList,
     211             :                            theTransitionPresetList>
     212             :     {
     213             :     };
     214             : }
     215             : 
     216          42 : const TransitionPresetList& TransitionPreset::getTransitionPresetList()
     217             : {
     218          42 :     return theTransitionPresetList::get().getList();
     219             : }
     220             : 
     221           0 : void TransitionPreset::apply( SdPage* pSlide ) const
     222             : {
     223           0 :     if( pSlide )
     224             :     {
     225           0 :         pSlide->setTransitionType( mnTransition );
     226           0 :         pSlide->setTransitionSubtype( mnSubtype );
     227           0 :         pSlide->setTransitionDirection( mbDirection );
     228           0 :         pSlide->setTransitionFadeColor( mnFadeColor );
     229             :     }
     230           0 : }
     231             : 
     232             : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11