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

Generated by: LCOV version 1.10