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/XMacroExpander.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 ::rtl::OUString;
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 : String 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 : break;
129 : }
130 0 : }
131 0 : } catch( Exception& ) {
132 0 : return false;
133 : }
134 :
135 0 : return true;
136 : }
137 :
138 : #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
139 :
140 0 : bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
141 : {
142 0 : bool bRet = false;
143 :
144 : try
145 : {
146 : uno::Reference< uno::XComponentContext > xContext(
147 0 : comphelper::getProcessComponentContext() );
148 : Reference< XMultiServiceFactory > xServiceFactory(
149 0 : xContext->getServiceManager(), UNO_QUERY_THROW );
150 :
151 : uno::Reference< util::XMacroExpander > xMacroExpander(
152 0 : xContext->getValueByName("/singletons/com.sun.star.util.theMacroExpander"),
153 0 : UNO_QUERY );
154 :
155 : // import ui strings
156 : Reference< XMultiServiceFactory > xConfigProvider =
157 0 : configuration::theDefaultProvider::get( xContext );
158 :
159 0 : UStringMap aTransitionNameMape;
160 0 : const OUString aTransitionPath("/org.openoffice.Office.UI.Effects/UserInterface/Transitions" );
161 0 : implImportLabels( xConfigProvider, aTransitionPath, aTransitionNameMape );
162 :
163 : // read path to transition effects files from config
164 : Any propValue = uno::makeAny(
165 : beans::PropertyValue("nodepath", -1,
166 : uno::makeAny( OUString("/org.openoffice.Office.Impress/Misc")),
167 0 : beans::PropertyState_DIRECT_VALUE ) );
168 :
169 : Reference<container::XNameAccess> xNameAccess(
170 0 : xConfigProvider->createInstanceWithArguments(
171 : "com.sun.star.configuration.ConfigurationAccess",
172 0 : Sequence<Any>( &propValue, 1 ) ),
173 0 : UNO_QUERY_THROW );
174 0 : uno::Sequence< rtl::OUString > aFiles;
175 0 : xNameAccess->getByName("TransitionFiles") >>= aFiles;
176 :
177 0 : for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
178 : {
179 0 : rtl::OUString aURL = aFiles[i];
180 0 : if( aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL )) == 0 )
181 : {
182 : // cut protocol
183 0 : rtl::OUString aMacro( aURL.copy( sizeof ( EXPAND_PROTOCOL ) -1 ) );
184 : // decode uric class chars
185 0 : aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
186 : // expand macro string
187 0 : aURL = xMacroExpander->expandMacros( aMacro );
188 : }
189 :
190 : bRet |= importTransitionsFile( rList,
191 : xServiceFactory,
192 : aTransitionNameMape,
193 0 : aURL );
194 0 : }
195 :
196 0 : return bRet;
197 : }
198 0 : catch( Exception& )
199 : {
200 : OSL_FAIL( "sd::TransitionPreset::importResources(), Exception cought!" );
201 : }
202 :
203 0 : return bRet;
204 : }
205 :
206 : namespace
207 : {
208 0 : class ImportedTransitionPresetList
209 : {
210 : private:
211 : sd::TransitionPresetList m_aTransitionPresetList;
212 : public:
213 0 : ImportedTransitionPresetList()
214 0 : {
215 : sd::TransitionPreset::importTransitionPresetList(
216 0 : m_aTransitionPresetList);
217 0 : }
218 0 : const sd::TransitionPresetList& getList() const
219 : {
220 0 : return m_aTransitionPresetList;
221 : }
222 : };
223 :
224 : class theTransitionPresetList :
225 : public rtl::Static<ImportedTransitionPresetList,
226 : theTransitionPresetList>
227 : {
228 : };
229 : }
230 :
231 0 : const TransitionPresetList& TransitionPreset::getTransitionPresetList()
232 : {
233 0 : return theTransitionPresetList::get().getList();
234 : }
235 :
236 0 : void TransitionPreset::apply( SdPage* pSlide ) const
237 : {
238 0 : if( pSlide )
239 : {
240 0 : pSlide->setTransitionType( mnTransition );
241 0 : pSlide->setTransitionSubtype( mnSubtype );
242 0 : pSlide->setTransitionDirection( mbDirection );
243 0 : pSlide->setTransitionFadeColor( mnFadeColor );
244 : }
245 0 : }
246 :
247 : }
248 :
249 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|