/src/libreoffice/oox/source/ppt/soundactioncontext.cxx
Line | Count | Source |
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 <config_features.h> |
21 | | |
22 | | #include <oox/ppt/soundactioncontext.hxx> |
23 | | |
24 | | #include <com/sun/star/io/XInputStream.hpp> |
25 | | |
26 | | #include <oox/helper/attributelist.hxx> |
27 | | #include <oox/helper/propertymap.hxx> |
28 | | #include <drawingml/embeddedwavaudiofile.hxx> |
29 | | #include <oox/token/namespaces.hxx> |
30 | | #include <oox/token/properties.hxx> |
31 | | #include <oox/token/tokens.hxx> |
32 | | #include <oox/core/xmlfilterbase.hxx> |
33 | | #include <avmedia/mediaitem.hxx> |
34 | | |
35 | | using namespace ::oox::core; |
36 | | using namespace ::com::sun::star::uno; |
37 | | |
38 | | namespace oox::ppt { |
39 | | |
40 | | SoundActionContext::SoundActionContext( FragmentHandler2 const & rParent, PropertyMap & aProperties ) noexcept |
41 | 0 | : FragmentHandler2( rParent ) |
42 | 0 | , maSlideProperties( aProperties ) |
43 | 0 | , mbHasStartSound( false ) |
44 | 0 | , mbLoopSound( false ) |
45 | 0 | , mbStopSound( false ) |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | SoundActionContext::~SoundActionContext() noexcept |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | | void SoundActionContext::onEndElement() |
54 | 0 | { |
55 | 0 | if ( !isCurrentElement( PPT_TOKEN( sndAc ) ) ) |
56 | 0 | return; |
57 | | |
58 | 0 | if( !mbHasStartSound ) |
59 | 0 | return; |
60 | | |
61 | 0 | OUString url; |
62 | 0 | #if HAVE_FEATURE_AVMEDIA |
63 | 0 | if ( !msSndName.isEmpty() ) |
64 | 0 | { |
65 | 0 | Reference<css::io::XInputStream> |
66 | 0 | xInputStream = getFilter().openInputStream(msSndName); |
67 | 0 | if (xInputStream.is()) |
68 | 0 | { |
69 | 0 | ::avmedia::EmbedMedia(getFilter().getModel(), msSndName, url, xInputStream); |
70 | 0 | xInputStream->closeInput(); |
71 | 0 | } |
72 | 0 | } |
73 | 0 | #endif |
74 | 0 | if ( !url.isEmpty() ) |
75 | 0 | { |
76 | 0 | maSlideProperties.setProperty( PROP_Sound, url); |
77 | 0 | maSlideProperties.setProperty( PROP_SoundOn, true); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | | ::oox::core::ContextHandlerRef SoundActionContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) |
82 | 0 | { |
83 | 0 | switch( aElementToken ) |
84 | 0 | { |
85 | 0 | case PPT_TOKEN( snd ): |
86 | 0 | if( mbHasStartSound ) |
87 | 0 | { |
88 | 0 | msSndName = drawingml::getEmbeddedWAVAudioFile( getRelations(), rAttribs ); |
89 | 0 | } |
90 | 0 | return this; |
91 | 0 | case PPT_TOKEN( endSnd ): |
92 | | // CT_Empty |
93 | 0 | mbStopSound = true; |
94 | 0 | return this; |
95 | 0 | case PPT_TOKEN( stSnd ): |
96 | 0 | mbHasStartSound = true; |
97 | 0 | mbLoopSound = rAttribs.getBool( XML_loop, false ); |
98 | 0 | return this; |
99 | 0 | default: |
100 | 0 | break; |
101 | 0 | } |
102 | | |
103 | 0 | return this; |
104 | 0 | } |
105 | | |
106 | | } |
107 | | |
108 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |