LCOV - code coverage report
Current view: top level - sd/source/core - TransitionPreset.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 64 76 84.2 %
Date: 2014-11-03 Functions: 9 10 90.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             : 
      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         324 : TransitionPreset::TransitionPreset( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode )
      64             : {
      65             :     // first locate preset id
      66         324 :     Sequence< NamedValue > aUserData( xNode->getUserData() );
      67         324 :     sal_Int32 nLength = aUserData.getLength();
      68         324 :     const NamedValue* p = aUserData.getConstArray();
      69         324 :     while( nLength-- )
      70             :     {
      71         324 :         if ( p->Name == "preset-id" )
      72             :         {
      73         324 :             p->Value >>= maPresetId;
      74         324 :             break;
      75             :         }
      76             :     }
      77             : 
      78             :     // second, locate transition filter element
      79         648 :     Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
      80         648 :     Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
      81         648 :     Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW );
      82             : 
      83         324 :     mnTransition = xTransition->getTransition();
      84         324 :     mnSubtype = xTransition->getSubtype();
      85         324 :     mbDirection = xTransition->getDirection();
      86         648 :     mnFadeColor = xTransition->getFadeColor();
      87         324 : }
      88             : 
      89           8 : bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList,
      90             :                                               Reference< XMultiServiceFactory >& xServiceFactory,
      91             :                                               UStringMap& rTransitionNameMape,
      92             :                                               const OUString& aURL )
      93             : {
      94             :     // import transition presets
      95           8 :     Reference< XAnimationNode > xAnimationNode;
      96             : 
      97             :     try {
      98           8 :         xAnimationNode = implImportEffects( xServiceFactory, aURL );
      99           8 :         Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW );
     100          16 :         Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
     101             : 
     102         340 :         while( xEnumeration->hasMoreElements() )
     103             :         {
     104         324 :             Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
     105         324 :             if( xChildNode->getType() == AnimationNodeType::PAR )
     106             :             {
     107             :                 // create it
     108         324 :                 TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) );
     109             : 
     110             :                 // name it
     111         648 :                 OUString aPresetId( pPreset->getPresetId() );
     112         324 :                 if( !aPresetId.isEmpty() )
     113             :                 {
     114         324 :                     UStringMap::const_iterator aIter( rTransitionNameMape.find( aPresetId ) );
     115         324 :                     if( aIter != rTransitionNameMape.end() )
     116         284 :                         pPreset->maUIName = (*aIter).second;
     117             : 
     118             :                                 // add it
     119         324 :                     rList.push_back( pPreset );
     120         324 :                 }
     121             :             }
     122             :             else
     123             :                 {
     124             :                     OSL_FAIL( "sd::TransitionPreset::importTransitionPresetList(), malformed xml configuration file, giving up!" );
     125           0 :                     break;
     126             :                 }
     127         332 :         }
     128           0 :     } catch( Exception& ) {
     129           0 :         return false;
     130             :     }
     131             : 
     132           8 :     return true;
     133             : }
     134             : 
     135           4 : bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
     136             : {
     137           4 :     bool bRet = false;
     138             : 
     139             :     try
     140             :     {
     141             :         uno::Reference< uno::XComponentContext > xContext(
     142           4 :             comphelper::getProcessComponentContext() );
     143             :         Reference< XMultiServiceFactory > xServiceFactory(
     144           8 :             xContext->getServiceManager(), UNO_QUERY_THROW );
     145             : 
     146             :         uno::Reference< util::XMacroExpander > xMacroExpander =
     147           8 :             util::theMacroExpander::get(xContext);
     148             : 
     149             :         // import ui strings
     150             :         Reference< XMultiServiceFactory > xConfigProvider =
     151           8 :             configuration::theDefaultProvider::get( xContext );
     152             : 
     153           8 :         UStringMap aTransitionNameMape;
     154           8 :         const OUString aTransitionPath("/org.openoffice.Office.UI.Effects/UserInterface/Transitions" );
     155           4 :         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           8 :                 beans::PropertyState_DIRECT_VALUE ) );
     162             : 
     163             :         Reference<container::XNameAccess> xNameAccess(
     164           4 :             xConfigProvider->createInstanceWithArguments(
     165             :                 "com.sun.star.configuration.ConfigurationAccess",
     166           4 :                 Sequence<Any>( &propValue, 1 ) ),
     167           8 :                 UNO_QUERY_THROW );
     168           8 :         uno::Sequence< OUString > aFiles;
     169           4 :         xNameAccess->getByName("TransitionFiles") >>= aFiles;
     170             : 
     171          12 :         for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
     172             :         {
     173           8 :             OUString aURL = ::comphelper::getExpandedFilePath(aFiles[i]);
     174             : 
     175             :             bRet |= importTransitionsFile( rList,
     176             :                                            xServiceFactory,
     177             :                                            aTransitionNameMape,
     178           8 :                                            aURL );
     179           8 :         }
     180             : 
     181           8 :         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           4 :     class ImportedTransitionPresetList
     194             :     {
     195             :     private:
     196             :         sd::TransitionPresetList m_aTransitionPresetList;
     197             :     public:
     198           4 :         ImportedTransitionPresetList()
     199           4 :         {
     200             :             sd::TransitionPreset::importTransitionPresetList(
     201           4 :                 m_aTransitionPresetList);
     202           4 :         }
     203          26 :         const sd::TransitionPresetList& getList() const
     204             :         {
     205          26 :             return m_aTransitionPresetList;
     206             :         }
     207             :     };
     208             : 
     209             :     class theTransitionPresetList :
     210             :         public rtl::Static<ImportedTransitionPresetList,
     211             :                            theTransitionPresetList>
     212             :     {
     213             :     };
     214             : }
     215             : 
     216          26 : const TransitionPresetList& TransitionPreset::getTransitionPresetList()
     217             : {
     218          26 :     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         114 : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10