Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / core / TransitionPreset.cxx
blob2b52bb8bd3f3c4e84158cc5de467bf7625c90913
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/animations/XTransitionFilter.hpp>
21 #include <com/sun/star/container/XEnumerationAccess.hpp>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/configuration/theDefaultProvider.hpp>
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/util/theMacroExpander.hpp>
26 #include <com/sun/star/animations/AnimationNodeType.hpp>
27 #include <vcl/svapp.hxx>
28 #include <unotools/configmgr.hxx>
29 #include <unotools/streamwrap.hxx>
30 #include <comphelper/getexpandeduri.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/propertysequence.hxx>
33 #include <unotools/pathoptions.hxx>
34 #include <officecfg/Office/UI/Effects.hxx>
35 #include <tools/stream.hxx>
37 #include <rtl/uri.hxx>
38 #include <rtl/instance.hxx>
40 #include <CustomAnimationPreset.hxx>
41 #include <TransitionPreset.hxx>
43 #include <algorithm>
45 #include <sdpage.hxx>
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::animations;
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;
60 namespace sd {
62 TransitionPreset::TransitionPreset( const css::uno::Reference< css::animations::XAnimationNode >& xNode )
64 // first locate preset id
65 Sequence< NamedValue > aUserData( xNode->getUserData() );
66 sal_Int32 nLength = aUserData.getLength();
67 const NamedValue* p = aUserData.getConstArray();
68 while( nLength-- )
70 if ( p->Name == "preset-id" )
72 p->Value >>= maPresetId;
73 break;
77 // second, locate transition filter element
78 Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY_THROW );
79 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
80 Reference< XTransitionFilter > xTransition( xEnumeration->nextElement(), UNO_QUERY_THROW );
82 mnTransition = xTransition->getTransition();
83 mnSubtype = xTransition->getSubtype();
84 mbDirection = xTransition->getDirection();
85 mnFadeColor = xTransition->getFadeColor();
88 bool TransitionPreset::importTransitionsFile( TransitionPresetList& rList,
89 Reference< XMultiServiceFactory > const & xServiceFactory,
90 const OUString& aURL )
92 SAL_INFO("sd.transitions", "Importing " << aURL);
94 Reference< container::XNameAccess > xTransitionSets( officecfg::Office::UI::Effects::UserInterface::TransitionSets::get() );
95 Reference< container::XNameAccess > xTransitionGroups( officecfg::Office::UI::Effects::UserInterface::TransitionGroups::get() );
96 Reference< container::XNameAccess > xTransitionVariants( officecfg::Office::UI::Effects::UserInterface::TransitionVariants::get() );
97 Reference< container::XNameAccess > xTransitions( officecfg::Office::UI::Effects::UserInterface::Transitions::get() );
99 // import transition presets
100 Reference< XAnimationNode > xAnimationNode;
102 try {
103 xAnimationNode = implImportEffects( xServiceFactory, aURL );
104 Reference< XEnumerationAccess > xEnumerationAccess( xAnimationNode, UNO_QUERY_THROW );
105 Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
107 while( xEnumeration->hasMoreElements() )
109 Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY_THROW );
110 if( xChildNode->getType() == AnimationNodeType::PAR )
112 TransitionPresetPtr pPreset( new TransitionPreset( xChildNode ) );
114 OUString aPresetId( pPreset->getPresetId() );
116 if( !aPresetId.isEmpty() )
118 Reference< container::XNameAccess > xTransitionNode;
120 if (xTransitions->hasByName( aPresetId ) &&
121 (xTransitions->getByName( aPresetId ) >>= xTransitionNode) &&
122 xTransitionNode.is() )
124 OUString sSet;
125 OUString sVariant;
127 xTransitionNode->getByName( "Set" ) >>= sSet;
128 xTransitionNode->getByName( "Variant" ) >>= sVariant;
130 Reference< container::XNameAccess > xSetNode;
132 xTransitionSets->getByName( sSet ) >>= xSetNode;
133 if( xSetNode.is() )
135 pPreset->maSetId = sSet;
136 xSetNode->getByName( "Label" ) >>= sSet;
137 pPreset->maSetLabel = sSet;
139 OUString sGroup;
141 xSetNode->getByName( "Group" ) >>= sGroup;
143 Reference< container::XNameAccess > xGroupNode;
144 xTransitionGroups->getByName( sGroup ) >>= xGroupNode;
146 if( xGroupNode.is() )
148 pPreset->maGroupId = sGroup;
149 xGroupNode->getByName( "Label" ) >>= sGroup;
150 if( !sVariant.isEmpty() )
152 Reference< container::XNameAccess > xVariantNode;
153 xTransitionVariants->getByName( sVariant ) >>= xVariantNode;
154 if( xVariantNode.is() )
156 xVariantNode->getByName( "Label" ) >>= sVariant;
157 pPreset->maVariantLabel = sVariant;
161 pPreset->maSetLabel = sSet;
162 SAL_INFO("sd.transitions", aPresetId << ": " << sGroup << "/" << sSet << (sVariant.isEmpty() ? OUString() : OUString("/" + sVariant)));
164 rList.push_back( pPreset );
166 else
167 SAL_WARN("sd.transitions", "group node " << sGroup << " not found");
169 else
170 SAL_WARN("sd.transitions", "set node " << sSet << " not found");
172 else
173 SAL_WARN("sd.transitions", "transition node " << aPresetId << " not found");
176 else
178 SAL_WARN("sd.transitions", " malformed xml configuration file " << aURL );
179 break;
182 } catch( Exception& ) {
183 return false;
186 return true;
189 bool TransitionPreset::importTransitionPresetList( TransitionPresetList& rList )
191 if (utl::ConfigManager::IsFuzzing())
192 return false;
194 bool bRet = false;
198 uno::Reference< uno::XComponentContext > xContext(
199 comphelper::getProcessComponentContext() );
200 Reference< XMultiServiceFactory > xServiceFactory(
201 xContext->getServiceManager(), UNO_QUERY_THROW );
203 // import ui strings
204 Reference< XMultiServiceFactory > xConfigProvider =
205 configuration::theDefaultProvider::get( xContext );
207 // read path to transition effects files from config
208 uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence(
210 {"nodepath", uno::Any(OUString("/org.openoffice.Office.Impress/Misc"))}
211 }));
212 Reference<container::XNameAccess> xNameAccess(
213 xConfigProvider->createInstanceWithArguments(
214 "com.sun.star.configuration.ConfigurationAccess",
215 aArgs),
216 UNO_QUERY_THROW );
217 uno::Sequence< OUString > aFiles;
218 xNameAccess->getByName("TransitionFiles") >>= aFiles;
220 for( sal_Int32 i=0; i<aFiles.getLength(); ++i )
222 OUString aURL = comphelper::getExpandedUri(xContext, aFiles[i]);
224 bRet |= importTransitionsFile( rList,
225 xServiceFactory,
226 aURL );
229 return bRet;
231 catch( Exception& )
233 OSL_FAIL( "sd::TransitionPreset::importResources(), exception caught!" );
236 return bRet;
239 namespace
241 class ImportedTransitionPresetList
243 private:
244 sd::TransitionPresetList m_aTransitionPresetList;
245 public:
246 ImportedTransitionPresetList()
248 sd::TransitionPreset::importTransitionPresetList(
249 m_aTransitionPresetList);
251 const sd::TransitionPresetList& getList() const
253 return m_aTransitionPresetList;
257 class theTransitionPresetList :
258 public rtl::Static<ImportedTransitionPresetList,
259 theTransitionPresetList>
264 const TransitionPresetList& TransitionPreset::getTransitionPresetList()
266 return theTransitionPresetList::get().getList();
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */