Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <pptexsoundcollection.hxx>
30 : : #include "epptdef.hxx"
31 : : #include <tools/urlobj.hxx>
32 : : #include <ucbhelper/content.hxx>
33 : : #include <ucbhelper/contentbroker.hxx>
34 : : #include <cppuhelper/proptypehlp.hxx>
35 : : #include <unotools/ucbstreamhelper.hxx>
36 : :
37 : : namespace ppt
38 : : {
39 : :
40 : 0 : ExSoundEntry::ExSoundEntry(const rtl::OUString& rString)
41 : : : nFileSize(0)
42 : 0 : , aSoundURL(rString)
43 : : {
44 : : try
45 : : {
46 : : ::ucbhelper::Content aCnt( aSoundURL,
47 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
48 : 0 : sal_Int64 nVal = 0;
49 [ # # ][ # # ]: 0 : ::cppu::convertPropertyValue( nVal, aCnt.getPropertyValue( ::rtl::OUString( "Size" ) ) );
50 [ # # ][ # # ]: 0 : nFileSize = (sal_uInt32)nVal;
51 : : }
52 [ # # ]: 0 : catch( ::com::sun::star::uno::Exception& )
53 : : {
54 : :
55 : : }
56 : 0 : };
57 : :
58 : 0 : rtl::OUString ExSoundEntry::ImplGetName() const
59 : : {
60 [ # # ]: 0 : INetURLObject aTmp( aSoundURL );
61 [ # # ][ # # ]: 0 : return aTmp.GetName();
62 : : }
63 : :
64 : 0 : rtl::OUString ExSoundEntry::ImplGetExtension() const
65 : : {
66 [ # # ]: 0 : INetURLObject aTmp( aSoundURL );
67 [ # # ][ # # ]: 0 : String aExtension( aTmp.GetExtension() );
68 [ # # ]: 0 : if ( aExtension.Len() )
69 [ # # ]: 0 : aExtension.Insert( (sal_Unicode)'.', 0 );
70 [ # # ][ # # ]: 0 : return aExtension;
[ # # ]
71 : : }
72 : :
73 : 0 : sal_Bool ExSoundEntry::IsSameURL(const rtl::OUString& rURL) const
74 : : {
75 : 0 : return ( rURL == aSoundURL );
76 : : }
77 : :
78 : 0 : sal_uInt32 ExSoundEntry::GetSize( sal_uInt32 nId ) const
79 : : {
80 [ # # ]: 0 : rtl::OUString aName( ImplGetName() );
81 [ # # ]: 0 : rtl::OUString aExtension( ImplGetExtension() );
82 : :
83 : 0 : sal_uInt32 nSize = 8; // SoundContainer Header
84 [ # # ]: 0 : if ( !aName.isEmpty() ) // String Atom ( instance 0 - name of sound )
85 : 0 : nSize += aName.getLength() * 2 + 8;
86 [ # # ]: 0 : if ( !aExtension.isEmpty() ) // String Atom ( instance 1 - extension of sound )
87 : 0 : nSize += aExtension.getLength() * 2 + 8;
88 : :
89 : 0 : rtl::OUString aId( rtl::OUString::valueOf(static_cast<sal_Int32>(nId)) ); // String Atom ( instance 2 - reference id )
90 : 0 : nSize += 2 * aId.getLength() + 8;
91 : :
92 : 0 : nSize += nFileSize + 8; // SoundData Atom
93 : :
94 : 0 : return nSize;
95 : : }
96 : :
97 : 0 : void ExSoundEntry::Write( SvStream& rSt, sal_uInt32 nId ) const
98 : : {
99 : : try
100 : : {
101 : : ::ucbhelper::Content aCnt( aSoundURL,
102 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
103 : :
104 : : // create SoundContainer
105 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( ( EPP_Sound << 16 ) | 0xf ) << (sal_uInt32)( GetSize( nId ) - 8 );
[ # # ]
106 : :
107 [ # # ]: 0 : rtl::OUString aSoundName( ImplGetName() );
108 : 0 : sal_Int32 i, nSoundNameLen = aSoundName.getLength();
109 [ # # ]: 0 : if ( nSoundNameLen )
110 : : {
111 : : // name of sound ( instance 0 )
112 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( EPP_CString << 16 ) << (sal_uInt32)( nSoundNameLen * 2 );
113 [ # # ]: 0 : for ( i = 0; i < nSoundNameLen; ++i )
114 [ # # ]: 0 : rSt << aSoundName[i];
115 : : }
116 [ # # ]: 0 : rtl::OUString aExtension( ImplGetExtension() );
117 : 0 : sal_Int32 nExtensionLen = aExtension.getLength();
118 [ # # ]: 0 : if ( nExtensionLen )
119 : : {
120 : : // extension of sound ( instance 1 )
121 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( ( EPP_CString << 16 ) | 16 ) << (sal_uInt32)( nExtensionLen * 2 );
122 [ # # ]: 0 : for ( i = 0; i < nExtensionLen; ++i )
123 [ # # ]: 0 : rSt << aExtension[i];
124 : : }
125 : : // id of sound ( instance 2 )
126 : 0 : rtl::OUString aId( rtl::OUString::valueOf(static_cast<sal_Int32>(nId) ) );
127 : 0 : sal_Int32 nIdLen = aId.getLength();
128 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( ( EPP_CString << 16 ) | 32 ) << (sal_uInt32)( nIdLen * 2 );
129 [ # # ]: 0 : for ( i = 0; i < nIdLen; ++i )
130 [ # # ]: 0 : rSt << aId[i];
131 : :
132 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( EPP_SoundData << 16 ) << (sal_uInt32)( nFileSize );
133 : 0 : sal_uInt32 nBytesLeft = nFileSize;
134 [ # # ][ # # ]: 0 : SvStream* pSourceFile = ::utl::UcbStreamHelper::CreateStream( aSoundURL, STREAM_READ );
[ # # ]
135 [ # # ]: 0 : if ( pSourceFile )
136 : : {
137 [ # # ]: 0 : sal_uInt8* pBuf = new sal_uInt8[ 0x10000 ]; // 64 kB Buffer
138 [ # # ]: 0 : while ( nBytesLeft )
139 : : {
140 : 0 : sal_uInt32 nToDo = ( nBytesLeft > 0x10000 ) ? 0x10000 : nBytesLeft;
141 [ # # ]: 0 : pSourceFile->Read( pBuf, nToDo );
142 [ # # ]: 0 : rSt.Write( pBuf, nToDo );
143 : 0 : nBytesLeft -= nToDo;
144 : : }
145 [ # # ][ # # ]: 0 : delete pSourceFile;
146 [ # # ]: 0 : delete[] pBuf;
147 [ # # ][ # # ]: 0 : }
148 : : }
149 : 0 : catch( ::com::sun::star::uno::Exception& )
150 : : {
151 : :
152 : : }
153 : 0 : }
154 : :
155 : 0 : sal_uInt32 ExSoundCollection::GetId(const rtl::OUString& rString)
156 : : {
157 : 0 : sal_uInt32 nSoundId = 0;
158 [ # # ]: 0 : if (!rString.isEmpty())
159 : : {
160 : 0 : const sal_uInt32 nSoundCount = maEntries.size();
161 [ # # ]: 0 : boost::ptr_vector<ExSoundEntry>::const_iterator iter;
162 : :
163 [ # # ][ # # ]: 0 : for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++nSoundId)
[ # # ][ # # ]
[ # # ][ # # ]
164 : : {
165 [ # # ][ # # ]: 0 : if (iter->IsSameURL(rString))
166 : 0 : break;
167 : : }
168 : :
169 [ # # ]: 0 : if ( nSoundId++ == nSoundCount )
170 : : {
171 [ # # ][ # # ]: 0 : ExSoundEntry* pEntry = new ExSoundEntry( rString );
172 [ # # ]: 0 : if ( pEntry->GetFileSize() )
173 [ # # ]: 0 : maEntries.push_back(pEntry);
174 : : else
175 : : {
176 : 0 : nSoundId = 0; // only insert sounds that are accessible
177 [ # # ]: 0 : delete pEntry;
178 : : }
179 : : }
180 : : }
181 : 0 : return nSoundId;
182 : : }
183 : :
184 : 0 : sal_uInt32 ExSoundCollection::GetSize() const
185 : : {
186 : 0 : sal_uInt32 nSize = 0;
187 [ # # ]: 0 : if (!maEntries.empty())
188 : : {
189 : 0 : nSize += 8 + 12; // size of SoundCollectionContainerHeader + SoundCollAtom
190 [ # # ]: 0 : boost::ptr_vector<ExSoundEntry>::const_iterator iter;
191 : 0 : sal_uInt32 i = 1;
192 [ # # ][ # # ]: 0 : for ( iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++i)
[ # # ][ # # ]
[ # # ]
193 [ # # ][ # # ]: 0 : nSize += iter->GetSize(i);
194 : : }
195 : 0 : return nSize;
196 : : }
197 : :
198 : 0 : void ExSoundCollection::Write( SvStream& rSt ) const
199 : : {
200 [ # # ]: 0 : if (!maEntries.empty())
201 : : {
202 : 0 : sal_uInt32 i = 1;
203 : 0 : sal_uInt32 nSoundCount = maEntries.size();
204 : :
205 : : // create SoundCollection Container
206 [ # # ][ # # ]: 0 : rSt << (sal_uInt16)0xf << (sal_uInt16)EPP_SoundCollection << (sal_uInt32)( GetSize() - 8 );
[ # # ][ # # ]
207 : :
208 : : // create SoundCollAtom ( reference to the next free SoundId );
209 [ # # ][ # # ]: 0 : rSt << (sal_uInt32)( EPP_SoundCollAtom << 16 ) << (sal_uInt32)4 << nSoundCount;
[ # # ]
210 : :
211 [ # # ]: 0 : boost::ptr_vector<ExSoundEntry>::const_iterator iter;
212 [ # # ][ # # ]: 0 : for ( iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++i)
[ # # ][ # # ]
[ # # ]
213 [ # # ][ # # ]: 0 : iter->Write(rSt,i);
214 : : }
215 : 0 : }
216 : :
217 : :
218 : : } // namespace ppt;
219 : :
220 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|