|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Recognizes MIME type for a file. |
|
16 * Maps MIME types to media types. |
|
17 * Creates media info object for a file. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <e32std.h> |
|
26 #include <e32base.h> // CBase |
|
27 #include <apmstd.h> // TDataType |
|
28 #include <f32file.h> // RFs, RFile |
|
29 #include <apgcli.h> // RApaLsSession |
|
30 #include <apmrec.h> |
|
31 |
|
32 #include <coemain.h> |
|
33 #include <barsread.h> |
|
34 #include <bautils.h> |
|
35 #include <data_caging_path_literals.hrh> |
|
36 |
|
37 #include <DRMHelper.h> |
|
38 #include <fileprotectionresolver.h> |
|
39 |
|
40 // Features |
|
41 #include <featmgr.h> |
|
42 #include <bldvariant.hrh> |
|
43 #include <messagingvariant.hrh> |
|
44 |
|
45 // Resources |
|
46 #include <MsgMimeToMediaMapping.rsg> |
|
47 |
|
48 #include "MsgMedia.hrh" |
|
49 #include "MsgMediaResolver.h" |
|
50 #include "MsgMediaTypeGroup.h" |
|
51 #include "MsgMediaPanic.h" |
|
52 #include "MsgMediaInfo.h" |
|
53 #include "MsgImageInfo.h" |
|
54 #include "MsgAudioInfo.h" |
|
55 #include "MsgTextInfo.h" |
|
56 #include "MsgVideoInfo.h" |
|
57 #include "MsgMimeTypes.h" |
|
58 |
|
59 // LOCAL CONSTANTS AND MACROS |
|
60 // Unrecognised media type is 'x-epoc/x-app0'. |
|
61 // Media type 'x-epoc/x-appN', in which N>0 may also be possible. |
|
62 // N stands for Uid of the app handling the content on the Symbian OS platform |
|
63 _LIT8( KMmsSymbianInternalPattern, "x-epoc/x-app0"); |
|
64 |
|
65 _LIT( KMsgMediaResourceFileName, "MsgMimeToMediaMapping.rsc" ); |
|
66 |
|
67 // ============================ MEMBER FUNCTIONS =============================== |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Factory |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C CMsgMediaResolver* CMsgMediaResolver::NewLC() |
|
74 { |
|
75 CMsgMediaResolver* self = new ( ELeave ) CMsgMediaResolver(); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // Factory |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CMsgMediaResolver* CMsgMediaResolver::NewL() |
|
86 { |
|
87 CMsgMediaResolver* self = NewLC(); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // C++ constructor |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CMsgMediaResolver::CMsgMediaResolver() : |
|
97 iRecognizeCharSet( ETrue ) // CharSet recognition is on by default. |
|
98 { |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // Destructor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CMsgMediaResolver::~CMsgMediaResolver() |
|
106 { |
|
107 iFs.Close(); |
|
108 iApaLsSession.Close(); |
|
109 iMimeGroupArray.ResetAndDestroy(); |
|
110 delete iFileProt; |
|
111 delete iDRMHelper; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // 2nd phase constructor |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CMsgMediaResolver::ConstructL() |
|
119 { |
|
120 // Create own shared file server session. |
|
121 User::LeaveIfError( iFs.Connect() ); |
|
122 User::LeaveIfError( iFs.ShareProtected() ); |
|
123 User::LeaveIfError( iApaLsSession.Connect() ); |
|
124 |
|
125 iDRMHelper = CDRMHelper::NewL(); |
|
126 iFileProt = CFileProtectionResolver::NewL( iFs ); |
|
127 CreateMediaTypeGroupsL(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CMsgMediaResolver::CreateMediaTypeGroupsL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CMsgMediaResolver::CreateMediaTypeGroupsL() |
|
135 { |
|
136 TFileName fileName; |
|
137 TFindFile finder( iFs ); |
|
138 //Search Y->A then Z: |
|
139 TInt err = finder.FindByDir( KMsgMediaResourceFileName, KDC_RESOURCE_FILES_DIR ); |
|
140 if(err == KErrNone) |
|
141 { |
|
142 fileName = finder.File(); |
|
143 RResourceFile resourceFile; |
|
144 resourceFile.OpenL( iFs, fileName ); |
|
145 CleanupClosePushL( resourceFile ); |
|
146 resourceFile.ConfirmSignatureL( 0 ); |
|
147 |
|
148 HBufC8* dataBuffer = resourceFile.AllocReadLC( R_MSG_MEDIAGROUPS ); |
|
149 |
|
150 TResourceReader reader; |
|
151 reader.SetBuffer( dataBuffer ); |
|
152 |
|
153 TInt numMediaGroups( reader.ReadInt16() ); |
|
154 |
|
155 for ( TInt i = 0; i < numMediaGroups; i++ ) |
|
156 { |
|
157 CMsgMediaTypeGroup* mimeTypeGroup = CMsgMediaTypeGroup::NewLC( reader ); |
|
158 iMimeGroupArray.AppendL( mimeTypeGroup ); |
|
159 CleanupStack::Pop( mimeTypeGroup ); |
|
160 } |
|
161 |
|
162 CleanupStack::PopAndDestroy( 2, &resourceFile ); // resourceFile.Close, dataBuffer |
|
163 } |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CMsgMediaResolver::FileHandleL |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C RFile CMsgMediaResolver::FileHandleL( const TDesC& aFileName ) |
|
171 { |
|
172 RFile file; |
|
173 User::LeaveIfError( file.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly ) ); |
|
174 return file; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CMsgMediaResolver::RecognizeL |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C void CMsgMediaResolver::RecognizeL( RFile& aFile, |
|
182 TDataType& aMimeType ) |
|
183 { |
|
184 TFileName* name = new ( ELeave ) TFileName; |
|
185 CleanupStack::PushL( name ); |
|
186 User::LeaveIfError( aFile.Name( *name ) ); |
|
187 TParsePtrC parse( *name ); |
|
188 if ( parse.Ext().CompareF( KMsgExtSmil1 ) == 0 || |
|
189 parse.Ext().CompareF( KMsgExtSmil2 ) == 0 || |
|
190 parse.Ext().CompareF( KMsgExtSmil3 ) == 0 ) |
|
191 { |
|
192 aMimeType = KMsgMimeSmil(); |
|
193 } |
|
194 else |
|
195 { |
|
196 TDataRecognitionResult dataType; |
|
197 TInt err = iApaLsSession.RecognizeData( aFile, dataType ); |
|
198 // Unrecognised content and no leaves in recogniser plugins |
|
199 // return err = KErrNone & dataType = 'x-epoc/x-app0'. |
|
200 // Unrecognised content and a leave in recogniser plugins |
|
201 // return err = <leave-code-in-recogniser> |
|
202 if ( err |
|
203 || dataType.iDataType.Des8().Length() == 0 |
|
204 || !dataType.iDataType.Des8().CompareF( KMmsSymbianInternalPattern ) ) |
|
205 { |
|
206 // Not recognized |
|
207 aMimeType = KMsgMimeUnknown(); |
|
208 } |
|
209 else |
|
210 { |
|
211 aMimeType = dataType.iDataType; |
|
212 } |
|
213 } |
|
214 CleanupStack::PopAndDestroy( name ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CMsgMediaResolver::MediaType |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 EXPORT_C TMsgMediaType CMsgMediaResolver::MediaType( const TDesC8& aMimeType ) const |
|
222 { |
|
223 TInt mimeGroupCount( iMimeGroupArray.Count() ); |
|
224 for ( TInt i = 0; i < mimeGroupCount; i++ ) |
|
225 { |
|
226 CMsgMediaTypeGroup* group = iMimeGroupArray[ i ]; |
|
227 if ( group->HasMimeType( aMimeType ) ) |
|
228 { |
|
229 return group->MediaType(); |
|
230 } |
|
231 } |
|
232 return EMsgMediaUnknown; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CMsgMediaResolver::MediaInfoL |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C CMsgMediaInfo* CMsgMediaResolver::CreateMediaInfoL( RFile& aFile ) |
|
240 { |
|
241 TDataType* mimeType = new ( ELeave ) TDataType; |
|
242 CleanupStack::PushL( mimeType ); |
|
243 RecognizeL( aFile, *mimeType ); |
|
244 CMsgMediaInfo* info = DoCreateMediaInfoL( aFile, *mimeType ); |
|
245 CleanupStack::PopAndDestroy( mimeType ); |
|
246 return info; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CMsgMediaResolver::MediaInfoL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C CMsgMediaInfo* CMsgMediaResolver::CreateMediaInfoL( RFile& aFile, TDataType& aMimeType ) |
|
254 { |
|
255 return DoCreateMediaInfoL( aFile, aMimeType ); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CMsgMediaResolver::ParseInfoDetailsL |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 EXPORT_C void CMsgMediaResolver::ParseInfoDetailsL( CMsgMediaInfo* aInfo, RFile& aFile ) |
|
263 { |
|
264 aInfo->ParseInfoDetailsL( aFile, *iDRMHelper, *this ); |
|
265 if ( iWait.IsStarted() ) |
|
266 { |
|
267 // Stop active wait. |
|
268 iWait.AsyncStop(); |
|
269 } |
|
270 // Start active wait |
|
271 iWait.Start(); |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CMsgMediaResolver::DoCreateMediaInfoL |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 CMsgMediaInfo* CMsgMediaResolver::DoCreateMediaInfoL( RFile& aFile, |
|
279 TDataType& aMimeType ) |
|
280 { |
|
281 CMsgMediaInfo* mediaInfo = NULL; |
|
282 TMsgMediaType mediaType = MediaType( aMimeType.Des8() ); |
|
283 switch ( mediaType ) |
|
284 { |
|
285 case EMsgMediaText: |
|
286 { |
|
287 mediaInfo = CMsgTextInfo::NewL( aFile, aMimeType, iFs ); |
|
288 if ( !iRecognizeCharSet ) |
|
289 { |
|
290 // Suppress charset recognition. |
|
291 static_cast< CMsgTextInfo* >( mediaInfo )->SetCharacterSet( 0 ); |
|
292 } |
|
293 break; |
|
294 } |
|
295 case EMsgMediaImage: |
|
296 { |
|
297 mediaInfo = CMsgImageInfo::NewL( aFile, aMimeType ); |
|
298 break; |
|
299 } |
|
300 case EMsgMediaVideo: |
|
301 { |
|
302 mediaInfo = CMsgVideoInfo::NewL( aFile, aMimeType ); |
|
303 break; |
|
304 } |
|
305 case EMsgMediaAudio: |
|
306 { |
|
307 mediaInfo = CMsgAudioInfo::NewL( aFile, aMimeType ); |
|
308 break; |
|
309 } |
|
310 case EMsgMediaUnknown: |
|
311 default: |
|
312 { |
|
313 mediaInfo = CMsgMediaInfo::NewL( aFile, aMimeType, mediaType ); |
|
314 break; |
|
315 } |
|
316 } |
|
317 |
|
318 CleanupStack::PushL( mediaInfo ); |
|
319 |
|
320 TUid appUid( KNullUid ); |
|
321 // Ignore possible error. |
|
322 TInt err = iApaLsSession.AppForDataType( aMimeType, appUid ); |
|
323 mediaInfo->SetHandlerApplicationUid( appUid ); |
|
324 |
|
325 HBufC8* drmUri = NULL; |
|
326 TInt protection = iFileProt->ProtectionStatusL( aFile, aMimeType, drmUri ); |
|
327 mediaInfo->SetProtection( protection ); |
|
328 mediaInfo->SetDRMContentURI( drmUri ); // ownership transferred |
|
329 |
|
330 CleanupStack::Pop( mediaInfo ); |
|
331 |
|
332 return mediaInfo; |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CMsgMediaResolver::MediaInfoParsed |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 void CMsgMediaResolver::MediaInfoParsed() |
|
340 { |
|
341 if ( iWait.IsStarted() ) |
|
342 { |
|
343 // Stop active wait. |
|
344 iWait.AsyncStop(); |
|
345 } |
|
346 } |
|
347 |
|
348 // End of File |