|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 #include "contentmgr.h" |
|
22 #include <apmstd.h> |
|
23 #include <mdaaudiosampleplayer.h> |
|
24 #include <apparc.h> |
|
25 #include <apgcli.h> |
|
26 |
|
27 GLDEF_C TInt E32Dll( |
|
28 ) |
|
29 { |
|
30 return(KErrNone); |
|
31 } |
|
32 |
|
33 // |
|
34 // class CTestPictureAudio |
|
35 // |
|
36 |
|
37 class CTestPictureAudio : public CPicture, public MMdaAudioPlayerCallback |
|
38 { |
|
39 public: |
|
40 static CTestPictureAudio* NewL(RFs& aFs,const TDesC& aFileName); |
|
41 static CTestPictureAudio* NewL(RFs& aFs,const CStreamStore& aStore,TStreamId aStreamId); |
|
42 ~CTestPictureAudio(); |
|
43 // |
|
44 void PlayL(); |
|
45 private: // from CPicture |
|
46 void Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* aMap) const; |
|
47 void ExternalizeL(RWriteStream& aStream) const; |
|
48 void GetOriginalSizeInTwips(TSize& aSize) const; |
|
49 private: // from MMdaAudioPlayerCallback |
|
50 void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration); |
|
51 void MapcPlayComplete(TInt aError); |
|
52 private: |
|
53 CTestPictureAudio(RFs& aFs); |
|
54 void ConstructL(const TDesC& aFileName); |
|
55 void ConstructL(const CStreamStore& aStore,TStreamId aStreamId); |
|
56 void CommonConstructL(); |
|
57 void RestoreL(const CStreamStore& aStore,TStreamId aStreamId); |
|
58 void StopPlay(); |
|
59 private: |
|
60 RFs& iFs; |
|
61 CFbsBitmap* iBitmap; |
|
62 CMdaAudioPlayerUtility* iSoundPlayer; |
|
63 HBufC8* iPlayBuf; |
|
64 TPtr8 iPtr; |
|
65 }; |
|
66 |
|
67 _LIT(KBitmapName,"\\system\\data\\contentmgr.mbm"); |
|
68 |
|
69 CTestPictureAudio* CTestPictureAudio::NewL(RFs& aFs,const TDesC& aFileName) |
|
70 { // static |
|
71 CTestPictureAudio* self=new(ELeave) CTestPictureAudio(aFs); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(aFileName); |
|
74 CleanupStack::Pop(); // self |
|
75 return self; |
|
76 } |
|
77 |
|
78 CTestPictureAudio* CTestPictureAudio::NewL(RFs& aFs,const CStreamStore& aStore,TStreamId aStreamId) |
|
79 { // static |
|
80 CTestPictureAudio* self=new(ELeave) CTestPictureAudio(aFs); |
|
81 CleanupStack::PushL(self); |
|
82 self->ConstructL(aStore,aStreamId); |
|
83 CleanupStack::Pop(); // self |
|
84 return self; |
|
85 } |
|
86 |
|
87 CTestPictureAudio::~CTestPictureAudio() |
|
88 { |
|
89 StopPlay(); |
|
90 delete iBitmap; |
|
91 delete iPlayBuf; |
|
92 } |
|
93 |
|
94 void CTestPictureAudio::PlayL() |
|
95 { |
|
96 StopPlay(); |
|
97 iSoundPlayer=CMdaAudioPlayerUtility::NewDesPlayerL(iPtr,*this); |
|
98 } |
|
99 |
|
100 void CTestPictureAudio::Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect, |
|
101 MGraphicsDeviceMap* /*aMap*/) const |
|
102 { |
|
103 TSize sizeInPixels=iBitmap->SizeInPixels(); |
|
104 TRect originalRectInPixels(aTopLeft,sizeInPixels); |
|
105 aGc.SetClippingRect(aClipRect); |
|
106 aGc.DrawBitmap(originalRectInPixels,iBitmap); |
|
107 aGc.CancelClippingRect(); |
|
108 } |
|
109 |
|
110 void CTestPictureAudio::ExternalizeL(RWriteStream& aStream) const |
|
111 { |
|
112 aStream.WriteInt32L(iPtr.Length()); |
|
113 aStream.WriteL(iPtr); |
|
114 } |
|
115 |
|
116 void CTestPictureAudio::GetOriginalSizeInTwips(TSize& aSize) const |
|
117 { |
|
118 TSize sizeInPixels=iBitmap->SizeInPixels(); |
|
119 TInt vert=iBitmap->VerticalPixelsToTwips(sizeInPixels.iHeight); |
|
120 TInt horiz=iBitmap->HorizontalPixelsToTwips(sizeInPixels.iWidth); |
|
121 aSize=TSize(horiz,vert); |
|
122 } |
|
123 |
|
124 void CTestPictureAudio::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
125 { |
|
126 if (aError) |
|
127 { |
|
128 StopPlay(); |
|
129 return;; |
|
130 } |
|
131 iSoundPlayer->Play(); |
|
132 } |
|
133 |
|
134 void CTestPictureAudio::MapcPlayComplete(TInt /*aError*/) |
|
135 { |
|
136 StopPlay(); |
|
137 } |
|
138 |
|
139 CTestPictureAudio::CTestPictureAudio(RFs& aFs) |
|
140 : iFs(aFs), iPtr(NULL,0) |
|
141 {} |
|
142 |
|
143 LOCAL_C void GetFullPath(TDes& aPath) |
|
144 { |
|
145 TFileName dllName; |
|
146 Dll::FileName(dllName); |
|
147 TBuf<2> drive=dllName.Left(2); |
|
148 aPath.Insert(0,drive); |
|
149 } |
|
150 |
|
151 void CTestPictureAudio::CommonConstructL() |
|
152 { |
|
153 TFileName bitmapFile=KBitmapName(); |
|
154 GetFullPath(bitmapFile); |
|
155 iBitmap=new(ELeave) CFbsBitmap; |
|
156 User::LeaveIfError(iBitmap->Load(bitmapFile)); |
|
157 } |
|
158 |
|
159 void CTestPictureAudio::ConstructL(const TDesC& aFileName) |
|
160 { |
|
161 CommonConstructL(); // creates bitmap |
|
162 RFile file; |
|
163 User::LeaveIfError(file.Open(iFs,aFileName,EFileRead)); |
|
164 CleanupClosePushL(file); |
|
165 TInt size; |
|
166 User::LeaveIfError(file.Size(size)); |
|
167 iPlayBuf=HBufC8::NewL(size); |
|
168 TPtr8 ptr=iPlayBuf->Des(); |
|
169 iPtr.Set(ptr); |
|
170 User::LeaveIfError(file.Read(iPtr)); |
|
171 CleanupStack::PopAndDestroy(); // file.Close() |
|
172 } |
|
173 |
|
174 void CTestPictureAudio::ConstructL(const CStreamStore& aStore,TStreamId aStreamId) |
|
175 { |
|
176 CommonConstructL(); // creates bitmap |
|
177 // following is a poor example. There's no reason for us to waste time restoring the embedded |
|
178 // stream yet. We could wait till its really needed but that requires more faffing with Store |
|
179 // than can be justified for some quick example code. |
|
180 RestoreL(aStore,aStreamId); |
|
181 } |
|
182 |
|
183 void CTestPictureAudio::RestoreL(const CStreamStore& aStore,TStreamId aStreamId) |
|
184 { |
|
185 RStoreReadStream stream; |
|
186 stream.OpenLC(aStore,aStreamId); |
|
187 const TInt len=stream.ReadInt32L(); |
|
188 iPlayBuf=HBufC8::NewL(len); |
|
189 TPtr8 ptr=iPlayBuf->Des(); |
|
190 stream.ReadL(ptr,len); |
|
191 CleanupStack::PopAndDestroy(); // stream |
|
192 iPtr.Set(ptr); |
|
193 } |
|
194 |
|
195 void CTestPictureAudio::StopPlay() |
|
196 { |
|
197 delete iSoundPlayer; |
|
198 iSoundPlayer=NULL; |
|
199 } |
|
200 |
|
201 // |
|
202 // class CTestAudioContent |
|
203 // |
|
204 |
|
205 class CTestAudioContent : public CBase |
|
206 { |
|
207 public: |
|
208 CStreamStore* iHost; |
|
209 TFileName iSourceFile; |
|
210 }; |
|
211 |
|
212 // |
|
213 // class CEikTestContentManager |
|
214 // |
|
215 |
|
216 _LIT8(KContentDataTypeAudio,"audio/*"); |
|
217 const TUid KTestContentType={5711}; |
|
218 |
|
219 EXPORT_C CEikTestContentManager* CEikTestContentManager::NewL(RFs& aFs) |
|
220 { // static |
|
221 CEikTestContentManager* self=new(ELeave) CEikTestContentManager(aFs); |
|
222 return self; |
|
223 } |
|
224 |
|
225 EXPORT_C CEikTestContentManager::~CEikTestContentManager() |
|
226 { |
|
227 } |
|
228 |
|
229 EXPORT_C void CEikTestContentManager::GetPictureTypeFromDataL(TUid& aPictureType,CBase*& aData, |
|
230 const TDesC& aFileName,const TDesC8& aSrcData) const |
|
231 { |
|
232 RApaLsSession ls; |
|
233 User::LeaveIfError(ls.Connect()); |
|
234 CleanupClosePushL(ls); |
|
235 TDataRecognitionResult res; |
|
236 User::LeaveIfError(ls.RecognizeData(aFileName,aSrcData,res)); |
|
237 CleanupStack::PopAndDestroy(); // ls |
|
238 // |
|
239 TUid type=KNullUid; |
|
240 if (res.iDataType.Des8().MatchF(KContentDataTypeAudio)==0) |
|
241 { |
|
242 CTestAudioContent* data=new(ELeave) CTestAudioContent; |
|
243 data->iSourceFile=aFileName; |
|
244 aData=data; |
|
245 type=KTestContentType; |
|
246 } |
|
247 aPictureType=type; |
|
248 } |
|
249 |
|
250 TBool CEikTestContentManager::SupportsPictureType(TUid aPictureType) const |
|
251 { |
|
252 return (aPictureType==KTestContentType); |
|
253 } |
|
254 |
|
255 const MPictureFactory* CEikTestContentManager::PictureFactory(TUid aPictureType) const |
|
256 { |
|
257 if (aPictureType==KTestContentType) |
|
258 { |
|
259 return this; |
|
260 } |
|
261 return NULL; |
|
262 } |
|
263 |
|
264 TPictureHeader CEikTestContentManager::InsertL(TUid aPictureType,CBase* aData) |
|
265 { |
|
266 TPictureHeader header; |
|
267 if (aPictureType==KTestContentType) |
|
268 { |
|
269 CPicture* picture=CTestPictureAudio::NewL(iFs,static_cast<CTestAudioContent*>(aData)->iSourceFile); |
|
270 header.iPicture=picture; |
|
271 header.iPictureType=aPictureType; |
|
272 picture->GetOriginalSizeInTwips(header.iSize); |
|
273 } |
|
274 return header; |
|
275 } |
|
276 |
|
277 void CEikTestContentManager::EditL(const TPictureHeader& aPictureHeader,TBool /*aReadOnly*/) |
|
278 { |
|
279 CTestPictureAudio* picture=static_cast<CTestPictureAudio*>(aPictureHeader.iPicture.AsPtr()); |
|
280 picture->PlayL(); |
|
281 } |
|
282 |
|
283 void CEikTestContentManager::NewPictureL(TPictureHeader& aHeader,const CStreamStore& aDeferredPictureStore) const |
|
284 { |
|
285 if (aHeader.iPictureType!=KTestContentType) |
|
286 { |
|
287 User::Leave(KErrNotSupported); |
|
288 } |
|
289 TStreamId id=aHeader.iPicture.AsId(); |
|
290 CTestPictureAudio* picture=CTestPictureAudio::NewL(iFs,aDeferredPictureStore,id); |
|
291 aHeader.iPicture=picture; |
|
292 } |
|
293 |
|
294 CEikTestContentManager::CEikTestContentManager(RFs& aFs) |
|
295 : iFs(aFs) |
|
296 {} |