author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 00:13:15 +0300 | |
changeset 72 | 6f657153cbc5 |
parent 44 | 36f374c67aa8 |
child 47 | 5b14749788d7 |
permissions | -rw-r--r-- |
31 | 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 |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
46 |
#include <msgmimetomediamapping.rsg> |
31 | 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 |
if ( iWait.IsStarted() ) |
|
108 |
{ |
|
109 |
// Stop active wait. |
|
110 |
iWait.AsyncStop(); |
|
111 |
} |
|
112 |
||
113 |
iFs.Close(); |
|
114 |
iApaLsSession.Close(); |
|
115 |
iMimeGroupArray.ResetAndDestroy(); |
|
116 |
delete iFileProt; |
|
117 |
delete iDRMHelper; |
|
118 |
} |
|
119 |
||
120 |
// ----------------------------------------------------------------------------- |
|
121 |
// 2nd phase constructor |
|
122 |
// ----------------------------------------------------------------------------- |
|
123 |
// |
|
124 |
void CMsgMediaResolver::ConstructL() |
|
125 |
{ |
|
126 |
// Create own shared file server session. |
|
127 |
User::LeaveIfError( iFs.Connect() ); |
|
128 |
User::LeaveIfError( iFs.ShareProtected() ); |
|
129 |
User::LeaveIfError( iApaLsSession.Connect() ); |
|
130 |
||
131 |
iDRMHelper = CDRMHelper::NewL(); |
|
132 |
iFileProt = CFileProtectionResolver::NewL( iFs ); |
|
133 |
CreateMediaTypeGroupsL(); |
|
134 |
} |
|
135 |
||
136 |
// ----------------------------------------------------------------------------- |
|
137 |
// CMsgMediaResolver::CreateMediaTypeGroupsL |
|
138 |
// ----------------------------------------------------------------------------- |
|
139 |
// |
|
140 |
void CMsgMediaResolver::CreateMediaTypeGroupsL() |
|
141 |
{ |
|
142 |
TFileName fileName; |
|
143 |
TFindFile finder( iFs ); |
|
144 |
//Search Y->A then Z: |
|
145 |
TInt err = finder.FindByDir( KMsgMediaResourceFileName, KDC_RESOURCE_FILES_DIR ); |
|
146 |
if(err == KErrNone) |
|
147 |
{ |
|
148 |
fileName = finder.File(); |
|
149 |
RResourceFile resourceFile; |
|
150 |
resourceFile.OpenL( iFs, fileName ); |
|
151 |
CleanupClosePushL( resourceFile ); |
|
152 |
resourceFile.ConfirmSignatureL( 0 ); |
|
153 |
||
154 |
HBufC8* dataBuffer = resourceFile.AllocReadLC( R_MSG_MEDIAGROUPS ); |
|
155 |
||
156 |
TResourceReader reader; |
|
157 |
reader.SetBuffer( dataBuffer ); |
|
158 |
||
159 |
TInt numMediaGroups( reader.ReadInt16() ); |
|
160 |
||
161 |
for ( TInt i = 0; i < numMediaGroups; i++ ) |
|
162 |
{ |
|
163 |
CMsgMediaTypeGroup* mimeTypeGroup = CMsgMediaTypeGroup::NewLC( reader ); |
|
164 |
iMimeGroupArray.AppendL( mimeTypeGroup ); |
|
165 |
CleanupStack::Pop( mimeTypeGroup ); |
|
166 |
} |
|
167 |
||
168 |
CleanupStack::PopAndDestroy( 2, &resourceFile ); // resourceFile.Close, dataBuffer |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
// ----------------------------------------------------------------------------- |
|
173 |
// CMsgMediaResolver::FileHandleL |
|
174 |
// ----------------------------------------------------------------------------- |
|
175 |
// |
|
176 |
EXPORT_C RFile CMsgMediaResolver::FileHandleL( const TDesC& aFileName ) |
|
177 |
{ |
|
178 |
RFile file; |
|
179 |
User::LeaveIfError( file.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly ) ); |
|
180 |
return file; |
|
181 |
} |
|
182 |
||
183 |
// ----------------------------------------------------------------------------- |
|
184 |
// CMsgMediaResolver::RecognizeL |
|
185 |
// ----------------------------------------------------------------------------- |
|
186 |
// |
|
187 |
EXPORT_C void CMsgMediaResolver::RecognizeL( RFile& aFile, |
|
188 |
TDataType& aMimeType ) |
|
189 |
{ |
|
190 |
TFileName* name = new ( ELeave ) TFileName; |
|
191 |
CleanupStack::PushL( name ); |
|
192 |
User::LeaveIfError( aFile.Name( *name ) ); |
|
193 |
TParsePtrC parse( *name ); |
|
194 |
if ( parse.Ext().CompareF( KMsgExtSmil1 ) == 0 || |
|
195 |
parse.Ext().CompareF( KMsgExtSmil2 ) == 0 || |
|
196 |
parse.Ext().CompareF( KMsgExtSmil3 ) == 0 ) |
|
197 |
{ |
|
198 |
aMimeType = KMsgMimeSmil(); |
|
199 |
} |
|
200 |
else |
|
201 |
{ |
|
202 |
TDataRecognitionResult dataType; |
|
203 |
TInt err = iApaLsSession.RecognizeData( aFile, dataType ); |
|
204 |
// Unrecognised content and no leaves in recogniser plugins |
|
205 |
// return err = KErrNone & dataType = 'x-epoc/x-app0'. |
|
206 |
// Unrecognised content and a leave in recogniser plugins |
|
207 |
// return err = <leave-code-in-recogniser> |
|
208 |
if ( err |
|
209 |
|| dataType.iDataType.Des8().Length() == 0 |
|
210 |
|| !dataType.iDataType.Des8().CompareF( KMmsSymbianInternalPattern ) ) |
|
211 |
{ |
|
212 |
// Not recognized |
|
213 |
aMimeType = KMsgMimeUnknown(); |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
aMimeType = dataType.iDataType; |
|
218 |
} |
|
219 |
} |
|
220 |
CleanupStack::PopAndDestroy( name ); |
|
221 |
} |
|
222 |
||
223 |
// ----------------------------------------------------------------------------- |
|
224 |
// CMsgMediaResolver::MediaType |
|
225 |
// ----------------------------------------------------------------------------- |
|
226 |
// |
|
227 |
EXPORT_C TMsgMediaType CMsgMediaResolver::MediaType( const TDesC8& aMimeType ) const |
|
228 |
{ |
|
229 |
TInt mimeGroupCount( iMimeGroupArray.Count() ); |
|
230 |
for ( TInt i = 0; i < mimeGroupCount; i++ ) |
|
231 |
{ |
|
232 |
CMsgMediaTypeGroup* group = iMimeGroupArray[ i ]; |
|
233 |
if ( group->HasMimeType( aMimeType ) ) |
|
234 |
{ |
|
235 |
return group->MediaType(); |
|
236 |
} |
|
237 |
} |
|
238 |
return EMsgMediaUnknown; |
|
239 |
} |
|
240 |
||
241 |
// ----------------------------------------------------------------------------- |
|
242 |
// CMsgMediaResolver::MediaInfoL |
|
243 |
// ----------------------------------------------------------------------------- |
|
244 |
// |
|
245 |
EXPORT_C CMsgMediaInfo* CMsgMediaResolver::CreateMediaInfoL( RFile& aFile ) |
|
246 |
{ |
|
247 |
TDataType* mimeType = new ( ELeave ) TDataType; |
|
248 |
CleanupStack::PushL( mimeType ); |
|
249 |
RecognizeL( aFile, *mimeType ); |
|
250 |
CMsgMediaInfo* info = DoCreateMediaInfoL( aFile, *mimeType ); |
|
251 |
CleanupStack::PopAndDestroy( mimeType ); |
|
252 |
return info; |
|
253 |
} |
|
254 |
||
255 |
// ----------------------------------------------------------------------------- |
|
256 |
// CMsgMediaResolver::MediaInfoL |
|
257 |
// ----------------------------------------------------------------------------- |
|
258 |
// |
|
259 |
EXPORT_C CMsgMediaInfo* CMsgMediaResolver::CreateMediaInfoL( RFile& aFile, TDataType& aMimeType ) |
|
260 |
{ |
|
261 |
return DoCreateMediaInfoL( aFile, aMimeType ); |
|
262 |
} |
|
263 |
||
264 |
// ----------------------------------------------------------------------------- |
|
265 |
// CMsgMediaResolver::ParseInfoDetailsL |
|
266 |
// ----------------------------------------------------------------------------- |
|
267 |
// |
|
268 |
EXPORT_C void CMsgMediaResolver::ParseInfoDetailsL( CMsgMediaInfo* aInfo, RFile& aFile ) |
|
269 |
{ |
|
270 |
aInfo->ParseInfoDetailsL( aFile, *iDRMHelper, *this ); |
|
271 |
if ( iWait.IsStarted() ) |
|
272 |
{ |
|
273 |
// Stop active wait. |
|
274 |
iWait.AsyncStop(); |
|
275 |
} |
|
276 |
// Start active wait |
|
277 |
iWait.Start(); |
|
278 |
} |
|
279 |
||
280 |
// ----------------------------------------------------------------------------- |
|
281 |
// CMsgMediaResolver::DoCreateMediaInfoL |
|
282 |
// ----------------------------------------------------------------------------- |
|
283 |
// |
|
284 |
CMsgMediaInfo* CMsgMediaResolver::DoCreateMediaInfoL( RFile& aFile, |
|
285 |
TDataType& aMimeType ) |
|
286 |
{ |
|
287 |
CMsgMediaInfo* mediaInfo = NULL; |
|
288 |
TMsgMediaType mediaType = MediaType( aMimeType.Des8() ); |
|
289 |
switch ( mediaType ) |
|
290 |
{ |
|
291 |
case EMsgMediaText: |
|
292 |
{ |
|
293 |
mediaInfo = CMsgTextInfo::NewL( aFile, aMimeType, iFs ); |
|
294 |
if ( !iRecognizeCharSet ) |
|
295 |
{ |
|
296 |
// Suppress charset recognition. |
|
297 |
static_cast< CMsgTextInfo* >( mediaInfo )->SetCharacterSet( 0 ); |
|
298 |
} |
|
299 |
break; |
|
300 |
} |
|
301 |
case EMsgMediaImage: |
|
302 |
{ |
|
303 |
mediaInfo = CMsgImageInfo::NewL( aFile, aMimeType ); |
|
304 |
break; |
|
305 |
} |
|
306 |
case EMsgMediaVideo: |
|
307 |
{ |
|
308 |
mediaInfo = CMsgVideoInfo::NewL( aFile, aMimeType ); |
|
309 |
break; |
|
310 |
} |
|
311 |
case EMsgMediaAudio: |
|
312 |
{ |
|
313 |
mediaInfo = CMsgAudioInfo::NewL( aFile, aMimeType ); |
|
314 |
break; |
|
315 |
} |
|
316 |
case EMsgMediaUnknown: |
|
317 |
default: |
|
318 |
{ |
|
319 |
mediaInfo = CMsgMediaInfo::NewL( aFile, aMimeType, mediaType ); |
|
320 |
break; |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
CleanupStack::PushL( mediaInfo ); |
|
325 |
||
326 |
TUid appUid( KNullUid ); |
|
327 |
// Ignore possible error. |
|
328 |
TInt err = iApaLsSession.AppForDataType( aMimeType, appUid ); |
|
329 |
mediaInfo->SetHandlerApplicationUid( appUid ); |
|
330 |
||
331 |
HBufC8* drmUri = NULL; |
|
332 |
TInt protection = iFileProt->ProtectionStatusL( aFile, aMimeType, drmUri ); |
|
333 |
mediaInfo->SetProtection( protection ); |
|
334 |
mediaInfo->SetDRMContentURI( drmUri ); // ownership transferred |
|
335 |
||
336 |
CleanupStack::Pop( mediaInfo ); |
|
337 |
||
338 |
return mediaInfo; |
|
339 |
} |
|
340 |
||
341 |
// ----------------------------------------------------------------------------- |
|
342 |
// CMsgMediaResolver::MediaInfoParsed |
|
343 |
// ----------------------------------------------------------------------------- |
|
344 |
// |
|
345 |
void CMsgMediaResolver::MediaInfoParsed() |
|
346 |
{ |
|
347 |
if ( iWait.IsStarted() ) |
|
348 |
{ |
|
349 |
// Stop active wait. |
|
350 |
iWait.AsyncStop(); |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
// End of File |