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

Generated by: LCOV version 1.10